I am new to tensorflow, I can’t understand the difference in variable and constant, I understand that we use variables for equations and constants for direct values, but why is code # 1 only working and why not code # 2 and # 3, and please , explain in which cases we must first run our graph (a), and then our variable (b), i.e.
(a) session.run(model)
(b) print(session.run(y))
and in this case, I can directly execute this iee command
print(session.run(y))
Code No. 1:
x = tf.constant(35, name='x')
y = tf.Variable(x + 5, name='y')
model = tf.global_variables_initializer()
with tf.Session() as session:
session.run(model)
print(session.run(y))
Code No. 2:
x = tf.Variable(35, name='x')
y = tf.Variable(x + 5, name='y')
model = tf.global_variables_initializer()
with tf.Session() as session:
session.run(model)
print(session.run(y))
Code No. 3:
x = tf.constant(35, name='x')
y = tf.constant(x + 5, name='y')
model = tf.global_variables_initializer()
with tf.Session() as session:
session.run(model)
print(session.run(y))
source
share