Birla Institute of Technology and Science Pilani, Hyderabad Campus
11.11.2025
BITS F464: Machine Learning (1st Sem 2025-26)
DEEP LEARNING: CNN, RNN, LSTM, AUTOREGRESSIVE, & GAN
Chittaranjan Hota, Sr. Professor
Dept. of Computer Sc. and Information Systems
hota@hyderabad.bits-pilani.ac.in
Convolutional Neural Networks (CNNs)
•
•
So far…classified real values or discrete categories. What about Images & Sequences?
Multi-layer Perceptrons (MLPs) are generally fully connected (each neuron in one
layer is connected to every neuron in the subsequent layer).
•
If Input: M units and Output N units, we need MXN connections. For an input image
M of 256X256 = 65563 grayscale pixels, and output N of 1000 units, we would need
65 million connections.
•
In Image data: We might want ‘Share structure property (weight sharing): efficient
learning” and “Invariance (translation invariance): better generalization” property to
be encoded into the NN’s architecture. CNNs to rescue.
(Img. Source: https://developersbreach.com/)
Spatial structure to 1-D vector
CNN Applications
CNNs excel in recognizing local patterns across grid-like data (images, signals,
text).
• Image and Video: Image Classification, Object Detection, Image
Segmentation, Face Recognition, Image Enhancement, Video Analysis etc.
• Medical and Healthcare: X-ray, MRI, CT-scan Analysis, Histopathology,
ECG/EEG Feature Extraction etc.
•
Autonomous Systems: Self-driving Cars, Drone Vision, Robotics etc.
•
Remote Sensing: Satellite Image Analysis, Disaster Monitoring, Agriculture
etc.
•
Natural Language and Audio: Speech Recognition, Audio Classification,
Text Classification etc.
•
Security and Forensics: Anomaly Detection in Video, Deep fake Detection,
Biometric Authentication etc.
•
Business and Industry: Product Search, and Recommendations, Quality
Inspection, Document Image Processing etc.
Classifying an Image: An example CNN
Classification
FC1
(RELU)
Feature Extraction
FC2
256
(RELU)
Ou
tp
ut
Feature Extraction through Convolution
Image source: https://learnopencv.com/
CNN: Convolution Layer
•
What is the need of Convolution Operation?
• To extract features from input data by applying a kernel (also known as a
filter) over the input.
•
When a convolutional layer is applied to an input image, the resulting feature
maps often have smaller spatial dimensions compared to the input.
Dot product:
.
*
Corners or edges
Horizontal Sobel Kernel
Vertical Sobel Kernel
Another Example of Convolution
Image source: https://learnopencv.com/
Convolution in CNNs continued…
Laplacian kernel
-1 -1
-1 8
-1 -1
Input
-1
-1
-1
Feature map (sharpened image)
Who provides these filters or kernels?
• When you first build a CNN, the values inside every filter are initialized to
small, random numbers. At this stage, filters detect nothing meaningful.
•
Feature learning (i.e. weight matrix in the filter) happens over training
through back-propagation and gradient descent.
• Early layers learn simple features (like sobel, laplacian kernel), and deeper layers
combine those to learn complex features like texture, eyes, wheels, etc.
Calculating the Output Size
Formula for Output width and height:
Padding = 0, Stride = 2
Padding = 0, Stride = 1
Hout=[(5 – 3 + 2X0) / 2]+1=2
[(5 – 3 + 2X0) / 1 ] + 1 = 3
One Layer with many kernels Vs. many layers with few kernels
•
The key difference lies in feature
hierarchy and non-linearity.
Vs.
CNN: Pooling (or Sub-sampling) Layer
Spatial/ Translation Invariance: Pooling layers aggregate information from local
neighborhoods of the input feature map, which helps in creating spatial invariance.
Spatial variations in the input (such as translation, rotation, or scaling) are tolerated
to some extent, making the network more robust to variations in input data.
Dimensionality Reduction: downsamples the feature maps while retaining the
important features. This reduces the number of parameters (weights) reducing the
chances of Overfitting.
Local feature detection: Salient features within the local neighborhood is identified.
(Img. Source: https://developersbreach.com/)
CNN: Padding
• It controls the spatial dimensions of feature maps and prevents information loss at
the borders of the image.
Img. Source: geeksforgeeks
Other Types of Convolutional Networks: FCN, SSMD
• Semantic segmentation, where the goal is to assign a class label to each pixel in the
input image, the fully connected layer is not well-suited as they do NOT preserve
spatial information.
• In Fully Convolutional Networks (FCNs), the final fully connected layers of the
traditional CNN are replaced with convolutional layers. They allow the network to
produce an output feature map with the same spatial dimensions as that of input.
• Some Object Detection Networks: In object detection architectures like YOLO (You
Only Look Once) or SSD (Single Shot Multibox Detector), fully connected layers are
often replaced by convolutional layers with spatial dimensions reduced to 1x1.
Making network to predict bounding boxes and class probabilities at different
spatial locations in the image.
Img. Source: https://www.mathworks.com/
YOLO: You Only Look Once
(Image source: deepseek)
(Look Once, detect everything)
Mini-Project: Hand gesture recognition using CNNs
(Smriti Nagpal, Indian
Sign Language
Interpreter)
Many others: ResNet, AlexNet, ImageNet
I
M
P
L
E
M
E
N
T
A
T
I
O
N
Continued…
Height/Width: 64 → 62 → 31 → 29 → 14 → 12 → 6
Channels: 3 → 32 → 32 → 64 → 64 → 128 → 128
(Output Dimensions of Layers)
Continued…
CNN uses at our Lab (SmartNet AI Lab@BPHC)
Recurrent Neural Networks (RNNs)
● Feed Forward Neural Networks are Acyclic where data passes from input to the
output nodes and not vice versa.
− Once the FFNN is trained, its state is fixed and does not alter as new data is
presented to it. It does not have memory.
memory
R
N
N
memory
f
u
n
?
t1
t2
Applications
Hyderabad
t3
t4
RNN Applications
cat
rabbit
dog
Image Classification
Image Captioning
आप
Example Usages…
Dog
on
the
कैसे
हैं
o2
couch
How
are
you
Negative
Such
a
terrible
movie
Modelling sequential data: RNN
•
•
A hidden state captures information about previous inputs. State is
plugged back into itself.
The hidden state is updated recurrently based on the current input and
the previous hidden state.
unrolled representation
Img. Source: stanford.edu/cs-230
Activation:
Output:
g1 and g2: Activation functions: Sigmoid or Tanh or ReLU
https://www.simplilearn.com/
RNN Architectures
One-to-one:
Traditional NN
without considering temporal
dependencies between
reviews.
One-to-Many: Music generation
Continued…
Many-to-One:
Sentiment Classification
Continued…
Many-to-Many: Named
Entity Recognition
Example1: Simulate Heart Rate Data using RNN
Continued…
Total parameters: 50 + 2500
+ 50 + 50 + 1
= 2651
Input to hidden parameters?
1X50
50 neurons with recurrent
connections.
No. of parameters? 50X50
Bias terms? 50
Combines the 50 learned
features into a single
prediction.
50X1
Bias terms? 1
(Image created using Gemini)
Many-to-One What is the Architecture?
Example2: Music Generation using RNN
Many-to-Many
Applies the same Dense layer to each time step.
Input Sequence (40 chars): "Tere sang jina yahan, tere sang mar ja"
Target Sequence (40 chars): "ere sang jina yahan, tere sang mar jan" 40 × 128 = 5,120 128 × 128 = 16,384
What type of RNN Architecture?
128 × 40 = 5,120
128
40 21,632 + 5,160 = 26,792
Since the same weights are used at every time step, the gradients (the measure of how much a weight contributes to the
error) must be accumulated across the entire sequence. W s and W x influence the error through every time step.
RNN Training: Backpropagation Through Time
Y2
N
v
E = (1/N) ∑ (Yi – Yi )2
i=1
Adjusting WY (E3 is a function
of Y3 and Y3 is a function of
Wy):
3
3
=
.
3
3
Y
Y
Similarly, now adjusting WS:
3
s
=
For Wx:
3
x
=
3
.
3
3
.
3
3
+
s
3
.
3
3
.
3
x
.
3
.
.
2
3
3
3
2
+
s
3
+
3
3
.
3
3
.
3
2
.
.
3
.
3
.
2
.
1
1
s
2
.
1
1
x
2
3
3
With respect to S1
With respect to S2
E3 --- Y3 --- S3 --- Ws
3
3
2
x
+
3
3
.
3
3
.
3
2
.
Long Short-Term Memory (LSTM) Networks:
Special type of RNNs
Simple RNNs struggle with:
- Long-term dependencies (remembering information from many time steps
back)
- Vanishing gradients (gradients become too small during backpropagation
through time)
- Exploding gradients (gradients become too large)
Solution: LSTM is a special RNN architecture designed to handle long-term
dependencies.
- Uses gates to control information flow: Forget, Input, Output gates.
- Helps avoid vanishing gradient problems.
- Stores long-term context in a cell state.
Exploding gradients prob. may be solved by Gradient clipping or regularization
etc.
The LSTM does have the ability to remove or add information to the cell state, carefully
regulated by structures called gates.
Why LSTM Networks?
•
In practice, RNNs cannot remember or handle information distant from
the current point of processing. Recurrent connections are good to handle
local information (or more recent parts of the input sequence).
•
For Ex: An RNN might be good to forecast next 6 hours or 24 hours
weather at Hyderabad by using past 3 to 4 days data. What about
vanishing gradient in BPTT here?
•
RNN’s inability to carry forward critical information
•
•
•
Tanh makes RNN suffer from Vanishing Gradient problem during BPTT
ReLU makes RNN suffer from Exploding Gradient problem during BPTT
Solution: Maintain the relevant context over a longer period
• By removing/ forgetting the information no longer needed from the context
• By adding information likely to be needed for latter decision making
•
For Ex: An LSTM might be good to predict snowfall in Hyderabad in next two
months by using past 7 to 10 years data.
Working of LSTM: Forget Gate
Forget Gate:
The Forget Gate in the LSTM uses
the current November 2025 data
(XNov) and the previous hidden
state (hOct) to generate a filter
vector f(t). This filter is then
applied to the Cell State (COct) (the
network's long-term memory) to
decide what to discard and what
to keep for the upcoming Dec
2025 forecasting of Hyderabad
weather.
f(t) will be 0 for high monsoon humidity, extreme summer (July-Aug) temps etc. which
are called noise, and are erased from the cell state. f(t) will be 1 for recent cold trend at
Hyderabad and is preserved in new cell state C(Nov) and is carried forward.
LSTM Input Gate: What new information to add?
Input Gate:
Now, combining old state and
new candidate information:
kept old
added new
LSTM Output Gate: What part becomes hidden?
Output Gate:
For ex: allow current cold trend
(Nov) to pass through (with 1),
allow high-altitude areas to pass
through (with 0.5) and last
summer’s heat to get blocked (with
0).
Another Example of LSTM
I loved
the
food,
but
the
servi
ce
was
terri
ble.
Ack: Gemini
Anomaly detection using LSTM
model = Sequential([
# Encoder
LSTM(64, activation='relu', input_shape=(sequence_length, n_features),
return_sequences=True),
Dropout(0.2),
LSTM(32, activation='relu', return_sequences=False),
Dropout(0.2),
# Bottleneck
RepeatVector(sequence_length),
# Decoder
LSTM(32, activation='relu', return_sequences=True),
Dropout(0.2),
LSTM(64, activation='relu', return_sequences=True),
Dropout(0.2),
TimeDistributed(Dense(n_features))
])
Autoregressive Models
•
A generative model that generates new data points by regressing each
observation on previous observations within the series.
•
Mathematically:
Current
value
Previous
value
Where, Φ0, Φ1 are coefficients to
be estimated. ξt is error term at
time ‘t’.
What would be AR(2),
AR(3),…
predicted
Probabilistically, Autoregression can be expressed as:
Image source: WaveNet (Google DeepMind)
AR(1): Order 1
Yt = Φ0 + Φ1.Yt-1 + ξt
Generative Adversarial Networks (GANs)
• GANs are neural networks (Deep ANNs) that learn to create synthetic data similar to
some known input data. Or have the capability to generate new data (image, music,
videos, handwritten-digits etc).
• Ex: BITS Admission office (Discriminator) checking the transcripts of newly admitted
students during the admission day (Who is the Generator?).
update
Real Samples
random seed
generator
F
A
K
E
d
i
s
c
r
i
m
i
n
a
t
o
r
update
fake real
Adversarial Training in a GAN
Real
Samples
The generator tries
to minimize the loss.
Generator
It does not care
about the first term.
Why?
In short: The Discriminator's goal is to make both D(x) and (1 - D(G(z))) large,
maximizing the sum of their logs.
Discriminator
Loss
Discriminator
Fake
Samples
Generator
Loss
Practical Generator’s goal: maximize log D(G(z)), in
place of minimizing log (1-D(G(z))).
The Generator tries to minimize the probability of being caught and the Discriminator tries to
maximize the probability of catching the fake data.
+
))]
Loss
Discriminators’ goal: max D part.
First term: For a real image, D(x) is close to 1 log 1 = 0, so this part of the loss is 0 (best
possible). If it mistakenly labels it as fake, D(x) = 0 log 0 = a large negative number (very bad).
Second term: For a fake image, discriminator would want D(G(z)) = 0 log (1 – 0) = log 1 = 0
(good). If it fooled by the fake image and labels it as real, D(G(z)) = 1 log (1-1) = log 0 = a large
negative number (very bad).
Backpropagation in GAN
Backpropagation
Real
Samples
Discriminator
Generator
Discriminator
Loss
Fake
Samples
Generator
Loss
Backpropagation in GAN
Real
Samples
Generator
Backpropagation
Fake
Samples
Discriminator
Loss
Discriminator
Generator
Loss
GAN Applications
Applications: synthetic image/ video generation (deepfake),
Image-to-image translation, Anomaly detection,…
(Deep Convolutional GAN: Better Quality)
Image Source: https://theaisummer.com
(Generated Vanilla GAN images in MNIST)
StyleGAN:
https://github.com/NVlabs/stylegan
(Tero Karras)
Adaptive Instance Normalization
Thank You!