Basic CNN Architecture: A Detailed Explanation of the 5 Layers in Convolutional Neural Networks
Updated on Mar 03, 2025 | 12 min read | 281.9k views
Share:
For working professionals
For fresh graduates
More
Updated on Mar 03, 2025 | 12 min read | 281.9k views
Share:
Table of Contents
Did you know machine learning models can detect heart disease from sound signals with 95.65% accuracy? The technology driving this impressive result is Convolutional Neural Networks (CNN), which are powering advancements across various industries.
CNNs are a fundamental architecture in machine learning, allowing machines to learn from training data and make accurate predictions. In today’s world, machine learning separates efficiency from complacency and success from failure. To enhance system accuracy and performance, understanding the basic CNN architecture is essential.
If you're looking to learn CNN for a career in machine learning, understanding basic CNN architecture is essential. You’ll explore CNN architecture and its real-world applications. Let’s get started!
Convolutional Neural Networks (CNNs) are a type of deep learning model used for image recognition, processing, and classification. With basic CNN architecture, you can automatically and efficiently extract features from input data.
The working of basic CNN architecture is like solving a puzzle. It first identifies individual pieces (comparable to identifying features like edges or shapes in an image) and then puts them to get the full picture (similar to classification or output).
In today’s world, CNNs are widely used for purposes such as video recognition (e.g., facial recognition), medical imaging (e.g., detecting cancerous tumors), self-driving cars (e.g., identifying road signs), and natural language processing (e.g., text classification).
The CNN architecture can be divided into five components. Here’s an overview of the five layers.
Convolutional layers scan the input data using filters (kernels) to detect patterns like edges, textures, or shapes.
Pooling layers preserve key features while reducing computational complexity. This helps reduce multiple dimensions.
Activation layers apply non-linear functions like ReLU to introduce non-linearity. This enables the network to learn complex patterns.
Once the feature has been extracted, the data is converted into a vector and passed through fully connected layers for classification.
The output layer provides the final prediction using a Softmax function for classification tasks.
Among all CNN operations, convolution is the core operation in basic CNN architecture that enables the model to extract meaningful features from input data. It applies filters to the input, detecting patterns like edges, textures, and shapes in an image. Mastering basic CNN architecture is crucial for developing models that excel in image recognition and classification tasks.
Here is the importance of convolution in CNN.
Feature | Description |
Feature Detection | Convolution starts from low-level features like edges and textures and then learns complex patterns like shapes and objects. |
Spatial Hierarchy | Convolution focuses on small parts of an image to detect patterns and their positions. |
Parameter Efficiency | It reduces the number of parameters in input, making the network computationally efficient. |
Translation Invariance | Through convolution, the network recognizes patterns regardless of their position in the input. |
Layered Learning | Hierarchical learning combines simple features to form complex structures for accurate predictions. |
Now that you’ve seen an overview of basic CNN architecture, let’s explore the five layers of CNN architecture in detail.
The convolutional layer, pooling layer, fully connected layer, dropout layer, and activation functions work together in CNNs to extract features and classify data efficiently. Here’s a breakdown of all the five layers in CNN architecture.
This layer performs a convolution operation, which is to apply filters to the input image to generate a feature map. It helps detect patterns such as edges or textures, thereby preserving spatial relationships between pixels. Maintaining the spatial features allows it to identify local features.
In this layer, a mathematical convolutional operation is performed between the image and the filter of size MxM. The filter slides over the input image, and the dot product of the filter and the part of the image is taken with respect to the filter size (MxM).
The output is called the feature map, which gives us information about the image such as the corners and edges. This information is then fed to other layers to learn several other features of the input image.
Example: Let’s consider an example of identifying whether an image contains a cat. This layer detects the cat's whiskers or ears in the image.
The polling layer reduces the dimensions of the feature map without affecting the key features. Max Pooling (selecting the maximum value), Average Pooling (average value), and Sum Pooling (sum of values) are the common types used. Pooling summarizes the features generated by a convolution layer.
In Max Pooling, the largest element from the feature map is taken. Average Pooling calculates the average of the elements in a certain Image section. The Sum Pooling calculates the total sum of the elements in a predefined section. The Pooling Layer acts as a bridge between the Convolutional Layer and the FC Layer.
By generalizing the features extracted by the convolution layer, the poling layer helps the networks recognize the features independently and also reduces the chances of overfitting.
Example: For detecting a cat in an image, the pooling layer simplifies the whiskers' feature by summarising their presence in a smaller region.
This layer connects every neuron in one layer to every neuron in the next. The flattening process is used to convert all the multi-dimensional features into a one-dimensional vector. These layers in CNN reduce human supervision.
In this layer, the input images from the previous layers are flattened and fed to the FC layer. The flattened vector then passes through a few more FC layers where the mathematical functions operations usually take place. At this stage, the classification process begins to take place. The reason why two layers are connected is that two fully connected layers perform better than a single connected layer.
Example: For identifying a cat in an image, this layer checks if the detected features collectively represent a cat.
The dropout layer randomly deactivates a fraction of neurons during training to prevent overfitting. Overfitting occurs when a particular model works well on the training data, causing a negative impact when used on new data. This process ensures that the model generalizes well for unseen data.
A dropout layer is used wherein a few neurons are dropped from the neural network during the training process, reducing the model size. This layer ensures that the model reduces dependency on specific neurons.
Example: For the same example, 30% of neurons in a layer are turned off during each training iteration.
Also Read: What is Overfitting & Underfitting In Machine Learning? [Everything You Need to Learn]
The activation function introduces non-linearity (learn making conditional decisions for controlling the computational flow), thus helping the network to identify complex relationships in the data. The activation function decides which information of the model should fire in the forward direction and which ones should not at the end of the network.
ReLU, Softmax, and Sigmoid are common activation functions. Each of these functions has a specific usage. For a binary classification CNN model, sigmoid and softmax functions are preferred, while softmax is used for multi-class classification.
Example: ReLU makes sure that the model focuses only on meaningful features like a cat’s distinct patterns.
Now that you’ve explored the layers in CNN architecture, let’s understand how ReLU functions in CNN.
ReLU (Rectified Linear Unit) is the most widely used activation function in CNNs. It introduces non-linearity in CNN, thus allowing the network to learn and model complex patterns efficiently.
Here’s the ability of ReLU to introduce non-linearity in CNN.
ReLU’s ability to introduce non-linearity allows the model to learn complex patterns in data. Here’s how ReLU impacts the learning of these patterns.
ReLU removes irrelevant negative values, ensuring the network focuses on useful patterns.
Unlike activation functions like tanH or Sigmoid, ReLU doesn’t saturate for large positive values. This allows better gradient flow during training.
ReLU’s simple mathematical operation increases training speed by reducing computation time.
ReLU’s effectiveness in passing gradients helps prevent the vanishing gradient problem, making it suitable for deep networks.
Also Read: Everything you need to know about Activation Function in ML
Now that you understand ReLU and its role in enhancing CNN’s capabilities, let’s take a closer look at LeNet-5.
LeNet-5 was one of the first convolutional neural networks designed for handwritten digit recognition. It was introduced by Yann LeCun in 1998. LeNet-5 is said to have laid the foundation for modern deep-learning models.
Here’s an in-depth breakdown of the seven layers in the LeNet-5 architecture.
1. The Input Layer
The input layer takes a 32x32 grayscale image as an input. It normalizes pixel values to a range of 0 to 1, ensuring consistent input for the network.
The dimensions of the image shift from 32x32x1 to 28x28x6.
2. Convolutional Layer 1
This layer makes use of 6 filters of size 5x5 with a stride of 1 (filter moves one filter at a time) to scan the input. It captures low-level features like edges and corners and produces 6 feature maps of size 28x28.
ReLU activation introduces non-linearity at this layer, allowing the network to learn complex patterns.
3. Pooling Layer 1
A pooling layer with a 2x2 filter and stride 2 (spatial dimensions are reduced by half) cuts down the size of each feature map to 14x14.
4. Convolutional Layer 2
It applies 16 filters of size 5x5 with a stride of 1 (scans pixel by pixel) to the 14x14 feature maps from the previous layer.
The layer generates 16 feature maps of size 10x10 by extracting higher-level features like shapes or specific patterns. ReLU activation reapplied to improve learning.
5. Pooling Layer 2
The pooling layer with a 2x2 filter and stride 2 (reducing spatial dimensions by half) further reduces the size of the feature maps to 5x5. This simplifies the data while preserving critical data.
6. Fully-Connected Layer
The 5x5 feature maps are flattened into a vector of 400 values. This vector is connected to 120 neurons in the first fully connected layer, which represents the features in more abstract representations. A second fully connected layer with 84 neurons further refines the learned representations. ReLU activation is used to maintain non-linearity.
7. Output Layer
The final output contains 10 neurons, each corresponding to one of the digit classes (0–9). A softmax activation function converts the raw scores into probabilities, enabling the network to classify the input into the most likely category.
Here’s a Python implementation of LeNet-5 using Keras and TensorFlow.
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, AveragePooling2D, Flatten, Dense, Softmax
# Define the LeNet-5 model
model = Sequential([
Conv2D(filters=6, kernel_size=(5, 5), activation='relu', input_shape=(32, 32, 1)),
AveragePooling2D(pool_size=(2, 2)),
Conv2D(filters=16, kernel_size=(5, 5), activation='relu'),
AveragePooling2D(pool_size=(2, 2)),
Flatten(),
Dense(units=120, activation='relu'),
Dense(units=84, activation='relu'),
Dense(units=10, activation='softmax') # Output layer for 10 classes
])
# Compile the model
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
# Display the model summary
model.summary()
Also Read: Top 10 Neural Network Architectures in 2024 ML Engineers Need to Learn
Now that you’ve explored LeNet-5 in detail, let’s examine the best practices for implementing CNNs.
Adherence to best practices in Convolutional Neural Networks (CNNs) ensures optimal performance, prevents overfitting, and enhances model generalization. Here are the best practices for CNN implementation.
Data preprocessing improves the model’s ability to learn effectively by standardizing input data and increasing dataset diversity. You can apply techniques like rotation, flipping, and scaling to expand the dataset and improve the model’s generalization.
Optimal hyperparameters balance the model’s complexity and computational efficiency. Use smaller filters for detailed feature extraction. Select the appropriate number of layers and neurons to match the complexity of the task.
Overfitting takes place when a model performs well on training data but poorly on unseen data. To avoid overfitting, randomly deactivate neurons during training. Penalize large weights to discourage overfitting (using the L2 for regularization). Stop training when validation performance stabilizes.
Use appropriate tools to simplify development and optimize performance. Use Python frameworks and libraries like Tensorflow, PyTorch, and Keras.
Optimization ensures the model trains efficiently and achieves high accuracy within a reasonable timeframe. Use GPUs or TPUs to increase training speed. Improve convergence by adjusting the learning rate.
Also Read: Types of Optimizers in Deep Learning: Best Optimizers for Neural Networks in 2025
Now that you’re familiar with the best practices for implementing basic CNN architecture, let’s explore its top real-world applications.
CNNs’ ability to extract and process features from complex data like images, text, and videos has led to their widespread use in sectors such as surveillance and healthcare. Here are the top applications of CNNs in the real world.
Application | Description |
Image Recognition and Classification | CNNs are used to identify objects, people, or scenes in photos and videos. Example: Facebook uses image recognition to automatically tag people in photos by recognising their faces. |
Medical Imaging Diagnostics | CNNs can help in disease detection by analyzing medical images like X-rays, MRIs, and CT scans. Example: AI systems use CNNs to detect abnormalities like tumours in radiology. |
Autonomous Vehicles | CNNs are used in autonomous vehicles to analyze visual data from cameras and sensors to navigate safely. Example: Tesla autopilot uses CNNs to detect pedestrians, road signs, and vehicles while navigating. |
Natural Language Processing (NLP) | You can use CNNs for tasks like text classification, sentiment analysis, and translation. Example: CNNs are used in email spam filters to identify and classify spam messages. |
Retail and E-Commerce | CNNs can be used for recommendation systems, virtual try-on tools, and inventory management. Example: Amazon’s product recommendation engine uses CNNs to suggest visually similar items. |
Learn how to solve real-world problems by combining AI and machine learning. Join the free course on Artificial Intelligence in the Real World.
Now that you’ve explored real-life applications of CNNs, let’s explore ways to deepen your knowledge of CNN.
CNNs are a vital component of deep learning and machine learning. Their ability to process complex data, such as images, has revolutionized how machines understand and interpret visual information.
To succeed in this field, you’ll need a blend of technical expertise (neural networks, programming language, and data analytics) and soft skills (problem-solving, analytical thinking, and critical thinking).
upGrad’s machine learning courses equip you with essential skills, covering everything from neural networks to advanced CNN techniques, providing a strong foundation to build your career.
Here are the courses that can help you master CNN.
Similar Read:
Expand your expertise with the best resources available. Browse the programs below to find your ideal fit in Best Machine Learning and AI Courses Online.
Basic CNN architecture is the foundation of modern deep learning models, enabling efficient feature extraction and accurate predictions. The five layers in CNN architecture—convolutional, pooling, activation, fully connected, and output—each play a crucial role in processing and interpreting data.
As deep learning advances in 2025, optimizing these layers will be key to building more robust and efficient AI systems. A solid grasp of basic CNN architecture opens the door to innovation in fields like healthcare, finance, and autonomous technologies.
Also Read about differences between deep learning and neural networks.
Discover in-demand Machine Learning skills to expand your expertise. Explore the programs below to find the perfect fit for your goals.
Discover popular AI and ML blogs and free courses to deepen your expertise. Explore the programs below to find your perfect fit.
Reference Link:
https://www.nature.com/articles/s41598-024-53778-7
Get Free Consultation
By submitting, I accept the T&C and
Privacy Policy
Top Resources