concept filter in category deep learning

appears as: filter, filter, filters, filters
Deep Learning Design Patterns

This is an excerpt from Manning's book Deep Learning Design Patterns.

The convolutional layer uses no padding when sliding the filter across the image. Thus, when the filter reaches the edge of the image it stops. Since the last pixels before an edge do not have their own slide by the filter, the output size is smaller than the input size, as depicted below. The consequence of this is that the size of the input and output feature maps are not preserved. For example, in a convolutional of stride 1, filter size of 3x3 and input feature map size 32x32, the output feature maps will be 30x30. It is straightforward to calculate the loss in size. If the filter size is NxN, then the loss will in size will be N-1 pixels. In TF.Keras this is specified with the keyword parameter padding=’valid’ to the Conv2D layer.

Alternatively, one can slide the filter over the edge until the last row and column are covered. But, part of the filter would hang over imaginary pixels. This way, the last pixels before an edge have their own slide by the filter and the size of the outputted feature map is preserved.

Unlike the SOTA models we’ve covered so far, MobileNets are categorized not by their number of layers, but by the input resolution. Thus a MobileNet-224 has input (224, 224, 3). The convolutional groups follow the convention of doubling the number of filters from the previous group.

Figure 5.3 is a depiction of a MobileNet group. You can see that it uses a strided convolution for the first block for the feature map reduction (principle 2) and, while not depicted, each group doubles the number of filters (principle 1) starting at 128.

Fig. 5.3 MobileNet v1 Group Micro-Architecture consisting of a sequence of depthwise convolutional blocks.

Figure 5.4 is a depiction of a MobileNet depthwise convolutional block. In v1, the authors used a convolutional block design instead of a residual block design -- that is, there is no identity link. Each block is essentially a single depthwise separable convolution constructed as two separate convolutional layers. The first layer is a 3x3 depthwise convolution followed by the 1x1 pointwise convolution; when combined form the depthwise separable convolution. The number of filters, which corresponds to the number of feature maps, can be further reduced for network thinning by the metaparameter α (alpha).

""" Construct a Depthwise Separable Convolution block
        x         : input to the block
        n_filters : number of filters
        alpha     : width multiplier
        strides   : strides
    """
    filters = int(n_filters * alpha)    #A
 
    if strides == (2, 2):    #B
        x = ZeroPadding2D(padding=((0, 1), (0, 1)))(x)
        padding = 'valid'
    else:
        padding = 'same'
 
    x = DepthwiseConv2D((3, 3), strides, padding=padding)(x)    #C
    x = BatchNormalization()(x)
    x = ReLU(6.0)(x)
 
    x = Conv2D(filters, (1, 1), strides=(1, 1), padding='same')(x)    #D
    x = BatchNormalization()(x)
    x = ReLU(6.0)(x)
    return x