import tensorflow as tf
W = tf.Variable(initial_value = tf.random_normal(shape = (1 , 4) ,mean = 100 , stddev = 0.35 ), name = "W")
b = tf.Variable(tf.zeros([4]) , name="b")
[W , b]
[<tf.Variable 'W:0' shape=(1, 4) dtype=float32_ref>,
<tf.Variable 'b:0' shape=(4,) dtype=float32_ref>]
sess = tf.Session()
sess.run(tf.global_variables_initializer())
sess.run( [W , b])
[array([[100.40549 , 99.182625, 100.23513 , 99.42683 ]], dtype=float32),
array([0., 0., 0., 0.], dtype=float32)]
sess.run(tf.assign_add(b , [1,1,1,1] ))
sess.run(tf.assign_add(b , [1,1,1,1] ))
array([1., 1., 1., 1.], dtype=float32)
sess.run(b)
array([1., 1., 1., 1.], dtype=float32)
saver = tf.train.Saver({'W' : W , 'b' : b})
saver.save(sess , './summary/data.ckpt' , global_step = 0)
WARNING:tensorflow:Issue encountered when serializing trainable_variables.
Type is unsupported, or the types of the items don't match field type in CollectionDef. Note this is a warning and probably safe to ignore.
'test' has type str, but expected one of: int, long, bool
WARNING:tensorflow:Issue encountered when serializing variables.
Type is unsupported, or the types of the items don't match field type in CollectionDef. Note this is a warning and probably safe to ignore.
'test' has type str, but expected one of: int, long, bool
'./summary/data.ckpt-0'
sess.run(tf.assign_add(b , [1,1,1,1] ))
sess.run(b)
array([2., 2., 2., 2.], dtype=float32)
saver.restore(sess , './summary/data.ckpt-0')
saver.restore(sess , './summary/data.ckpt-0')
sess.run(b)
INFO:tensorflow:Restoring parameters from ./summary/data.ckpt-0
array([1., 1., 1., 1.], dtype=float32)
展开