Try this:
import tensorflow as tf
#%%
graph = tf.Graph()
with graph.as_default():
a=tf.Variable(1, name="a")
b=tf.Variable(2, name="b")
init=tf.compat.v1.global_variables_initializer()
f=a+b
with tf.compat.v1.Session(graph = graph) as s:
s.run(init)
print(f.eval())
If you want to use TensorFlow V1.X, you need to construct a graph that basically lines up all the operations and the flow of your data. Then you pass that graph to a session and you will run the session.
Here is a good intro I found: https://www.easy-tensorflow.com/tf-tutorials/basics/graph-and-session
Another thing I noticed about your code is that you initialized your variables after you used them to calculate f
. This should come before.
So I changed that as well.
Lastly, you wrote s.run(**int**)
while I think you meant s.run(**init**)
. So I changed that as well.