def testWithOutputStride8(self):
   out, _ = mobilenet.mobilenet_base(
       tf.placeholder(tf.float32, (10, 224, 224, 16)),
       conv_defs=mobilenet_v2.V2_DEF,
       output_stride=8,
       scope='MobilenetV2')
   self.assertEqual(out.get_shape().as_list()[1:3], [28, 28])
 def testWithOutputStride16(self):
   tf.reset_default_graph()
   out, _ = mobilenet.mobilenet_base(
       tf.placeholder(tf.float32, (10, 224, 224, 16)),
       conv_defs=mobilenet_v2.V2_DEF,
       output_stride=16)
   self.assertEqual(out.get_shape().as_list()[1:3], [14, 14])
Ejemplo n.º 3
0
def _mobilenet_v2(net,
                  depth_multiplier,
                  output_stride,
                  reuse=None,
                  scope=None,
                  final_endpoint=None):
    """Auxiliary function to add support for 'reuse' to mobilenet_v2.

  Args:
    net: Input tensor of shape [batch_size, height, width, channels].
    depth_multiplier: Float multiplier for the depth (number of channels)
      for all convolution ops. The value must be greater than zero. Typical
      usage will be to set this value in (0, 1) to reduce the number of
      parameters or computation cost of the model.
    output_stride: An integer that specifies the requested ratio of input to
      output spatial resolution. If not None, then we invoke atrous convolution
      if necessary to prevent the network from reducing the spatial resolution
      of the activation maps. Allowed values are 8 (accurate fully convolutional
      mode), 16 (fast fully convolutional mode), 32 (classification mode).
    reuse: Reuse model variables.
    scope: Optional variable scope.
    final_endpoint: The endpoint to construct the network up to.

  Returns:
    Features extracted by MobileNetv2.
  """
    with tf.variable_scope(scope, 'MobilenetV2', [net], reuse=reuse) as scope:
        return mobilenet_lib.mobilenet_base(net,
                                            conv_defs=mobilenet_v2.V2_DEF,
                                            multiplier=depth_multiplier,
                                            final_endpoint=final_endpoint
                                            or _MOBILENET_V2_FINAL_ENDPOINT,
                                            output_stride=output_stride,
                                            scope=scope)
 def testWithOutputStride8AndExplicitPadding(self):
   tf.reset_default_graph()
   out, _ = mobilenet.mobilenet_base(
       tf.placeholder(tf.float32, (10, 224, 224, 16)),
       conv_defs=mobilenet_v2.V2_DEF,
       output_stride=8,
       use_explicit_padding=True,
       scope='MobilenetV2')
   self.assertEqual(out.get_shape().as_list()[1:3], [28, 28])