MCPcopy Index your code
hub / github.com/MorvanZhou/Tensorflow-Tutorial / reload

Function reload

tutorial-contents/303_save_reload.py:52–72  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

50
51
52def reload():
53 print('This is reload')
54 # build entire net again and restore
55 tf_x = tf.placeholder(tf.float32, x.shape) # input x
56 tf_y = tf.placeholder(tf.float32, y.shape) # input y
57 l_ = tf.layers.dense(tf_x, 10, tf.nn.relu) # hidden layer
58 o_ = tf.layers.dense(l_, 1) # output layer
59 loss_ = tf.losses.mean_squared_error(tf_y, o_) # compute cost
60
61 sess = tf.Session()
62 # don't need to initialize variables, just restoring trained variables
63 saver = tf.train.Saver() # define a saver for saving and restoring
64 saver.restore(sess, './params')
65
66 # plotting
67 pred, l = sess.run([o_, loss_], {tf_x: x, tf_y: y})
68 plt.subplot(122)
69 plt.scatter(x, y)
70 plt.plot(x, pred, 'r-', lw=5)
71 plt.text(-1, 1.2, 'Reload Loss=%.4f' % l, fontdict={'size': 15, 'color': 'red'})
72 plt.show()
73
74
75save()

Callers 1

303_save_reload.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected