本文整理匯總了Python中tensorflow.python.eager.context.in_graph_mode方法的典型用法代碼示例。如果您正苦於以下問題:Python context.in_graph_mode方法的具體用法?Python context.in_graph_mode怎麽用?Python context.in_graph_mode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tensorflow.python.eager.context
的用法示例。
在下文中一共展示了context.in_graph_mode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _create_slots
# 需要導入模塊: from tensorflow.python.eager import context [as 別名]
# 或者: from tensorflow.python.eager.context import in_graph_mode [as 別名]
def _create_slots(self, var_list):
first_var = min(var_list, key=lambda x: x.name)
create_new = self._beta1_power is None
if not create_new and context.in_graph_mode():
create_new = (self._beta1_power.graph is not first_var.graph)
if create_new:
with ops.colocate_with(first_var):
self._beta1_power = variable_scope.variable(
self._beta1, name="beta1_power", trainable=False)
self._beta2_power = variable_scope.variable(
self._beta2, name="beta2_power", trainable=False)
# Create slots for the first and second moments.
for v in var_list:
self._zeros_slot(v, "m", self._name)
self._zeros_slot(v, "v", self._name)
self._zeros_slot(v, "vhat", self._name)
示例2: _create_slots
# 需要導入模塊: from tensorflow.python.eager import context [as 別名]
# 或者: from tensorflow.python.eager.context import in_graph_mode [as 別名]
def _create_slots(self, var_list):
first_var = min(var_list, key=lambda x: x.name)
create_new = self._beta1_power is None
if not create_new and context.in_graph_mode():
create_new = (self._beta1_power.graph is not first_var.graph)
if create_new:
with ops.colocate_with(first_var):
self._beta1_power = variable_scope.variable(self._beta1, name="beta1_power", trainable=False)
self._beta2_power = variable_scope.variable(self._beta2, name="beta2_power", trainable=False)
# Create slots for the first and second moments.
for v in var_list :
self._zeros_slot(v, "m", self._name)
self._zeros_slot(v, "v", self._name)
self._zeros_slot(v, "vhat", self._name)
示例3: _create_slots
# 需要導入模塊: from tensorflow.python.eager import context [as 別名]
# 或者: from tensorflow.python.eager.context import in_graph_mode [as 別名]
def _create_slots(self, var_list):
first_var = min(var_list, key=lambda x: x.name)
if StrictVersion(tf.__version__) >= StrictVersion('1.10.0'):
graph = None if context.executing_eagerly() else ops.get_default_graph()
else:
graph = ops.get_default_graph()
create_new = self._get_non_slot_variable("beta1_power", graph) is None
if not create_new and context.in_graph_mode():
create_new = (self._get_non_slot_variable("beta1_power", graph).graph is not first_var.graph)
if create_new:
self._create_non_slot_variable(initial_value=self._beta1,
name="beta1_power",
colocate_with=first_var)
self._create_non_slot_variable(initial_value=self._beta2,
name="beta2_power",
colocate_with=first_var)
self._create_non_slot_variable(initial_value=self._gamma,
name="gamma_multi",
colocate_with=first_var)
# Create slots for the first and second moments.
for v in var_list :
self._zeros_slot(v, "m", self._name)
self._zeros_slot(v, "v", self._name)
self._zeros_slot(v, "vhat", self._name)
示例4: _create_slots
# 需要導入模塊: from tensorflow.python.eager import context [as 別名]
# 或者: from tensorflow.python.eager.context import in_graph_mode [as 別名]
def _create_slots(self, var_list):
first_var = min(var_list, key=lambda x: x.name)
create_new = self._beta1_power is None
if not create_new and context.in_graph_mode():
create_new = (self._beta1_power.graph is not first_var.graph)
if create_new:
with ops.colocate_with(first_var):
self._beta1_power = variable_scope.variable(self._beta1, name="beta1_power", trainable=False)
self._beta2_power = variable_scope.variable(self._beta2, name="beta2_power", trainable=False)
# Create slots for the first and second moments.
for v in var_list:
self._zeros_slot(v, "m", self._name)
self._zeros_slot(v, "v", self._name)
self._zeros_slot(v, "vhat", self._name)
示例5: _create_slots
# 需要導入模塊: from tensorflow.python.eager import context [as 別名]
# 或者: from tensorflow.python.eager.context import in_graph_mode [as 別名]
def _create_slots(self, var_list):
first_var = min(var_list, key=lambda x: x.name)
graph = None if context.executing_eagerly() else ops.get_default_graph()
create_new = self._get_non_slot_variable("beta1_power", graph) is None
if not create_new and context.in_graph_mode():
create_new = (self._get_non_slot_variable("beta1_power", graph).graph is not first_var.graph)
if create_new:
self._create_non_slot_variable(initial_value=self._beta1,
name="beta1_power",
colocate_with=first_var)
self._create_non_slot_variable(initial_value=self._beta2,
name="beta2_power",
colocate_with=first_var)
self._create_non_slot_variable(initial_value=self._gamma,
name="gamma_multi",
colocate_with=first_var)
# Create slots for the first and second moments.
for v in var_list :
self._zeros_slot(v, "m", self._name)
self._zeros_slot(v, "v", self._name)
self._zeros_slot(v, "vhat", self._name)
示例6: __init__
# 需要導入模塊: from tensorflow.python.eager import context [as 別名]
# 或者: from tensorflow.python.eager.context import in_graph_mode [as 別名]
def __init__(self, dtype, shape, accumulator_ref):
"""Creates a new ConditionalAccumulator.
Args:
dtype: Datatype of the accumulated gradients.
shape: Shape of the accumulated gradients.
accumulator_ref: A handle to the conditional accumulator, created by sub-
classes
"""
self._dtype = dtype
if shape is not None:
self._shape = tensor_shape.TensorShape(shape)
else:
self._shape = tensor_shape.unknown_shape()
self._accumulator_ref = accumulator_ref
if context.in_graph_mode():
self._name = self._accumulator_ref.op.name.split("/")[-1]
else:
self._name = context.context().scope_name
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:21,代碼來源:data_flow_ops.py
示例7: identity
# 需要導入模塊: from tensorflow.python.eager import context [as 別名]
# 或者: from tensorflow.python.eager.context import in_graph_mode [as 別名]
def identity(input, name=None): # pylint: disable=redefined-builtin
r"""Return a tensor with the same shape and contents as input.
Args:
input: A `Tensor`.
name: A name for the operation (optional).
Returns:
A `Tensor`. Has the same type as `input`.
"""
if context.in_graph_mode():
return gen_array_ops.identity(input, name=name)
else:
if context.context().device_name != input.device:
return input._copy() # pylint: disable=protected-access
return input
# pylint: disable=redefined-builtin,protected-access
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:21,代碼來源:array_ops.py
示例8: _flatten_outer_dims
# 需要導入模塊: from tensorflow.python.eager import context [as 別名]
# 或者: from tensorflow.python.eager.context import in_graph_mode [as 別名]
def _flatten_outer_dims(logits):
"""Flattens logits' outer dimensions and keep its last dimension."""
rank = array_ops.rank(logits)
last_dim_size = array_ops.slice(
array_ops.shape(logits), [math_ops.subtract(rank, 1)], [1])
output = array_ops.reshape(logits, array_ops.concat([[-1], last_dim_size], 0))
# Set output shape if known.
if context.in_graph_mode():
shape = logits.get_shape()
if shape is not None and shape.dims is not None:
shape = shape.as_list()
product = 1
product_valid = True
for d in shape[:-1]:
if d is None:
product_valid = False
break
else:
product *= d
if product_valid:
output_shape = [product, shape[-1]]
output.set_shape(output_shape)
return output
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:27,代碼來源:nn_ops.py
示例9: _TileGrad
# 需要導入模塊: from tensorflow.python.eager import context [as 別名]
# 或者: from tensorflow.python.eager.context import in_graph_mode [as 別名]
def _TileGrad(op, grad):
"""Sum reduces grad along the tiled dimensions."""
assert isinstance(grad, ops.Tensor)
input_shape = array_ops.shape(op.inputs[0])
# We interleave multiples and input_shape to get split_shape,
# reshape grad to split_shape, and reduce along all even
# dimensions (the tiled dimensions) to get the result
# with shape input_shape. For example
# input_shape = [20, 30, 40]
# multiples = [2, 3, 4]
# split_shape = [2, 20, 3, 30, 4, 40]
# axes = [0, 2, 4]
split_shape = array_ops.reshape(
array_ops.transpose(array_ops.stack([op.inputs[1], input_shape])), [-1])
axes = math_ops.range(0, array_ops.size(split_shape), 2)
input_grad = math_ops.reduce_sum(array_ops.reshape(grad, split_shape), axes)
# Fix shape inference
if context.in_graph_mode():
input_grad.set_shape(op.inputs[0].get_shape())
return [input_grad, None]
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:22,代碼來源:array_grad.py
示例10: __init__
# 需要導入模塊: from tensorflow.python.eager import context [as 別名]
# 或者: from tensorflow.python.eager.context import in_graph_mode [as 別名]
def __init__(self, table_ref, default_value, initializer):
"""Construct a table object from a table reference.
If requires a table initializer object (subclass of `TableInitializerBase`).
It provides the table key and value types, as well as the op to initialize
the table. The caller is responsible to execute the initialization op.
Args:
table_ref: The table reference, i.e. the output of the lookup table ops.
default_value: The value to use if a key is missing in the table.
initializer: The table initializer to use.
"""
if context.in_graph_mode():
name = table_ref.op.name.split("/")[-1]
else:
name = context.context().scope_name
super(InitializableLookupTableBase,
self).__init__(initializer.key_dtype, initializer.value_dtype,
name)
self._table_ref = table_ref
self._default_value = ops.convert_to_tensor(
default_value, dtype=self._value_dtype)
self._default_value.get_shape().merge_with(tensor_shape.scalar())
self._init = initializer.initialize(self)
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:26,代碼來源:lookup_ops.py
示例11: _create_slots
# 需要導入模塊: from tensorflow.python.eager import context [as 別名]
# 或者: from tensorflow.python.eager.context import in_graph_mode [as 別名]
def _create_slots(self, var_list):
# Create the beta1 and beta2 accumulators on the same device as the first
# variable. Sort the var_list to make sure this device is consistent across
# workers (these need to go on the same PS, otherwise some updates are
# silently ignored).
first_var = min(var_list, key=lambda x: x.name)
create_new = self._beta1_power is None
if not create_new and context.in_graph_mode():
create_new = (self._beta1_power.graph is not first_var.graph)
if create_new:
with ops.colocate_with(first_var):
self._beta1_power = variable_scope.variable(self._beta1,
name="beta1_power",
trainable=False)
self._beta2_power = variable_scope.variable(self._beta2,
name="beta2_power",
trainable=False)
# Create slots for the first and second moments.
for v in var_list:
self._zeros_slot(v, "m", self._name)
self._zeros_slot(v, "v", self._name)
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:25,代碼來源:adam.py
示例12: control_dependencies
# 需要導入模塊: from tensorflow.python.eager import context [as 別名]
# 或者: from tensorflow.python.eager.context import in_graph_mode [as 別名]
def control_dependencies(control_inputs):
"""Wrapper for `Graph.control_dependencies()` using the default graph.
See @{tf.Graph.control_dependencies}
for more details.
Args:
control_inputs: A list of `Operation` or `Tensor` objects which
must be executed or computed before running the operations
defined in the context. Can also be `None` to clear the control
dependencies.
Returns:
A context manager that specifies control dependencies for all
operations constructed within the context.
"""
if context.in_graph_mode():
return get_default_graph().control_dependencies(control_inputs)
else:
return _NullContextmanager()
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:22,代碼來源:ops.py
示例13: add_to_graph
# 需要導入模塊: from tensorflow.python.eager import context [as 別名]
# 或者: from tensorflow.python.eager.context import in_graph_mode [as 別名]
def add_to_graph(self, g):
"""Adds this function into the graph g."""
self._create_definition_if_needed()
# Adds this function into 'g'.
# pylint: disable=protected-access
if context.in_graph_mode():
g._add_function(self)
else:
context.context().add_function_def(self.definition)
# pylint: enable=protected-access
# Ensures related sub-routines are defined in 'g', too.
for f in self._sub_functions.values():
f.add_to_graph(g)
# Adds its gradient function, too.
if self._grad_func:
self._grad_func.add_to_graph(g)
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:21,代碼來源:function.py
示例14: _create_slots
# 需要導入模塊: from tensorflow.python.eager import context [as 別名]
# 或者: from tensorflow.python.eager.context import in_graph_mode [as 別名]
def _create_slots(self, var_list):
# Create the beta1 and beta2 accumulators on the same device as the first
# variable. Sort the var_list to make sure this device is consistent across
# workers (these need to go on the same PS, otherwise some updates are
# silently ignored).
first_var = min(var_list, key=lambda x: x.name)
create_new = self._iterations is None
if not create_new and context.in_graph_mode():
create_new = (self._iterations.graph is not first_var.graph)
if create_new:
with ops.colocate_with(first_var):
self._beta1_power = variable_scope.variable(self._beta1,
name="beta1_power",
trainable=False)
self._beta2_power = variable_scope.variable(self._beta2,
name="beta2_power",
trainable=False)
self._iterations = variable_scope.variable(0.,
name="iterations",
trainable=False)
self._m_schedule = variable_scope.variable(1.,
name="m_schedule",
trainable=False)
# Create slots for the first and second moments.
for v in var_list:
self._zeros_slot(v, "m", self._name)
self._zeros_slot(v, "v", self._name)
示例15: __op
# 需要導入模塊: from tensorflow.python.eager import context [as 別名]
# 或者: from tensorflow.python.eager.context import in_graph_mode [as 別名]
def __op(self, kernel, inputs, shape):
if len(shape) > 2:
# Broadcasting is required for the inputs.
outputs = tf.tensordot(inputs, kernel, [[len(shape) - 1],[0]])
# Reshape the output back to the original ndim of the input.
# if context.in_graph_mode():
# for tf > 1.5.0
if not context.executing_eagerly():
output_shape = shape[:-1] + [self.units]
outputs.set_shape(output_shape)
else:
outputs = tf.matmul(inputs, kernel)
return outputs