-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathch9_simple_graph.py
52 lines (37 loc) · 1.03 KB
/
ch9_simple_graph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import tensorflow as tf
def main():
x = tf.Variable(3, name="x")
y = tf.Variable(4, name="y")
f = x*x*y + y + 2
init = tf.global_variables_initializer()
with tf.Session() as sess:
init.run()
#x.initializer.run()
#y.initializer.run()
results = sess.run(f)
print(results)
graph = tf.Graph()
with graph.as_default():
x2 = tf.Variable(3)
print(graph)
if x2.graph is tf.get_default_graph():
print("True")
if x.graph is tf.get_default_graph():
print("True")
w = tf.constant(3)
x = w + 2
y = x + 5
z = x * 3
# the evaluations are performed twice, once for y and z
with tf.Session() as sess:
print(y.eval())
print(z.eval())
# evaluations are run at the same time
with tf.Session() as sess:
yval, zval = sess.run([y,z])
print(yval)
print(zval)
if __name__ == "__main__":
main()