lib/nets/mobilenet_v1.py
def mobilenet_v1_base(inputs,
                      conv_defs,
                      starting_layer=0,
                      min_depth=8,
                      depth_multiplier=1.0,
                      output_stride=None,
                      reuse=None,
                      scope=None):
  """Mobilenet v1.
  Constructs a Mobilenet v1 network from inputs to the given final endpoint.
  Args:
    inputs: a tensor of shape [batch_size, height, width, channels].
    starting_layer: specifies the current starting layer. For region proposal 
      network it is 0, for region classification it is 12 by default.
    min_depth: Minimum depth value (number of channels) for all convolution ops.
      Enforced when depth_multiplier < 1, and not an active constraint when
      depth_multiplier >= 1.
    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.
    conv_defs: A list of ConvDef named tuples specifying the net architecture.
    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. 
    scope: Optional variable_scope.
  Returns:
    tensor_out: output tensor corresponding to the final_endpoint.
  Raises:
    ValueError: if depth_multiplier <= 0, or convolution type is not defined.
  """
  depth = lambda d: max(int(d * depth_multiplier), min_depth)
  end_points = {}

  # Used to find thinned depths for each layer.
  if depth_multiplier <= 0:
    raise ValueError('depth_multiplier is not greater than zero.')

  with tf.variable_scope(scope, 'MobilenetV1', [inputs], reuse=reuse):
    # The current_stride variable keeps track of the output stride of the
    # activations, i.e., the running product of convolution strides up to the
    # current network layer. This allows us to invoke atrous convolution
    # whenever applying the next convolution would result in the activations
    # having output stride larger than the target output_stride.
    current_stride = 1

    # The atrous convolution rate parameter.
    rate = 1

    net = inputs
    for i, conv_def in enumerate(conv_defs):
      end_point_base = 'Conv2d_%d' % (i + starting_layer)

      if output_stride is not None and current_stride == output_stride:
        # If we have reached the target output_stride, then we need to employ
        # atrous convolution with stride=1 and multiply the atrous rate by the
        # current unit's stride for use in subsequent layers.
        layer_stride = 1
        layer_rate = rate
        rate *= conv_def.stride
      else:
        layer_stride = conv_def.stride
        layer_rate = 1
        current_stride *= conv_def.stride

      if isinstance(conv_def, Conv):
        end_point = end_point_base
        net = resnet_utils.conv2d_same(net, depth(conv_def.depth), conv_def.kernel,
                          stride=conv_def.stride,
                          scope=end_point)

      elif isinstance(conv_def, DepthSepConv):
        end_point = end_point_base + '_depthwise'
        
        net = separable_conv2d_same(net, conv_def.kernel,
                                    stride=layer_stride,
                                    rate=layer_rate,
                                    scope=end_point)

        end_point = end_point_base + '_pointwise'

        net = slim.conv2d(net, depth(conv_def.depth), [1, 1],
                          stride=1,
                          scope=end_point)

      else:
        raise ValueError('Unknown convolution type %s for layer %d'
                         % (conv_def.ltype, i))

    return net
Mobilenet v1.
  Constructs a Mobilenet v1 network from inputs to the given final endpoint.
  Args:
    inputs: a tensor of shape [batch_size, height, width, channels].
    starting_layer: specifies the current starting layer. For region proposal 
      network it is 0, for region classification it is 12 by default.
    min_depth: Minimum depth value (number of channels) for all convolution ops.
      Enforced when depth_multiplier < 1, and not an active constraint when
      depth_multiplier >= 1.
    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.
    conv_defs: A list of ConvDef named tuples specifying the net architecture.
    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. 
    scope: Optional variable_scope.
  Returns:
    tensor_out: output tensor corresponding to the final_endpoint.
  Raises:
    ValueError: if depth_multiplier <= 0, or convolution type is not defined.
  
Mobilenet v1.
Constructs a Mobilenet v1 network from inputs to the given final endpoint.
Mobilenet v1 . Constructs a Mobilenet v1 network from inputs to the given final endpoint .
def mobilenet_v1_base(inputs,
                      conv_defs,
                      starting_layer=0,
                      min_depth=8,
                      depth_multiplier=1.0,
                      output_stride=None,
                      reuse=None,
                      scope=None):
  depth = lambda d: max(int(d * depth_multiplier), min_depth)
  end_points = {}
  if depth_multiplier <= 0:
    raise ValueError('depth_multiplier is not greater than zero.')
  with tf.variable_scope(scope, 'MobilenetV1', [inputs], reuse=reuse):
    current_stride = 1
    rate = 1
    net = inputs
    for i, conv_def in enumerate(conv_defs):
      end_point_base = 'Conv2d_%d' % (i + starting_layer)
      if output_stride is not None and current_stride == output_stride:
        layer_stride = 1
        layer_rate = rate
        rate *= conv_def.stride
      else:
        layer_stride = conv_def.stride
        layer_rate = 1
        current_stride *= conv_def.stride
      if isinstance(conv_def, Conv):
        end_point = end_point_base
        net = resnet_utils.conv2d_same(net, depth(conv_def.depth), conv_def.kernel,
                          stride=conv_def.stride,
                          scope=end_point)
      elif isinstance(conv_def, DepthSepConv):
        end_point = end_point_base + '_depthwise'
        net = separable_conv2d_same(net, conv_def.kernel,
                                    stride=layer_stride,
                                    rate=layer_rate,
                                    scope=end_point)
        end_point = end_point_base + '_pointwise'
        net = slim.conv2d(net, depth(conv_def.depth), [1, 1],
                          stride=1,
                          scope=end_point)
      else:
        raise ValueError('Unknown convolution type %s for layer %d'
                         % (conv_def.ltype, i))
    return net
def mobilenet_v1_base ( inputs , conv_defs , starting_layer = 0 , min_depth = 8 , depth_multiplier = 1.0 , output_stride = None , reuse = None , scope = None ) : depth = lambda d : max ( int ( d * depth_multiplier ) , min_depth ) end_points = { } if depth_multiplier <= 0 : raise ValueError ( 'depth_multiplier is not greater than zero.' ) with tf . variable_scope ( scope , 'MobilenetV1' , [ inputs ] , reuse = reuse ) : current_stride = 1 rate = 1 net = inputs for i , conv_def in enumerate ( conv_defs ) : end_point_base = 'Conv2d_%d' % ( i + starting_layer ) if output_stride is not None and current_stride == output_stride : layer_stride = 1 layer_rate = rate rate *= conv_def . stride else : layer_stride = conv_def . stride layer_rate = 1 current_stride *= conv_def . stride if isinstance ( conv_def , Conv ) : end_point = end_point_base net = resnet_utils . conv2d_same ( net , depth ( conv_def . depth ) , conv_def . kernel , stride = conv_def . stride , scope = end_point ) elif isinstance ( conv_def , DepthSepConv ) : end_point = end_point_base + '_depthwise' net = separable_conv2d_same ( net , conv_def . kernel , stride = layer_stride , rate = layer_rate , scope = end_point ) end_point = end_point_base + '_pointwise' net = slim . conv2d ( net , depth ( conv_def . depth ) , [ 1 , 1 ] , stride = 1 , scope = end_point ) else : raise ValueError ( 'Unknown convolution type %s for layer %d' % ( conv_def . ltype , i ) ) return net
Mobilenet v1.
Mobilenet v1 .
"""Mobilenet v1.
  Constructs a Mobilenet v1 network from inputs to the given final endpoint.
  Args:
    inputs: a tensor of shape [batch_size, height, width, channels].
    starting_layer: specifies the current starting layer. For region proposal 
      network it is 0, for region classification it is 12 by default.
    min_depth: Minimum depth value (number of channels) for all convolution ops.
      Enforced when depth_multiplier < 1, and not an active constraint when
      depth_multiplier >= 1.
    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.
    conv_defs: A list of ConvDef named tuples specifying the net architecture.
    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. 
    scope: Optional variable_scope.
  Returns:
    tensor_out: output tensor corresponding to the final_endpoint.
  Raises:
    ValueError: if depth_multiplier <= 0, or convolution type is not defined.
  """ # Used to find thinned depths for each layer. # The current_stride variable keeps track of the output stride of the # activations, i.e., the running product of convolution strides up to the # current network layer. This allows us to invoke atrous convolution # whenever applying the next convolution would result in the activations # having output stride larger than the target output_stride. # The atrous convolution rate parameter. # If we have reached the target output_stride, then we need to employ # atrous convolution with stride=1 and multiply the atrous rate by the # current unit's stride for use in subsequent layers.
output tensor corresponding to the final_endpoint.
output tensor corresponding to the final_endpoint .
tensor_out
if depth_multiplier <= 0, or convolution type is not defined.
if depth_multiplier < = 0 or convolution type is not defined .
ValueError
inputs
a tensor of shape [batch_size, height, width, channels].
a tensor of shape [ batch_size height width channels ] .
conv_defs
A list of ConvDef named tuples specifying the net architecture.
A list of ConvDef named tuples specifying the net architecture .
starting_layer
specifies the current starting layer. For region proposal
network it is 0, for region classification it is 12 by default.
specifies the current starting layer . For region proposal network it is 0 for region classification it is 12 by default .
min_depth
Minimum depth value (number of channels) for all convolution ops.
Enforced when depth_multiplier < 1, and not an active constraint when
depth_multiplier >= 1.
Minimum depth value ( number of channels ) for all convolution ops . Enforced when depth_multiplier < 1 and not an active constraint when depth_multiplier > = 1 .
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.
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.
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 .
reuse
scope
None