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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2020-10-01 UTC."],[],[]]