TensorFlow: Constants, Variables and Placeholders
TensorFlow is a framework developed by Google on 9th November 2015. It is written in Python, C++ and Cuda. It supports platforms like Linux, Microsoft Windows, macOS, and Android. TensorFlow provides multiple API's in Python, C++, Java etc. The most widely used API is Python.
The name TensorFlow is derived from the operations, such as adding or multiplying, that artificial neural networks perform on multidimensional data arrays. These arrays are called tensors in this framework.
So why is there a mention of a flow when you're talking about operations? Let's consider a simple equation and its diagram, represented as a computational graph.
prediction = tf.nn.softmax(tf.matmul(W,x) + b)
In TensorFlow, every line of code that you write has to go through a computational graph. As in the above figure, you can see that first
W
and x
get multiplied and then comes b
which is added to the output of W
and x
. After adding the output of W
and x
withb
, a softmax function is applied and a final output is generated.
You'll find that, when you're working with TensorFlow, constants, variables and placeholders come handy to define the input data, class labels, weights and biases.
Constants take no input, they are used to store constant values. They produce a constant output that it stores.
import tensorflow as tf
a = tf.constant(2.0)
b = tf.constant(3.0)
c = a * b