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


Python resource_variable_ops.read_variable_op函数代码示例

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


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

示例1: 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

示例2: testSharedName

  def testSharedName(self):
    v = resource_variable_ops.ResourceVariable(300.0, name="var4")
    self.evaluate(variables.global_variables_initializer())

    w = resource_variable_ops.var_handle_op(
        dtype=v.dtype.base_dtype, shape=v.get_shape(), shared_name="var4")
    w_read = resource_variable_ops.read_variable_op(w, v.dtype.base_dtype)
    self.assertEqual(300.0, self.evaluate(w_read))

    x = resource_variable_ops.var_handle_op(
        dtype=v.dtype.base_dtype, shape=v.get_shape(), shared_name="var5")
    with self.assertRaisesOpError("Resource .*/var5/.* does not exist"):
      x_read = resource_variable_ops.read_variable_op(x, v.dtype.base_dtype)
      self.evaluate(x_read)
开发者ID:1000sprites,项目名称:tensorflow,代码行数:14,代码来源:resource_variable_ops_test.py

示例3: testSharedName

  def testSharedName(self):
    with self.test_session():
      v = resource_variable_ops.ResourceVariable(300.0, name="var1")
      v.initializer.run()

      w = resource_variable_ops.var_handle_op(
          dtype=v.dtype.base_dtype, shape=v.get_shape(), shared_name="var1")
      w_read = resource_variable_ops.read_variable_op(w, v.dtype.base_dtype)
      self.assertEqual(300.0, w_read.eval())

      x = resource_variable_ops.var_handle_op(
          dtype=v.dtype.base_dtype, shape=v.get_shape(), shared_name="var1/")
      x_read = resource_variable_ops.read_variable_op(x, v.dtype.base_dtype)
      with self.assertRaisesOpError("Resource .*/var1//.* does not exist"):
        _ = x_read.eval()
开发者ID:piyushjaiswal98,项目名称:tensorflow,代码行数:15,代码来源:resource_variable_ops_test.py

示例4: 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

示例5: 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

示例6: testReadVariableDtypeMismatchEager

 def testReadVariableDtypeMismatchEager(self):
   with context.eager_mode():
     handle = resource_variable_ops.var_handle_op(
         dtype=dtypes.int32, shape=[1], name="foo")
     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:AbhinavJain13,项目名称:tensorflow,代码行数:8,代码来源:resource_variable_ops_test.py

示例7: 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

示例8: testSharedName

  def testSharedName(self):
    with self.cached_session():
      v = resource_variable_ops.ResourceVariable(300.0, name="var4")
      variables.global_variables_initializer().run()

      w = resource_variable_ops.var_handle_op(
          dtype=v.dtype.base_dtype, shape=v.get_shape(), shared_name="var4",
          # Needed in Eager since we get a unique container name by default.
          container=ops.get_default_graph()._container)
      w_read = resource_variable_ops.read_variable_op(w, v.dtype.base_dtype)
      self.assertEqual(300.0, self.evaluate(w_read))

      x = resource_variable_ops.var_handle_op(
          dtype=v.dtype.base_dtype, shape=v.get_shape(), shared_name="var5",
          container=ops.get_default_graph()._container)
      with self.assertRaisesOpError("Resource .*/var5/.* does not exist"):
        resource_variable_ops.read_variable_op(x, v.dtype.base_dtype).eval()
开发者ID:aeverall,项目名称:tensorflow,代码行数:17,代码来源:resource_variable_ops_test.py

示例9: testSharedNameWithNamescope

  def testSharedNameWithNamescope(self):
    with ops.name_scope("foo"):
      v = resource_variable_ops.ResourceVariable(300.0, name="var3")
      self.evaluate(variables.global_variables_initializer())

    w = resource_variable_ops.var_handle_op(
        dtype=v.dtype.base_dtype, shape=v.get_shape(), shared_name="foo/var3")
    w_read = resource_variable_ops.read_variable_op(w, v.dtype.base_dtype)
    self.assertEqual(300.0, self.evaluate(w_read))
开发者ID:chdinh,项目名称:tensorflow,代码行数:9,代码来源:resource_variable_ops_test.py

示例10: 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

示例11: testReturnMultipleResourceHandles

  def testReturnMultipleResourceHandles(self):
    with self.test_scope():
      v1 = resource_variable_ops.ResourceVariable(1.25)
      v2 = resource_variable_ops.ResourceVariable(2.0)

      def f(v):
        return v.handle, 3.0 * v, v2.handle, v + v2

      f = function.defun(f)
      v1_handle, v1_times_3, v2_handle, variable_sum = f(v1)
      self.assertAllEqual(v1.numpy(),
                          resource_variable_ops.read_variable_op(
                              v1_handle, dtypes.float32).numpy())
      self.assertEqual(3.75, v1_times_3.numpy())
      self.assertAllEqual(v2.numpy(),
                          resource_variable_ops.read_variable_op(
                              v2_handle, dtypes.float32).numpy())
      self.assertEqual(3.25, variable_sum.numpy())
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:18,代码来源:eager_test.py

示例12: 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

示例13: 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

示例14: testSharedNameWithNamescope

  def testSharedNameWithNamescope(self):
    with self.test_session():
      with ops.name_scope("foo"):
        v = resource_variable_ops.ResourceVariable(300.0, name="var1")
        v.initializer.run()

      w = resource_variable_ops.var_handle_op(
          dtype=v.dtype.base_dtype, shape=v.get_shape(), shared_name="foo/var1")
      w_read = resource_variable_ops.read_variable_op(w, v.dtype.base_dtype)
      self.assertEqual(300.0, w_read.eval())
开发者ID:piyushjaiswal98,项目名称:tensorflow,代码行数:10,代码来源:resource_variable_ops_test.py

示例15: testSharedName

  def testSharedName(self):
    v = resource_variable_ops.ResourceVariable(300.0, name="var1")
    self.evaluate(variables.global_variables_initializer())

    w = resource_variable_ops.var_handle_op(
        dtype=v.dtype.base_dtype, shape=v.get_shape(), shared_name="var1")
    w_read = resource_variable_ops.read_variable_op(w, v.dtype.base_dtype)
    self.assertEqual(300.0, self.evaluate(w_read))

    x = resource_variable_ops.var_handle_op(
        dtype=v.dtype.base_dtype, shape=v.get_shape(), shared_name="var2")
    if context.in_graph_mode():
      with self.assertRaisesOpError("Resource .*/var2/.* does not exist"):
        x_read = resource_variable_ops.read_variable_op(x, v.dtype.base_dtype)
        self.evaluate(x_read)
    else:
      with self.assertRaisesRegexp(errors.NotFoundError,
                                   "Attempted to read a nonexistent variable."):
        _ = resource_variable_ops.read_variable_op(x, v.dtype.base_dtype)
开发者ID:chdinh,项目名称:tensorflow,代码行数:19,代码来源:resource_variable_ops_test.py


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