当前位置: 首页>>代码示例>>Python>>正文


Python tensorflow.space_to_depth方法代码示例

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


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

示例1: yolo_body

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import space_to_depth [as 别名]
def yolo_body(inputs, num_anchors, num_classes):
    """Create YOLO_V2 model CNN body in Keras."""
    darknet = Model(inputs, darknet_body()(inputs))
    conv13 = darknet.get_layer('batchnormalization_13').output
    conv20 = compose(
        DarknetConv2D_BN_Leaky(1024, 3, 3),
        DarknetConv2D_BN_Leaky(1024, 3, 3))(darknet.output)

    # TODO: Allow Keras Lambda to use func arguments for output_shape?
    conv13_reshaped = Lambda(
        space_to_depth_x2,
        output_shape=space_to_depth_x2_output_shape,
        name='space_to_depth')(conv13)

    # Concat conv13 with conv20.
    x = merge([conv13_reshaped, conv20], mode='concat')
    x = DarknetConv2D_BN_Leaky(1024, 3, 3)(x)
    x = DarknetConv2D(num_anchors * (num_classes + 5), 1, 1)(x)
    return Model(inputs, x) 
开发者ID:PiSimo,项目名称:PiCamNN,代码行数:21,代码来源:keras_yolo.py

示例2: yolo_body

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import space_to_depth [as 别名]
def yolo_body(inputs, num_anchors, num_classes):
    """Create YOLO_V2 model CNN body in Keras."""
    darknet = Model(inputs, darknet_body()(inputs))
    conv20 = compose(
        DarknetConv2D_BN_Leaky(1024, (3, 3)),
        DarknetConv2D_BN_Leaky(1024, (3, 3)))(darknet.output)

    conv13 = darknet.layers[43].output
    conv21 = DarknetConv2D_BN_Leaky(64, (1, 1))(conv13)
    # TODO: Allow Keras Lambda to use func arguments for output_shape?
    conv21_reshaped = Lambda(
        space_to_depth_x2,
        output_shape=space_to_depth_x2_output_shape,
        name='space_to_depth')(conv21)

    x = concatenate([conv21_reshaped, conv20])
    x = DarknetConv2D_BN_Leaky(1024, (3, 3))(x)
    x = DarknetConv2D(num_anchors * (num_classes + 5), (1, 1))(x)
    return Model(inputs, x) 
开发者ID:kaka-lin,项目名称:object-detection,代码行数:21,代码来源:keras_yolo.py

示例3: _checkGrad

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import space_to_depth [as 别名]
def _checkGrad(self, x, block_size):
    assert 4 == x.ndim
    with self.test_session(use_gpu=True):
      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)

  # Tests a gradient for space_to_depth of x which is a four dimensional
  # tensor of shape [b, h * block_size, w * block_size, d]. 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:20,代码来源:spacetodepth_op_test.py

示例4: build_graph

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import space_to_depth [as 别名]
def build_graph(self):
    super(FFDNet, self).build_graph()  # build inputs placeholder
    with tf.variable_scope(self.name):
      # build layers
      inputs = self.inputs_preproc[-1] / 255
      if self.training:
        sigma = tf.random_uniform((), maxval=self.sigma / 255)
        inputs += tf.random_normal(tf.shape(inputs)) * sigma
      else:
        sigma = self.sigma / 255
      inputs = tf.space_to_depth(inputs, block_size=self.space_down)
      noise_map = tf.ones_like(inputs)[..., 0:1] * sigma
      x = tf.concat([inputs, noise_map], axis=-1)
      x = self.relu_conv2d(x, 64, 3)
      for i in range(1, self.layers - 1):
        x = self.bn_relu_conv2d(x, 64, 3, use_bias=False)
      # the last layer w/o BN and ReLU
      x = self.conv2d(x, self.channel * self.space_down ** 2, 3)
      denoised = tf.depth_to_space(x, block_size=self.space_down)
      self.outputs.append(denoised * 255) 
开发者ID:LoSealL,项目名称:VideoSuperResolution,代码行数:22,代码来源:FFDNet.py

示例5: compute_repeatable_loss

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import space_to_depth [as 别名]
def compute_repeatable_loss(pred_d_heatmaps, trans_heatmaps, block_size, name='REPEAT-LOSS'):
    '''
    Args:
        pred_d_heatmaps: [batch, height/N, width/N, N**2+1]
        trans_heatmaps: [batch, height, width, 1]
    '''
    with tf.name_scope(name):
        trans_d_heatmaps = tf.space_to_depth(trans_heatmaps, block_size)
        kp_bg_map = tf.reduce_sum(trans_d_heatmaps, axis=-1, keep_dims=True)
        kp_bg_map = tf.cast(tf.less(kp_bg_map, 1.0), tf.float32)
        kp_fg_map = 1.0 - tf.squeeze(kp_bg_map, axis=-1)

        trans_d_heatmaps = tf.concat([trans_d_heatmaps, kp_bg_map], axis=3) # add BG channels

        xentropy = tf.nn.softmax_cross_entropy_with_logits(labels=trans_d_heatmaps,
                                                        logits=pred_d_heatmaps) # shape = [batch,height/N,width/N]
        kp_count = tf.maximum(1.0, tf.reduce_sum(kp_fg_map))
        repeat_loss = tf.div(tf.reduce_sum(kp_fg_map * xentropy), kp_count)

        return repeat_loss 
开发者ID:ethz-asl,项目名称:hfnet,代码行数:22,代码来源:det_tools.py

示例6: detector_loss

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import space_to_depth [as 别名]
def detector_loss(inp, out, config):
    if 'keypoint_map' in inp:  # hard labels
        labels = tf.to_float(inp['keypoint_map'][..., tf.newaxis])  # for GPU
        labels = tf.space_to_depth(labels, config['local']['detector_grid'])
        shape = tf.concat([tf.shape(labels)[:3], [1]], axis=0)
        labels = tf.argmax(tf.concat([2*labels, tf.ones(shape)], 3), axis=3)
        with tf.device('/cpu:0'):
            d = tf.nn.sparse_softmax_cross_entropy_with_logits(
                    labels=labels, logits=out['logits'])
        mask = None
    elif 'dense_scores' in inp:  # soft labels
        d = tf.nn.softmax_cross_entropy_with_logits_v2(
                labels=inp['dense_scores'], logits=out['logits'], dim=-1)
        mask = inp.get('dense_scores_valid_mask', None)
    else:
        raise ValueError

    if mask is not None:
        mask = tf.to_float(mask)
        d = (tf.reduce_sum(d * mask, axis=[1, 2])
             / tf.reduce_sum(mask, axis=[1, 2]))
    else:
        d = tf.reduce_mean(d, axis=[1, 2])
    return d 
开发者ID:ethz-asl,项目名称:hfnet,代码行数:26,代码来源:hf_net.py

示例7: space_to_depth_x2

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import space_to_depth [as 别名]
def space_to_depth_x2(x):
    """Thin wrapper for Tensorflow space_to_depth with block_size=2."""
    # Import currently required to make Lambda work.
    # See: https://github.com/fchollet/keras/issues/5088#issuecomment-273851273
    import tensorflow as tf
    return tf.space_to_depth(x, block_size=2) 
开发者ID:PiSimo,项目名称:PiCamNN,代码行数:8,代码来源:keras_yolo.py

示例8: space_to_depth_x2_output_shape

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import space_to_depth [as 别名]
def space_to_depth_x2_output_shape(input_shape):
    """Determine space_to_depth output shape for block_size=2.

    Note: For Lambda with TensorFlow backend, output shape may not be needed.
    """
    return (input_shape[0], input_shape[1] // 2, input_shape[2] // 2, 4 *
            input_shape[3]) if input_shape[1] else (input_shape[0], None, None,
                                                    4 * input_shape[3]) 
开发者ID:PiSimo,项目名称:PiCamNN,代码行数:10,代码来源:keras_yolo.py

示例9: conv_pixel_shuffle_down

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import space_to_depth [as 别名]
def conv_pixel_shuffle_down(x, scale_factor=2, use_bias=True, sn=False, scope='pixel_shuffle'):
    channel = x.get_shape()[-1] // (scale_factor ** 2)
    x = conv(x, channel, kernel=1, stride=1, use_bias=use_bias, sn=sn, scope=scope)
    x = tf.space_to_depth(x, block_size=scale_factor)

    return x 
开发者ID:taki0112,项目名称:Tensorflow-Cookbook,代码行数:8,代码来源:ops.py

示例10: _PDS

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import space_to_depth [as 别名]
def _PDS(self, X, r):
        X = tf.space_to_depth(X, r)
        return X 
开发者ID:thangvubk,项目名称:FEQE,代码行数:5,代码来源:desubpixel.py

示例11: extract_features

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import space_to_depth [as 别名]
def extract_features(self, preprocessed_inputs):
    """Extract features from preprocessed inputs.
    Args:
      preprocessed_inputs: a [batch, height, width, channels] float tensor
        representing a batch of images.
    Returns:
      feature_maps: a list of tensors where the ith tensor has shape
        [batch, height_i, width_i, depth_i]
    """
    preprocessed_inputs.get_shape().assert_has_rank(4)
    shape_assert = tf.Assert(
        tf.logical_and(tf.greater_equal(tf.shape(preprocessed_inputs)[1], 33),
                       tf.greater_equal(tf.shape(preprocessed_inputs)[2], 33)),
        ['image size must at least be 33 in both height and width.'])

    with tf.control_dependencies([shape_assert]):
      with slim.arg_scope(darknet.darknet_arg_scope(is_training = self._is_training)):
      #with slim.arg_scope(darknet.darknet_arg_scope()):
        with tf.variable_scope('darknet_19',
                               reuse=self._reuse_weights) as scope:
          net, end_points = darknet.darknet_19_base(preprocessed_inputs, 
                                                        scope='base')
          net = slim.conv2d(net, 1024, [3, 3], scope='Conv2D_19')
          net = slim.conv2d(net, 1024, [3, 3], scope='Conv2D_20')
          scope_name = end_points['scope_name']
          conv_13 = end_points[scope_name+'/Conv2D_13']          
          conv_21 = slim.conv2d(conv_13, 64, [1, 1], scope='Conv2D_21')
          conv_21 = tf.space_to_depth(conv_21, block_size=2)
          net = tf.concat([conv_21, net], axis=-1)
          net = slim.conv2d(net, 1024, [3, 3], scope='Conv2D_22')
          feature_map = net
          
    return [feature_map] 
开发者ID:rky0930,项目名称:yolo_v2,代码行数:35,代码来源:yolo_v2_darknet_19_feature_extractor.py

示例12: _space_to_depth

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import space_to_depth [as 别名]
def _space_to_depth(self, inputs=None, block_size=2, name=''):
        if self.data_format != 'NHWC':
            inputs = tf.transpose(inputs, perm=[self.data_format.find(d) for d in 'NHWC'])
        output = tf.space_to_depth(inputs, block_size=block_size, name=name)
        if self.data_format != 'NHWC':
            output = tf.transpose(output, perm=['NHWC'.find(d) for d in self.data_format])
        return output 
开发者ID:blue-oil,项目名称:blueoil,代码行数:9,代码来源:lm_segnet_v1.py

示例13: _space_to_depth

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import space_to_depth [as 别名]
def _space_to_depth(self, name, inputs=None, block_size=2):
        output = tf.space_to_depth(inputs, block_size=block_size, name=name)
        return output 
开发者ID:blue-oil,项目名称:blueoil,代码行数:5,代码来源:lm_bisenet.py

示例14: _reorg

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import space_to_depth [as 别名]
def _reorg(self, name, inputs, stride, data_format, use_space_to_depth=True, darknet_original=False):
        with tf.name_scope(name):
            # darknet original reorg layer is weird.
            # As default we don't use darknet original reorg.
            # See detail: https://github.com/LeapMind/lmnet/issues/16
            if darknet_original:
                # TODO(wakisaka): You can use only data_format == "NHWC", yet.
                assert data_format == "NHWC"
                input_shape = tf.shape(inputs)
                # channel shape use static.
                b, h, w, c = input_shape[0], input_shape[1], input_shape[2], inputs.get_shape().as_list()[3]
                output_h = h // stride
                output_w = w // stride
                output_c = c * stride * stride
                transpose_tensor = tf.transpose(inputs, [0, 3, 1, 2])
                reshape_tensor = tf.reshape(transpose_tensor, [b, (c // (stride * stride)), h, stride, w, stride])
                transpose_tensor = tf.transpose(reshape_tensor, [0, 3, 5, 1, 2, 4])
                reshape_tensor = tf.reshape(transpose_tensor, [b, output_c, output_h, output_w])
                transpose_tensor = tf.transpose(reshape_tensor, [0, 2, 3, 1])
                outputs = tf.reshape(transpose_tensor, [b, output_h, output_w, output_c])

                return outputs
            else:
                # tf.extract_image_patches() raise error with images_placeholder `None` shape as dynamic image.
                # Github issue: https://github.com/leapmindadmin/lmnet/issues/17
                # Currently, I didn't try to space_to_depth with images_placeholder `None` shape as dynamic image.
                if use_space_to_depth:

                    outputs = tf.space_to_depth(inputs, stride, data_format=data_format)
                    return outputs

                else:
                    # TODO(wakisaka): You can use only data_format == "NHWC", yet.
                    assert data_format == "NHWC"
                    ksize = [1, stride, stride, 1]
                    strides = [1, stride, stride, 1]
                    rates = [1, 1, 1, 1]
                    outputs = tf.extract_image_patches(inputs, ksize, strides, rates, "VALID")

                    return outputs 
开发者ID:blue-oil,项目名称:blueoil,代码行数:42,代码来源:yolo_v2.py

示例15: _space_to_depth

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import space_to_depth [as 别名]
def _space_to_depth(self, inputs=None, block_size=2, name=''):
        if self.data_format != 'NHWC':
            inputs = tf.transpose(inputs, perm=[self.data_format.find(d) for d in 'NHWC'])

        output = tf.space_to_depth(inputs, block_size=block_size, name=name)

        if self.data_format != 'NHWC':
            output = tf.transpose(output, perm=['NHWC'.find(d) for d in self.data_format])
        return output 
开发者ID:blue-oil,项目名称:blueoil,代码行数:11,代码来源:lmnet_v1.py


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