Convolutional Neural Networks (CNNs)
Overview
Convolutional Neural Networks are a class of deep neural networks that excel at processing data with a grid-like topology, such as images. They automatically learn spatial hierarchies of features through convolutional layers, pooling, and non‑linear activations.
Typical Architecture
- Input Layer – raw pixel data (e.g., 224×224×3).
- Convolutional Layers – apply learnable filters to extract local patterns.
- Activation Functions – commonly ReLU to introduce non‑linearity.
- Pooling Layers – down‑sample feature maps (max‑pool or average‑pool).
- Fully Connected Layers – interpret high‑level features for classification.
- Output Layer – softmax or sigmoid for the final prediction.
Convolutional Layer Explained
A convolution operation slides a filter (kernel) over the input, computing dot products to produce a feature map.
The demo visualizes a 3×3 edge‑detecting kernel applied to a grayscale image.
Implementation with TensorFlow/Keras
import tensorflow as tf
from tensorflow.keras import layers, models
model = models.Sequential([
layers.Input(shape=(32, 32, 3)),
layers.Conv2D(32, (3,3), activation='relu', padding='same'),
layers.MaxPooling2D((2,2)),
layers.Conv2D(64, (3,3), activation='relu', padding='same'),
layers.MaxPooling2D((2,2)),
layers.Flatten(),
layers.Dense(128, activation='relu'),
layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.summary()