TensorFlow is a deep learning module. It’s created by Google and open-source. It has a Python API and can be used with one or more CPUs or GPUs.
TensorFlow is the deep learning library Google made and released as open source. It runs on CPUs and GPUs, it has a Python API, and most of the deep learning tutorials you find online use it.
It is a big library, so you only need a part of it to start.
It runs on Windows, iOS, Linux, Raspberry Pi, Android and server farms.
There are many other deep learning libraries (Torch, Theano, Cafe, CNTK), but TensorFlow is the most popular.
install tensorflow
The TensorFlow module is available in the PyPi repository and can be installed with pip.
To start, write this line of code:import tensorflow as tf
That’s all to load the module.
Whats a tensor
Tensors are data.
A tensor is an n-dimensional array
0-d tensor: scalar (number)
1-d tensor: vector
2-d tensor: matrix
tensorflow session
Lets start with a simple program and introducing the concept of sessions. Create a program that adds two numbers (2,6).
Tensorflow has a method tf.add(x,y). The parameters x and y are tensors. The method returns a tensor.
We can visualize our advanced mathematics (2+6) in a data flow graph:

Tensorflow (TF) automatically gives names to nodes, in this case x=2 and y=6.
Code shown below:import tensorflow as tf
x = tf.add(2, 6)
print(x)
If you run it you’ll see:
Tensor("Add:0", shape=(), dtype=int32) |
That’s not the value of x, so how do you get it?
Create a session. Within the session, you can get the variable x.
import tensorflow as tf |
This will then give you>> 8
You can also write this as:import tensorflow as tf
a = tf.add(2, 6)
with tf.Session() as ses:
print(ses.run(a))
So what does ts.Session() do?
A session object evaluates Tensor objects and Operation objects are executed.
The idea in short
- You build a graph: a list of operations and the order they run in.
- You open a session and run the graph with data.
- Data goes in through
feed_dictor straight as a function argument in TensorFlow 2. tf.nnholds the neural network parts:relu,softmax,sigmoid.tf.train.GradientDescentOptimizerdoes the learning.tf.summarywrites files that TensorBoard reads.
It runs on Windows, Linux, macOS, Raspberry Pi and Android, so the code you write moves between them.
TensorFlow 2 hides the graph and the session, so most new code just builds the
layers and calls model.fit(). If you follow an older tutorial with
tf.compat.v1 in it, that is why.
Reading helps, writing fixes it. PyChallenge has exercises on this and you can try them right now.
