當前位置: 首頁>>代碼示例>>Python>>正文


Python slot_creator.create_slot方法代碼示例

本文整理匯總了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)] 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:19,代碼來源:optimizer.py

示例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] 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:19,代碼來源:optimizer.py

示例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] 
開發者ID:yushu-liu,項目名稱:icra2017-visual-navigation,代碼行數:7,代碼來源:rmsprop_applier.py

示例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]) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:13,代碼來源:slot_creator_test.py

示例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]) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:13,代碼來源:slot_creator_test.py

示例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") 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:9,代碼來源:slot_creator_test.py

示例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] 
開發者ID:SuReLI,項目名稱:Deep-RL-agents,代碼行數:7,代碼來源:rmsprop_applier.py

示例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 
開發者ID:JGuillaumin,項目名稱:swa-tf,代碼行數:49,代碼來源:stochastic_weight_averaging.py


注:本文中的tensorflow.python.training.slot_creator.create_slot方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。