-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
79 lines (55 loc) · 1.63 KB
/
example.py
File metadata and controls
79 lines (55 loc) · 1.63 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import os
import mini_tf as tf
# import tensorflow as tf
# Makes comparing with tensorflow easier
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
with tf.Session() as sess:
vec = tf.random_uniform(shape=(3, ))
one = tf.constant(1, dtype=tf.float32)
out1 = vec + one
out2 = vec + 2
print(sess.run(vec))
print(sess.run(vec))
print(sess.run((out1, out2)))
print()
with tf.Session() as sess:
x = tf.placeholder(tf.float32)
y = tf.placeholder(tf.float32)
z = x + y
print(sess.run(z, feed_dict={x: 3, y: 4.5}))
print(sess.run(z, feed_dict={x: [1, 3], y: [2, 4]}))
print()
with tf.Session() as sess:
my_variable = tf.get_variable(
"my_variable", [1, 2, 3],
initializer=tf.random_uniform_initializer)
sess.run(tf.global_variables_initializer())
# sess.run(my_variable.initializer)
print(sess.run(my_variable))
print()
def sequential(*layers):
def run(x):
for layer in layers:
x = layer(x)
return x
return run
with tf.Session() as sess:
x = tf.placeholder(tf.float32, shape=[None, 3])
model = sequential(
tf.layers.Dense(units=10),
tf.layers.Dense(units=1),
)
y = model(x)
sess.run(tf.global_variables_initializer())
print(sess.run((x, y), {x: [[1, 2, 3], [4, 5, 6]]}))
print()
g_1 = tf.Graph()
with g_1.as_default():
with tf.Session() as sess_1:
assert sess_1.graph is g_1
assert tf.get_default_graph() is g_1
g_2 = tf.Graph()
with g_2.as_default():
with tf.Session() as sess_2:
assert sess_2.graph is g_2
assert tf.get_default_graph() is g_2