Coding Hubs School of AI – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 8448811540
Back to Deep Learning Notes
Topic #349

What Is CNN?

A Convolutional Neural Network (CNN) is a neural network architecture specialized for grid-structured data — most commonly images — built around a single core operation, convolution, that fundamentally changes how a network connects to its input compared to the fully-connected MLPs covered earlier in this hub.

The High-Level Idea

Instead of connecting every input pixel to every neuron (as an MLP would), a CNN slides small, learnable filters across the image, each one detecting a specific local pattern — an edge, a texture, a color transition — at every position. Stacking several such layers builds up a hierarchy: early layers detect simple patterns (edges, corners), middle layers combine these into more complex shapes (textures, object parts), and later layers assemble those into recognizable whole objects.

A Typical CNN Pipeline

Input Image Conv + ReLU Pooling (repeated) Conv + Pool Flatten Fully Connected Layer(s) → Output (class probabilities)

Convolution and pooling layers extract increasingly abstract spatial features; flattening and fully connected layers turn those features into a final prediction.

Code — A Minimal CNN

import torch.nn as nn

model = nn.Sequential(
    nn.Conv2d(in_channels=3, out_channels=16, kernel_size=3, padding=1),   # convolution
    nn.ReLU(),
    nn.MaxPool2d(kernel_size=2),                                            # pooling

    nn.Conv2d(16, 32, kernel_size=3, padding=1),
    nn.ReLU(),
    nn.MaxPool2d(kernel_size=2),

    nn.Flatten(),
    nn.Linear(32 * 8 * 8, 10)   # fully connected output layer (assuming input was 32x32)
)

Every Term in the Rest of This Category, Previewed

TermRole
ConvolutionThe sliding, weight-sharing pattern-detection operation itself
Kernel / FilterThe small learnable weight matrix that gets slid across the input
Feature mapThe output produced by applying one filter across the whole input
Stride, paddingControls over how the kernel moves and how edges are handled
PoolingDownsampling feature maps to reduce size and add robustness

Common Mistakes

  • Assuming a CNN is just "an MLP for images" with no structural difference — the entire point of convolution (covered starting next note) is a fundamentally different, far more parameter-efficient way of connecting to spatial input, not simply a renamed MLP.
  • Thinking CNNs are exclusively for images — the same convolution operation applies to any grid-like, spatially-structured data (1-D convolutions for audio/time-series, 3-D convolutions for video or volumetric medical scans).

Interview Relevance

Q: "At a high level, what makes a CNN different from a standard fully-connected network?" A CNN uses convolution — sliding small, learnable filters across the input, sharing the same weights at every spatial position — instead of connecting every input value to every neuron. This gives CNNs far fewer parameters for image-sized inputs, an inductive bias toward detecting local patterns, and a degree of translation invariance that plain MLPs lack entirely.

Practice Question

In your own words, why might a network built from convolution operations naturally suit image data better than one built purely from fully-connected layers?

Related DL Notes

Want to go beyond the notes?

Join Coding Hubs School of AI's Deep Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →