1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
def model(x):
with tf.name_scope('model'):
w = tf.Variable(tf.random_normal((5, 5), 0.0, 1.0), name='w')
b = tf.Variable(tf.random_normal((1, 5), 0.0, 1.0), name='b')
return x @ w + b, w, b
tf.reset_default_graph()
x = tf.placeholder(tf.float32, (1, 5,))
h, w, b = model(x)
saver = tf.train.Saver()
dirname = 'mysave'
import os
if not os.path.exists(dirname):
os.mkdir(dirname)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
path = os.path.join(dirname, 'save')
saver.save(sess, path)
saver.save(sess, path, global_step=10)
w_val, b_val = sess.run((w, b,))
print(w_val)
print(b_val)
|