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


Python resource_variable_ops.assign_variable_op方法代碼示例

本文整理匯總了Python中tensorflow.python.ops.resource_variable_ops.assign_variable_op方法的典型用法代碼示例。如果您正苦於以下問題:Python resource_variable_ops.assign_variable_op方法的具體用法?Python resource_variable_ops.assign_variable_op怎麽用?Python resource_variable_ops.assign_variable_op使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.python.ops.resource_variable_ops的用法示例。


在下文中一共展示了resource_variable_ops.assign_variable_op方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testManyAssigns

# 需要導入模塊: from tensorflow.python.ops import resource_variable_ops [as 別名]
# 或者: from tensorflow.python.ops.resource_variable_ops import assign_variable_op [as 別名]
def testManyAssigns(self):
    with self.test_session() as session:
      handle = resource_variable_ops.var_handle_op(dtype=dtypes.int32, shape=[])
      create = resource_variable_ops.create_variable_op(
          handle, constant_op.constant(1, dtype=dtypes.int32))
      with ops.control_dependencies([create]):
        first_read = resource_variable_ops.read_variable_op(
            handle, dtype=dtypes.int32)
      with ops.control_dependencies([first_read]):
        write = resource_variable_ops.assign_variable_op(
            handle, constant_op.constant(2, dtype=dtypes.int32))
      with ops.control_dependencies([write]):
        second_read = resource_variable_ops.read_variable_op(
            handle, dtype=dtypes.int32)
      f, s = session.run([first_read, second_read])
      self.assertEqual(f, 1)
      self.assertEqual(s, 2) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:19,代碼來源:resource_variable_ops_test.py

示例2: restore

# 需要導入模塊: from tensorflow.python.ops import resource_variable_ops [as 別名]
# 或者: from tensorflow.python.ops.resource_variable_ops import assign_variable_op [as 別名]
def restore(self, restored_tensors, restored_shapes):
      restored_tensor = restored_tensors[0]
      if restored_shapes is not None:
        restored_tensor = array_ops.reshape(restored_tensor, restored_shapes[0])
      return resource_variable_ops.assign_variable_op(
          self.handle_op, restored_tensor) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:8,代碼來源:saver.py

示例3: restore

# 需要導入模塊: from tensorflow.python.ops import resource_variable_ops [as 別名]
# 或者: from tensorflow.python.ops.resource_variable_ops import assign_variable_op [as 別名]
def restore(self, restored_tensors, restored_shapes):
      restored_tensor = restored_tensors[0]
      if restored_shapes is not None:
        restored_tensor = array_ops.reshape(restored_tensor, restored_shapes[0])
      return resource_variable_ops.assign_variable_op(
          self.read_op.op.inputs[0],
          restored_tensor) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:9,代碼來源:saver.py

示例4: restore

# 需要導入模塊: from tensorflow.python.ops import resource_variable_ops [as 別名]
# 或者: from tensorflow.python.ops.resource_variable_ops import assign_variable_op [as 別名]
def restore(self, restored_tensors, restored_shapes):
      restored_tensor = restored_tensors[0]
      if restored_shapes is not None:
        restored_tensor = array_ops.reshape(restored_tensor, restored_shapes[0])
      # Copy the restored tensor to the variable's device.
      with ops.device(self._var_device):
        restored_tensor = array_ops.identity(restored_tensor)
      return resource_variable_ops.assign_variable_op(
          self.handle_op, restored_tensor) 
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:11,代碼來源:saver.py

示例5: initializing_scope

# 需要導入模塊: from tensorflow.python.ops import resource_variable_ops [as 別名]
# 或者: from tensorflow.python.ops.resource_variable_ops import assign_variable_op [as 別名]
def initializing_scope(self):
    """Context manager to capture variable creations.

    Forcibly initializes all created variables.

    Yields:
      nothing
    """
    # TODO(apassos) ignoring the regularizer and partitioner here; figure out
    # how to deal with these.
    def _custom_getter(getter=None, name=None, shape=None, dtype=dtypes.float32,  # pylint: disable=missing-docstring
                       initializer=None, regularizer=None, reuse=None,
                       trainable=True, collections=None, caching_device=None,  # pylint: disable=redefined-outer-name
                       partitioner=None, validate_shape=True,
                       use_resource=None):
      del getter, regularizer, collections, caching_device, partitioner
      del use_resource, validate_shape
      if name in self.tf_variables:
        if reuse:
          return self.tf_variables[name].initialized_value()
        else:
          raise ValueError("Specified reuse=%s but tried to reuse variables."
                           % reuse)
      # TODO(apassos): ensure this is on the same device as above
      v = _CapturedVariable(name, initializer, shape, dtype, trainable)
      self.variables[name] = v

      graph_mode_resource = resource_variable_ops.var_handle_op(
          shared_name=name, shape=shape, dtype=dtype)
      if initializer is None:
        initializer = _default_initializer(name, shape, dtype)
      resource_variable_ops.assign_variable_op(
          graph_mode_resource, initializer(shape, dtype))
      return _VariableFromResource(
          graph_mode_resource, dtype, name, shape=v.shape)

    scope = variable_scope.get_variable_scope()
    with variable_scope.variable_scope(scope, custom_getter=_custom_getter):
      yield 
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:41,代碼來源:graph_callable.py


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