runtime-modeling/model_def.py
def _build(self):
    """Builds MnasNet block according to the arguments."""
    filters = self._block_args.input_filters * self._block_args.expand_ratio
    if self._block_args.expand_ratio != 1:
      # Expansion phase:
      self._expand_conv = tf.keras.layers.Conv2D(
          filters,
          kernel_size=[1, 1],
          strides=[1, 1],
          kernel_initializer=conv_kernel_initializer,
          padding='same',
          use_bias=False)
      self._bn0 = tf.layers.BatchNormalization(
          axis=self._channel_axis,
          momentum=self._batch_norm_momentum,
          epsilon=self._batch_norm_epsilon,
          fused=True)

    kernel_size = self._block_args.kernel_size
    # Depth-wise convolution phase:
    self._depthwise_conv = tf.keras.layers.DepthwiseConv2D(
        [kernel_size, kernel_size],
        strides=self._block_args.strides,
        depthwise_initializer=conv_kernel_initializer,
        padding='same',
        use_bias=False)
    self._bn1 = tf.layers.BatchNormalization(
        axis=self._channel_axis,
        momentum=self._batch_norm_momentum,
        epsilon=self._batch_norm_epsilon,
        fused=True)

    if self.has_se:
      num_reduced_filters = max(
          1, int(self._block_args.input_filters * self._block_args.se_ratio))
      # Squeeze and Excitation layer.
      self._se_reduce = tf.keras.layers.Conv2D(
          num_reduced_filters,
          kernel_size=[1, 1],
          strides=[1, 1],
          kernel_initializer=conv_kernel_initializer,
          padding='same',
          use_bias=True)
      self._se_expand = tf.keras.layers.Conv2D(
          filters,
          kernel_size=[1, 1],
          strides=[1, 1],
          kernel_initializer=conv_kernel_initializer,
          padding='same',
          use_bias=True)

    # Output phase:
    filters = self._block_args.output_filters
    self._project_conv = tf.keras.layers.Conv2D(
        filters,
        kernel_size=[1, 1],
        strides=[1, 1],
        kernel_initializer=conv_kernel_initializer,
        padding='same',
        use_bias=False)
    self._bn2 = tf.layers.BatchNormalization(
        axis=self._channel_axis,
        momentum=self._batch_norm_momentum,
        epsilon=self._batch_norm_epsilon,
        fused=True)
Builds MnasNet block according to the arguments.
Builds MnasNet block according to the arguments.
Builds MnasNet block according to the arguments .
def _build(self):
    filters = self._block_args.input_filters * self._block_args.expand_ratio
    if self._block_args.expand_ratio != 1:
      self._expand_conv = tf.keras.layers.Conv2D(
          filters,
          kernel_size=[1, 1],
          strides=[1, 1],
          kernel_initializer=conv_kernel_initializer,
          padding='same',
          use_bias=False)
      self._bn0 = tf.layers.BatchNormalization(
          axis=self._channel_axis,
          momentum=self._batch_norm_momentum,
          epsilon=self._batch_norm_epsilon,
          fused=True)
    kernel_size = self._block_args.kernel_size
    self._depthwise_conv = tf.keras.layers.DepthwiseConv2D(
        [kernel_size, kernel_size],
        strides=self._block_args.strides,
        depthwise_initializer=conv_kernel_initializer,
        padding='same',
        use_bias=False)
    self._bn1 = tf.layers.BatchNormalization(
        axis=self._channel_axis,
        momentum=self._batch_norm_momentum,
        epsilon=self._batch_norm_epsilon,
        fused=True)
    if self.has_se:
      num_reduced_filters = max(
          1, int(self._block_args.input_filters * self._block_args.se_ratio))
      self._se_reduce = tf.keras.layers.Conv2D(
          num_reduced_filters,
          kernel_size=[1, 1],
          strides=[1, 1],
          kernel_initializer=conv_kernel_initializer,
          padding='same',
          use_bias=True)
      self._se_expand = tf.keras.layers.Conv2D(
          filters,
          kernel_size=[1, 1],
          strides=[1, 1],
          kernel_initializer=conv_kernel_initializer,
          padding='same',
          use_bias=True)
    filters = self._block_args.output_filters
    self._project_conv = tf.keras.layers.Conv2D(
        filters,
        kernel_size=[1, 1],
        strides=[1, 1],
        kernel_initializer=conv_kernel_initializer,
        padding='same',
        use_bias=False)
    self._bn2 = tf.layers.BatchNormalization(
        axis=self._channel_axis,
        momentum=self._batch_norm_momentum,
        epsilon=self._batch_norm_epsilon,
        fused=True)
def _build ( self ) : filters = self . _block_args . input_filters * self . _block_args . expand_ratio if self . _block_args . expand_ratio != 1 : self . _expand_conv = tf . keras . layers . Conv2D ( filters , kernel_size = [ 1 , 1 ] , strides = [ 1 , 1 ] , kernel_initializer = conv_kernel_initializer , padding = 'same' , use_bias = False ) self . _bn0 = tf . layers . BatchNormalization ( axis = self . _channel_axis , momentum = self . _batch_norm_momentum , epsilon = self . _batch_norm_epsilon , fused = True ) kernel_size = self . _block_args . kernel_size self . _depthwise_conv = tf . keras . layers . DepthwiseConv2D ( [ kernel_size , kernel_size ] , strides = self . _block_args . strides , depthwise_initializer = conv_kernel_initializer , padding = 'same' , use_bias = False ) self . _bn1 = tf . layers . BatchNormalization ( axis = self . _channel_axis , momentum = self . _batch_norm_momentum , epsilon = self . _batch_norm_epsilon , fused = True ) if self . has_se : num_reduced_filters = max ( 1 , int ( self . _block_args . input_filters * self . _block_args . se_ratio ) ) self . _se_reduce = tf . keras . layers . Conv2D ( num_reduced_filters , kernel_size = [ 1 , 1 ] , strides = [ 1 , 1 ] , kernel_initializer = conv_kernel_initializer , padding = 'same' , use_bias = True ) self . _se_expand = tf . keras . layers . Conv2D ( filters , kernel_size = [ 1 , 1 ] , strides = [ 1 , 1 ] , kernel_initializer = conv_kernel_initializer , padding = 'same' , use_bias = True ) filters = self . _block_args . output_filters self . _project_conv = tf . keras . layers . Conv2D ( filters , kernel_size = [ 1 , 1 ] , strides = [ 1 , 1 ] , kernel_initializer = conv_kernel_initializer , padding = 'same' , use_bias = False ) self . _bn2 = tf . layers . BatchNormalization ( axis = self . _channel_axis , momentum = self . _batch_norm_momentum , epsilon = self . _batch_norm_epsilon , fused = True )
Builds MnasNet block according to the arguments.
Builds MnasNet block according to the arguments .
"""Builds MnasNet block according to the arguments.""" # Expansion phase: # Depth-wise convolution phase: # Squeeze and Excitation layer. # Output phase:
self