TensorFlow Variable objects for storing and updating model parameters
We covered Tensor
objects in Chapter 13, Parallelizing Neural Network Training with TensorFlow. In the context of TensorFlow, a Variable
is a special Tensor
object that allows us to store and update the parameters of our models during training. A Variable
can be created by just calling the tf.Variable
class on user-specified initial values. In the following code, we will generate Variable
objects of type float32
, int32
, bool
, and string
:
>>> a = tf.Variable(initial_value=3.14, name='var_a')
>>> print(a)
<tf.Variable 'var_a:0' shape=() dtype=float32, numpy=3.14>
>>> b = tf.Variable(initial_value=[1, 2, 3], name='var_b')
>>> print(b)
<tf.Variable 'var_b:0' shape=(3,) dtype=int32, numpy=array([1, 2, 3], dtype=int32)>
>>> c = tf.Variable(initial_value=[True, False], dtype=tf.bool)
>>> print(c)
<tf.Variable...