Lesson 32: Convolutional Neural Networks (CNNs)

How CNNs learn to recognize images, patterns, and spatial features

What Are CNNs?

Convolutional Neural Networks (CNNs) are specialized neural networks designed to process grid‑like data such as images. They automatically learn spatial features like edges, textures, shapes, and objects, making them essential for computer vision.

Why CNNs Work Well for Images

Key Components of CNNs

Convolutional Layers

These layers apply filters (kernels) that slide across the image to detect features.

output = convolution(input, filter)

Activation Functions

ReLU is the most common activation in CNNs.

Pooling Layers

Pooling reduces spatial size and keeps important features.

Fully Connected Layers

These layers perform classification after feature extraction.

A Simple CNN Example (Keras)

from tensorflow import keras
from tensorflow.keras import layers

model = keras.Sequential([
    layers.Conv2D(32, (3,3), activation="relu", input_shape=(28,28,1)),
    layers.MaxPooling2D((2,2)),
    layers.Conv2D(64, (3,3), activation="relu"),
    layers.MaxPooling2D((2,2)),
    layers.Flatten(),
    layers.Dense(64, activation="relu"),
    layers.Dense(10, activation="softmax")
])

model.compile(optimizer="adam",
              loss="sparse_categorical_crossentropy",
              metrics=["accuracy"])

print(model.summary())

How CNNs Learn

Common CNN Architectures

Applications of CNNs

Next Steps

Now that you understand CNNs, you're ready to explore sequence‑based models in Lesson 33: Recurrent Neural Networks (RNNs).

← Back to Lesson Index