November 2017
Intermediate to advanced
274 pages
6h 16m
English
When training a model, we use variables to hold and update the parameters. Variables are like in-memory buffers containing tensors. All tensors we used previously were constant tensors, not variables.
Variables are managed or maintained by the session object. Variables persist between sessions, which is useful because tensor and operation objects are immutable:
# tensor variables W1 = tf.ones((3,3))W2 = tf.Variable(tf.zeros((3,3)), name="weights") with tf.Session() as sess: print(sess.run(W1)) sess.run(tf.global_variables_initializer()) print(sess.run(W2))
The preceding code gives the following output:
[[ 1. 1. 1.] [ 1. 1. 1.] [ 1. 1. 1.]][[ 0. 0. 0.] [ 0. 0. 0.] [ 0. 0. 0.]]
TensorFlow variables must be initialized before they ...
Read now
Unlock full access