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


Python stepper.NodeStepper类代码示例

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


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

示例1: testRemoveNonexistentOverrideValue

  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,代码行数:7,代码来源:stepper_test.py

示例2: testIsFeedableShouldGiveCorrectAnswers

  def testIsFeedableShouldGiveCorrectAnswers(self):
    stepper = NodeStepper(self.sess, self.e)

    self.assertTrue(stepper.is_feedable("a/read:0"))
    self.assertTrue(stepper.is_feedable("b/read:0"))
    self.assertTrue(stepper.is_feedable("c:0"))
    self.assertTrue(stepper.is_feedable("d:0"))
开发者ID:kdavis-mozilla,项目名称:tensorflow,代码行数:7,代码来源:stepper_test.py

示例3: testIsFeedable

  def testIsFeedable(self):
    stepper = NodeStepper(self.sess, self.e)

    self.assertTrue(stepper.is_feedable("a/read:0"))
    self.assertTrue(stepper.is_feedable("b/read:0"))
    self.assertTrue(stepper.is_feedable("c:0"))
    self.assertTrue(stepper.is_feedable("d:0"))
开发者ID:brchiu,项目名称:tensorflow,代码行数:7,代码来源:stepper_test.py

示例4: testUsingNodesNotUsingIntermediateTensors

  def testUsingNodesNotUsingIntermediateTensors(self):
    stepper = NodeStepper(self.sess, self.e)

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

    # Before the cont() call, the stepper should not have access to the value
    # of c:0.
    with self.assertRaisesRegexp(
        ValueError,
        "This stepper instance does not have access to the value of tensor "
        "\"c:0\""):
      stepper.get_tensor_value("c:0")

    # Using the node/tensor itself, instead of the name str, should work on
    # cont().
    result = stepper.cont(self.c)
    self.assertAllClose(6.0, result)
    self.assertEqual({}, stepper.last_feed_types())

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

    # After the cont() call, the stepper should have access to the value of c:0
    # via a tensor handle.
    self.assertAllClose(6.0, stepper.get_tensor_value("c:0"))

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

示例5: testTransitiveClosureWithCrossLinksShouldHaveCorrectOrder

  def testTransitiveClosureWithCrossLinksShouldHaveCorrectOrder(self):
    stepper = NodeStepper(self.sess, "z:0")

    sorted_nodes = stepper.sorted_nodes()
    self.assertEqual(4, len(sorted_nodes))
    self.assertLess(sorted_nodes.index("x"), sorted_nodes.index("x/read"))
    self.assertLess(sorted_nodes.index("x"), sorted_nodes.index("y"))
    self.assertLess(sorted_nodes.index("x"), sorted_nodes.index("z"))
    self.assertLess(sorted_nodes.index("y"), sorted_nodes.index("z"))
开发者ID:kdavis-mozilla,项目名称:tensorflow,代码行数:9,代码来源:stepper_test.py

示例6: testContWithPlaceholders

  def testContWithPlaceholders(self):
    stepper = NodeStepper(
        self.sess,
        self.y,
        feed_dict={
            self.ph0: [[1.0, 2.0], [-3.0, 5.0]],
            self.ph1: [[-1.0], [0.5]]
        })

    self.assertEqual(4, len(stepper.sorted_nodes()))
    self.assertSetEqual({"ph0:0", "ph1:0", "x:0", "y:0"},
                        set(stepper.closure_elements()))

    result = stepper.cont(self.x)
    self.assertAllClose([[0.0], [5.5]], result)
    self.assertEqual({
        "ph0:0": NodeStepper.FEED_TYPE_CLIENT,
        "ph1:0": NodeStepper.FEED_TYPE_CLIENT,
    }, stepper.last_feed_types())

    self.assertEqual(["x:0"], stepper.handle_names())
    self.assertSetEqual({"x"}, stepper.handle_node_names())

    result = stepper.cont(self.y)
    self.assertAllClose([[-1.0], [6.0]], result)
    self.assertEqual({
        "x:0": NodeStepper.FEED_TYPE_HANDLE,
        "ph1:0": NodeStepper.FEED_TYPE_CLIENT,
    }, stepper.last_feed_types())
开发者ID:kdavis-mozilla,项目名称:tensorflow,代码行数:29,代码来源:stepper_test.py

示例7: testContToUpdateA

  def testContToUpdateA(self):
    stepper = NodeStepper(self.sess, "optim")

    result = stepper.cont("a:0")
    self.assertAllClose(1.0, result)
    self.assertEqual({}, stepper.last_feed_types())

    result = stepper.cont("optim/learning_rate:0")
    self.assertAllClose(0.01, result)
    self.assertEqual({}, stepper.last_feed_types())

    # Before any cont calls on ApplyGradientDescent, there should be no "dirty"
    # variables.
    self.assertEqual(set(), stepper.dirty_variables())

    # First, all the two control inputs to optim.
    result = stepper.cont("optim/update_a/ApplyGradientDescent")

    # Now variable a should have been marked as dirty due to the update
    # by optim/update_a/ApplyGradientDescent.
    self.assertEqual({"a:0"}, stepper.dirty_variables())
    self.assertIsNone(result)
    self.assertEqual({
        "optim/learning_rate:0": NodeStepper.FEED_TYPE_HANDLE
    }, stepper.last_feed_types())

    # Check that Variable "a" has been updated properly, but "b", "c" and "d"
    # remain the same.
    # For backprop on Variable a:
    #   Because f = a * b * b * c, df / da = b * b * c.
    #   1.0 - learning_rate * b * b * c
    #     = 1.0 -  0.01 * 2.0 * 2.0 * 4.0 = 0.84.
    self.assertAllClose(0.84, self.sess.run(self.a))
    self.assertAllClose(2.0, self.sess.run(self.b))
    self.assertAllClose(4.0, self.sess.run(self.c))
开发者ID:brchiu,项目名称:tensorflow,代码行数:35,代码来源:stepper_test.py

示例8: testRestoreVariableValues

  def testRestoreVariableValues(self):
    """Test restore_variable_values() restores the old values of variables."""

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

    stepper.cont(
        "optim/update_b/ApplyGradientDescent", restore_variable_values=True)
    self.assertAllClose(1.84, self.sess.run(self.b))

    stepper.restore_variable_values()
    self.assertAllClose(2.0, self.sess.run(self.b))
开发者ID:kdavis-mozilla,项目名称:tensorflow,代码行数:11,代码来源:stepper_test.py

示例9: testAttemptToContToPlaceholder

  def testAttemptToContToPlaceholder(self):
    stepper = NodeStepper(
        self.sess,
        self.y,
        feed_dict={
            self.ph0: [[1.0, 2.0], [-3.0, 5.0]],
            self.ph1: [[-1.0], [0.5]]
        })

    with self.assertRaisesRegexp(ValueError,
                                 r"Should not call cont\(\) on a Placeholder"):
      stepper.cont(self.ph0)
开发者ID:brchiu,项目名称:tensorflow,代码行数:12,代码来源:stepper_test.py

示例10: testIsPlaceholdersShouldGiveCorrectAnswers

  def testIsPlaceholdersShouldGiveCorrectAnswers(self):
    stepper = NodeStepper(self.sess, self.y)

    self.assertTrue(stepper.is_placeholder(self.ph0.name))
    self.assertTrue(stepper.is_placeholder(self.ph1.name))

    self.assertFalse(stepper.is_placeholder(self.x.name))
    self.assertFalse(stepper.is_placeholder(self.y.name))

    with self.assertRaisesRegexp(ValueError,
                                 "A is not in the transitive closure"):
      self.assertFalse(stepper.is_placeholder("A"))
开发者ID:kdavis-mozilla,项目名称:tensorflow,代码行数:12,代码来源:stepper_test.py

示例11: testAttemptToContToFetchNotInTransitiveClosure

  def testAttemptToContToFetchNotInTransitiveClosure(self):
    stepper = NodeStepper(self.sess, "e:0")

    self.assertEqual(
        ["a:0", "b:0", "b/read:0", "a/read:0", "c:0", "d:0", "e:0"],
        stepper.sorted_transitive_closure())

    with self.assertRaisesRegexp(
        ValueError,
        "Target \"f:0\" is not in the transitive closure for the fetch of the "
        "stepper: \"e:0\""):
      stepper.cont("f:0")
开发者ID:brchiu,项目名称:tensorflow,代码行数:12,代码来源:stepper_test.py

示例12: testAttemptToContToPlaceholderWithTensorNameFeedKeysShouldWork

  def testAttemptToContToPlaceholderWithTensorNameFeedKeysShouldWork(self):

    ph0_feed = [[1.0, 2.0], [-3.0, 5.0]]
    ph1_feed = [[-1.0], [0.5]]
    stepper = NodeStepper(
        self.sess,
        self.y,
        feed_dict={
            self.ph0.name: ph0_feed,
            self.ph1.name: ph1_feed,
        })

    self.assertAllClose(ph0_feed, stepper.cont(self.ph0))
    self.assertEqual({
        self.ph0.name: NodeStepper.FEED_TYPE_CLIENT
    }, stepper.last_feed_types())

    self.assertAllClose(ph1_feed, stepper.cont(self.ph1))
    self.assertEqual({
        self.ph1.name: NodeStepper.FEED_TYPE_CLIENT
    }, stepper.last_feed_types())

    ph0_node = self.sess.graph.as_graph_element("ph0")
    self.assertAllClose(ph0_feed, stepper.cont(ph0_node))
    self.assertEqual({
        self.ph0.name: NodeStepper.FEED_TYPE_CLIENT
    }, stepper.last_feed_types())

    self.assertAllClose([[-1.0], [6.0]], stepper.finalize())
开发者ID:kdavis-mozilla,项目名称:tensorflow,代码行数:29,代码来源:stepper_test.py

示例13: testContToNodeWithOutputTensors

  def testContToNodeWithOutputTensors(self):
    """cont() to an op should cache its output tensors if appropriate."""

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

    # In the transitive closure of the stepper, look for an op of which the
    # output tensor also is in the transitive closure.
    # Do not assume a specific op, e.g., ""gradients/e_grad/Reshape_1",
    # because it may vary between builds.
    closure = stepper.sorted_transitive_closure()
    op_with_output_in_closure = None
    for element_name in closure:
      if element_name + ":0" in closure:
        op_with_output_in_closure = str(element_name)
        break

    self.assertIsNotNone(op_with_output_in_closure)
    output_tensor = op_with_output_in_closure + ":0"

    # The op "gradients/?_grad/Reshape_1" is in the transitive closure of the
    # stepper, because it is the control input to another o. However, its
    # output tensor "gradients/?_grad/Reshape_1:0" is also in the transitive
    # closure, because it is the (non-control) input of certain ops. Calling
    # cont() on the op should lead to the caching of the tensor handle for
    # the output tensor.
    stepper.cont(op_with_output_in_closure)

    self.assertEqual([output_tensor], stepper.handle_names())

    # Do a cont() call that uses the cached tensor of
    # "gradients/?_grad/Reshape_1:0".
    stepper.cont(output_tensor)
    self.assertEqual({
        output_tensor: NodeStepper.FEED_TYPE_HANDLE
    }, stepper.last_feed_types())
开发者ID:ComeOnGetMe,项目名称:tensorflow,代码行数:35,代码来源:stepper_test.py

示例14: testContToUpdateB

  def testContToUpdateB(self):
    stepper = NodeStepper(self.sess, "optim")

    result = stepper.cont("optim/update_b/ApplyGradientDescent")
    self.assertIsNone(result)
    self.assertEqual(set(["b:0"]), stepper.dirty_variables())

    # For backprop on Variable b:
    #   Because f = a * b * b * c, df / da = 2 * a * b * c.
    #   2.0 - learning_rate * 2 * a * b * c
    #     = 2.0 - 0.01 * 2 * 1.0 * 2.0 * 4.0 = 1.84
    self.assertAllClose(1.0, self.sess.run(self.a))
    self.assertAllClose(1.84, self.sess.run(self.b))
    self.assertAllClose(4.0, self.sess.run(self.c))
开发者ID:brchiu,项目名称:tensorflow,代码行数:14,代码来源:stepper_test.py

示例15: testUsingNamesNotUsingIntermediateTensors

  def testUsingNamesNotUsingIntermediateTensors(self):
    stepper = NodeStepper(self.sess, "e:0")

    # The first cont() call should have used no feeds.
    result = stepper.cont("c:0")
    self.assertAllClose(6.0, result)
    self.assertEqual({}, stepper.last_feed_types())

    # The second cont() call should have used the tensor handle from the
    # previous cont() call.
    result = stepper.cont("e:0")
    self.assertAllClose(24.0, result)
    self.assertEqual({
        "c:0": NodeStepper.FEED_TYPE_HANDLE
    }, stepper.last_feed_types())
开发者ID:brchiu,项目名称:tensorflow,代码行数:15,代码来源:stepper_test.py


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