1 of 43

Artificial Intelligence and Machine Learning

6CS012 - Week 5 – Introduction to CNN

2 of 43

Introduction � Convolutional Neural Network

3 of 43

Tasks in Computer Vision

3

4 of 43

How do computers see images?

Images are just numbers

5 of 43

Deep Learning task with images

5

6 of 43

Deep Learning Tasks with Images

7 of 43

We need features to Identify the images

Lets Identify the features

  • Nose
  • Eyes
  • Hair
  • Wheels
  • License Plate
  • Lights
  • Doors
  • Windows
  • Roof

8 of 43

Manual Feature Extraction

  • We need Domain Expertise
  • Time-consuming
  • Subjectivity
  • Limited Scalability

9 of 43

Manual Feature Extraction

10 of 43

Learning Feature Representations

  • Can we learn the hierarchical features directly from the data instead of hand engineering?

11 of 43

Fully Connected Neural Network

​

  • Automatic feature extraction

​

  • Learns representations directly from data

​

  • Reduces human bias

​

  • More generalizable across domains

12 of 43

Disadvantage of FCNN for image classification

Still Too Much Computation!!!!

13 of 43

Why are too many parameters a problem?

  • Computational Cost
  • Model Overfitting

14 of 43

Training Deep FCNNs: Vanishing Gradients

  • Vanishing Gradient Problem (Example case :Sigmoid activation )

15 of 43

Training Deep FCNNs: Vanishing Gradients

  • Vanishing Gradient Problem (Example case :Sigmoid activation )
  • Sigmoid function limits outputs to (0, 1) leading to saturation at extreme values.

​

  • In saturated regions, gradients approach zero, reducing weight updates.

​

  • This issue is minor in shallow networks but worsens in deep networks due to gradient multiplication.

​

  • As layers increase, gradients decay significantly, slowing training for early layers.

16 of 43

Disadvantage of FCNN for image classification

No Spatial Information

Sensitive to the location of the object in an image!!!!

​

17 of 43

Disadvantage of FCNN for image classification

No Spatial Information

Treats local pixels same as the pixels far apart

Connects all the nodes in the hidden layers to all the nodes in the input layer !

How can we use the spatial features in the input to inform the architecture of the network?

18 of 43

Using Spatial Features (Idea)

  • Idea: connect patches of input to neurons in hidden layer.

​

  • Neuron connected to region of input. Only "sees" these values.

19 of 43

Feature Extraction with Convolution

20 of 43

Intuition: Convolution Operation

  • Detects local patterns (loops, lines, curves)

​

  • Breaks down digit "9" into meaningful features

​

  • Identifies spatial components independently

​

  • Combines detected features for classification

​

  • Preserves spatial relationships between features

​

  • Applies same filters across entire image

21 of 43

Convolution Operation (Mathematically)

We slide the filter over the Input image, element wise multiply and add the output!!

22 of 43

Understanding Convolution Operation

23 of 43

Understanding Convolution Operation

The Loopy Pattern Detector can detect that pattern, all across the input image, no matter the position

24 of 43

Remember the Terminologies

  • Convolution: Operation that extracts features using filters

​

  • Kernel/Filter: Small matrix that detects specific patterns

​

  • Feature Map: Output after applying a filter to input

​

  • Stride: Step size when sliding the filter

25 of 43

Producing Feature Maps

You can change the weight values in filter to represent different filters which can detect different features in the image

26 of 43

Padding

Preserves pixels at image boundaries during convolution

  • Prevents cumulative spatial information loss in deep networks

​

​

  • Types:

Zero Padding: Adds zeros around image borders

Same Padding: Ensures output dimensions match input (for stride 1)

Valid Padding: No padding, resulting in smaller output

​

27 of 43

Output Dimension after Convolution Operation

28 of 43

A Bigger Picture (Convolution Layers)

29 of 43

Introducing Non-linearity

  • Apply after every convolution operation (i.e., after convolutional layers)
  • ReLU: pixel-by-pixel operation that replaces all negative values by zero. Non-linear operation!

30 of 43

Pooling Layer

  • It is a layer inserted in-between successive Convolution layers in a CNN.
  • It operates similar to convolution operation i.e. by sliding a filter over feature maps.
  • It down samples the convolved features by reducing the spatial dimensions (height and width) of the feature maps while still preserving the most critical feature information.
  • It has no learnable parameters, but it reduces the number of parameters in later layers and the computation in the network and hence also supports in controlling overfitting.
  • The most common algorithm used for this operation is called max pooling.

​

​

​

Week - 5 - Introduction to CNN

30

31 of 43

Pooling

  • Reduced Dimensionality
  • Spatial Invariance (robust to small shifts)

32 of 43

Output Dimensions After Pooling

33 of 43

Story So far!

Convolution Layer

ReLU Activation

Pooling

34 of 43

Representation Learning in Deep CNN

35 of 43

Feature Learning

Classification

CNNs For Classification: Feature Learning

  • Learn features in input image through convolution
  • Introduce non-linearity through activation function (real-world data is non-linear!)
  • Reduce dimensionality and preserve spatial invariance with pooling

36 of 43

Feature Learning

Classification

CNNs For Classification: Classification

  • CONV and POOL layers output high-level features of input
  • Fully connected layer uses these features for classifying input image
  • Express output as probability of image belonging to a particular class

​

37 of 43

Case Studies-CNN Architecture.

Classic Architecture-LeNet-5:

[Conv, ReLU, Pool]*N,🡪 flatten,[FC, ReLU]*N, FC 🡪 Softmax.

This is the architecture of LeNet-5 created by Yann LeCun in 1998 and was widely used for hand written digits recognition (MNIST).

Layer

Output Size

No Parameters

Flatten

5*5*16

= 400

0

Linear(120🡪84)

84

120*84 + 84 = 10,164

38 of 43

38

39 of 43

Training The CNN

40 of 43

Forward Computation @ Convolutional Layer.

40

Same Operation happens at every Layer, the inputs shall change depending on the layer.

Image from Internet: Subject to copyright.

41 of 43

Backward Pass @ Convolution Layer.

41

42 of 43

Backward Pass @ Convolution Layer.

42

43 of 43

References

​