No history yet

Introduction to CNNs

How Neural Networks Learn to See

Standard neural networks are powerful, but they have a weakness: they struggle with images. If you feed a network the pixels of a picture, it sees a massive, flat list of numbers. It has a hard time recognizing that pixels next to each other are related, forming lines, textures, and shapes. Shifting an object slightly in the image can confuse the network entirely.

Convolutional Neural Networks, or CNNs, are designed to solve this problem. Inspired by the human visual cortex, they're built to process data that comes in a grid, like an image. CNNs don't just see individual pixels; they see the whole picture and the relationships within it. They learn to identify features like edges, corners, and textures, no matter where they appear in the image.

CNNs are deep learning models designed to automatically learn hierarchical representations from images.

This ability to learn features in a spatial hierarchy is what makes them the powerhouse behind most modern computer vision tasks, from facial recognition on your phone to the systems that guide self-driving cars.

The Core Components

A CNN is built from three main types of layers, each with a specific job: convolutional layers, pooling layers, and fully connected layers. Let's break them down.

Convolution

noun

A mathematical operation on two functions that produces a third function expressing how the shape of one is modified by the other. In CNNs, it involves sliding a filter over an input to produce a feature map.

The convolutional layer is the heart of a CNN. Its job is to detect features. It uses a set of learnable filters, also called kernels. Think of a filter as a tiny magnifying glass that's trained to spot one specific thing, like a vertical edge, a patch of green, or a certain texture.

This filter slides over every part of the input image, one patch at a time. At each position, it performs a mathematical operation, essentially checking how well the patch of the image matches the feature the filter is looking for. The results are collected into a new grid called a feature map. A strong response in the feature map means the feature was detected at that location.

After a convolutional layer comes an activation function. Its purpose is to introduce non-linearity into the model. Without it, the network could only learn simple, linear relationships. The most common activation function in CNNs is the Rectified Linear Unit, or ReLU. Its job is simple: it looks at each number in the feature map and changes all negative values to zero, leaving positive values untouched. This helps the network learn more complex patterns.

ReLU(x)=max(0,x)ReLU(x) = \max(0, x)

Next up is the pooling layer. Its main goal is to reduce the spatial size of the feature map. This makes the computation faster and also helps the network become more robust to variations in where features appear in the image. The most common type is max pooling. It slides a window over the feature map and, for each patch, keeps only the largest value. It's like summarizing the most important information from a neighborhood of features.

Lesson image

Finally, after several rounds of convolution and pooling, the processed feature maps are flattened into a single, long vector of numbers. This vector is then fed into one or more fully connected layers. These are the same kind of layers you'd find in a standard neural network. Their job is to take the high-level features detected by the earlier layers and use them to make a final prediction, such as classifying the image as a 'cat', 'dog', or 'car'.

Building a Picture of the World

The magic of CNNs lies in stacking these layers. Early convolutional layers learn to recognize very simple features: basic edges, corners, colors, and gradients. The feature maps from these layers are then fed into the next set of convolutional layers.

These deeper layers learn to combine the simple features into more complex ones. For example, a second layer might learn to recognize combinations of edges and corners that form an eye, a nose, or a patch of fur. Layers deeper still might combine those features to recognize the face of a cat.

This process is called hierarchical feature extraction. The network automatically learns a hierarchy of features, from the most basic pixel patterns to complex, abstract concepts, all on its own. It builds a complete, layered understanding of the visual world, which is what allows it to 'see' with such remarkable accuracy.

Lesson image

Understanding these core concepts—convolution, activation, pooling, and hierarchical features—is the first step to mastering how CNNs work and how they can be improved.