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

Python tensorflow.space_to_depth函数代码示例

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

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



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

示例1: testDepthInterleaved

 def testDepthInterleaved(self):
   x_np = [[[[1, 10], [2, 20]],
            [[3, 30], [4, 40]]]]
   with self.test_session(use_gpu=False):
     block_size = 2
     out_tf = tf.space_to_depth(x_np, block_size)
     self.assertAllEqual(out_tf.eval(), [[[[1, 10, 2, 20, 3, 30, 4, 40]]]])
开发者ID:CdricGmd,项目名称:tensorflow,代码行数:7,代码来源:spacetodepth_op_test.py


示例2: testBlockSizeNotDivisibleWidth

 def testBlockSizeNotDivisibleWidth(self):
   # The block size divides width but not height.
   x_np = [[[[1], [2], [3]],
            [[3], [4], [7]]]]
   block_size = 3
   with self.assertRaises(IndexError):
     _ = tf.space_to_depth(x_np, block_size)
开发者ID:CdricGmd,项目名称:tensorflow,代码行数:7,代码来源:spacetodepth_op_test.py


示例3: testBlockSizeNotDivisibleBoth

 def testBlockSizeNotDivisibleBoth(self):
   # The block size does not divide neither width or height.
   x_np = [[[[1], [2]],
            [[3], [4]]]]
   block_size = 3
   with self.assertRaises(IndexError):
     _ = tf.space_to_depth(x_np, block_size)
开发者ID:CdricGmd,项目名称:tensorflow,代码行数:7,代码来源:spacetodepth_op_test.py


示例4: testBasic

 def testBasic(self):
   x_np = [[[[1], [2]],
            [[3], [4]]]]
   with self.test_session(use_gpu=False):
     block_size = 2
     out_tf = tf.space_to_depth(x_np, block_size)
     self.assertAllEqual(out_tf.eval(), [[[[1, 2, 3, 4]]]])
开发者ID:CdricGmd,项目名称:tensorflow,代码行数:7,代码来源:spacetodepth_op_test.py


示例5: 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):
     _ = tf.space_to_depth(x_np, block_size)
开发者ID:CdricGmd,项目名称:tensorflow,代码行数:7,代码来源:spacetodepth_op_test.py


示例6: testBlockSize0

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


示例7: 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 = tf.space_to_depth(x_np, block_size)
     out_tf.eval()
开发者ID:CdricGmd,项目名称:tensorflow,代码行数:8,代码来源:spacetodepth_op_test.py


示例8: 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(IndexError):
     out_tf = tf.space_to_depth(x_np, block_size)
     out_tf.eval()
开发者ID:CdricGmd,项目名称:tensorflow,代码行数:8,代码来源:spacetodepth_op_test.py


示例9: testBlockSizeNotDivisibleHeight

 def testBlockSizeNotDivisibleHeight(self):
   # The block size divides height but not width.
   x_np = [[[[1], [2]],
            [[3], [4]],
            [[5], [6]]]]
   block_size = 3
   with self.assertRaises(IndexError):
     _ = tf.space_to_depth(x_np, block_size)
开发者ID:CdricGmd,项目名称:tensorflow,代码行数:8,代码来源:spacetodepth_op_test.py


示例10: 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 = tf.space_to_batch(x, paddings, block_size=block_size)
     y2 = tf.transpose(tf.space_to_depth(tf.transpose(x, [3, 1, 2, 0]), block_size=block_size), [3, 1, 2, 0])
     with self.test_session():
         self.assertAllEqual(y1.eval(), y2.eval())
开发者ID:passiweinberger,项目名称:tensorflow,代码行数:8,代码来源:spacetobatch_op_test.py


示例11: testDepthInterleavedDepth3

 def testDepthInterleavedDepth3(self):
   x_np = [[[[1, 2, 3], [4, 5, 6]],
            [[7, 8, 9], [10, 11, 12]]]]
   with self.test_session(use_gpu=False):
     block_size = 2
     out_tf = tf.space_to_depth(x_np, block_size)
     self.assertAllEqual(out_tf.eval(),
                         [[[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]]]])
开发者ID:CdricGmd,项目名称:tensorflow,代码行数:8,代码来源:spacetodepth_op_test.py


示例12: 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 = tf.space_to_depth(x_np, block_size)
     out_tf.eval()
开发者ID:CdricGmd,项目名称:tensorflow,代码行数:8,代码来源: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(IndexError):
     _ = tf.space_to_depth(x_np, block_size)
开发者ID:AdamPalmar,项目名称:tensorflow,代码行数:9,代码来源:depthtospace_op_test.py


示例14: testLargerInput4x4

  def testLargerInput4x4(self):
    x_np = [[[[1], [2], [5], [6]],
             [[3], [4], [7], [8]],
             [[9], [10], [13], [14]],
             [[11], [12], [15], [16]]]]

    with self.test_session(use_gpu=False):
      block_size = 4
      out_tf = tf.space_to_depth(x_np, block_size)
      self.assertAllEqual(
          out_tf.eval(),
          [[[[1, 2, 5, 6, 3, 4, 7, 8, 9, 10, 13, 14, 11, 12, 15, 16]]]])
开发者ID:CdricGmd,项目名称:tensorflow,代码行数:12,代码来源:spacetodepth_op_test.py


示例15: testDepthInterleavedLarge

 def testDepthInterleavedLarge(self):
   x_np = [[[[1, 10], [2, 20], [5, 50], [6, 60]],
            [[3, 30], [4, 40], [7, 70], [8, 80]],
            [[9, 90], [10, 100], [13, 130], [14, 140]],
            [[11, 110], [12, 120], [15, 150], [16, 160]]]]
   with self.test_session(use_gpu=False):
     block_size = 2
     out_tf = tf.space_to_depth(x_np, block_size)
     self.assertAllEqual(out_tf.eval(),
                         [[[[1, 10, 2, 20, 3, 30, 4, 40],
                            [5, 50, 6, 60, 7, 70, 8, 80]],
                           [[9, 90, 10, 100, 11, 110, 12, 120],
                            [13, 130, 14, 140, 15, 150, 16, 160]]]])
开发者ID:CdricGmd,项目名称:tensorflow,代码行数:13,代码来源:spacetodepth_op_test.py


示例16: testNonSquare

 def testNonSquare(self):
   x_np = [[[[1, 10], [2, 20]],
            [[3, 30], [4, 40]],
            [[5, 50], [6, 60]],
            [[7, 70], [8, 80]],
            [[9, 90], [10, 100]],
            [[11, 110], [12, 120]]]]
   with self.test_session(use_gpu=False):
     block_size = 2
     out_tf = tf.space_to_depth(x_np, block_size)
     self.assertAllEqual(out_tf.eval(),
                         [[[[1, 10, 2, 20, 3, 30, 4, 40]],
                           [[5, 50, 6, 60, 7, 70, 8, 80]],
                           [[9, 90, 10, 100, 11, 110, 12, 120]]]])
开发者ID:CdricGmd,项目名称:tensorflow,代码行数:14,代码来源:spacetodepth_op_test.py


示例17: _checkGrad

  def _checkGrad(self, x, block_size):
    assert 4 == x.ndim
    with self.test_session():
      tf_x = tf.convert_to_tensor(x)
      tf_y = tf.space_to_depth(tf_x, block_size)
      epsilon = 1e-2
      ((x_jacob_t, x_jacob_n)) = tf.test.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:CdricGmd,项目名称:tensorflow,代码行数:15,代码来源:spacetodepth_op_test.py


示例18: __call__

 def __call__(self, shape, dtype='float32'):  # tf needs partition_info=None
     shape = list(shape)
     if self.scale == 1:
         return self.initializer(shape)
     new_shape = shape[:3] + [shape[3] // (self.scale ** 2)]
     if type(self.initializer) is dict:
         self.initializer = initializers.deserialize(self.initializer)
     var_x = self.initializer(new_shape, dtype)
     var_x = tf.transpose(var_x, perm=[2, 0, 1, 3])
     var_x = tf.image.resize_nearest_neighbor(
                      var_x,
                      size=(shape[0] * self.scale, shape[1] * self.scale),
                      align_corners=True)
     var_x = tf.space_to_depth(var_x, block_size=self.scale, data_format='NHWC')
     var_x = tf.transpose(var_x, perm=[1, 2, 0, 3])
     return var_x
开发者ID:stonezuohui,项目名称:faceswap,代码行数:16,代码来源:initializers.py


示例19: icnr_keras

def icnr_keras(shape, dtype=None):
    """
    Custom initializer for subpix upscaling
    From https://github.com/kostyaev/ICNR
    Note: upscale factor is fixed to 2, and the base initializer is fixed to random normal.
    """
    # TODO Roll this into ICNR_init when porting GAN 2.2
    shape = list(shape)
    scale = 2
    initializer = tf.keras.initializers.RandomNormal(0, 0.02)

    new_shape = shape[:3] + [int(shape[3] / (scale ** 2))]
    var_x = initializer(new_shape, dtype)
    var_x = tf.transpose(var_x, perm=[2, 0, 1, 3])
    var_x = tf.image.resize_nearest_neighbor(var_x, size=(shape[0] * scale, shape[1] * scale))
    var_x = tf.space_to_depth(var_x, block_size=scale)
    var_x = tf.transpose(var_x, perm=[1, 2, 0, 3])
    return var_x
开发者ID:stonezuohui,项目名称:faceswap,代码行数:18,代码来源:initializers.py


示例20: read_and_batchify_image

def read_and_batchify_image(image_path, shape, image_type="jpg"):
    """Return the original image as read from image_path and the image splitted as a batch tensor.
    Args:
        image_path: image path
        shape: batch shape, like: [no_patches_per_side**2, patch_side, patch_side, 3]
        image_type: image type
    Returns:
        original_image, patches
        where original image is a tensor in the format [widht, height 3]
        and patches is a tensor of processed images, ready to be classified, with size
        [batch_size, w, h, 3]"""

    original_image = read_image(image_path, 3, image_type)

    # extract values from shape
    patch_side = shape[1]
    no_patches_per_side = int(math.sqrt(shape[0]))
    resized_input_side = patch_side * no_patches_per_side

    resized_image = resize_bl(original_image, resized_input_side)

    resized_image = tf.expand_dims(resized_image, 0)
    patches = tf.space_to_depth(resized_image, patch_side)
    print(patches)
    patches = tf.squeeze(patches, [0])  #4,4,192*192*3
    print(patches)
    patches = tf.reshape(patches,
                         [no_patches_per_side**2, patch_side, patch_side, 3])
    print(patches)
    patches_a = tf.split(0, no_patches_per_side**2, patches)
    print(patches_a)
    normalized_patches = []
    for patch in patches_a:
        patch_as_input_image = zm_mp(
            tf.reshape(tf.squeeze(patch, [0]), [patch_side, patch_side, 3]))
        print(patch_as_input_image)
        normalized_patches.append(patch_as_input_image)

    # the last patch is not a "patch" but the whole image resized to patch_side² x 3
    # to give a glance to the whole image, in parallel with the patch analysis
    normalized_patches.append(zm_mp(resize_bl(original_image, patch_side)))
    batch_of_patches = tf.pack(normalized_patches)
    return tf.image.convert_image_dtype(original_image,
                                        tf.uint8), batch_of_patches
开发者ID:galeone,项目名称:pgnet,代码行数:44,代码来源:image_processing.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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