Convolutional Neural Networks (CNNs)
CNNs and their architecture explained
Convolutional Neural Networks (CNNs)
What is a Convolutional Neural Network?
A Convolutional Neural Network (CNN) is a specialized deep learning architecture that is designed to automatically and adaptively learn spatial hierarchies of features from data through convolution operations. It is particularly for tasks involving grid-like data such as images. It begins by identifying low-level patterns (edges, corners) and progressively learns high-level features (shapes, objects, faces). CNNs are highly effective in computer vision tasks such as image classification, object detection, facial recognition, and medical imaging.

Convolutional Neural Network — CNN Architecture
Architecture of a Convolutional Neural Network (CNN)
The architecture of a CNN is inspired by the human visual system and is built with multiple layers that extract features from input data step by step. Each layer has a specific purpose — from detecting simple edges to understanding entire objects.
A typical CNN architecture consists of the following main components:
1. Input layer:
It is the first and most fundamental layer, serving as the entry point for the raw data that the network will process. It does not perform any complex computations or feature extraction. It’s primary job is to feed data into the network for further processing.
Before the input data enters the first convolutional layer, it usually undergoes some form of preprocessing like resizing and normalization to improve stability during training and speed up convergence.
For image-based CNNs, the input layer receives the image in 3-dimensional tensor form, containing raw pixel information.
1.1 Structure of Input Data:
The image is represented as a 3D volume (W × H × D), where:

- RGB color image → 3 channels (D = 3)
- Grayscale → 1 channel (D = 1)
- Example input size: 224 × 224 × 3 for a standard RGB image
- The values stored are/represent pixel intensities, typically in the range 0–255.
2. Convolutional Layer (Feature Extraction Layer):
The convolutional layer is the core building block of a CNN, responsible for automatically and adaptively learning spatial features from input data. It uses small, learnable filters/kernels that slide over the input image and perform dot-product operations to generate feature maps (activation maps), which highlight important patterns.
It extracts simple features like edges, curves, and textures in early layers, and more complex structures (shapes, object parts) in deeper layers.
2.1 Key Components & Working
a. Filter / Kernel
It is a small matrix of learnable weights (e.g. 3×3, 5×5) that slides across the input image during the convolution operation. Each filter is designed to detect a specific, local pattern — a horizontal edge, a specific color blob, or a corner. The values within the filter are the parameters that the network learns or adjusts during training (via backpropagation). A filter spans the full depth of the input → e.g., for RGB: filter depth = 3.
b. Convolution Operation
It involves sliding the kernel/filter over the input image like a scanning window.
Steps:
- A filter (kernel) is placed on a small region of the input image.
- An element-wise multiplication is performed between the filter’s values and the corresponding input patch values.
- All the resulting products are summed up into a single number.
- This single number becomes one pixel in the output Feature Map.
- The filter is then slid across the entire input image, and the same process is repeated. The step size by which the filter moves is called the stride.
c. Feature Map (Activation Map)
Output generated from convolution of one filter across the entire input image is called Feature Map. It shows where and how strongly the feature is detected. A high value at a location (x,y) indicates that the feature is strongly detected at that position. If the layer uses k filters, it produces k feature maps → forming the output volume of the layer.

Convolution Operation
2.2 Key benefits of the Convolutional Layer
1) Parameter Sharing (Weight Sharing)
In CNNs, the same filter (the same set of weights) is applied across the entire input image, instead of learning separate weights for every pixel location.
- this drastically reduces the total number of learnable parameters
- Makes training faster and more memory-efficient
2) Translation Invariance or Spatial Invariance
Because one filter slides over all spatial locations, a feature learned in one part of the image(e.g., a nose in the top-left) can be recognized anywhere else in the image(bottom-right).
- Makes CNNs robust to position changes
- Helps in recognizing objects regardless of location within the image
2.3 Padding and Stride
Padding and stride are hyperparameters of the convolution operation that determine how the filter is applied. They control the spatial dimensions (height and width) of the output feature map by preserving, reducing, or expanding the input size.
2.3.1 Padding
Padding is the process of adding extra rows and columns of pixels (usually zeros) around the input data (image or feature map) before applying a convolution operation. It helps preserve the spatial size of the feature map, prevents loss of boundary information, and allows the filter to process edge pixels effectively.

Padding
Purpose of Padding
1. To preserve spatial dimensions:
When a filter (kernel) is convolved over an image, the resulting output feature map is mathematically smaller than the input if no padding is used. If the input image size is N × N and the filter size is F × F, with a stride of 1 and no padding (valid convolution), the output size is:
(N − F + 1) × (N − F + 1)
In deep neural networks, repeatedly applying convolutional layers without padding causes the feature maps to shrink rapidly. After only a few layers, the spatial dimensions may reduce to 1 × 1, which restricts the network’s ability to learn rich hierarchical features and limits network depth. Padding addresses this issue by adding extra pixels (typically zeros) around the input image, enabling the construction of much deeper convolutional architectures.
2. To avoid losing edge information:
Without padding, the pixels on the edges and corners of the input image participate in the convolution operation far less frequently than the pixels in the center. As a result, features near the borders are underrepresented, leading to a loss of potentially important information. By adding padding, we ensure that edge and corner pixels are processed effectively, allowing all pixels to contribute equally to the output feature maps.
3. To control output size:
Padding is used to control the spatial dimensions of the output feature map. In valid convolution, no padding is applied and the output size shrinks/decreases. In same convolution, appropriate padding is applied such that the output size remains the same as the input size.
2.3.2 Stride
The step size of the convolution filter movement across the input is called the stride. Stride controls how the filter moves over the input, i.e., the number of pixels the filter shifts across the input matrix. If the stride is set to 1, the filter moves one pixel at a time; if the stride is 2, it moves two pixels at a time.

Convolution Operation with Stride=2
A larger stride results in a smaller output feature map, and a smaller stride results in a larger output feature map.

Convolution Operation with Stride = 1 and 2
3. Pooling Layer:
Pooling Layers (also known as subsampling or downsampling layers) are a fundamental component of Convolutional Neural Networks (CNNs). They are typically inserted between successive convolutional layers to progressively reduce the spatial dimensions (width and height) of the feature maps while retaining the most important information.
3.1 Main Functions of Pooling
- Dimensionality Reduction: Pooling significantly reduces the spatial size of the feature maps, which decreases the number of parameters and computations in the network. This lowers memory usage and speeds up training.
- Translation Invariance: Pooling makes the network less sensitive to the exact position of a feature in the input image. Even if an object is slightly shifted or distorted, the pooled output remains largely unchanged, making the model more robust and better at generalization.
- Overfitting Control: By reducing the number of parameters and consolidating features, pooling provides a form of regularization, helping to prevent the model from overfitting the training data.
- Dominant Feature Extraction: Pooling, especially max pooling, captures the most prominent or strongest features within a region, ensuring that important features are preserved while less significant details are discarded.
3.2 How Pooling Works?
It involves a sliding window process, similar to convolution, but without any learnable weights:
- Define a Window: A pooling window (e.g., 2×2) and a stride (the step size) are defined.
- Slide and Select: The window slides across the input feature map, and a fixed operation (Max or Average) is applied to the values within that region.
- Output: The result of the operation (the maximum value or the average value) becomes a single element in the new, smaller feature map.
For example, a 4×4 feature map with 2×2 Max Pooling and a stride of 2 will be reduced to a 2×2 output map.
3.3 Types of Pooling
The operation used within the pooling window determines the type of pooling.
- Max Pooling: It slides a window (e.g., 2×2) over the input feature map and outputs the maximum value found within that window. It preserves the most dominant feature from that region.
- Average Pooling: It calculates the average of the values within the pooling window.

Types of Pooling
4. Flatten Layer:
The Flatten layer converts the multi-dimensional feature maps obtained after convolution and pooling operation into a single 1D vector so that it can be fed into Fully Connected (Dense) layers for final classification.
It bridges the convolution or pooling part of the neural network with the fully connected /dense part.
5. Dense Layers:
In a dense layer, each neuron is connected to every neuron in the previous layer. In CNNs, dense layers typically follow the convolutional and pooling layers and are responsible for mapping the learned features to the final output.
- Flattening: Before the first dense layer, the 3D output volume from the final pooling layer is flattened into a single 1D vector.
- Matrix Multiplication: The dense layer performs standard matrix multiplication between this vector and the learnable weights.
- High-level reasoning: It combines the high-level features learned by earlier layers.
- Output generation: The output layer (the final dense layer) produces the final result of the network’s processing, such as a prediction or class label. It applies an appropriate activation function — sigmoid for binary classification and softmax for multiclass classification — to output a probability distribution over the possible classes to convert raw outputs into class probabilities. Based on these probabilities (e.g., 0.8 for cat and 0.2 for dog), the network generates the final prediction.
Since a fully connected (dense) layer contains a large number of parameters, it is prone to overfitting. Dropout is a regularization technique used mainly in fully connected layers to reduce overfitting by randomly deactivating neurons during training.
5.1 Softmax Activation Function
The Softmax activation function is mainly used in the output layer of multi-class classification problems (when we have more than two classes to predict). It ensures that each class is assigned a probability, helping to identify which class the input belongs to.
Softmax converts a vector of raw scores (logits) into probabilities, such that:
- Each output value lies between 0 and 1
- The sum of all output values = 1
So, it tells how likely each class is.



So, the model predicts the class with highest probability i.e. Cat with 62% probability.
Applications of Convolutional Neural Networks
- Image Classification CNNs are used to identify and categorize images into predefined classes (e.g., cat, dog, vehicle).
- Object Detection CNNs detect and locate multiple objects within an image using bounding boxes (e.g., YOLO, SSD).
- Face Recognition Used in Attendance systems, surveillance, and smartphone authentication.
- Medical Image Analysis CNNs assist in detecting diseases from X-rays, MRIs, CT scans, and pathology images.
- Autonomous Vehicles Applied in lane detection, traffic sign recognition, pedestrian detection, and obstacle avoidance.
- Video Analysis and Surveillance Used for activity recognition, motion detection, and real-time monitoring.
- Optical Character Recognition (OCR) CNNs recognize handwritten and printed text in documents and images (cheques, forms, postal codes).
메타데이터
- post_id
- 5442d9971bbf
- slug
- convolutional-neural-networks-5442d9971bbf
- url
- https://medium.com/@pavitrarao2274/convolutional-neural-networks-5442d9971bbf
- canonical_url
- https://medium.com/@pavitrarao2274/convolutional-neural-networks-5442d9971bbf
- author_url
- https://medium.com/@pavitrarao2274
- status
- ok
- fetched_at
- 2026-07-18 22:05:24