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


Python NodeStepper.override_names方法代码示例

本文整理汇总了Python中tensorflow.python.debug.stepper.NodeStepper.override_names方法的典型用法代码示例。如果您正苦于以下问题:Python NodeStepper.override_names方法的具体用法?Python NodeStepper.override_names怎么用?Python NodeStepper.override_names使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow.python.debug.stepper.NodeStepper的用法示例。


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

示例1: testOverrideValueTwice

# 需要导入模块: from tensorflow.python.debug.stepper import NodeStepper [as 别名]
# 或者: from tensorflow.python.debug.stepper.NodeStepper import override_names [as 别名]
  def testOverrideValueTwice(self):
    stepper = NodeStepper(self.sess, self.e)

    # Override once.
    stepper.override_tensor("c:0", 7.0)
    self.assertAllClose(28.0, stepper.cont(self.e))
    self.assertEqual({
        "c:0": NodeStepper.FEED_TYPE_OVERRIDE
    }, stepper.last_feed_types())

    self.assertEqual(["e:0"], stepper.handle_names())
    self.assertEqual(["c:0"], stepper.override_names())

    # Calling cont(self.e) again. This time the cached tensor handle of e
    # should be used.
    self.assertEqual(28.0, stepper.cont(self.e))
    self.assertEqual({
        "e:0": NodeStepper.FEED_TYPE_HANDLE
    }, stepper.last_feed_types())

    # Override c again. This should have invalidated the cache for e.
    stepper.override_tensor("c:0", 8.0)

    self.assertEqual([], stepper.handle_names())
    self.assertEqual(["c:0"], stepper.override_names())

    self.assertAllClose(32.0, stepper.cont(self.e))
    self.assertEqual({
        "c:0": NodeStepper.FEED_TYPE_OVERRIDE
    }, stepper.last_feed_types())
开发者ID:brchiu,项目名称:tensorflow,代码行数:32,代码来源:stepper_test.py

示例2: testRemoveOverrideValue

# 需要导入模块: from tensorflow.python.debug.stepper import NodeStepper [as 别名]
# 或者: from tensorflow.python.debug.stepper.NodeStepper import override_names [as 别名]
  def testRemoveOverrideValue(self):
    stepper = NodeStepper(self.sess, self.e)

    result = stepper.cont(self.c)
    self.assertAllClose(6.0, result)
    self.assertEqual({}, stepper.last_feed_types())

    # The previous cont() step should have generated a cached tensor handle.
    self.assertEqual(["c:0"], stepper.handle_names())
    self.assertSetEqual({"c"}, stepper.handle_node_names())

    # Override c:0.
    stepper.override_tensor("c:0", 7.0)

    # The overriding should have invalidated the tensor handle.
    self.assertEqual([], stepper.handle_names())
    self.assertSetEqual(set(), stepper.handle_node_names())
    self.assertEqual(["c:0"], stepper.override_names())

    result = stepper.cont(self.e)
    self.assertAllClose(28.0, result)  # Should reflect the overriding value.
    self.assertEqual({
        "c:0": NodeStepper.FEED_TYPE_OVERRIDE
    }, stepper.last_feed_types())

    # The handle to tensor e:0 should have been cached, even though its
    # transitive closure contains an override.
    self.assertIn("e:0", stepper.handle_names())
    self.assertSetEqual({"e"}, stepper.handle_node_names())

    # Remove the override.
    stepper.remove_override("c:0")
    # c:0 should not be in the overrides anymore.
    self.assertEqual([], stepper.override_names())

    # Removing the override should have invalidated the tensor handle for c.
    self.assertNotIn("e:0", stepper.handle_names())
    self.assertNotIn("e", stepper.handle_node_names())

    # Should reflect the non-overriding value.
    self.assertAllClose(24.0, stepper.cont(self.e))

    # This time, the handle to tensor e:0 should have been cached again, even
    # thought its transitive closure contains an override.
    self.assertIn("e:0", stepper.handle_names())
    self.assertIn("e", stepper.handle_node_names())

    # Calling cont(self.e) again should have used the tensor handle to e:0.
    self.assertAllClose(24.0, stepper.cont(self.e))
    self.assertEqual({
        "e:0": NodeStepper.FEED_TYPE_HANDLE
    }, stepper.last_feed_types())
开发者ID:kdavis-mozilla,项目名称:tensorflow,代码行数:54,代码来源:stepper_test.py

示例3: testRemoveNonexistentOverrideValue

# 需要导入模块: from tensorflow.python.debug.stepper import NodeStepper [as 别名]
# 或者: from tensorflow.python.debug.stepper.NodeStepper import override_names [as 别名]
  def testRemoveNonexistentOverrideValue(self):
    stepper = NodeStepper(self.sess, self.e)
    self.assertEqual([], stepper.override_names())

    with self.assertRaisesRegexp(
        ValueError, "No overriding value exists for tensor \"c:0\""):
      stepper.remove_override("c:0")
开发者ID:brchiu,项目名称:tensorflow,代码行数:9,代码来源:stepper_test.py

示例4: testOverrideValue

# 需要导入模块: from tensorflow.python.debug.stepper import NodeStepper [as 别名]
# 或者: from tensorflow.python.debug.stepper.NodeStepper import override_names [as 别名]
  def testOverrideValue(self):
    stepper = NodeStepper(self.sess, self.e)

    result = stepper.cont(self.c)
    self.assertAllClose(6.0, result)
    self.assertEqual({}, stepper.last_feed_types())

    # There should be no overrides before any cont() calls.
    self.assertEqual([], stepper.override_names())

    # Calling cont() on c again should lead to use of the handle.
    result = stepper.cont(self.c)
    self.assertAllClose(6.0, result)
    self.assertEqual({
        "c:0": NodeStepper.FEED_TYPE_HANDLE
    }, stepper.last_feed_types())

    # Override c:0.
    stepper.override_tensor("c:0", 7.0)

    # After the overriding, calling get_tensor_value() on c:0 should yield the
    # overriding value.
    self.assertEqual(7.0, stepper.get_tensor_value("c:0"))

    # Now c:0 should have only an override value, but no cached handle, because
    # the handle should have been invalidated.
    self.assertEqual([], stepper.handle_names())
    self.assertSetEqual(set(), stepper.handle_node_names())
    self.assertEqual(["c:0"], stepper.override_names())

    # Run a downstream tensor after the value override.
    result = stepper.cont(self.e)
    self.assertAllClose(28.0, result)  # Should reflect the overriding value.

    # Should use override, instead of the handle.
    self.assertEqual({
        "c:0": NodeStepper.FEED_TYPE_OVERRIDE
    }, stepper.last_feed_types())
开发者ID:kdavis-mozilla,项目名称:tensorflow,代码行数:40,代码来源:stepper_test.py

示例5: testFinalizeWithPreviousOverrides

# 需要导入模块: from tensorflow.python.debug.stepper import NodeStepper [as 别名]
# 或者: from tensorflow.python.debug.stepper.NodeStepper import override_names [as 别名]
  def testFinalizeWithPreviousOverrides(self):
    stepper = NodeStepper(self.sess, self.e)

    stepper.override_tensor("a/read:0", 20.0)
    self.assertEqual(["a/read:0"], stepper.override_names())

    # Should reflect the overriding value.
    self.assertAllClose(24000.0, stepper.cont("e:0"))
    self.assertEqual({
        "a/read:0": NodeStepper.FEED_TYPE_OVERRIDE
    }, stepper.last_feed_types())

    # Finalize call should have ignored the overriding value.
    self.assertAllClose(24.0, stepper.finalize())
开发者ID:brchiu,项目名称:tensorflow,代码行数:16,代码来源:stepper_test.py

示例6: testOverrideThenContToUpdate

# 需要导入模块: from tensorflow.python.debug.stepper import NodeStepper [as 别名]
# 或者: from tensorflow.python.debug.stepper.NodeStepper import override_names [as 别名]
  def testOverrideThenContToUpdate(self):
    """Test cont() to update nodes after overriding tensor values."""

    stepper = NodeStepper(self.sess, "optim")

    result = stepper.cont("d:0")
    self.assertAllClose(2.0, result)
    self.assertEqual({}, stepper.last_feed_types())
    self.assertEqual(set(), stepper.dirty_variables())
    self.assertEqual(["d:0"], stepper.handle_names())

    # Override the value from 1.0 to 10.0.
    stepper.override_tensor("a/read:0", 10.0)

    self.assertEqual(["a/read:0"], stepper.override_names())

    result = stepper.cont("optim/update_c/ApplyGradientDescent",
                          restore_variable_values=True)
    self.assertIsNone(result)

    # The last cont() call should have not used the tensor handle to d:0,
    # because the transitive closure of d:0 contains an override tensor.
    self.assertEqual({
        "a/read:0": NodeStepper.FEED_TYPE_OVERRIDE
    }, stepper.last_feed_types())

    # The tensor handle to d:0 should have been removed due to the dirty
    # transitive closure.
    self.assertEqual([], stepper.handle_names())

    # For this backprop on c, the overriding value of a/read:0 should have been
    # used:
    #   4.0 - learning_rate * a * b * b
    #     = 4.0 - 0.01 * 10.0 * 2.0 * 2.0 = 3.6.
    self.assertAllClose(3.6, self.sess.run(self.c))

    # Now remove the overriding value of a/read:0.
    stepper.remove_override("a/read:0")
    self.assertEqual([], stepper.override_names())

    # Obtain the tensor handle to d:0 again.
    result = stepper.cont("d:0")
    self.assertAllClose(2.0, result)
    self.assertEqual(["d:0"], stepper.handle_names())

    # Then call update_c again, without restoring c.
    result = stepper.cont(
        "optim/update_c/ApplyGradientDescent", restore_variable_values=False)
    self.assertIsNone(result)

    # This time, the d:0 tensor handle should have been used, because its
    # transitive closure is clean.
    self.assertEqual({
        "d:0": NodeStepper.FEED_TYPE_HANDLE
    }, stepper.last_feed_types())

    # For this backprop on c, the overriding value of a/read:0 should have been
    # used:
    #   3.6 - learning_rate * a * b * b
    #     = 3.6 - 0.01 * 1.0 * 2.0 * 2.0 = 3.56.
    self.assertAllClose(3.56, self.sess.run(self.c))
开发者ID:brchiu,项目名称:tensorflow,代码行数:63,代码来源:stepper_test.py


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