本文整理匯總了Python中tensorflow.python.ops.state_ops.variable_op_v2方法的典型用法代碼示例。如果您正苦於以下問題:Python state_ops.variable_op_v2方法的具體用法?Python state_ops.variable_op_v2怎麽用?Python state_ops.variable_op_v2使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tensorflow.python.ops.state_ops
的用法示例。
在下文中一共展示了state_ops.variable_op_v2方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: define_local
# 需要導入模塊: from tensorflow.python.ops import state_ops [as 別名]
# 或者: from tensorflow.python.ops.state_ops import variable_op_v2 [as 別名]
def define_local(self, name, value):
if name in self._locals:
raise Exception("Local already defined: %s" % name)
should_wrap_in_var = False
if self._wrap_locals_in_vars:
if isinstance(value, tf.Tensor):
should_wrap_in_var = True
# HACK(adamb) Unwrapping in here really isn't great, since auto-unwrapping can create unexpected behavior.
if isinstance(value, RetvalBag) and value.len() == 1:
if isinstance(value.get(None), tf.Tensor):
should_wrap_in_var = True
value = value.get(None)
if should_wrap_in_var:
variable = state_ops.variable_op_v2(
value.get_shape(),
value.dtype.base_dtype)
with tf.control_dependencies(None):
value = tf.identity(
tf.cond(
tf.is_variable_initialized(variable),
lambda: variable,
lambda: tf.assign(variable, value)
)
)
print("value", value)
self._locals[name] = value
return value