Convolutional Neural Networks
A convolutional neural network is a two-dimensional scanning network designed for data with spatial structure, such as images. A CNN applies the same learned local function (a convolutional kernel) to many overlapping spatial patches of the input, producing feature maps that detect patterns regardless of their position.
Given an input , a convolutional layer applies a bank of filters, each of size . The -th filter produces an feature map,
where is a nonlinearity such as ReLU. Note that padding is frequently employed to restore the feature map to the shape of the original input, such that in general, padding by rows and columns leads to a shape of . If convolution is done with a stride of , then the dimension of the output isA CNN therefore inherits the key properties of scanning networks:
- Sparse connectivity: each neuron sees only an patch.
- Shared connectivity pattern: the same kernel weights are reused at every spatial location.
- Shift equivariance: shifting the input produces a corresponding shift in the activation map.
Stacking convolution layers grows receptive fields hierarchically, enabling early layers to detect edges and later layers to capture textures, shapes, and object-level structure. Optional pooling layers (max-pooling or average-pooling) downsample spatial dimensions by aggregating over local neighborhoods, providing robustness to small shifts and scale variations:
After several such layers extract increasingly abstract features, the final spatial representation is flattened and passed to one or more fully connected layers that compute the output
Examples
Convolution Operation in CNNs
In this question, we will look at the mechanism of weight sharing in convolutions. Suppose that we have an input vector with dimensions:
We compute a 1D convolution with the kernel filter that has weights (parameters):
What’s the output dimension if we apply filter with no padding and stride of ? What are the first and last elements of the output? Given a stride of and no padding, . The first element is , whereas the last element is .
What’s the output dimension if we apply filter with padding of size 1 and stride of 2? What are the first and last elements of the output? Given a stride of and padding of , we have that . The first element will be , whereas the last element will be .
Recall that CNN filters have the property of weight sharing, meaning that different portions of an image can share the same weight to extract the same set of features. A convolution is actually a linear operation, which we can express as for some weight matrix .
Find for the convolution applied in the first part. What is its dimension? has a dimension of : it needs to match the shape of the input which has a dimension of , as well as map the input to an output vector with dimension (as calculated in the first part). Each row has 3 nonzero elements:
Consider now a 2-dimensional example with the following image and kernel filter:
Using no padding and a stride of , compute the output, and describe the effect of this filter. We overlap the filter with each window of the image and record the values: