Convolutional Neural Networks
Convolutional Neural Networks (CNNs) are a class of deep learning models particularly well-suited for processing data with a grid-like topology, such as images. They are designed to automatically and adaptively learn spatial hierarchies of features through the use of convolutional layers, pooling layers, and fully connected layers.
Why not NNs for Images?
Traditional Neural Networks (NNs) (called Dense or Fully Connected networks) treat input data as a flat vector, which can lead to several issues when dealing with images:
- High Dimensionality: Images often have a large number of pixels, leading to a high-dimensional input space. This can result in a massive number of parameters in the NN, making it computationally expensive and prone to overfitting. Previously we worked with MNIST images of size pixels ( features), that's already parameters just for a first hidden layer with neurons! For an image of pixels ( features), this number skyrockets to parameters just for the first hidden layer!
- Loss of Spatial Structure: By flattening the image, our NN has no idea that two pixels are next to each other. It loses all information about edges, corners, and shapes.
How CNNs Solve These Issues
CCNs solve these by using new type of layers (not Dense layers like in traditional NNs) at the beginning of the network. Instead of connecting every input pixel to every neuron in the next layer, they use:
- Convolutional Layers: These use small filters or kernels (like or windows) that slide across the image to find local patterns such as edges, textures, corners, or a patch of color. This is the core new concept in CNNs.
- Pooling Layers: These shrink the image (downsample) to make it more manageable and help the network recognize a pattern no matter where it appears in the image.
After these new layers find the patterns, the final flattened output is fed into a regular Dense network just like the one we built for NNs on MNIST.