当前位置: 首页>>代码示例>>Python>>正文


Python resource_variable_ops.assign_variable_op函数代码示例

本文整理汇总了Python中tensorflow.python.ops.resource_variable_ops.assign_variable_op函数的典型用法代码示例。如果您正苦于以下问题:Python assign_variable_op函数的具体用法?Python assign_variable_op怎么用?Python assign_variable_op使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了assign_variable_op函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testAssignAdd

 def testAssignAdd(self):
     with self.test_session():
         handle = resource_variable_ops.var_handle_op(dtype=dtypes.int32, shape=[])
         resource_variable_ops.assign_variable_op(handle, constant_op.constant(1, dtype=dtypes.int32)).run()
         resource_variable_ops.assign_add_variable_op(handle, constant_op.constant(1, dtype=dtypes.int32)).run()
         read = resource_variable_ops.read_variable_op(handle, dtype=dtypes.int32)
         self.assertEqual(read.eval(), 2)
开发者ID:kdavis-mozilla,项目名称:tensorflow,代码行数:7,代码来源:resource_variable_ops_test.py

示例2: _custom_getter

    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)
开发者ID:rajeev921,项目名称:tensorflow,代码行数:25,代码来源:graph_callable.py

示例3: assign_fn

 def assign_fn():
   with ops.name_scope("Assign") as n, ops.colocate_with(self._handle):
     resource_variable_ops.assign_variable_op(
         self._handle,
         initial_value,
         name=n)
     # Returning values to keep tf.cond happy.
   return ops.convert_to_tensor(1)
开发者ID:kylin9872,项目名称:tensorflow,代码行数:8,代码来源:def_function.py

示例4: testDtypeSurvivesIdentity

 def testDtypeSurvivesIdentity(self):
   with self.test_session():
     handle = resource_variable_ops.var_handle_op(dtype=dtypes.int32, shape=[])
     id_handle = array_ops.identity(handle)
     resource_variable_ops.assign_variable_op(id_handle,
                                              constant_op.constant(
                                                  0,
                                                  dtype=dtypes.int32)).run()
开发者ID:piyushjaiswal98,项目名称:tensorflow,代码行数:8,代码来源:resource_variable_ops_test.py

示例5: testCreateRead

 def testCreateRead(self):
   with self.test_session():
     handle = resource_variable_ops.var_handle_op(dtype=dtypes.int32, shape=[])
     resource_variable_ops.assign_variable_op(
         handle, constant_op.constant(1, dtype=dtypes.int32)).run()
     value = resource_variable_ops.read_variable_op(
         handle, dtype=dtypes.int32).eval()
     self.assertAllEqual(1, value)
开发者ID:AutumnQYN,项目名称:tensorflow,代码行数:8,代码来源:resource_variable_ops_test.py

示例6: testScatterAdd

 def testScatterAdd(self):
     with self.test_session():
         handle = resource_variable_ops.var_handle_op(dtype=dtypes.int32, shape=[1, 1])
         resource_variable_ops.assign_variable_op(handle, constant_op.constant([[1]], dtype=dtypes.int32)).run()
         resource_variable_ops.resource_scatter_add(
             handle, [0], constant_op.constant([[2]], dtype=dtypes.int32)
         ).run()
         read = resource_variable_ops.read_variable_op(handle, dtype=dtypes.int32)
         self.assertEqual(read.eval(), [[3]])
开发者ID:kdavis-mozilla,项目名称:tensorflow,代码行数:9,代码来源:resource_variable_ops_test.py

示例7: testReadVariableDtypeMismatchEager

 def testReadVariableDtypeMismatchEager(self):
   with context.eager_mode():
     handle = resource_variable_ops.var_handle_op(
         dtype=dtypes.int32, shape=[1], name="foo")
     resource_variable_ops.assign_variable_op(handle, 1)
     with self.assertRaisesRegexp(errors.InvalidArgumentError,
                                  "Trying to read variable with wrong dtype. "
                                  "Expected float got int32."):
       _ = resource_variable_ops.read_variable_op(handle, dtype=dtypes.float32)
开发者ID:aeverall,项目名称:tensorflow,代码行数:9,代码来源:resource_variable_ops_test.py

示例8: testAssignVariableDtypeMismatchEager

 def testAssignVariableDtypeMismatchEager(self):
   with context.eager_mode():
     handle = resource_variable_ops.var_handle_op(
         dtype=dtypes.int32, shape=[1], name="foo")
     resource_variable_ops.assign_variable_op(
         handle, constant_op.constant([1]))
     with self.assertRaisesRegexp(errors.InvalidArgumentError,
                                  "Trying to assign variable with wrong "
                                  "dtype. Expected int32 got float."):
       resource_variable_ops.assign_variable_op(
           handle, constant_op.constant([1.], dtype=dtypes.float32))
开发者ID:aeverall,项目名称:tensorflow,代码行数:11,代码来源:resource_variable_ops_test.py

示例9: testManyAssigns

 def testManyAssigns(self):
     with self.test_session() as session:
         handle = resource_variable_ops.var_handle_op(dtype=dtypes.int32, shape=[])
         create = resource_variable_ops.assign_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:kdavis-mozilla,项目名称:tensorflow,代码行数:13,代码来源:resource_variable_ops_test.py

示例10: testCreateRead

 def testCreateRead(self):
   handle = resource_variable_ops.var_handle_op(dtype=dtypes.int32, shape=[])
   self.evaluate(resource_variable_ops.assign_variable_op(
       handle, constant_op.constant(1, dtype=dtypes.int32)))
   value = self.evaluate(
       resource_variable_ops.read_variable_op(handle, dtype=dtypes.int32))
   self.assertAllEqual(1, value)
开发者ID:aeverall,项目名称:tensorflow,代码行数:7,代码来源:resource_variable_ops_test.py

示例11: testAssignAdd

 def testAssignAdd(self):
   handle = resource_variable_ops.var_handle_op(dtype=dtypes.int32, shape=[])
   self.evaluate(resource_variable_ops.assign_variable_op(
       handle, constant_op.constant(1, dtype=dtypes.int32)))
   self.evaluate(resource_variable_ops.assign_add_variable_op(
       handle, constant_op.constant(1, dtype=dtypes.int32)))
   read = self.evaluate(
       resource_variable_ops.read_variable_op(handle, dtype=dtypes.int32))
   self.assertEqual(read, 2)
开发者ID:aeverall,项目名称:tensorflow,代码行数:9,代码来源:resource_variable_ops_test.py

示例12: testScatterAdd

 def testScatterAdd(self):
   handle = resource_variable_ops.var_handle_op(
       dtype=dtypes.int32, shape=[1, 1])
   self.evaluate(resource_variable_ops.assign_variable_op(
       handle, constant_op.constant([[1]], dtype=dtypes.int32)))
   self.evaluate(resource_variable_ops.resource_scatter_add(
       handle, [0], constant_op.constant([[2]], dtype=dtypes.int32)))
   read = resource_variable_ops.read_variable_op(handle, dtype=dtypes.int32)
   self.assertEqual(self.evaluate(read), [[3]])
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:9,代码来源:resource_variable_ops_test.py

示例13: testScatterUpdateString

 def testScatterUpdateString(self):
   handle = resource_variable_ops.var_handle_op(
       dtype=dtypes.string, shape=[1, 1])
   self.evaluate(resource_variable_ops.assign_variable_op(
       handle, constant_op.constant([["a"]], dtype=dtypes.string)))
   self.evaluate(resource_variable_ops.resource_scatter_update(
       handle, [0], constant_op.constant([["b"]], dtype=dtypes.string)))
   read = resource_variable_ops.read_variable_op(handle, dtype=dtypes.string)
   self.assertEqual(compat.as_bytes(self.evaluate(read)[0][0]),
                    compat.as_bytes("b"))
开发者ID:aeverall,项目名称:tensorflow,代码行数:10,代码来源:resource_variable_ops_test.py

示例14: testScatterDiv

 def testScatterDiv(self):
   with self.test_session() as sess, self.test_scope():
     handle = resource_variable_ops.var_handle_op(
         dtype=dtypes.int32, shape=[1, 1])
     sess.run(
         resource_variable_ops.assign_variable_op(
             handle, constant_op.constant([[6]], dtype=dtypes.int32)))
     sess.run(
         resource_variable_ops.resource_scatter_div(
             handle, [0], constant_op.constant([[3]], dtype=dtypes.int32)))
     read = resource_variable_ops.read_variable_op(handle, dtype=dtypes.int32)
     self.assertAllEqual(sess.run(read), [[2]])
开发者ID:AnishShah,项目名称:tensorflow,代码行数:12,代码来源:variable_ops_test.py

示例15: testScatterMaxScalar

 def testScatterMaxScalar(self):
   with self.test_session() as sess, self.test_scope():
     handle = resource_variable_ops.var_handle_op(
         dtype=dtypes.int32, shape=[1, 1])
     sess.run(
         resource_variable_ops.assign_variable_op(
             handle, constant_op.constant([[6]], dtype=dtypes.int32)))
     sess.run(
         resource_variable_ops.resource_scatter_max(
             handle, [0], constant_op.constant(3, dtype=dtypes.int32)))
     read = resource_variable_ops.read_variable_op(handle, dtype=dtypes.int32)
     self.assertEqual(self.evaluate(read), [[6]])
开发者ID:Albert-Z-Guo,项目名称:tensorflow,代码行数:12,代码来源:variable_ops_test.py


注:本文中的tensorflow.python.ops.resource_variable_ops.assign_variable_op函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。