tf.keras.backend.get_value
Stay organized with collections
Save and categorize content based on your preferences.
Returns the value of a variable.
tf.keras.backend.get_value(
x
)
backend.get_value
is the compliment of backend.set_value
, and provides
a generic interface for reading from variables while abstracting away the
differences between TensorFlow 1.x and 2.x semantics.
K = tf.keras.backend # Common keras convention
v = K.variable(1.)
# reassign
K.set_value(v, 2.)
print(K.get_value(v))
2.0
# increment
K.set_value(v, K.get_value(v) + 1)
print(K.get_value(v))
3.0
Variable semantics in TensorFlow 2 are eager execution friendly. The above
code is roughly equivalent to:
v = tf.Variable(1.)
_ = v.assign(2.)
print(v.numpy())
2.0
_ = v.assign_add(1.)
print(v.numpy())
3.0
Arguments |
x
|
input variable.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.keras.backend.get_value\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/keras/backend/get_value) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.2.0/tensorflow/python/keras/backend.py#L3279-L3310) |\n\nReturns the value of a variable.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.keras.backend.get_value`](/api_docs/python/tf/keras/backend/get_value)\n\n\u003cbr /\u003e\n\n tf.keras.backend.get_value(\n x\n )\n\n[`backend.get_value`](../../../tf/keras/backend/get_value) is the compliment of [`backend.set_value`](../../../tf/keras/backend/set_value), and provides\na generic interface for reading from variables while abstracting away the\ndifferences between TensorFlow 1.x and 2.x semantics. \n\n K = tf.keras.backend # Common keras convention\n v = K.variable(1.)\n\n # reassign\n K.set_value(v, 2.)\n print(K.get_value(v))\n 2.0\n\n # increment\n K.set_value(v, K.get_value(v) + 1)\n print(K.get_value(v))\n 3.0\n\nVariable semantics in TensorFlow 2 are eager execution friendly. The above\ncode is roughly equivalent to: \n\n v = tf.Variable(1.)\n\n _ = v.assign(2.)\n print(v.numpy())\n 2.0\n\n _ = v.assign_add(1.)\n print(v.numpy())\n 3.0\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Arguments --------- ||\n|-----|-----------------|\n| `x` | input variable. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A Numpy array. ||\n\n\u003cbr /\u003e"]]