⬡ Hub
Skip to content

Convolutional Neural Networks (CNNs)

While standard Artificial Neural Networks (ANNs) accept 1D vectors of data, CNNs are designed specifically to process spatial data like 2D images and 3D videos.

If you feed a 1000x1000 pixel image into a standard ANN, the first layer would require $1000 \times 1000 = 1,000,000$ input neurons. Connected to a hidden layer of 1000 neurons, that equals 1 Billion weights just for the first layer! The model would immediately overfit and crash the computer's memory.

1. The Convolutional Layer

Instead of connecting every pixel to every neuron, a CNN sweeps small "filters" (or kernels, usually 3x3 matrices) across the image. - Local Connectivity: The network only looks at a small 3x3 patch of pixels at a time. - Shared Weights: The same 3x3 filter is used across the entire image. This reduces the number of parameters from 1 Billion down to literally just 9. - Feature Maps: As the filters slide across the image, they perform matrix math (Dot Products) to detect spatial features: horizontal lines, vertical lines, curves, and eventually complex shapes like eyes or wheels.

2. Pooling (Subsampling)

After a Convolutional layer detects features, the image is passed through a Pooling layer (usually Max Pooling). - Function: It slides a 2x2 window across the image and only keeps the maximum pixel value from that window, discarding the rest. - Result: This mathematically shrinking the image's dimensions by 50% while retaining the most important features. It makes the network vastly more efficient and provides "translation invariance" (meaning the network can recognize a cat even if it is shifted slightly to the left in the frame).

3. The Fully Connected (Dense) Classifier

After passing through multiple alternating Convolutional and Pooling layers, the image is compressed into a tiny, deep array of rich features. This array is mathematically Flattened into a 1D vector and passed into a standard ANN (Dense Layers) to perform the final classification (e.g., "Is this a Dog or a Cat?").

How to execute the examples:

Go to the Examples/ folder and run the script: python CNN_ImageClassification.py