• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python array_ops.strided_slice_grad函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: testInt64Shape

 def testInt64Shape(self):
     with self.test_session(use_gpu=True) as sess:
         original_dy = tf.reshape(tf.cast(tf.range(1, 5, 1), tf.float32), shape=(4, 1, 1))
         original_shape = tf.constant([6, 4, 4], dtype=tf.int64)
         sess.run(tf.global_variables_initializer())
         begin = tf.constant([0, 0, 0], dtype=tf.int64)
         end = tf.constant([4, 1, 1], dtype=tf.int64)
         strides = tf.constant([1, 1, 1], dtype=tf.int64)
         dx = array_ops.strided_slice_grad(original_shape, begin, end, strides, original_dy)
         sess.run(dx)
开发者ID:ppwwyyxx,项目名称:tensorflow,代码行数:10,代码来源:array_ops_test.py


示例2: testHostVsDevice

 def testHostVsDevice(self):
     with self.test_session(use_gpu=True) as sess:
         var2 = tf.Variable(tf.reshape(tf.cast(tf.range(1, 5, 1), tf.float32), shape=(4, 1, 1)))
         varshape = tf.Variable([6, 4, 4], dtype=tf.int32)
         sess.run(tf.global_variables_initializer())
         begin = tf.constant([0, 0, 0])
         end = tf.constant([4, 1, 1])
         strides = tf.constant([1, 1, 1])
         foo = array_ops.strided_slice_grad(varshape, begin, end, strides, var2)
         sess.run(foo)
开发者ID:ppwwyyxx,项目名称:tensorflow,代码行数:10,代码来源:array_ops_test.py


示例3: testMixedIndexTypes

 def testMixedIndexTypes(self):
   with self.test_session(use_gpu=True) as sess:
     original_dy = tf.reshape(
         tf.cast(tf.range(1, 5, 1), tf.float32), shape=(4, 1, 1))
     original_shape = tf.constant([6, 4, 4], dtype=tf.int64)
     sess.run(tf.initialize_all_variables())
     begin = tf.constant([0, 0, 0], dtype=tf.int32)
     end = tf.constant([4, 1, 1], dtype=tf.int64)
     strides = tf.constant([1, 1, 1], dtype=tf.int64)
     with self.assertRaisesRegexp(
         TypeError, "Input 'begin' of 'StridedSliceGrad' Op has type int32"
         " that does not match type int64 of argument 'shape'"):
       dx = array_ops.strided_slice_grad(original_shape, begin, end, strides,
                                         original_dy)
       sess.run(dx)
开发者ID:Qstar,项目名称:tensorflow,代码行数:15,代码来源:array_ops_test.py


示例4: testStridedSliceGradWithNonConstAxis

  def testStridedSliceGradWithNonConstAxis(self):
    if test.is_gpu_available(cuda_only=True):
      random_seed.set_random_seed(0)
      x = random_ops.truncated_normal([1, 784], seed=0)
      conv = _two_layer_model(x)
      end = array_ops.placeholder(dtype='int32')
      shape = array_ops.shape(conv)
      end_val = [1, 2, 3, 4]
      s = array_ops.strided_slice(
          conv, [0, 0, 0, 0], end_val, strides=[1, 2, 3, 1])
      s_grad = array_ops.strided_slice_grad(shape, [0, 0, 0, 0], end,
                                            [1, 2, 3, 1], s)
      output = array_ops.identity(s_grad)

      with session.Session() as sess:
        output_val_ref = sess.run(output, feed_dict={end: end_val})

      with session.Session(config=_get_config()) as sess:
        metadata = config_pb2.RunMetadata()
        output_val = sess.run(
            output, run_metadata=metadata, feed_dict={
                end: end_val
            })

      nodes = []
      num_transposes = 0
      for node in metadata.cost_graph.node:
        if node.name.startswith('LayoutOptimizerTranspose'):
          num_transposes += 1
        nodes.append(node.name)

      # Four transposes were initially added in the Expand phase of
      # LayoutOptimizer; two of them are cancelled out in the Collapse phase.
      expected_num_transposes = 2
      self.assertEqual(expected_num_transposes, num_transposes)
      self.assertIn('LayoutOptimizerTransposeNHWCToNCHW-Conv2D-0', nodes)
      self.assertIn('LayoutOptimizerTransposeNCHWToNHWC-StridedSliceGrad-0-0',
                    nodes)
      self.assertIn('LayoutOptimizerVecPermuteNHWCToNCHW_StridedSliceGrad_2',
                    nodes)
      self.assertIn('LayoutOptimizer-StridedSlice-StridedSliceGrad/begin',
                    nodes)
      self.assertIn('LayoutOptimizer-StridedSlice-StridedSliceGrad/strides',
                    nodes)
      self.assertAllClose(output_val_ref, output_val, atol=1e-3)
开发者ID:autodrive,项目名称:tensorflow,代码行数:45,代码来源:layout_optimizer_test.py


示例5: _StridedSliceGrad

def _StridedSliceGrad(op, grad):
  """Gradient for StridedSlice op."""
  x = array_ops.shape(op.inputs[0])
  begin = op.inputs[1]
  end = op.inputs[2]
  strides = op.inputs[3]

  return array_ops.strided_slice_grad(
      x,
      begin,
      end,
      strides,
      grad,
      begin_mask=op.get_attr("begin_mask"),
      end_mask=op.get_attr("end_mask"),
      ellipsis_mask=op.get_attr("ellipsis_mask"),
      new_axis_mask=op.get_attr("new_axis_mask"),
      shrink_axis_mask=op.get_attr("shrink_axis_mask")), None, None, None
开发者ID:Jackhuang945,项目名称:tensorflow,代码行数:18,代码来源:array_grad.py


示例6: _StridedSliceGrad

def _StridedSliceGrad(op, grad):
  """Gradient for StridedSlice op."""
  begin = op.inputs[1]
  end = op.inputs[2]
  strides = op.inputs[3]
  # StridedSliceGrad requires `x`, `begin`, `end` and `strides` to be of the
  # same dtype so we build a shape of the same type as other args.
  # Note that the choice of `begin` for specifying `out_type` is arbitrary.
  # We could choose any of {begin|end|strides}.dtype since they are required to
  # be the same.
  x = array_ops.shape(op.inputs[0], out_type=begin.dtype)

  return array_ops.strided_slice_grad(
      x,
      begin,
      end,
      strides,
      grad,
      begin_mask=op.get_attr("begin_mask"),
      end_mask=op.get_attr("end_mask"),
      ellipsis_mask=op.get_attr("ellipsis_mask"),
      new_axis_mask=op.get_attr("new_axis_mask"),
      shrink_axis_mask=op.get_attr("shrink_axis_mask")), None, None, None
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:23,代码来源:array_grad.py


示例7: ssg_test

 def ssg_test(x):
   return array_ops.strided_slice_grad(*x, shrink_axis_mask=0x4,
                                       new_axis_mask=0x1)
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:3,代码来源:nary_ops_test.py


示例8: testStridedSliceGrad

  def testStridedSliceGrad(self):
    # Tests cases where input shape is empty.
    self._testNAry(lambda x: array_ops.strided_slice_grad(*x),
                   [np.array([], dtype=np.int32),
                    np.array([], dtype=np.int32),
                    np.array([], dtype=np.int32),
                    np.array([], dtype=np.int32),
                    np.float32(0.5)],
                   expected=np.array(np.float32(0.5), dtype=np.float32))

    # Tests case where input shape is non-empty, but gradients are empty.
    self._testNAry(lambda x: array_ops.strided_slice_grad(*x),
                   [np.array([3], dtype=np.int32),
                    np.array([0], dtype=np.int32),
                    np.array([0], dtype=np.int32),
                    np.array([1], dtype=np.int32),
                    np.array([], dtype=np.float32)],
                   expected=np.array([0, 0, 0], dtype=np.float32))

    self._testNAry(lambda x: array_ops.strided_slice_grad(*x),
                   [np.array([3, 0], dtype=np.int32),
                    np.array([1, 0], dtype=np.int32),
                    np.array([3, 0], dtype=np.int32),
                    np.array([1, 1], dtype=np.int32),
                    np.array([[], []], dtype=np.float32)],
                   expected=np.array([[], [], []], dtype=np.float32))

    self._testNAry(lambda x: array_ops.strided_slice_grad(*x),
                   [np.array([3, 3], dtype=np.int32),
                    np.array([1, 1], dtype=np.int32),
                    np.array([3, 3], dtype=np.int32),
                    np.array([1, 1], dtype=np.int32),
                    np.array([[5, 6], [8, 9]], dtype=np.float32)],
                   expected=np.array([[0, 0, 0], [0, 5, 6], [0, 8, 9]],
                                     dtype=np.float32))

    def ssg_test(x):
      return array_ops.strided_slice_grad(*x, shrink_axis_mask=0x4,
                                          new_axis_mask=0x1)

    self._testNAry(ssg_test,
                   [np.array([3, 1, 3], dtype=np.int32),
                    np.array([0, 0, 0, 2], dtype=np.int32),
                    np.array([0, 3, 1, -4], dtype=np.int32),
                    np.array([1, 2, 1, -3], dtype=np.int32),
                    np.array([[[1], [2]]], dtype=np.float32)],
                   expected=np.array([[[0, 0, 1]], [[0, 0, 0]], [[0, 0, 2]]],
                                     dtype=np.float32))

    ssg_test2 = lambda x: array_ops.strided_slice_grad(*x, new_axis_mask=0x15)
    self._testNAry(ssg_test2,
                   [np.array([4, 4], dtype=np.int32),
                    np.array([0, 0, 0, 1, 0], dtype=np.int32),
                    np.array([0, 3, 0, 4, 0], dtype=np.int32),
                    np.array([1, 2, 1, 2, 1], dtype=np.int32),
                    np.array([[[[[1], [2]]], [[[3], [4]]]]], dtype=np.float32)],
                   expected=np.array([[0, 1, 0, 2], [0, 0, 0, 0], [0, 3, 0, 4],
                                      [0, 0, 0, 0]], dtype=np.float32))

    self._testNAry(lambda x: array_ops.strided_slice_grad(*x),
                   [np.array([3, 3], dtype=np.int32),
                    np.array([0, 2], dtype=np.int32),
                    np.array([2, 0], dtype=np.int32),
                    np.array([1, -1], dtype=np.int32),
                    np.array([[1, 2], [3, 4]], dtype=np.float32)],
                   expected=np.array([[0, 2, 1], [0, 4, 3], [0, 0, 0]],
                                     dtype=np.float32))

    self._testNAry(lambda x: array_ops.strided_slice_grad(*x),
                   [np.array([3, 3], dtype=np.int32),
                    np.array([2, 2], dtype=np.int32),
                    np.array([0, 1], dtype=np.int32),
                    np.array([-1, -2], dtype=np.int32),
                    np.array([[1], [2]], dtype=np.float32)],
                   expected=np.array([[0, 0, 0], [0, 0, 2], [0, 0, 1]],
                                     dtype=np.float32))
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:76,代码来源:nary_ops_test.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python array_ops.tile函数代码示例发布时间:2022-05-27
下一篇:
Python array_ops.strided_slice函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap