Image Classification using
CNN
BS CS 8th Semester
Introduction
• Building an image classification system using Convolutional Neural
Networks (CNNs) is one of the most fundamental tasks in computer
vision.
• CNNs are a type of deep learning model specifically designed for
image recognition and classification.
• CNN automatically learn important features such as edges, textures,
and shapes from images.
Pattern 1: Feature Extraction & Classification
Convolutional nets are typically composed of two parts:
• Feature extraction: consists of a series of convolutional layers
• Classification part, consists of a series of fully connected layers
Common CNN architectures for classification are:
• AlexNet
• VGG16
• ResNet
• MobileNet
• Inception
Pattern 2: Image depth increase & Dimension Decreases
• The input data at each layer is an
image and a new convolutional layer
over an image.
• First, each image is a 3D object that
has a height, width, and depth.
• Depth is referred to as the color
channel, where depth is 1 for
grayscale images and 3 for color
images
• In the later layers, the images still
have depth, but they are not colors:
but feature maps that represent the
features extracted from the previous
layers.
• That’s why the depth increases as we
go deeper through the network
layers.
Pattern 3: Fully Connected Layer
• All fully connected layers in a network either have the same number
of hidden units or decrease at each layer.
• It is rare to find a network where the number of units in the fully
connected layers increases at each layer.
AlexNet: Introduction
• AlexNet is a well-known Convolutional Neural Network (CNN)
architecture designed for image classification.
• It was introduced in 2012 and became popular after achieving
outstanding performance in the ImageNet image classification
competition.
• AlexNet showed that deep CNNs can automatically learn useful
features from large image datasets and achieve high classification
accuracy.
• Its success played an important role in the growth of deep learning
for computer vision.
AlexNet Architecture
• It contains 8 learnable layers
• 5 Convolutional layers
• 3 Fully connected layers.
Large Input Image Size
• Accepts input images of 227 × 227 × 3 pixels.
• Designed to classify RGB color images.
Uses ReLU Activation Function
• Introduced the Rectified Linear Unit (ReLU) activation function.
• ReLU speeds up training and helps overcome the vanishing gradient problem.
Max Pooling Layers
• Uses Max Pooling after selected convolutional layers.
• Reduces the spatial dimensions of feature maps while retaining important features.
AlexNet Architecture
Dropout Regularization
• Uses Dropout in the fully connected layers.
• Prevents overfitting by randomly deactivating neurons during training.
Data Augmentation
• Employs techniques such as random cropping and horizontal flipping.
• Increases the diversity of the training data and improves generalization.
Large Convolution Filters: Uses larger filters in the early layers:
• 11 × 11 in the first convolutional layer
• 5 × 5 in the second layer
• 3 × 3 in the remaining layers
AlexNet
ImageNet Pretraining
• Originally trained on the ImageNet dataset containing over one million
images.
• Learns rich visual features that can be reused for transfer learning.
High Number of Parameters
• Contains approximately 60 million trainable parameters.
• Requires significant computational resources compared to modern
lightweight networks.
Image Classification
• Produces probabilities for 1,000 ImageNet classes using a Softmax output
layer.
Layer Purpose
Conv2D (96 filters, 11×11) Extract basic features such as edges and textures
BatchNormalization Stabilizes and speeds up training
MaxPooling Reduces image size while preserving important information
Conv2D (256 filters, 5×5) Learns more complex patterns
Conv2D (384 filters, 3×3) Learns higher-level features
Conv2D (384 filters, 3×3) Refines extracted features
Conv2D (256 filters, 3×3) Produces rich feature representations
Flatten Converts feature maps into a 1D vector
Dense (4096) Learns high-level representations
Dropout Reduces overfitting
Dense (4096) Further combines learned features
Softmax Predicts the probability of each class
VGGNet: Introduction
• VGGNet is a deep Convolutional Neural Network (CNN) architecture developed by
the Visual Geometry Group (VGG) at the University of Oxford.
• It was introduced in 2014 for image classification.
• VGGNet became popular because of its simple and uniform architecture, which
uses small 3 × 3 convolutional filters throughout the network.
• The most commonly used versions are VGG16 and VGG19, containing 16 and 19
learnable layers, respectively.
VGG16 Architecture
VGG16
• It consists of 16 learnable layers:
• 13 Convolutional Layers
• 3 Fully Connected Layers
Large Number of Parameters
• Contains approximately 138 million trainable parameters.
• Requires more memory and computational power than lightweight models
such as MobileNet.
Small Convolution Filters
• Uses only 3 × 3 convolution filters throughout the network.
• Small filters reduce the number of parameters while enabling the network to
learn complex features through multiple stacked layers
Main Characteristics
• Deep architecture: VGGNet is deeper than earlier CNN architectures such as
AlexNet.
• Small 3 × 3 filters: It consistently uses 3 × 3 convolutional filters to extract image
features.
• 2 × 2 max pooling: Max-pooling layers reduce the spatial dimensions of feature
maps.
• Increasing number of filters: The number of filters gradually increases from 64 →
128 → 256 → 512 as the network becomes deeper.
Main Characteristics
• ReLU activation: ReLU is used after convolutional and fully connected layers.
• Fully connected layers: The final feature maps are passed to fully connected
layers for classification.
• Simple and uniform design: All convolutional layers follow the same design:
• 3 × 3 kernel
• Stride = 1
• Padding = 'same'
• This makes the architecture simple, consistent, and easy to understand.
• Popular for transfer learning: Pretrained VGG16 and VGG19 models are widely
used as feature extractors for different computer vision tasks.
VGG16
Increasing Number of Filters
• The number of filters increases as the network becomes deeper.
Block Number of Filters
Block 1 64
Block 2 128
Block 3 256
Block 4 512
Block 5 512
MobileNet: Introduction
• MobileNet is a lightweight Convolutional Neural Network (CNN)
architecture designed for image classification and other computer
vision tasks on mobile and resource-constrained devices.
• It reduces computational cost and model size while maintaining good
accuracy.
• The key idea behind MobileNet is the use of depth-wise separable
convolutions instead of standard convolution operations.
Depthwise Separable Convolution
• A depthwise separable convolution is a type of neural network layer that factors a
standard convolution into two separate, smaller operations:
• Depthwise Convolution (filtering per input channel).
• Pointwise Convolution (combining channels with a 1x1 convolution).
• The result is a layer that does almost the exact same thing as a standard
convolution but uses
• Significantly fewer parameters and
• Less computation
• Core building block of efficient mobile models like MobileNet and Xception.
Example
Let’s say you have an input image with 16 channels (height x width x 16), and you
want to apply 32 filters (kernels) of size 3x3
Standard Convolution (The "Heavy" Way)
• In a standard convolution, each of your 32 filters is a 3x3x16 cube.
• When you slide this cube over the image, every filter looks at all 16 channels at
once, multiplies them, and sums them into a single number.
• Total multiplications:
3x3 (space) x 16 (channels) x 32 (filters)
= 4,608 multiplications per pixel.
Cont.…
Depthwise Separable Convolution (The "Smart" Way)
• Instead of doing it all at once, we split it into two steps:
Step A: Depthwise Convolution (Spatial Filtering)
• Instead of 32 filters that cover all 16 channels, we use exactly 16 filters, each of
size 3x3x1.
• Filter #1 looks only at Channel #1. Filter #2 looks only at Channel #2.
• This preserves the spatial information (edges, textures) but does not combine
information across channels. The output is still 16 channels.
• Multiplications
3x3 (space) x 16 (channels)
= 144 multiplications per pixel.
Cont.…
Step B: Pointwise Convolution (Channel Mixing)
• Now we take the 16-channel output from Step A and apply a 1x1 convolution.
• We use 32 filters, each of size 1x1x16. This mixes all the channels together at each pixel
to create the final 32 output channels.
• Multiplications now:
1x1 (space) x 16 (channels) x 32 (filters)
= 512 multiplications per pixel.
Final Calculation
• Standard Conv: 3 x 3 x 16 x 32 = 4,608 operations.
• Separable Conv: (3 x 3 x 16) + (1 x 1 x 16 x 32) = 144 + 512 = 656 operations.
Example 2
Standard Convolution (The "Heavy" Way)
• You have an input with 3 channels (R, G, B).
• Each of your 32 filters is a 3x3x3 cube.
• As this cube slides over the image, every filter looks at all 3 RGB channels at
once, multiplies them, and sums them into a single output number.
Total multiplications per pixel:
3x3 (space) x 3 (RGB channels) x 32 (filters)
= 864 multiplications.
Cont.…
Depthwise Separable Convolution (The "Smart" Way): We split it into two steps
Step A: Depthwise Convolution (Spatial Filtering)
Instead of 32 filters that cover all 3 channels, we use exactly 3 filters, each of
size 3x3x1.
• Filter #1 looks only at the Red channel.
• Filter #2 looks only at the Green channel.
• Filter #3 looks only at the Blue channel.
Multiplications
3x3 (space) x 3 (RGB channels)
= 27 multiplications per pixel.
Cont.…
• Step B: Pointwise Convolution (Channel Mixing)
• Now we take the 3-channel output from Step A and apply a 1x1 convolution.
• We use 32 filters, each of size 1x1x3. This steps across every pixel, takes the 3
RGB values at that exact spot, and mixes them together to create the final 32
output channels.
Multiplications
1x1 (space) x 3 (RGB channels) x 32 (filters)
= 96 multiplications per pixel.
Comparison
Standard Conv: 3 x 3 x 3 x 32 = 864 operations.
Separable Conv: (3 x 3 x 3) + (1 x 1 x 3 x 32) = 27 + 96 = 123 operations.
This separation requires far fewer computations and parameters, which is why MobileNet is suitable for
mobile phones and resource-constrained devices.
Main Characteristics
• Lightweight architecture
• Designed to use fewer parameters and less memory.
• Depthwise separable convolution
• Replaces standard convolution with depthwise convolution followed by
pointwise (1 × 1) convolution.
• Computationally efficient
• Requires fewer computations than traditional CNN architectures such as
VGGNet.
• Suitable for mobile devices
• Can run efficiently on smartphones and embedded systems.
Main Characteristics
• Smaller model size
• Requires less storage compared with large CNN models.
• Good accuracy–efficiency balance
• Provides competitive accuracy while reducing computational cost.
• Supports transfer learning
• Pretrained MobileNet models can be adapted to new image classification
tasks.
• Multiple versions
• Common versions include MobileNetV1, MobileNetV2, and MobileNetV3.
Number of Parameters
Architecture Approx. Total Parameters
MobileNetV1 4.2 million
MobileNetV2 3.5 million
MobileNetV3-Small 2.5 million
MobileNetV3-Large 5.4 million
MobileNetV1 has approximately 4.2 million trainable parameters, which is
much smaller than VGG16 (~138 million parameters).