W3cubDocs

/TensorFlow 2.3

tf.keras.backend.variable

View source on GitHub

Instantiates a variable and returns it.

Arguments
value Numpy array, initial value of the tensor.
dtype Tensor type.
name Optional name string for the tensor.
constraint Optional projection function to be applied to the variable after an optimizer update.
Returns
A variable instance (with Keras metadata included).

Examples:

val = np.array([[1, 2], [3, 4]])
kvar = tf.keras.backend.variable(value=val, dtype='float64',
                                 name='example_var')
tf.keras.backend.dtype(kvar)
'float64'
print(kvar)
<tf.Variable 'example_var:...' shape=(2, 2) dtype=float64, numpy=
  array([[1., 2.],
         [3., 4.]])>

© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r2.3/api_docs/python/tf/keras/backend/variable