-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm3_graphs.py
41 lines (28 loc) · 950 Bytes
/
m3_graphs.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
import tensorflow as tf
g1 = tf.Graph()
with g1.as_default():
with tf.Session() as sess:
# y = Ax + b
A = tf.constant([5, 7], tf.int32, name='A')
x = tf.placeholder(tf.int32, name='x')
b = tf.constant([3, 4], tf.int32, name='b')
y = A * x + b
print(sess.run(y, feed_dict={x: [10, 100]}))
assert y.graph is g1
g2 = tf.Graph()
with g2.as_default():
with tf.Session() as sess:
# y = A^x
A = tf.constant([5, 7], tf.int32, name='A')
x = tf.placeholder(tf.int32, name='x')
y = tf.pow(A, x, name='y')
print(sess.run(y, feed_dict={x: [3, 5]}))
assert y.graph is g2
default_graph = tf.get_default_graph()
with tf.Session() as sess:
# y = A + x
A = tf.constant([5, 7], tf.int32, name='A')
x = tf.placeholder(tf.int32, name='x')
y = A + x
print(sess.run(y, feed_dict={x: [3, 5]}))
assert y.graph is default_graph