本文整理汇总了Python中tensorflow.python.training.slot_creator.create_slot方法的典型用法代码示例。如果您正苦于以下问题:Python slot_creator.create_slot方法的具体用法?Python slot_creator.create_slot怎么用?Python slot_creator.create_slot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.training.slot_creator
的用法示例。
在下文中一共展示了slot_creator.create_slot方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_or_make_slot
# 需要导入模块: from tensorflow.python.training import slot_creator [as 别名]
# 或者: from tensorflow.python.training.slot_creator import create_slot [as 别名]
def _get_or_make_slot(self, var, val, slot_name, op_name):
"""Find or create a slot for a variable.
Args:
var: A `Variable` object.
val: A `Tensor`. The initial value of the slot.
slot_name: Name for the slot.
op_name: Name to use when scoping the Variable that
needs to be created for the slot.
Returns:
A `Variable` object.
"""
named_slots = self._slot_dict(slot_name)
if _var_key(var) not in named_slots:
named_slots[_var_key(var)] = slot_creator.create_slot(var, val, op_name)
return named_slots[_var_key(var)]
示例2: _get_or_make_slot
# 需要导入模块: from tensorflow.python.training import slot_creator [as 别名]
# 或者: from tensorflow.python.training.slot_creator import create_slot [as 别名]
def _get_or_make_slot(self, var, val, slot_name, op_name):
"""Find or create a slot for a variable.
Args:
var: A `Variable` object.
val: A `Tensor`. The initial value of the slot.
slot_name: Name for the slot.
op_name: Name to use when scoping the Variable that
needs to be created for the slot.
Returns:
A `Variable` object.
"""
named_slots = self._slot_dict(slot_name)
if var not in named_slots:
named_slots[var] = slot_creator.create_slot(var, val, op_name)
return named_slots[var]
示例3: _get_or_make_slot
# 需要导入模块: from tensorflow.python.training import slot_creator [as 别名]
# 或者: from tensorflow.python.training.slot_creator import create_slot [as 别名]
def _get_or_make_slot(self, var, val, slot_name, op_name):
"""Find or create a slot for a variable.
Args:
var: A `Variable` object.
val: A `Tensor`. The initial value of the slot.
slot_name: Name for the slot.
op_name: Name to use when scoping the Variable that
needs to be created for the slot.
Returns:
A `Variable` object.
"""
named_slots = self._slot_dict(slot_name)
if _var_key(var) not in named_slots:
named_slots[_var_key(var)] = slot_creator.create_slot(var, val, op_name)
return named_slots[_var_key(var)]
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:19,代码来源:optimizer.py
示例4: _get_or_make_slot
# 需要导入模块: from tensorflow.python.training import slot_creator [as 别名]
# 或者: from tensorflow.python.training.slot_creator import create_slot [as 别名]
def _get_or_make_slot(self, var, val, slot_name, op_name):
named_slots = self._slot_dict(slot_name)
if var not in named_slots:
named_slots[var] = slot_creator.create_slot(var, val, op_name)
return named_slots[var]
示例5: testCreateSlotFromVariable
# 需要导入模块: from tensorflow.python.training import slot_creator [as 别名]
# 或者: from tensorflow.python.training.slot_creator import create_slot [as 别名]
def testCreateSlotFromVariable(self):
with self.test_session():
v = tf.Variable([1.0, 2.5], name="var")
slot = slot_creator.create_slot(v, v.initialized_value(), name="slot")
tf.global_variables_initializer().run()
self.assertEqual(slot.op.name, "var/slot")
self.assertEqual(slot.get_shape().as_list(), [2])
self.assertEqual(slot.dtype.base_dtype, tf.float32)
self.assertAllEqual(slot.eval(), [1.0, 2.5])
示例6: testCreateSlotFromTensor
# 需要导入模块: from tensorflow.python.training import slot_creator [as 别名]
# 或者: from tensorflow.python.training.slot_creator import create_slot [as 别名]
def testCreateSlotFromTensor(self):
with self.test_session():
v = tf.constant([1.0, 2.5], name="const")
slot = slot_creator.create_slot(v, v * 2, name="slot")
tf.global_variables_initializer().run()
self.assertEqual(slot.op.name, "const/slot")
self.assertEqual(slot.get_shape().as_list(), [2])
self.assertEqual(slot.dtype.base_dtype, tf.float32)
self.assertAllEqual(slot.eval(), [2.0, 5.0])
示例7: testCreateSlotFromVariableRespectsScope
# 需要导入模块: from tensorflow.python.training import slot_creator [as 别名]
# 或者: from tensorflow.python.training.slot_creator import create_slot [as 别名]
def testCreateSlotFromVariableRespectsScope(self):
# See discussion on #2740.
with self.test_session():
with tf.variable_scope("scope"):
v = tf.Variable([1.0, 2.5], name="var")
slot = slot_creator.create_slot(v, v.initialized_value(), name="slot")
self.assertEqual(slot.op.name, "scope/scope/var/slot")
示例8: _get_or_make_slot
# 需要导入模块: from tensorflow.python.training import slot_creator [as 别名]
# 或者: from tensorflow.python.training.slot_creator import create_slot [as 别名]
def _get_or_make_slot(self, var, val, slot_name, op_name):
named_slots = self._slot_dict(slot_name)
if var not in named_slots:
named_slots[var] = slot_creator.create_slot(var, val, op_name)
return named_slots[var]
示例9: apply
# 需要导入模块: from tensorflow.python.training import slot_creator [as 别名]
# 或者: from tensorflow.python.training.slot_creator import create_slot [as 别名]
def apply(self, var_list=None):
if var_list is None:
var_list = variables.trainable_variables()
for var in var_list:
if var.dtype.base_dtype not in [dtypes.float16, dtypes.float32,
dtypes.float64]:
raise TypeError("The variables must be half, float, or double: %s" %
var.name)
if var not in self._averages:
# For variables: to lower communication bandwidth across devices we keep
# the moving averages on the same device as the variables. For other
# tensors, we rely on the existing device allocation mechanism.
with ops.init_scope():
if isinstance(var, variables.Variable):
avg = slot_creator.create_slot(var,
var.initialized_value(),
self.name,
colocate_with_primary=True)
# NOTE(mrry): We only add `tf.Variable` objects to the
# `MOVING_AVERAGE_VARIABLES` collection.
ops.add_to_collection(ops.GraphKeys.MOVING_AVERAGE_VARIABLES, var)
else:
avg = slot_creator.create_zeros_slot(
var,
self.name,
colocate_with_primary=(var.op.type in ["Variable",
"VariableV2",
"VarHandleOp"]))
self._averages[var] = avg
with ops.device('/cpu:0'):
self._n_models = variable_scope.get_variable(shape=[],
dtype=dtypes.float32,
name='n_models',
initializer=init_ops.constant_initializer(0.),
trainable=False)
with ops.name_scope(self.name) as scope:
updates = []
for var in var_list:
updates.append(assign_stochastic_average(self._averages[var], var, self._n_models))
with ops.control_dependencies(updates):
update_n_models = state_ops.assign_add(self._n_models, 1., name=scope)
return update_n_models