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

Python array_ops.space_to_depth函数代码示例

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

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



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

示例1: testSpaceToDepth

  def testSpaceToDepth(self):
    for dtype in self.numeric_types:
      self._assertOpOutputMatchesExpected(
          lambda x: array_ops.space_to_depth(x, block_size=2),
          np.array([[[[1], [2]],
                     [[3], [4]]]], dtype=dtype),
          expected=np.array([[[[1, 2, 3, 4]]]], dtype=dtype))

      self._assertOpOutputMatchesExpected(
          lambda x: array_ops.space_to_depth(x, block_size=2),
          np.array([[[[1, 2, 3], [4, 5, 6]],
                     [[7, 8, 9], [10, 11, 12]]]], dtype=dtype),
          expected=np.array([[[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]]]],
                            dtype=dtype))

      self._assertOpOutputMatchesExpected(
          lambda x: array_ops.space_to_depth(x, block_size=2),
          np.array([[[[1], [2], [5], [6]],
                     [[3], [4], [7], [8]],
                     [[9], [10], [13], [14]],
                     [[11], [12], [15], [16]]]], dtype=dtype),
          expected=np.array([[[[1, 2, 3, 4],
                               [5, 6, 7, 8]],
                              [[9, 10, 11, 12],
                               [13, 14, 15, 16]]]], dtype=dtype))
开发者ID:Mazecreator,项目名称:tensorflow,代码行数:25,代码来源:unary_ops_test.py


示例2: compareToTranspose

  def compareToTranspose(self, batch_size, out_height, out_width, in_channels,
                         block_size, data_format, use_gpu):
    in_height = out_height * block_size
    in_width = out_width * block_size
    nhwc_input_shape = [batch_size, in_height, in_width, in_channels]
    nchw_input_shape = [batch_size, in_channels, in_height, in_width]
    total_size = np.prod(nhwc_input_shape)

    if data_format == "NCHW_VECT_C":
      # Initialize the input tensor with qint8 values that circle -127..127.
      x = [((f + 128) % 255) - 127 for f in range(total_size)]
      t = constant_op.constant(x, shape=nhwc_input_shape, dtype=dtypes.float32)
      expected = self.spaceToDepthUsingTranspose(t, block_size, "NHWC")
      t = test_util.NHWCToNCHW_VECT_C(t)
      t, _, _ = gen_array_ops.quantize_v2(t, -128.0, 127.0, dtypes.qint8)
      t = array_ops.space_to_depth(t, block_size, data_format="NCHW_VECT_C")
      t = gen_array_ops.dequantize(t, -128, 127)
      actual = test_util.NCHW_VECT_CToNHWC(t)
    else:
      # Initialize the input tensor with ascending whole numbers as floats.
      x = [f * 1.0 for f in range(total_size)]
      shape = nchw_input_shape if data_format == "NCHW" else nhwc_input_shape
      t = constant_op.constant(x, shape=shape, dtype=dtypes.float32)
      expected = self.spaceToDepthUsingTranspose(t, block_size, data_format)
      actual = array_ops.space_to_depth(t, block_size, data_format=data_format)

    with self.cached_session(use_gpu=use_gpu) as sess:
      actual_vals, expected_vals = sess.run([actual, expected])
      self.assertTrue(np.array_equal(actual_vals, expected_vals))
开发者ID:becster,项目名称:tensorflow,代码行数:29,代码来源:spacetodepth_op_test.py


示例3: testBlockSizeOne

 def testBlockSizeOne(self):
   # The block size is 1. The block size needs to be > 1.
   x_np = [[[[1], [2]], [[3], [4]]]]
   block_size = 1
   with self.assertRaises(ValueError):
     out_tf = array_ops.space_to_depth(x_np, block_size)
     out_tf.eval()
开发者ID:becster,项目名称:tensorflow,代码行数:7,代码来源:spacetodepth_op_test.py


示例4: testInputWrongDimMissingDepth

 def testInputWrongDimMissingDepth(self):
   # The input is missing the last dimension ("depth")
   x_np = [[[1, 2], [3, 4]]]
   block_size = 2
   with self.assertRaises(ValueError):
     out_tf = array_ops.space_to_depth(x_np, block_size)
     out_tf.eval()
开发者ID:becster,项目名称:tensorflow,代码行数:7,代码来源:spacetodepth_op_test.py


示例5: testBlockSize0

 def testBlockSize0(self):
   # The block size is 0.
   x_np = [[[[1], [2]], [[3], [4]]]]
   block_size = 0
   with self.assertRaises(ValueError):
     out_tf = array_ops.space_to_depth(x_np, block_size)
     self.evaluate(out_tf)
开发者ID:zhaoyongke,项目名称:tensorflow,代码行数:7,代码来源:spacetodepth_op_test.py


示例6: compareToTranspose

  def compareToTranspose(self, data_format, use_gpu):
    if use_gpu and not test.is_gpu_available():
      print("gpu not available")
      return

    dtype = dtypes.float32
    batch_size = 3
    height = 4
    width = 6
    channels = 4
    block_size = 2

    if data_format == "NHWC":
      input_shape = [batch_size, height, width, channels]
    elif data_format == "NCHW":
      input_shape = [batch_size, channels, height, width]
    else:
      print("unsupported format")

    # Initialize the input tensor with ascending whole numbers.
    total_size = 1
    for dim_size in input_shape:
      total_size *= dim_size
    x = [f for f in range(total_size)]
    inputs = constant_op.constant(x, shape=input_shape, dtype=dtype)

    expected = self.spaceToDepthUsingTranspose(inputs, block_size, data_format)
    actual = array_ops.space_to_depth(
        inputs, block_size, data_format=data_format)

    with self.test_session(use_gpu=use_gpu) as sess:
      actual_vals, expected_vals = sess.run([actual, expected])
      self.assertTrue(np.array_equal(actual_vals, expected_vals))
开发者ID:Crazyonxh,项目名称:tensorflow,代码行数:33,代码来源:spacetodepth_op_test.py


示例7: testBlockSizeLarger

 def testBlockSizeLarger(self):
   # The block size is too large for this input.
   x_np = [[[[1], [2]], [[3], [4]]]]
   block_size = 10
   with self.assertRaises(ValueError):
     out_tf = array_ops.space_to_depth(x_np, block_size)
     out_tf.eval()
开发者ID:becster,项目名称:tensorflow,代码行数:7,代码来源:spacetodepth_op_test.py


示例8: testBatchSize0

  def testBatchSize0(self):
    block_size = 2
    batch_size = 0
    input_nhwc = array_ops.ones([batch_size, 4, 6, 3])
    x_out = array_ops.ones([batch_size, 2, 3, 12])

    with self.session(use_gpu=False):
      # test NHWC (default) on CPU
      x_tf = array_ops.space_to_depth(input_nhwc, block_size)
      self.assertAllEqual(x_tf.shape, x_out.shape)
      x_tf.eval()
    if test.is_gpu_available():
      with self.session(use_gpu=True):
        # test NHWC (default) on GPU
        x_tf = array_ops.space_to_depth(input_nhwc, block_size)
        self.assertAllEqual(x_tf.shape, x_out.shape)
        x_tf.eval()
开发者ID:becster,项目名称:tensorflow,代码行数:17,代码来源:spacetodepth_op_test.py


示例9: _testOne

 def _testOne(self, inputs, block_size, outputs, dtype=dtypes.float32):
   input_nhwc = math_ops.cast(inputs, dtype)
   with self.cached_session(use_gpu=False):
     # test NHWC (default) on CPU
     x_tf = array_ops.space_to_depth(input_nhwc, block_size)
     self.assertAllEqual(x_tf.eval(), outputs)
   if test.is_gpu_available():
     with self.cached_session(use_gpu=True):
       # test NHWC (default) on GPU
       x_tf = array_ops.space_to_depth(input_nhwc, block_size)
       self.assertAllEqual(x_tf.eval(), outputs)
       # test NCHW on GPU
       input_nchw = test_util.NHWCToNCHW(input_nhwc)
       output_nchw = array_ops.space_to_depth(
           input_nchw, block_size, data_format="NCHW")
       output_nhwc = test_util.NCHWToNHWC(output_nchw)
       self.assertAllEqual(output_nhwc.eval(), outputs)
开发者ID:becster,项目名称:tensorflow,代码行数:17,代码来源:spacetodepth_op_test.py


示例10: _DepthToSpaceGrad

def _DepthToSpaceGrad(op, grad):
  # Its gradient is the opposite op: SpaceToDepth.
  block_size = op.get_attr("block_size")
  data_format = op.get_attr("data_format")
  if data_format == "NCHW_VECT_C":
    raise ValueError("Cannot compute DepthToSpace gradient with NCHW_VECT_C. "
                     "NCHW_VECT_C requires qint8 data type.")
  return array_ops.space_to_depth(grad, block_size, data_format=data_format)
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:8,代码来源:array_grad.py


示例11: _testOne

  def _testOne(self, inputs, block_size, outputs, dtype=dtypes.float32):
    input_nhwc = math_ops.cast(inputs, dtype)
    with test_util.force_cpu():
      # test NHWC (default) on CPU
      x_tf = array_ops.space_to_depth(input_nhwc, block_size)
      self.assertAllEqual(self.evaluate(x_tf), outputs)

    if test_util.is_gpu_available():
      with test_util.force_gpu():
        # test NHWC (default) on GPU
        x_tf = array_ops.space_to_depth(input_nhwc, block_size)
        self.assertAllEqual(self.evaluate(x_tf), outputs)
        # test NCHW on GPU
        input_nchw = test_util.NHWCToNCHW(input_nhwc)
        output_nchw = array_ops.space_to_depth(
            input_nchw, block_size, data_format="NCHW")
        output_nhwc = test_util.NCHWToNHWC(output_nchw)
        self.assertAllEqual(self.evaluate(output_nhwc), outputs)
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:18,代码来源:spacetodepth_op_test.py


示例12: testBatchSize0

  def testBatchSize0(self):
    block_size = 2
    batch_size = 0
    input_nhwc = array_ops.ones([batch_size, 4, 6, 3])
    x_out = array_ops.ones([batch_size, 2, 3, 12])

    with test_util.force_cpu():
      # test NHWC (default) on CPU
      x_tf = array_ops.space_to_depth(input_nhwc, block_size)
      self.assertAllEqual(x_tf.shape, x_out.shape)
      self.evaluate(x_tf)

    if test.is_gpu_available():
      with test_util.use_gpu():
        # test NHWC (default) on GPU
        x_tf = array_ops.space_to_depth(input_nhwc, block_size)
        self.assertAllEqual(x_tf.shape, x_out.shape)
        self.evaluate(x_tf)
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:18,代码来源:spacetodepth_op_test.py


示例13: testBlockSizeNotDivisibleDepth

 def testBlockSizeNotDivisibleDepth(self):
   # The depth is not divisible by the square of the block size.
   x_np = [[[[1, 1, 1, 1],
             [2, 2, 2, 2]],
            [[3, 3, 3, 3],
             [4, 4, 4, 4]]]]
   block_size = 3
   with self.assertRaises(ValueError):
     _ = array_ops.space_to_depth(x_np, block_size)
开发者ID:DjangoPeng,项目名称:tensorflow,代码行数:9,代码来源:depthtospace_op_test.py


示例14: testSpaceToDepthTranspose

 def testSpaceToDepthTranspose(self):
   x = np.arange(5 * 10 * 16 * 7, dtype=np.float32).reshape([5, 10, 16, 7])
   block_size = 2
   paddings = np.zeros((2, 2), dtype=np.int32)
   y1 = self.space_to_batch(x, paddings, block_size=block_size)
   y2 = array_ops.transpose(
       array_ops.space_to_depth(
           array_ops.transpose(x, [3, 1, 2, 0]), block_size=block_size),
       [3, 1, 2, 0])
   with self.test_session(use_gpu=True):
     self.assertAllEqual(y1.eval(), y2.eval())
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:11,代码来源:spacetobatch_op_test.py


示例15: _checkGrad

  def _checkGrad(self, x, block_size):
    assert 4 == x.ndim
    with self.test_session(use_gpu=True):
      tf_x = ops.convert_to_tensor(x)
      tf_y = array_ops.space_to_depth(tf_x, block_size)
      epsilon = 1e-2
      ((x_jacob_t, x_jacob_n)) = gradient_checker.compute_gradient(
          tf_x,
          x.shape,
          tf_y,
          tf_y.get_shape().as_list(),
          x_init_value=x,
          delta=epsilon)

    self.assertAllClose(x_jacob_t, x_jacob_n, rtol=1e-2, atol=epsilon)
开发者ID:1000sprites,项目名称:tensorflow,代码行数:15,代码来源:spacetodepth_op_test.py


示例16: _checkGrad

  def _checkGrad(self, x, block_size, data_format):
    # NCHW is implemented for only GPU.
    if data_format == "NCHW" and not test.is_gpu_available():
      return

    assert 4 == x.ndim
    with self.cached_session(use_gpu=True):
      tf_x = ops.convert_to_tensor(x)
      tf_y = array_ops.space_to_depth(tf_x, block_size, data_format=data_format)
      epsilon = 1e-2
      ((x_jacob_t, x_jacob_n)) = gradient_checker.compute_gradient(
          tf_x,
          x.shape,
          tf_y,
          tf_y.get_shape().as_list(),
          x_init_value=x,
          delta=epsilon)

    self.assertAllClose(x_jacob_t, x_jacob_n, rtol=1e-2, atol=epsilon)
开发者ID:becster,项目名称:tensorflow,代码行数:19,代码来源:spacetodepth_op_test.py


示例17: _DepthToSpaceGrad

def _DepthToSpaceGrad(op, grad):
  # Its gradient is the opposite op: SpaceToDepth.
  block_size = op.get_attr("block_size")
  return array_ops.space_to_depth(grad, block_size)
开发者ID:0ruben,项目名称:tensorflow,代码行数:4,代码来源:array_grad.py


示例18: op

 def op(x):
   return array_ops.space_to_depth(x, block_size=2,
                                   data_format=data_format)
开发者ID:AnddyWang,项目名称:tensorflow,代码行数:3,代码来源:unary_ops_test.py


示例19: _testOne

 def _testOne(self, inputs, block_size, outputs):
   with self.test_session(use_gpu=True):
     x_tf = array_ops.space_to_depth(math_ops.to_float(inputs), block_size)
     self.assertAllEqual(x_tf.eval(), outputs)
开发者ID:1000sprites,项目名称:tensorflow,代码行数:4,代码来源:spacetodepth_op_test.py


示例20: testInputWrongDimMissingBatch

 def testInputWrongDimMissingBatch(self):
   # The input is missing the first dimension ("batch")
   x_np = [[[1], [2]], [[3], [4]]]
   block_size = 2
   with self.assertRaises(ValueError):
     _ = array_ops.space_to_depth(x_np, block_size)
开发者ID:becster,项目名称:tensorflow,代码行数:6,代码来源:spacetodepth_op_test.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python array_ops.sparse_placeholder函数代码示例发布时间:2022-05-27
下一篇:
Python array_ops.space_to_batch_nd函数代码示例发布时间: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