A TensorFlow program is generally divided into three phases:
- Construction of the computational graph
- Running a session, which is performed for the operations defined in the graph
- Resulting data collection and analysis
These main steps define the programming model in TensorFlow.
Consider the following example, in which we want to multiply two numbers.
import tensorflow as tf
with tf.Session() as session:
x = tf.placeholder(tf.float32,[1],name="x")
y = tf.placeholder(tf.float32,[1],name="y")
z = tf.constant(2.0)
y = x * z
x_in = [100]
y_output = session.run(y,{x:x_in})
print(y_output)
Surely TensorFlow is not necessary to multiply two numbers; also the number of lines of the code for this simple operation is so many. However, the example wants to clarify how to structure any code, from the simplest as in this instance, to the most complex.
Furthermore, the...