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

Python tensorflow.space_to_batch函数代码示例

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

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



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

示例1: testBlockSizeNotDivisibleBoth

 def testBlockSizeNotDivisibleBoth(self):
   # The block size does not divide neither width or height.
   x_np = [[[[1], [2]], [[3], [4]]]]
   paddings = np.zeros((2, 2), dtype=np.int32)
   block_size = 3
   with self.assertRaises(IndexError):
     _ = tf.space_to_batch(x_np, paddings, block_size)
开发者ID:0-T-0,项目名称:tensorflow,代码行数:7,代码来源:spacetobatch_op_test.py


示例2: testInputWrongDimMissingBatch

 def testInputWrongDimMissingBatch(self):
   # The input is missing the first dimension ("batch")
   x_np = [[[1], [2]], [[3], [4]]]
   paddings = np.zeros((2, 2), dtype=np.int32)
   block_size = 2
   with self.assertRaises(ValueError):
     _ = tf.space_to_batch(x_np, paddings, block_size)
开发者ID:0-T-0,项目名称:tensorflow,代码行数:7,代码来源:spacetobatch_op_test.py


示例3: testBlockSizeNotDivisibleHeight

 def testBlockSizeNotDivisibleHeight(self):
   # The block size divides height but not width.
   x_np = [[[[1], [2]], [[3], [4]], [[5], [6]]]]
   paddings = np.zeros((2, 2), dtype=np.int32)
   block_size = 3
   with self.assertRaises(IndexError):
     _ = tf.space_to_batch(x_np, paddings, block_size)
开发者ID:0-T-0,项目名称:tensorflow,代码行数:7,代码来源:spacetobatch_op_test.py


示例4: testBlockSizeNotDivisibleWidth

 def testBlockSizeNotDivisibleWidth(self):
   # The block size divides width but not height.
   x_np = [[[[1], [2], [3]], [[3], [4], [7]]]]
   paddings = np.zeros((2, 2), dtype=np.int32)
   block_size = 3
   with self.assertRaises(ValueError):
     _ = tf.space_to_batch(x_np, paddings, block_size)
开发者ID:apollos,项目名称:tensorflow,代码行数:7,代码来源:spacetobatch_op_test.py


示例5: testBlockSizeLarger

 def testBlockSizeLarger(self):
   # The block size is too large for this input.
   x_np = [[[[1], [2]], [[3], [4]]]]
   paddings = np.zeros((2, 2), dtype=np.int32)
   block_size = 10
   with self.assertRaises(IndexError):
     out_tf = tf.space_to_batch(x_np, paddings, block_size)
     out_tf.eval()
开发者ID:0-T-0,项目名称:tensorflow,代码行数:8,代码来源:spacetobatch_op_test.py


示例6: testBlockSizeOne

 def testBlockSizeOne(self):
   # The block size is 1. The block size needs to be > 1.
   x_np = [[[[1], [2]], [[3], [4]]]]
   paddings = np.zeros((2, 2), dtype=np.int32)
   block_size = 1
   with self.assertRaises(ValueError):
     out_tf = tf.space_to_batch(x_np, paddings, block_size)
     out_tf.eval()
开发者ID:0-T-0,项目名称:tensorflow,代码行数:8,代码来源:spacetobatch_op_test.py


示例7: 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


示例8: testAtrousSequence

  def testAtrousSequence(self):
    """Tests optimization of sequence of atrous convolutions.

    Verifies that a sequence of `atrous_conv2d` operations with identical `rate`
    parameters, 'SAME' `padding`, and `filters` with odd heights/ widths:

        net = atrous_conv2d(net, filters1, rate, padding="SAME")
        net = atrous_conv2d(net, filters2, rate, padding="SAME")
        ...
        net = atrous_conv2d(net, filtersK, rate, padding="SAME")

    is equivalent to:

        pad = ...  # padding so that the input dims are multiples of rate
        net = space_to_batch(net, paddings=pad, block_size=rate)
        net = conv2d(net, filters1, strides=[1, 1, 1, 1], padding="SAME")
        net = conv2d(net, filters2, strides=[1, 1, 1, 1], padding="SAME")
        ...
        net = conv2d(net, filtersK, strides=[1, 1, 1, 1], padding="SAME")
        net = batch_to_space(net, crops=pad, block_size=rate)
    """
    padding = "SAME"  # The padding needs to be "SAME"
    np.random.seed(1)  # Make it reproducible.

    default_graph_controller = env.g.as_default()
    default_graph_controller.__enter__()

    with self.test_session():
      # Input: [batch, height, width, input_depth]
#      for height in range(15, 17):
      for height in range(15, 16):
#        for width in range(15, 17):
        for width in range(15, 16):
          x_shape = [3, height, width, 2]
          x = np.random.random_sample(x_shape).astype(np.float32)

          for kernel in [1]:  # The kernel size needs to be odd.
#          for kernel in [1, 3, 5]:  # The kernel size needs to be odd.
            # Filter: [kernel_height, kernel_width, input_depth, output_depth]
            f_shape = [kernel, kernel, 2, 2]
            f = 1e-2 * np.random.random_sample(f_shape).astype(np.float32)

            for rate in range(2, 3):
#            for rate in range(2, 4):
              # y1: three atrous_conv2d in a row.
              y1 = tf.nn.atrous_conv2d(x, f, rate, padding=padding)
              y1 = tf.nn.atrous_conv2d(y1, f, rate, padding=padding)
              y1 = tf.nn.atrous_conv2d(y1, f, rate, padding=padding)
              # y2: space_to_batch, three conv2d in a row, batch_to_space
              pad_bottom = 0 if height % rate == 0 else rate - height % rate
              pad_right = 0 if width % rate == 0 else rate - width % rate
              pad = [[0, pad_bottom], [0, pad_right]]
              y2 = tf.space_to_batch(x, paddings=pad, block_size=rate)
              y2 = tf.nn.conv2d(y2, f, strides=[1, 1, 1, 1], padding=padding)
              y2 = tf.nn.conv2d(y2, f, strides=[1, 1, 1, 1], padding=padding)
              y2 = tf.nn.conv2d(y2, f, strides=[1, 1, 1, 1], padding=padding)
              y2 = tf.batch_to_space(y2, crops=pad, block_size=rate)
              self.assertAllClose(y1.eval(), y2.eval(), rtol=1e-2, atol=1e-2)
开发者ID:yaroslavvb,项目名称:imperative,代码行数:58,代码来源:nn_test.py


示例9: _testPad

 def _testPad(self, inputs, paddings, block_size, outputs):
     for use_gpu in [False, True]:
         with self.test_session(use_gpu=use_gpu):
             # outputs = space_to_batch(inputs)
             x_tf = tf.space_to_batch(tf.to_float(inputs), paddings, block_size=block_size)
             self.assertAllEqual(x_tf.eval(), outputs)
             # inputs = batch_to_space(outputs)
             x_tf = tf.batch_to_space(tf.to_float(outputs), paddings, block_size=block_size)
             self.assertAllEqual(x_tf.eval(), inputs)
开发者ID:passiweinberger,项目名称:tensorflow,代码行数:9,代码来源:spacetobatch_op_test.py


示例10: _checkGrad

    def _checkGrad(self, x, paddings, block_size):
        assert 4 == x.ndim
        with self.test_session():
            tf_x = tf.convert_to_tensor(x)
            tf_y = tf.space_to_batch(tf_x, paddings, block_size)
            epsilon = 1e-5
            ((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:passiweinberger,项目名称:tensorflow,代码行数:11,代码来源:spacetobatch_op_test.py


示例11: atrous_conv2d

def atrous_conv2d(value, filters, rate, name):
    """ Returns the result of a convolution with holes from value and filters.
    Do not use the tensorflow implementation because of issues with shape definition
    of the result. The semantic is the same.
    It uses only the "VALID" padding.

    Warning: this implementation is PGNet specific. It's used only to define the last
    convolutional layer and therefore depends on pgnet constants
    """

    pad_top = 0
    pad_bottom = 0
    pad_left = 0
    pad_right = 0

    in_height = value.get_shape()[1].value + pad_top + pad_bottom
    in_width = value.get_shape()[2].value + pad_left + pad_right

    # More padding so that rate divides the height and width of the input.
    pad_bottom_extra = (rate - in_height % rate) % rate
    pad_right_extra = (rate - in_width % rate) % rate

    # The paddings argument to space_to_batch includes both padding components.
    space_to_batch_pad = ((pad_top, pad_bottom + pad_bottom_extra),
                          (pad_left, pad_right + pad_right_extra))

    value = tf.space_to_batch(
        input=value, paddings=space_to_batch_pad, block_size=rate)

    value = tf.nn.conv2d(
        input=value,
        filter=filters,
        strides=(1, LAST_CONV_OUTPUT_STRIDE, LAST_CONV_OUTPUT_STRIDE, 1),
        padding="VALID",
        name=name)

    # The crops argument to batch_to_space is just the extra padding component.
    batch_to_space_crop = ((0, pad_bottom_extra), (0, pad_right_extra))

    value = tf.batch_to_space(
        input=value, crops=batch_to_space_crop, block_size=rate)

    return value
开发者ID:galeone,项目名称:pgnet,代码行数:43,代码来源:model.py


示例12: testUnknownShape

 def testUnknownShape(self):
     t = tf.space_to_batch(tf.placeholder(tf.float32), tf.placeholder(tf.int32), block_size=4)
     self.assertEqual(4, t.get_shape().ndims)
开发者ID:passiweinberger,项目名称:tensorflow,代码行数:3,代码来源:spacetobatch_op_test.py


示例13: space_to_batch

 def space_to_batch(*args, **kwargs):
   return tf.space_to_batch(*args, **kwargs)
开发者ID:821760408-sp,项目名称:tensorflow,代码行数:2,代码来源:spacetobatch_op_test.py


示例14: build

    def build(self, rgb, train=False, num_classes=20, random_init_fc8=False,
              debug=False, use_dilated=False):
        """
        Build the VGG model using loaded weights
        Parameters
        ----------
        rgb: image batch tensor
            Image in rgb shap. Scaled to Intervall [0, 255]
        train: bool
            Whether to build train or inference graph
        num_classes: int
            How many classes should be predicted (by fc8)
        random_init_fc8 : bool
            Whether to initialize fc8 layer randomly.
            Finetuning is required in this case.
        debug: bool
            Whether to print additional Debug Information.
        """
        # Convert RGB to BGR

        with tf.name_scope('Processing'):

            red, green, blue = tf.split(rgb, 3, 3)
            # assert red.get_shape().as_list()[1:] == [224, 224, 1]
            # assert green.get_shape().as_list()[1:] == [224, 224, 1]
            # assert blue.get_shape().as_list()[1:] == [224, 224, 1]
            bgr = tf.concat([
                blue - VGG_MEAN[0],
                green - VGG_MEAN[1],
                red - VGG_MEAN[2],
            ], 3)

            if debug:
                bgr = tf.Print(bgr, [tf.shape(bgr)],
                               message='Shape of input image: ',
                               summarize=4, first_n=1)

        self.conv1_1 = self._conv_layer(bgr, "conv1_1")
        self.conv1_2 = self._conv_layer(self.conv1_1, "conv1_2")
        self.pool1 = self._max_pool(self.conv1_2, 'pool1', debug)

        self.conv2_1 = self._conv_layer(self.pool1, "conv2_1")
        self.conv2_2 = self._conv_layer(self.conv2_1, "conv2_2")
        self.pool2 = self._max_pool(self.conv2_2, 'pool2', debug)

        self.conv3_1 = self._conv_layer(self.pool2, "conv3_1")
        self.conv3_2 = self._conv_layer(self.conv3_1, "conv3_2")
        self.conv3_3 = self._conv_layer(self.conv3_2, "conv3_3")
        self.pool3 = self._max_pool(self.conv3_3, 'pool3', debug)

        self.conv4_1 = self._conv_layer(self.pool3, "conv4_1")
        self.conv4_2 = self._conv_layer(self.conv4_1, "conv4_2")
        self.conv4_3 = self._conv_layer(self.conv4_2, "conv4_3")

        if use_dilated:
            pad = [[0, 0], [0, 0]]
            self.pool4 = tf.nn.max_pool(self.conv4_3, ksize=[1, 2, 2, 1],
                                        strides=[1, 1, 1, 1],
                                        padding='SAME', name='pool4')
            self.pool4 = tf.space_to_batch(self.pool4,
                                           paddings=pad, block_size=2)
        else:
            self.pool4 = self._max_pool(self.conv4_3, 'pool4', debug)

        self.conv5_1 = self._conv_layer(self.pool4, "conv5_1")
        self.conv5_2 = self._conv_layer(self.conv5_1, "conv5_2")
        self.conv5_3 = self._conv_layer(self.conv5_2, "conv5_3")
        if use_dilated:
            pad = [[0, 0], [0, 0]]
            self.pool5 = tf.nn.max_pool(self.conv5_3, ksize=[1, 2, 2, 1],
                                        strides=[1, 1, 1, 1],
                                        padding='SAME', name='pool5')
            self.pool5 = tf.space_to_batch(self.pool5,
                                           paddings=pad, block_size=2)
        else:
            self.pool5 = self._max_pool(self.conv5_3, 'pool5', debug)

        self.fc6 = self._fc_layer(self.pool5, "fc6")

        if train:
            self.fc6 = tf.nn.dropout(self.fc6, 0.5)

        self.fc7 = self._fc_layer(self.fc6, "fc7")
        if train:
            self.fc7 = tf.nn.dropout(self.fc7, 0.5)

        if use_dilated:
            self.pool5 = tf.batch_to_space(self.pool5, crops=pad, block_size=2)
            self.pool5 = tf.batch_to_space(self.pool5, crops=pad, block_size=2)
            self.fc7 = tf.batch_to_space(self.fc7, crops=pad, block_size=2)
            self.fc7 = tf.batch_to_space(self.fc7, crops=pad, block_size=2)
            return

        if random_init_fc8:
            self.score_fr = self._score_layer(self.fc7, "score_fr",
                                              num_classes)
        else:
            self.score_fr = self._fc_layer(self.fc7, "score_fr",
                                           num_classes=num_classes,
                                           relu=False)
#.........这里部分代码省略.........
开发者ID:MarvinTeichmann,项目名称:tensorflow-fcn,代码行数:101,代码来源:fcn8_vgg.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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