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


Python gradient_checker.compute_gradient_error方法代碼示例

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


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

示例1: testSequenceToSequenceGradient

# 需要導入模塊: from tensorflow.python.ops import gradient_checker [as 別名]
# 或者: from tensorflow.python.ops.gradient_checker import compute_gradient_error [as 別名]
def testSequenceToSequenceGradient(self):
    with self.test_session():
      size = (17, 1, 15)
      output_size = (17, 1, 8)
      inputs = constant_op.constant(_rand(*size))
      outputs = lstm1d.ndlstm_base(inputs, 8, dynamic=False)
      variables.global_variables_initializer().run()
      gradients = gradients_impl.gradients(outputs, inputs)
      if 1:  # pylint: disable=using-constant-test
        gradients = gradients_impl.gradients(outputs, inputs)[0].eval()
        self.assertEqual(gradients.shape, size)
      else:
        # TODO(tmb) tf.test.compute_gradient error is currently broken
        # with dynamic_rnn. Enable this test case eventually.
        err = gradient_checker.compute_gradient_error(
            inputs, size, outputs, output_size, delta=1e-4)
        self.assert_(not np.isnan(err))
        self.assert_(err < 0.1) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:20,代碼來源:lstm1d_test.py

示例2: testSequenceToSequenceGradientReverse

# 需要導入模塊: from tensorflow.python.ops import gradient_checker [as 別名]
# 或者: from tensorflow.python.ops.gradient_checker import compute_gradient_error [as 別名]
def testSequenceToSequenceGradientReverse(self):
    with self.test_session():
      size = (17, 1, 15)
      output_size = (17, 1, 8)
      inputs = constant_op.constant(_rand(*size))
      outputs = lstm1d.ndlstm_base(inputs, 8, reverse=1, dynamic=False)
      variables.global_variables_initializer().run()
      if 1:  # pylint: disable=using-constant-test
        gradients = gradients_impl.gradients(outputs, inputs)[0].eval()
        self.assertEqual(gradients.shape, size)
      else:
        # TODO(tmb) tf.test.compute_gradient error is currently broken
        # with dynamic_rnn. Enable this test case eventually.
        err = gradient_checker.compute_gradient_error(
            inputs, size, outputs, output_size, delta=1e-4)
        self.assert_(not np.isnan(err))
        self.assert_(err < 0.1) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:19,代碼來源:lstm1d_test.py

示例3: testPoincareNormalizeGradient

# 需要導入模塊: from tensorflow.python.ops import gradient_checker [as 別名]
# 或者: from tensorflow.python.ops.gradient_checker import compute_gradient_error [as 別名]
def testPoincareNormalizeGradient(self):
    x_shape = [20, 7, 3]
    np.random.seed(1)
    x_np = np.random.random_sample(x_shape).astype(np.float64)
    for dim in range(len(x_shape)):
      with self.cached_session():
        x_tf = constant_op.constant(x_np, name='x')
        y_tf = _layers.poincare_normalize(x_tf, dim)
        err = gradient_checker.compute_gradient_error(x_tf, x_shape, y_tf,
                                                      x_shape)
      print('PoinCareNormalize gradient err = %g ' % err)
      self.assertLess(err, 1e-4)


# TODO(b/28426988): Add separate tests for non-legacy versions. 
開發者ID:google-research,項目名稱:tf-slim,代碼行數:17,代碼來源:layers_test.py

示例4: _test_gradient

# 需要導入模塊: from tensorflow.python.ops import gradient_checker [as 別名]
# 或者: from tensorflow.python.ops.gradient_checker import compute_gradient_error [as 別名]
def _test_gradient(device):

    if device == "gpu" and visible_gpu():
        pytest.xfail("no gpu is visible")

    with NumpySeed(100):
        with tf.device('/{}:0'.format(device)):
            sprites, scales, offsets, backgrounds = get_data(random_alpha=True, squash=0.99)

            sprites_tf = constant_op.constant(sprites)
            scales_tf = constant_op.constant(scales)
            offsets_tf = constant_op.constant(offsets)
            backgrounds_tf = constant_op.constant(backgrounds)

            images = render_sprites.render_sprites(sprites_tf, scales_tf, offsets_tf, backgrounds_tf)

            sess = get_session()
            with sess.as_default():
                with tf.device(device):
                    err = gradient_checker.compute_gradient_error(
                        [sprites_tf, scales_tf, offsets_tf, backgrounds_tf],
                        [sprites.shape, scales.shape, offsets.shape, backgrounds.shape],
                        images,
                        backgrounds.shape,
                        [sprites, scales, offsets, backgrounds],
                        delta=0.002)

            print("Jacobian error: {}".format(err))
            threshold = 2e-4
            assert err < threshold, "Jacobian error ({}) exceeded threshold ({})".format(err, threshold) 
開發者ID:e2crawfo,項目名稱:auto_yolo,代碼行數:32,代碼來源:test_render_sprites.py

示例5: test_basics

# 需要導入模塊: from tensorflow.python.ops import gradient_checker [as 別名]
# 或者: from tensorflow.python.ops.gradient_checker import compute_gradient_error [as 別名]
def test_basics(self):
    tf.set_random_seed(1234)
    x_shape = [4, 4, 4, 5]
    rnd = np.random.RandomState(0)
    x_np = rnd.uniform(-1.0, 1.0, x_shape).astype(np.float32)

    # test op max_pool_grad
    with tf.Graph().as_default(), tf.Session() as sess:
      x_tf = tf.constant(x_np, name="x")
      y_tf1, _ = tf.nn.max_pool_with_argmax(
          x_tf,
          ksize=[1, 3, 3, 1],
          strides=[1, 2, 2, 1],
          padding='SAME',
          name="y1")
      y_tf2 = tf.nn.max_pool(
          x_tf,
          ksize=[1, 3, 3, 1],
          strides=[1, 2, 2, 1],
          padding='SAME',
          name="y2")
      z_tf1 = tf.reduce_sum(tf.square(y_tf1))
      z_tf2 = tf.reduce_sum(tf.square(y_tf2))
      dx1 = tf.gradients(z_tf1, x_tf, name='dx1')[0]
      dx2 = tf.gradients(z_tf2, x_tf, name='dx2')[0]
      err = gradient_checker.compute_gradient_error(
          x_tf, x_shape, dx1, x_shape, delta=1e-3, x_init_value=x_np)
      self.assertTrue(err < 1e-3)
      err = gradient_checker.compute_gradient_error(
          x_tf, x_shape, dx2, x_shape, delta=1e-3, x_init_value=x_np)
      self.assertTrue(err < 1e-3) 
開發者ID:renmengye,項目名稱:tensorflow-forward-ad,代碼行數:33,代碼來源:maxpool_gradgrad_tests.py

示例6: test_grad_transform

# 需要導入模塊: from tensorflow.python.ops import gradient_checker [as 別名]
# 或者: from tensorflow.python.ops.gradient_checker import compute_gradient_error [as 別名]
def test_grad_transform(self):
    with self.test_session():
      cloud_source = self.small_cloud
      cloud_target = cloud_source + [0.05, 0, 0]
      ego_motion = self.identity_transform
      transform, unused_residual = self._run_icp(cloud_source, ego_motion,
                                                 cloud_target)
      err = gradient_checker.compute_gradient_error(ego_motion,
                                                    ego_motion.shape.as_list(),
                                                    transform,
                                                    transform.shape.as_list())
    # Since our gradient is an approximation, it doesn't pass a numerical check.
    # Nonetheless, this test verifies that icp_grad computes a gradient.
    self.assertGreater(err, 1e-3) 
開發者ID:generalized-iou,項目名稱:g-tensorflow-models,代碼行數:16,代碼來源:icp_grad_test.py

示例7: test_grad_transform_same_ego_motion

# 需要導入模塊: from tensorflow.python.ops import gradient_checker [as 別名]
# 或者: from tensorflow.python.ops.gradient_checker import compute_gradient_error [as 別名]
def test_grad_transform_same_ego_motion(self):
    with self.test_session():
      cloud_source = self.small_cloud
      cloud_target = cloud_source + [0.1, 0, 0]
      ego_motion = tf.constant([[0.1, 0.0, 0.0, 0.0, 0.0, 0.0]],
                               dtype=tf.float32)
      transform, unused_residual = self._run_icp(cloud_source, ego_motion,
                                                 cloud_target)
      err = gradient_checker.compute_gradient_error(ego_motion,
                                                    ego_motion.shape.as_list(),
                                                    transform,
                                                    transform.shape.as_list())
    # Since our gradient is an approximation, it doesn't pass a numerical check.
    # Nonetheless, this test verifies that icp_grad computes a gradient.
    self.assertGreater(err, 1e-3) 
開發者ID:generalized-iou,項目名稱:g-tensorflow-models,代碼行數:17,代碼來源:icp_grad_test.py

示例8: test_grad_residual

# 需要導入模塊: from tensorflow.python.ops import gradient_checker [as 別名]
# 或者: from tensorflow.python.ops.gradient_checker import compute_gradient_error [as 別名]
def test_grad_residual(self):
    with self.test_session():
      cloud_source = self.small_cloud
      cloud_target = cloud_source + [0.05, 0, 0]
      ego_motion = self.identity_transform
      unused_transform, residual = self._run_icp(cloud_source, ego_motion,
                                                 cloud_target)
      err = gradient_checker.compute_gradient_error(
          cloud_source, cloud_source.shape.as_list(), residual,
          residual.shape.as_list())
    # Since our gradient is an approximation, it doesn't pass a numerical check.
    # Nonetheless, this test verifies that icp_grad computes a gradient.
    self.assertGreater(err, 1e-3) 
開發者ID:generalized-iou,項目名稱:g-tensorflow-models,代碼行數:15,代碼來源:icp_grad_test.py


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