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


Python layers.conv2d方法代码示例

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


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

示例1: network_arg_scope

# 需要导入模块: from tensorflow.contrib.layers.python.layers import layers [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.layers import conv2d [as 别名]
def network_arg_scope(is_training=True,
                      weight_decay=cfg.train.weight_decay,
                      batch_norm_decay=0.997,
                      batch_norm_epsilon=1e-5,
                      batch_norm_scale=True):
    batch_norm_params = {
        'is_training': is_training, 'decay': batch_norm_decay,
        'epsilon': batch_norm_epsilon, 'scale': batch_norm_scale,
        'updates_collections': ops.GraphKeys.UPDATE_OPS,
        #'variables_collections': [ tf.GraphKeys.TRAINABLE_VARIABLES ],
        'trainable': cfg.train.bn_training,
    }

    with slim.arg_scope(
            [slim.conv2d, slim.separable_convolution2d],
            weights_regularizer=slim.l2_regularizer(weight_decay),
            weights_initializer=slim.variance_scaling_initializer(),
            trainable=is_training,
            activation_fn=tf.nn.relu6,
            #activation_fn=tf.nn.relu,
            normalizer_fn=slim.batch_norm,
            normalizer_params=batch_norm_params,
            padding='SAME'):
        with slim.arg_scope([slim.batch_norm], **batch_norm_params) as arg_sc:
            return arg_sc 
开发者ID:vicwer,项目名称:sense_classification,代码行数:27,代码来源:network.py

示例2: dense_block

# 需要导入模块: from tensorflow.contrib.layers.python.layers import layers [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.layers import conv2d [as 别名]
def dense_block(inputs, depth, depth_bottleneck, stride, name, rate=1):
    depth_in = inputs.get_shape()[3]
    if depth == depth_in:
        if stride == 1:
            shortcut = inputs
        else:
            shortcut = layers.max_pool2d(inputs, [1, 1], stride=factor, scope=name+'_shortcut')
    else:
        shortcut = layers.conv2d(
            inputs,
            depth, [1, 1],
            stride=stride,
            activation_fn=None,
            scope=name+'_shortcut')
    if PRINT_LAYER_LOG:
        print(name+'_shortcut', shortcut.get_shape())

    residual = layers.conv2d(
        inputs, depth_bottleneck, [1, 1], stride=1, scope=name+'_conv1')
    if PRINT_LAYER_LOG:
        print(name+'_conv1', residual.get_shape())
    residual = resnet_utils.conv2d_same(
        residual, depth_bottleneck, 3, stride, rate=rate, scope=name+'_conv2')
    if PRINT_LAYER_LOG:
        print(name+'_conv2', residual.get_shape())
    residual = layers.conv2d(
        residual, depth, [1, 1], stride=1, activation_fn=None, scope=name+'_conv3')
    if PRINT_LAYER_LOG:
        print(name+'_conv3', residual.get_shape())
    output = nn_ops.relu(shortcut + residual)
    return output 
开发者ID:vicwer,项目名称:sense_classification,代码行数:33,代码来源:network.py

示例3: conv2d

# 需要导入模块: from tensorflow.contrib.layers.python.layers import layers [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.layers import conv2d [as 别名]
def conv2d(inputs, c_outputs, s, name):
    output = slim.conv2d(inputs, num_outputs=c_outputs, kernel_size=[3,3], stride=s, scope=name)
    if PRINT_LAYER_LOG:
        print(name, output.get_shape())
    return output 
开发者ID:vicwer,项目名称:sense_classification,代码行数:7,代码来源:network.py

示例4: resnet_v1_backbone

# 需要导入模块: from tensorflow.contrib.layers.python.layers import layers [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.layers import conv2d [as 别名]
def resnet_v1_backbone(inputs,
              blocks,
              is_training=True,
              output_stride=None,
              include_root_block=True,
              reuse=None,
              scope=None):
  with variable_scope.variable_scope(
      scope, 'resnet_v1', [inputs], reuse=reuse) as sc:
    end_points_collection = sc.original_name_scope + '_end_points'
    with arg_scope(
        [layers.conv2d, bottleneck, resnet_utils.stack_blocks_dense],
        outputs_collections=end_points_collection):
      with arg_scope([layers.batch_norm], is_training=is_training):
        net = inputs
        if include_root_block:
          if output_stride is not None:
            if output_stride % 4 != 0:
              raise ValueError('The output_stride needs to be a multiple of 4.')
            output_stride /= 4
          net = resnet_utils.conv2d_same(net, 64, 7, stride=2, scope='conv1')
          net = layers_lib.max_pool2d(net, [3, 3], stride=2, scope='pool1')
        net = resnet_utils.stack_blocks_dense(net, blocks, output_stride)
        # Convert end_points_collection into a dictionary of end_points.
        end_points = utils.convert_collection_to_dict(end_points_collection)

        return net, end_points 
开发者ID:HiKapok,项目名称:X-Detector,代码行数:29,代码来源:slim_resnet_utils.py

示例5: inference

# 需要导入模块: from tensorflow.contrib.layers.python.layers import layers [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.layers import conv2d [as 别名]
def inference(self, mode, inputs, scope='SenseCls'):
        is_training = mode
        with slim.arg_scope(network_arg_scope(is_training=is_training)):
            with tf.variable_scope(scope, reuse=False):
                conv0 = slim.conv2d(inputs,
                                    num_outputs=64,
                                    kernel_size=[7,7],
                                    stride=2,
                                    scope='conv0')
                if PRINT_LAYER_LOG:
                    print(conv0.name, conv0.get_shape())
                pool0 = slim.max_pool2d(conv0, kernel_size=[3, 3], stride=2, scope='pool0')
                if PRINT_LAYER_LOG:
                    print('pool0', pool0.get_shape())

                block0_0 = block(pool0, 64, 1, 'block0_0')
                block0_1 = block(block0_0, 64, 1, 'block0_1')
                block0_2 = block(block0_1, 64, 1, 'block0_2')

                block1_0 = block(block0_2, 128, 2, 'block1_0')
                block1_1 = block(block1_0, 128, 1, 'block1_1')
                block1_2 = block(block1_1, 128, 1, 'block1_2')
                block1_3 = block(block1_2, 128, 1, 'block1_3')

                block2_0 = block(block1_3, 256, 2, 'block2_0')
                block2_1 = block(block2_0, 256, 1, 'block2_1')
                block2_2 = block(block2_1, 256, 1, 'block2_2')
                block2_3 = block(block2_2, 256, 1, 'block2_3')
                block2_4 = block(block2_3, 256, 1, 'block2_4')
                block2_5 = block(block2_4, 256, 1, 'block2_5')

                block3_0 = block(block2_5, 512, 2, 'block3_0')
                block3_1 = block(block3_0, 512, 1, 'block3_1')
                block3_2 = block(block3_1, 512, 1, 'block3_2')

                net = tf.reduce_mean(block3_2, [1, 2], keepdims=True, name='global_pool_v4')
                if PRINT_LAYER_LOG:
                    print('avg_pool', net.get_shape())
                net = slim.flatten(net, scope='PreLogitsFlatten')
                net = slim.dropout(net, 0.8, is_training=is_training, scope='dropout')
                logits = fully_connected(net, cfg.classes, name='fc')
                if PRINT_LAYER_LOG:
                    print('logits', logits.get_shape())
                if is_training:
                    l2_loss = tf.add_n(tf.losses.get_regularization_losses())
                    return logits, l2_loss
                else:
                    return logits 
开发者ID:vicwer,项目名称:sense_classification,代码行数:50,代码来源:network.py

示例6: block

# 需要导入模块: from tensorflow.contrib.layers.python.layers import layers [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.layers import conv2d [as 别名]
def block(inputs, c_outputs, s, name):
    se_module = True
    out1 = slim.conv2d(inputs,
                       num_outputs=c_outputs,
                       kernel_size=[3,3],
                       stride=s,
                       scope=name+'_0')
    if PRINT_LAYER_LOG:
        print(name+'_0', out1.get_shape())
    output = slim.conv2d(out1,
                       num_outputs=c_outputs,
                       kernel_size=[3,3],
                       stride=1,
                       activation_fn=None,
                       scope=name+'_1')
    if PRINT_LAYER_LOG:
        print(name+'_1', output.get_shape())
    if s == 2:
        return nn_ops.relu(output)
    else:
        if se_module:
            squeeze = tf.reduce_mean(output, [1, 2], keepdims=True, name='global_pool_v4')
            if PRINT_LAYER_LOG:
                print('squeeze', squeeze.get_shape())
            fc1 = slim.conv2d(squeeze,
                            num_outputs=squeeze.get_shape()[-1] // 16,
                            normalizer_fn=None,
                            normalizer_params=None,
                            weights_regularizer=None,
                            kernel_size=[1,1],
                            stride=1,
                            activation_fn=tf.nn.relu,
                            scope=name+'_fc1')
            if PRINT_LAYER_LOG:
                print('fc1', fc1.get_shape())
            fc2 = slim.conv2d(fc1,
                            num_outputs=squeeze.get_shape()[-1],
                            normalizer_fn=None,
                            normalizer_params=None,
                            weights_regularizer=None,
                            kernel_size=[1,1],
                            stride=1,
                            activation_fn=tf.sigmoid,
                            scope=name+'_fc2')
            if PRINT_LAYER_LOG:
                print('fc2', fc2.get_shape())
            output = output * fc2
        output = nn_ops.relu(inputs + output)
        if PRINT_LAYER_LOG:
            print(name, output.get_shape())
        return output 
开发者ID:vicwer,项目名称:sense_classification,代码行数:53,代码来源:network.py

示例7: conv2d_same

# 需要导入模块: from tensorflow.contrib.layers.python.layers import layers [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.layers import conv2d [as 别名]
def conv2d_same(inputs, num_outputs, kernel_size, stride, rate=1, scope=None):
  """Strided 2-D convolution with 'SAME' padding.

  When stride > 1, then we do explicit zero-padding, followed by conv2d with
  'VALID' padding.

  Note that

     net = conv2d_same(inputs, num_outputs, 3, stride=stride)

  is equivalent to

     net = tf.contrib.layers.conv2d(inputs, num_outputs, 3, stride=1,
     padding='SAME')
     net = subsample(net, factor=stride)

  whereas

     net = tf.contrib.layers.conv2d(inputs, num_outputs, 3, stride=stride,
     padding='SAME')

  is different when the input's height or width is even, which is why we add the
  current function. For more details, see ResnetUtilsTest.testConv2DSameEven().

  Args:
    inputs: A 4-D tensor of size [batch, height_in, width_in, channels].
    num_outputs: An integer, the number of output filters.
    kernel_size: An int with the kernel_size of the filters.
    stride: An integer, the output stride.
    rate: An integer, rate for atrous convolution.
    scope: Scope.

  Returns:
    output: A 4-D tensor of size [batch, height_out, width_out, channels] with
      the convolution output.
  """
  if stride == 1:
    return layers_lib.conv2d(
        inputs,
        num_outputs,
        kernel_size,
        stride=1,
        rate=rate,
        padding='SAME',
        scope=scope)
  else:
    kernel_size_effective = kernel_size + (kernel_size - 1) * (rate - 1)
    pad_total = kernel_size_effective - 1
    pad_beg = pad_total // 2
    pad_end = pad_total - pad_beg
    inputs = array_ops.pad(
        inputs, [[0, 0], [pad_beg, pad_end], [pad_beg, pad_end], [0, 0]])
    return layers_lib.conv2d(
        inputs,
        num_outputs,
        kernel_size,
        stride=stride,
        rate=rate,
        padding='VALID',
        scope=scope) 
开发者ID:HiKapok,项目名称:X-Detector,代码行数:62,代码来源:slim_resnet_utils.py

示例8: bottleneck

# 需要导入模块: from tensorflow.contrib.layers.python.layers import layers [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.layers import conv2d [as 别名]
def bottleneck(inputs,
               depth,
               depth_bottleneck,
               stride,
               rate=1,
               outputs_collections=None,
               scope=None):
  """Bottleneck residual unit variant with BN after convolutions.

  This is the original residual unit proposed in [1]. See Fig. 1(a) of [2] for
  its definition. Note that we use here the bottleneck variant which has an
  extra bottleneck layer.

  When putting together two consecutive ResNet blocks that use this unit, one
  should use stride = 2 in the last unit of the first block.

  Args:
    inputs: A tensor of size [batch, height, width, channels].
    depth: The depth of the ResNet unit output.
    depth_bottleneck: The depth of the bottleneck layers.
    stride: The ResNet unit's stride. Determines the amount of downsampling of
      the units output compared to its input.
    rate: An integer, rate for atrous convolution.
    outputs_collections: Collection to add the ResNet unit output.
    scope: Optional variable_scope.

  Returns:
    The ResNet unit's output.
  """
  with variable_scope.variable_scope(scope, 'bottleneck_v1', [inputs]) as sc:
    depth_in = utils.last_dimension(inputs.get_shape(), min_rank=4)
    if depth == depth_in:
      shortcut = resnet_utils.subsample(inputs, stride, 'shortcut')
    else:
      shortcut = layers.conv2d(
          inputs,
          depth, [1, 1],
          stride=stride,
          activation_fn=None,
          scope='shortcut')

    residual = layers.conv2d(
        inputs, depth_bottleneck, [1, 1], stride=1, scope='conv1')
    residual = resnet_utils.conv2d_same(
        residual, depth_bottleneck, 3, stride, rate=rate, scope='conv2')
    residual = layers.conv2d(
        residual, depth, [1, 1], stride=1, activation_fn=None, scope='conv3')

    output = nn_ops.relu(shortcut + residual)

    return utils.collect_named_outputs(outputs_collections, sc.name, output) 
开发者ID:HiKapok,项目名称:X-Detector,代码行数:53,代码来源:slim_resnet_utils.py


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