(self,
               num_channels,
               width_multiplier,
               strides,
               use_projection,
               kernel_initializer=tf.keras.initializers.he_normal(),
               kernel_regularizer=tf.keras.regularizers.l2(l=0.0001),
               name='bottleneck_residual_block')
Constructs a `BottleneckBlock`.

    Args:
      num_channels: An integer specifying the base number of filters in each
        convolutional layer in this `BottleneckBlock`.
      width_multiplier: An integer specifying the factor by which to increase
        the number of filters in the 3x3 convolution in this `BottleneckBlock`.
      strides: An integer or an iterable of integers, specifying the stride(s)
        of the 3x3 convolution in this `BottleneckBlock`.
      use_projection: If True, the additive residual component is projected with
        a 1x1 convolution with stride `strides`; otherwise, it is simply the
        input.
      kernel_initializer: A subclass of `tf.keras.regularizer.Initializer`, used
        as a default initializer for kernel (weight) matrices.
      kernel_regularizer: A subclass of `tf.keras.regularizer.Regularizer`, used
        as a default regularizer for kernel (weight) matrices.
      name: The name for this `BottleneckBlock`.
Constructs a `BottleneckBlock`.
Constructs a BottleneckBlock .
def __init__(self,
               num_channels,
               width_multiplier,
               strides,
               use_projection,
               kernel_initializer=tf.keras.initializers.he_normal(),
               kernel_regularizer=tf.keras.regularizers.l2(l=0.0001),
               name='bottleneck_residual_block'):
    """Constructs a `BottleneckBlock`.

    Args:
      num_channels: An integer specifying the base number of filters in each
        convolutional layer in this `BottleneckBlock`.
      width_multiplier: An integer specifying the factor by which to increase
        the number of filters in the 3x3 convolution in this `BottleneckBlock`.
      strides: An integer or an iterable of integers, specifying the stride(s)
        of the 3x3 convolution in this `BottleneckBlock`.
      use_projection: If True, the additive residual component is projected with
        a 1x1 convolution with stride `strides`; otherwise, it is simply the
        input.
      kernel_initializer: A subclass of `tf.keras.regularizer.Initializer`, used
        as a default initializer for kernel (weight) matrices.
      kernel_regularizer: A subclass of `tf.keras.regularizer.Regularizer`, used
        as a default regularizer for kernel (weight) matrices.
      name: The name for this `BottleneckBlock`.
    """
    super(BottleneckBlock, self).__init__(name=name)
    self.use_projection = use_projection

    self.conv_0 = tf.keras.layers.Conv2D(
        filters=num_channels,
        kernel_size=1,
        strides=1,
        use_bias=False,
        padding='same',
        kernel_initializer=kernel_initializer,
        kernel_regularizer=kernel_regularizer)

    self.bn_0 = self.normalization_layer(epsilon=1e-5)
    self.act_0 = tf.keras.layers.ReLU()

    self.padding_1 = tf.keras.layers.ZeroPadding2D(padding=(1, 1))
    self.conv_1 = tf.keras.layers.Conv2D(
        filters=num_channels * width_multiplier,
        kernel_size=3,
        strides=strides,
        use_bias=False,
        padding='valid',
        kernel_initializer=kernel_initializer,
        kernel_regularizer=kernel_regularizer)

    self.bn_1 = self.normalization_layer(epsilon=1e-5)
    self.act_1 = tf.keras.layers.ReLU()

    self.conv_2 = tf.keras.layers.Conv2D(
        filters=num_channels * self.expansion_factor,
        kernel_size=1,
        strides=1,
        use_bias=False,
        padding='same',
        kernel_initializer=kernel_initializer,
        kernel_regularizer=kernel_regularizer)

    # Zero-initialize the weights of the last batch-normalization layer in each
    # residual block, so that the (non-projected) residual branch starts with a
    # zero output and so each residual block starts as an identity mapping.
    # This improves model performance of ResNetV2 by 0.2~0.3% according to
    # https://arxiv.org/abs/1706.02677.
    self.bn_2 = self.normalization_layer(
        gamma_initializer=tf.keras.initializers.zeros(), epsilon=1e-5)

    if self.resnet_v2:
      self.act_2 = tf.keras.layers.ReLU()
    else:
      self.output_act = tf.keras.layers.ReLU()

    if self.use_projection:
      self.proj_conv = tf.keras.layers.Conv2D(
          filters=num_channels * self.expansion_factor,
          kernel_size=1,
          strides=strides,
          use_bias=False,
          padding='same',
          kernel_initializer=kernel_initializer,
          kernel_regularizer=kernel_regularizer)

      if not self.resnet_v2:
        self.proj_norm = self.normalization_layer(epsilon=1e-5)
def __init__ ( self , num_channels , width_multiplier , strides , use_projection , kernel_initializer = tf . keras . initializers . he_normal ( ) , kernel_regularizer = tf . keras . regularizers . l2 ( l = 0.0001 ) , name = 'bottleneck_residual_block' ) : super ( BottleneckBlock , self ) . __init__ ( name = name ) self . use_projection = use_projection self . conv_0 = tf . keras . layers . Conv2D ( filters = num_channels , kernel_size = 1 , strides = 1 , use_bias = False , padding = 'same' , kernel_initializer = kernel_initializer , kernel_regularizer = kernel_regularizer ) self . bn_0 = self . normalization_layer ( epsilon = 1e-5 ) self . act_0 = tf . keras . layers . ReLU ( ) self . padding_1 = tf . keras . layers . ZeroPadding2D ( padding = ( 1 , 1 ) ) self . conv_1 = tf . keras . layers . Conv2D ( filters = num_channels * width_multiplier , kernel_size = 3 , strides = strides , use_bias = False , padding = 'valid' , kernel_initializer = kernel_initializer , kernel_regularizer = kernel_regularizer ) self . bn_1 = self . normalization_layer ( epsilon = 1e-5 ) self . act_1 = tf . keras . layers . ReLU ( ) self . conv_2 = tf . keras . layers . Conv2D ( filters = num_channels * self . expansion_factor , kernel_size = 1 , strides = 1 , use_bias = False , padding = 'same' , kernel_initializer = kernel_initializer , kernel_regularizer = kernel_regularizer ) # Zero-initialize the weights of the last batch-normalization layer in each # residual block, so that the (non-projected) residual branch starts with a # zero output and so each residual block starts as an identity mapping. # This improves model performance of ResNetV2 by 0.2~0.3% according to # https://arxiv.org/abs/1706.02677. self . bn_2 = self . normalization_layer ( gamma_initializer = tf . keras . initializers . zeros ( ) , epsilon = 1e-5 ) if self . resnet_v2 : self . act_2 = tf . keras . layers . ReLU ( ) else : self . output_act = tf . keras . layers . ReLU ( ) if self . use_projection : self . proj_conv = tf . keras . layers . Conv2D ( filters = num_channels * self . expansion_factor , kernel_size = 1 , strides = strides , use_bias = False , padding = 'same' , kernel_initializer = kernel_initializer , kernel_regularizer = kernel_regularizer ) if not self . resnet_v2 : self . proj_norm = self . normalization_layer ( epsilon = 1e-5 )