當前位置: 首頁>>代碼示例>>Python>>正文


Python resnet_utils.conv2d_same方法代碼示例

本文整理匯總了Python中tensorflow.contrib.slim.python.slim.nets.resnet_utils.conv2d_same方法的典型用法代碼示例。如果您正苦於以下問題:Python resnet_utils.conv2d_same方法的具體用法?Python resnet_utils.conv2d_same怎麽用?Python resnet_utils.conv2d_same使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.contrib.slim.python.slim.nets.resnet_utils的用法示例。


在下文中一共展示了resnet_utils.conv2d_same方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testConv2DSameEven

# 需要導入模塊: from tensorflow.contrib.slim.python.slim.nets import resnet_utils [as 別名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.resnet_utils import conv2d_same [as 別名]
def testConv2DSameEven(self):
    n, n2 = 4, 2

    # Input image.
    x = create_test_input(1, n, n, 1)

    # Convolution kernel.
    w = create_test_input(1, 3, 3, 1)
    w = array_ops.reshape(w, [3, 3, 1, 1])

    variable_scope.get_variable('Conv/weights', initializer=w)
    variable_scope.get_variable('Conv/biases', initializer=array_ops.zeros([1]))
    variable_scope.get_variable_scope().reuse_variables()

    y1 = layers.conv2d(x, 1, [3, 3], stride=1, scope='Conv')
    y1_expected = math_ops.to_float([[14, 28, 43, 26], [28, 48, 66, 37],
                                     [43, 66, 84, 46], [26, 37, 46, 22]])
    y1_expected = array_ops.reshape(y1_expected, [1, n, n, 1])

    y2 = resnet_utils.subsample(y1, 2)
    y2_expected = math_ops.to_float([[14, 43], [43, 84]])
    y2_expected = array_ops.reshape(y2_expected, [1, n2, n2, 1])

    y3 = resnet_utils.conv2d_same(x, 1, 3, stride=2, scope='Conv')
    y3_expected = y2_expected

    y4 = layers.conv2d(x, 1, [3, 3], stride=2, scope='Conv')
    y4_expected = math_ops.to_float([[48, 37], [37, 22]])
    y4_expected = array_ops.reshape(y4_expected, [1, n2, n2, 1])

    with self.test_session() as sess:
      sess.run(variables.global_variables_initializer())
      self.assertAllClose(y1.eval(), y1_expected.eval())
      self.assertAllClose(y2.eval(), y2_expected.eval())
      self.assertAllClose(y3.eval(), y3_expected.eval())
      self.assertAllClose(y4.eval(), y4_expected.eval()) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:38,代碼來源:resnet_v2_test.py

示例2: testConv2DSameOdd

# 需要導入模塊: from tensorflow.contrib.slim.python.slim.nets import resnet_utils [as 別名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.resnet_utils import conv2d_same [as 別名]
def testConv2DSameOdd(self):
    n, n2 = 5, 3

    # Input image.
    x = create_test_input(1, n, n, 1)

    # Convolution kernel.
    w = create_test_input(1, 3, 3, 1)
    w = array_ops.reshape(w, [3, 3, 1, 1])

    variable_scope.get_variable('Conv/weights', initializer=w)
    variable_scope.get_variable('Conv/biases', initializer=array_ops.zeros([1]))
    variable_scope.get_variable_scope().reuse_variables()

    y1 = layers.conv2d(x, 1, [3, 3], stride=1, scope='Conv')
    y1_expected = math_ops.to_float([[14, 28, 43, 58, 34],
                                     [28, 48, 66, 84, 46],
                                     [43, 66, 84, 102, 55],
                                     [58, 84, 102, 120, 64],
                                     [34, 46, 55, 64, 30]])
    y1_expected = array_ops.reshape(y1_expected, [1, n, n, 1])

    y2 = resnet_utils.subsample(y1, 2)
    y2_expected = math_ops.to_float([[14, 43, 34],
                                     [43, 84, 55],
                                     [34, 55, 30]])
    y2_expected = array_ops.reshape(y2_expected, [1, n2, n2, 1])

    y3 = resnet_utils.conv2d_same(x, 1, 3, stride=2, scope='Conv')
    y3_expected = y2_expected

    y4 = layers.conv2d(x, 1, [3, 3], stride=2, scope='Conv')
    y4_expected = y2_expected

    with self.test_session() as sess:
      sess.run(variables.global_variables_initializer())
      self.assertAllClose(y1.eval(), y1_expected.eval())
      self.assertAllClose(y2.eval(), y2_expected.eval())
      self.assertAllClose(y3.eval(), y3_expected.eval())
      self.assertAllClose(y4.eval(), y4_expected.eval()) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:42,代碼來源:resnet_v2_test.py

示例3: testConv2DSameOdd

# 需要導入模塊: from tensorflow.contrib.slim.python.slim.nets import resnet_utils [as 別名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.resnet_utils import conv2d_same [as 別名]
def testConv2DSameOdd(self):
    n, n2 = 5, 3

    # Input image.
    x = create_test_input(1, n, n, 1)

    # Convolution kernel.
    w = create_test_input(1, 3, 3, 1)
    w = array_ops.reshape(w, [3, 3, 1, 1])

    variable_scope.get_variable('Conv/weights', initializer=w)
    variable_scope.get_variable('Conv/biases', initializer=array_ops.zeros([1]))
    variable_scope.get_variable_scope().reuse_variables()

    y1 = layers.conv2d(x, 1, [3, 3], stride=1, scope='Conv')
    y1_expected = math_ops.to_float([[14, 28, 43, 58, 34], [28, 48, 66, 84, 46],
                                     [43, 66, 84, 102, 55],
                                     [58, 84, 102, 120, 64],
                                     [34, 46, 55, 64, 30]])
    y1_expected = array_ops.reshape(y1_expected, [1, n, n, 1])

    y2 = resnet_utils.subsample(y1, 2)
    y2_expected = math_ops.to_float([[14, 43, 34], [43, 84, 55], [34, 55, 30]])
    y2_expected = array_ops.reshape(y2_expected, [1, n2, n2, 1])

    y3 = resnet_utils.conv2d_same(x, 1, 3, stride=2, scope='Conv')
    y3_expected = y2_expected

    y4 = layers.conv2d(x, 1, [3, 3], stride=2, scope='Conv')
    y4_expected = y2_expected

    with self.test_session() as sess:
      sess.run(variables.global_variables_initializer())
      self.assertAllClose(y1.eval(), y1_expected.eval())
      self.assertAllClose(y2.eval(), y2_expected.eval())
      self.assertAllClose(y3.eval(), y3_expected.eval())
      self.assertAllClose(y4.eval(), y4_expected.eval()) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:39,代碼來源:resnet_v1_test.py

示例4: _build_base

# 需要導入模塊: from tensorflow.contrib.slim.python.slim.nets import resnet_utils [as 別名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.resnet_utils import conv2d_same [as 別名]
def _build_base(self):
        with tf.variable_scope(self._scope, self._scope):
            net = resnet_utils.conv2d_same(self._image, 64, 7, stride=2, scope='conv1')
            net = tf.pad(net, [[0, 0], [1, 1], [1, 1], [0, 0]])
            net = slim.max_pool2d(net, [3, 3], stride=2, padding='VALID', scope='pool1')

        return net 
開發者ID:wanjinchang,項目名稱:SSH-TensorFlow,代碼行數:9,代碼來源:resnet_v1.py

示例5: _build_base

# 需要導入模塊: from tensorflow.contrib.slim.python.slim.nets import resnet_utils [as 別名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.resnet_utils import conv2d_same [as 別名]
def _build_base(self):
        with tf.variable_scope(self._resnet_scope):
            net = resnet_utils.conv2d_same(self._image, 64, 7, stride=2, scope='conv1')
            net = tf.pad(net, [[0, 0], [1, 1], [1, 1], [0, 0]])
            net = slim.max_pool2d(net, [3, 3], stride=2, padding='VALID', scope='pool1')

        return net 
開發者ID:InnerPeace-Wu,項目名稱:densecap-tensorflow,代碼行數:9,代碼來源:resnet_v1.py

示例6: build_base

# 需要導入模塊: from tensorflow.contrib.slim.python.slim.nets import resnet_utils [as 別名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.resnet_utils import conv2d_same [as 別名]
def build_base(self):
    #with tf.variable_scope('noise'):
      ##kernel = tf.get_variable('weights',
                            #shape=[5, 5, 3, 3],
                            #initializer=tf.constant_initializer(Wcnn))
      #conv = tf.nn.conv2d(self.noise, Wcnn, [1, 1, 1, 1], padding='SAME',name='srm')
      #conv = tf.nn.conv2d(self.noise, kernel, [1, 1, 1, 1], padding='SAME',name='srm')
      #srm_conv = tf.nn.tanh(conv, name='tanh')
    with tf.variable_scope(self._resnet_scope, self._resnet_scope):
      net = resnet_utils.conv2d_same(self._image, 64, 7, stride=2, scope='conv1')
      net = tf.pad(net, [[0, 0], [1, 1], [1, 1], [0, 0]])
      net = slim.max_pool2d(net, [3, 3], stride=2, padding='VALID', scope='pool1')

    return net 
開發者ID:pengzhou1108,項目名稱:RGB-N,代碼行數:16,代碼來源:resnet_fusion_noise.py

示例7: build_base

# 需要導入模塊: from tensorflow.contrib.slim.python.slim.nets import resnet_utils [as 別名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.resnet_utils import conv2d_same [as 別名]
def build_base(self):
    with tf.variable_scope(self._resnet_scope, self._resnet_scope):
      net = resnet_utils.conv2d_same(self._image, 64, 7, stride=2, scope='conv1')
      net = tf.pad(net, [[0, 0], [1, 1], [1, 1], [0, 0]])
      net = slim.max_pool2d(net, [3, 3], stride=2, padding='VALID', scope='pool1')

    return net 
開發者ID:pengzhou1108,項目名稱:RGB-N,代碼行數:9,代碼來源:resnet_fusion.py

示例8: _build_base

# 需要導入模塊: from tensorflow.contrib.slim.python.slim.nets import resnet_utils [as 別名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.resnet_utils import conv2d_same [as 別名]
def _build_base(self):
    with tf.variable_scope(self._scope, self._scope):
      net = resnet_utils.conv2d_same(self._image, 64, 7, stride=2, scope='conv1')
      net = tf.pad(net, [[0, 0], [1, 1], [1, 1], [0, 0]])
      net = slim.max_pool2d(net, [3, 3], stride=2, padding='VALID', scope='pool1')

    return net 
開發者ID:endernewton,項目名稱:tf-faster-rcnn,代碼行數:9,代碼來源:resnet_v1.py

示例9: build_base

# 需要導入模塊: from tensorflow.contrib.slim.python.slim.nets import resnet_utils [as 別名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.resnet_utils import conv2d_same [as 別名]
def build_base(self):
        with tf.variable_scope(self.scope, self.scope):
            net = resnet_utils.conv2d_same(self.image, 64, 7, stride=2, scope='conv1')
            net = tf.pad(net, [[0, 0], [1, 1], [1, 1], [0, 0]])
            net = slim.max_pool2d(net, [3, 3], stride=2, padding='VALID', scope='pool1')

        return net 
開發者ID:vt-vl-lab,項目名稱:iCAN,代碼行數:9,代碼來源:iCAN_ResNet50_VCOCO.py

示例10: build_base

# 需要導入模塊: from tensorflow.contrib.slim.python.slim.nets import resnet_utils [as 別名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.resnet_utils import conv2d_same [as 別名]
def build_base(self):
        with tf.variable_scope(self.scope, self.scope):
            net = resnet_utils.conv2d_same(self.image, 64, 7, stride=2, scope='conv1') # conv2d + subsample
            net = tf.pad(net, [[0, 0], [1, 1], [1, 1], [0, 0]])
            net = slim.max_pool2d(net, [3, 3], stride=2, padding='VALID', scope='pool1')

        return net

# Number of fixed blocks during training, by default ***the first of all 4 blocks*** is fixed (Resnet-50 block)
# Range: 0 (none) to 3 (all)
# __C.RESNET.FIXED_BLOCKS = 1

    # feature extractor 
開發者ID:DirtyHarryLYL,項目名稱:Transferable-Interactiveness-Network,代碼行數:15,代碼來源:TIN_HICO.py

示例11: resnet_v1_backbone

# 需要導入模塊: from tensorflow.contrib.slim.python.slim.nets import resnet_utils [as 別名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.resnet_utils import conv2d_same [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

示例12: bottleneck

# 需要導入模塊: from tensorflow.contrib.slim.python.slim.nets import resnet_utils [as 別名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.resnet_utils import conv2d_same [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:MingtaoGuo,項目名稱:Chinese-Character-and-Calligraphic-Image-Processing,代碼行數:53,代碼來源:resnet_v1.py

示例13: bottleneck

# 需要導入模塊: from tensorflow.contrib.slim.python.slim.nets import resnet_utils [as 別名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.resnet_utils import conv2d_same [as 別名]
def bottleneck(inputs,
               depth,
               depth_bottleneck,
               stride,
               rate=1,
               outputs_collections=None,
               scope=None):
  """Bottleneck residual unit variant with BN before convolutions.

  This is the full preactivation residual unit variant proposed in [2]. See
  Fig. 1(b) 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_v2', [inputs]) as sc:
    depth_in = utils.last_dimension(inputs.get_shape(), min_rank=4)
    preact = layers.batch_norm(
        inputs, activation_fn=nn_ops.relu, scope='preact')
    if depth == depth_in:
      shortcut = resnet_utils.subsample(inputs, stride, 'shortcut')
    else:
      shortcut = layers_lib.conv2d(
          preact,
          depth, [1, 1],
          stride=stride,
          normalizer_fn=None,
          activation_fn=None,
          scope='shortcut')

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

    output = shortcut + residual

    return utils.collect_named_outputs(outputs_collections, sc.name, output) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:61,代碼來源:resnet_v2.py


注:本文中的tensorflow.contrib.slim.python.slim.nets.resnet_utils.conv2d_same方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。