Module 3
Module 3
Formula = [i-k]+1
Stride is a parameter of the neural network’s filter that modifies the amount of
movement over the image or video. we had stride 1 so it will take one by one. If
we give stride 2 then it will take value by skipping the next 2 pixels.
Formula =[i-k/s]+1
Padding
Formula =[i-k+2p/s]+1
Pooling
Convolutional layer
Pooling layer
Convolutional layer
first layer that is used to extract the various features from the input images. In
this layer, We use a filter or Kernel method to extract features from the input
image.
Pooling layer
The primary aim of this layer is to decrease the size of the convolved feature
map to reduce computational costs. This is performed by decreasing the
connections between layers and independently operating on each feature map.
Depending upon the method used, there are several types of Pooling
operations. We have Max pooling and average pooling.
Fully-connected layer
The Fully Connected (FC) layer consists of the weights and biases along with
the neurons and is used to connect the neurons between two different layers.
These layers are usually placed before the output layer and form the last few
layers of a CNN Architecture.
Dropout
Activation Function
RelU- the main advantage of using the ReLU function over other activation
functions is that it does not activate all the neurons at the same time.
Convolution Operation
To apply the convolution:
Overlay the Kernel on the Image: Start from the top-left corner of the image and place the
kernel so that its center aligns with the current image pixel.
Element-wise Multiplication: Multiply each element of the kernel with the corresponding
element of the image it covers.
Summation: Sum up all the products obtained from the element-wise multiplication. This sum
forms a single pixel in the output feature map.
Continue the Process: Slide the kernel over to the next pixel and repeat the process across the
entire image.
Convolution Operation
Key Terms in Convolution Operation
Kernel Size: The convolution operation uses a filter, also known as a kernel, which is typically a
square matrix. Common kernel sizes are 3×3, 5×5, or even larger. Larger kernels analyze more
context within an image but come at the cost of reduced spatial resolution and increased
computational demands.
Stride: Stride is the number of pixels by which the kernel moves as it slides over the image. A
stride of 1 means the kernel moves one pixel at a time, leading to a high-resolution output of the
convolution. Increasing the stride reduces the output dimensions, which can help decrease
computational cost and control overfitting but at the loss of some image detail.
Padding: Padding involves adding an appropriate number of rows and columns (typically of
zeros) to the input image borders. This ensures that the convolution kernel fits perfectly at the
borders, allowing the output image to retain the same size as the input image, which is crucial for
deep networks to allow the stacking of multiple layers.
1D Convolution
In 1D convolution, a kernel or filter slides along the input data, performing element-wise multiplication
followed by a sum, just as in 2D, but here the data and kernel are vectors instead of matrices.
1D Convolution Operation
Applications:
1D convolution can extract features from various kinds of sequential data, and is especially prevalent in:
Audio Processing: For tasks such as speech recognition, sound classification, and music analysis,
where it can help identify specific features of audio like pitch or tempo.
Natural Language Processing (NLP): 1D convolutions can help in tasks such as sentiment
analysis, topic classification, and even in generating text.
Financial Time Series: For analyzing trends and patterns in financial markets, helping predict
future movements based on past data.
Sensor Data Analysis: Useful in analyzing sequences of sensor data in IoT applications, for
anomaly detection or predictive maintenance.
3D Convolution
3D convolution extends the concept of 2D convolution by adding a dimension, which is useful for
analyzing volumetric data.
Like 2D convolution, a three-dimensional kernel moves across the data, but it now simultaneously
processes three axes (height, width, and depth).
3D Convolution
Applications:
AI Video Analytics: Processing video as volumetric data (width, height, time), where
the temporal dimension (frames over time) can be treated similarly to spatial dimensions in
images. The latest video generation model by OpenAI called Sora used 3D CNNs.
Medical Imaging: Analyzing 3D scans, such as MRI or CT scans, where the additional dimension
represents depth, providing more contextual information.
Scientific Computing: Where volumetric data representations are common, such as in simulations
of physical phenomena.
Dilated Convolution
A variation of the standard convolution operation, dilated convolution expands the receptive field of the
filter without significantly increasing the number of parameters. It achieves this by introducing gaps, or
“dilations,” between the pixels in the convolution kernel.
In a dilated convolution, spaces are inserted between each element of the kernel to “spread out” the
kernel. The l (dilation rate) controls the stride with which we sample the input data, expanding the
kernel’s reach without adding more weights. For example, if d=2, there is one pixel skipped between each
adjacent kernel element, making the kernel cover a larger area of the input.
Dilated Convolution
Features
Increased Receptive Field: Dilated convolution allows the receptive field of the network to
grow exponentially with the depth of the network, rather than linearly. This is particularly useful
in dense prediction tasks where contextual information from a larger area is beneficial for making
accurate predictions at a pixel level.
Preservation of Resolution: Unlike pooling layers, which reduce the spatial dimensions of the
feature maps, dilated convolutions maintain the resolution of the input through the network
layers. This characteristic is crucial for tasks where detailed spatial relationships need to be
preserved, such as in pixel-level predictions.
Efficiency: Dilated convolutions achieve these benefits without increasing the number of
parameters, hence not increasing the model’s complexity or the computational cost as much as
increasing the kernel size directly would.
Dilated Convolution is applied in various tasks of computer vision. Here are a few of those:
Semantic Segmentation: In semantic segmentation, the goal is to assign a class label to each pixel
in an image. Dilated convolutions are extensively used in segmentation models like DeepLab,
where capturing broader context without losing detail is crucial. By using dilated convolutions,
these models can efficiently enlarge their receptive fields to incorporate larger contexts,
improving the accuracy of classifying each pixel.
Semantic Segmentation
Audio Processing: Dilated convolutions are also used in audio processing tasks, such as in
WaveNet for generating raw audio. Here, dilations help capture information over longer audio
sequences, which is essential when predicting subsequent audio samples.
Video Processing: In video frame prediction and analysis, dilated convolutions help in
understanding and leveraging the information over extended spatial and temporal contexts, which
is beneficial for tasks like anomaly detection or future frame prediction.
Transposed Convolution
Transposed convolution is primarily used to increase the spatial dimensions of an input tensor. While
standard convolution, by sliding a kernel over it produces a smaller output, a transposed convolution
starts with the input, spreads it out (typically adding zeros in between elements, known as upsampling),
and then applies a kernel to produce a larger output.
Standard convolutions typically extract features and reduce data dimensions, whereas transposed
convolutions generate or expand data dimensions, such as generating higher-resolution images from
lower-resolution ones. Instead of mapping multiple input pixels into one output pixel, transposed
convolution maps one input pixel to multiple outputs.
Unlike standard convolution, where striding controls how far the filter jumps after each operation, in
transposed convolution, the stride value represents the spacing between the inputs. For example, applying
a filter with a stride of 2 to every second pixel in each dimension effectively doubles the dimensions of
the output feature map if no padding is used.
The generator component of Generative Adversarial Networks (GANs) and the decoder part of
an AutoEncoder extensively use transposed convolutions.
In GANs, the generator starts with a random noise vector and applies several layers of transposed
convolution to produce an output that has the same dimension as the desired data (e.g., generating a
64×64 image from a 100-dimensional noise vector). This process involves learning to upsample lower-
dimensional feature representations to a full-resolution image.
A depthwise convolution, an efficient form of convolution used to reduce computational cost and the
number of parameters while maintaining similar performance, involves convolving each input channel
with a different filter. The convolution takes place in two steps: Depthwise Convolution and then
Pointwise Convolution. Here is how they work:
Depthwise Convolution
Depthwise Convolution: A single convolutional filter applies separately to each channel of the
input in depthwise convolution. A dedicated kernel convolves each channel. For instance, in an
RGB image with 3 channels, each channel receives its kernel, ensuring that the output retains the
same number of channels as the input.
Pointwise Convolution: After depthwise convolution, pointwise convolution is applied. This
step uses a 1×1 convolution to combine the outputs of the depthwise convolution across the
channels. This means it takes the depthwise convolved channels and applies a 1×1 convolutional
filter to each pixel, combining information across the different channels. Essentially, this step
integrates the features extracted independently by the depthwise step, creating an aggregated
feature map.
In standard convolutions, the number of parameters quickly escalates with increases in input depth and
output channels due to the full connection between input and output channels. Depthwise separable
convolutions separate this process, drastically reducing the number of parameters by focusing first on
spatial features independently per channel and then combining these features linearly.
Parameters =3×3×32×64
Total Parameters =18432
Depthwise Convolution:
o Parameters= 3 x 3 x 32
o Parameters=288
Pointwise Convolution:
o Parameteres= 1 x 1 x32 x 64
o Parameters= 2048
Total Prameters= 2336
Depthwise separable convolutions are particularly prominent in models designed for mobile and edge
computing, like the MobileNet architectures. These models are optimized for environments where
computational resources, power, and memory are limited:
Deformable Convolution
In traditional convolution, the filter applies over a fixed grid in the input feature map. However,
deformable convolution adds an offset to each spatial sampling location in the grid, learned during the
training process.
Deformable convolutions have been successfully integrated into several state-of-the-art object detection
frameworks, such as Faster R-CNN and YOLO, providing improvements in detecting objects with non-
rigid transformations and complex orientations. Here are its applications:
Image Recognition: It is beneficial in cases where objects can appear in different sizes, shapes, or
orientations.
Video Analysis: Deformable convolutions can adapt to movements and changes in posture, angle,
or scale within video frames, enhancing the ability of models to track and analyze objects
dynamically.
Enhancing Model Robustness: By allowing the convolutional operation to adapt to the data,
deformable convolutions can increase the robustness of models against variations in the
appearance of objects, leading to more accurate predictions across a wider range of conditions.
Convolutional Neural Networks (CNNs):
Motivation
Feedforward networks, or Multi-Layer Perceptrons (MLPs), are powerful tools. However,
when dealing with data like images, their standard structure reveals significant
limitations. Consider what happens when you feed an image into an MLP: typically, you
flatten the image matrix (e.g., a 28x28 pixel image becomes a 784-element vector).
This flattening process immediately discards important spatial information. Pixels that
were adjacent in the 2D grid, potentially forming a line or texture, are treated as
independent inputs after flattening. The network loses the inherent structure of the data;
it doesn't inherently understand that pixels (0,0) and (0,1) are closer and likely more
related than pixels (0,0) and (27,27). An MLP would have to learn these spatial
relationships from scratch, which is highly inefficient.
An MLP typically connects every input feature (flattened pixel) to every neuron in the
first hidden layer, ignoring spatial relationships and leading to a large number of
parameters.
In essence, CNNs are motivated by the need to build models that respect the spatial
hierarchy of image data. They learn features locally, share parameters efficiently, and
build up complex representations from simpler ones, making them the standard
approach for many computer vision tasks. The following sections will detail the specific
operations, like convolution and pooling, that enable these properties.
DATA TYPES
In a Convolutional Neural Network (CNN), data is represented and processed using a
fundamental data structure called a tensor. Tensors are multi-dimensional arrays that
can hold data with different dimensions, shapes, and types. For CNNs, which primarily
handle image and video data, the input, intermediate feature maps, and final outputs are
all structured as tensors.
Input data types
The raw data fed into a CNN, such as an image, first needs to be loaded and pre-
processed into a tensor.
o Data type: Typically, raw images are stored as uint8 (unsigned 8-bit integer),
where each pixel value ranges from 0 to 255.
o Example: A 10-second video with 30 frames per second and 128×128 color
images would be a tensor of shape (300,128,128,3)
o Data type: Usually float32 after converting from specialized medical file
formats.
o Tensor shape: ( ℎ, ℎ, ℎ, ℎ )
.
Data types for model training and inference
The choice of data type for model weights and intermediate computations is a critical design
decision that balances computational efficiency, memory usage, and numerical precision.
1. Full precision (float32): This is the standard data type for training most deep learning
models. It uses 32 bits for each value, providing high precision and a wide dynamic
range.
o Description: Many modern deep learning libraries and hardware (e.g., NVIDIA
Tensor Cores) use a mix of float32 and a 16-bit floating-point format to speed
up training.
o float16: Uses 16 bits. Halves memory usage and can significantly increase
training speed. It has a smaller dynamic range, making it potentially unstable for
some operations.
o bfloat16: Also 16 bits, but designed to have the same wide dynamic range as
float32 by trading some precision. This makes it more stable than float16 for
training.
o Method: For mixed-precision training, the model's master weights are typically
kept in float32, while computationally intensive parts of the forward and
backward pass are done in float16 or bfloat16.
o Application: This is primarily used for inference on edge devices with limited
resources, such as mobile phones or IoT devices. It is less common for training
due to the significant loss of precision.
Efficient convolution algorithms are crucial in deep learning due to the computational intensity of
convolutional layers. Several approaches aim to optimize these operations:
1. Winograd Convolution:
This algorithm reduces the number of multiplications required for convolution, especially for
small kernel sizes common in CNNs.
It achieves this by applying transforms to the input and filter, performing element-wise
multiplication, and then an inverse transform.
Winograd convolution can be significantly faster than direct or FFT-based methods for certain
configurations.
2. FFT-based Convolution:
Convolution in the spatial domain is equivalent to element-wise multiplication in the frequency
domain.
This method leverages the Fast Fourier Transform (FFT) to convert the input and filter to the
frequency domain, multiply them, and then use the Inverse FFT (IFFT) to return to the spatial
domain.
It is particularly efficient for large kernel sizes and inputs.
5. Separable Convolutions:
If a multi-dimensional kernel can be decomposed into a series of one-dimensional kernels (e.g.,
a 2D kernel into two 1D kernels), the convolution can be performed more efficiently.
This reduces the number of operations and parameters, especially for higher-dimensional
convolutions.
Examples include spatial separable convolutions and depthwise separable convolutions.
The choice of the most efficient algorithm depends on factors such as kernel size, input
size, available hardware, and memory constraints. Often, deep learning frameworks employ a
combination of these techniques and dynamically select the most optimal algorithm for a given
layer.
classification. It is also the only use case involving the most advanced frameworks
Deconstruct an image and find its distinguishing feature. The system employs a
Reduces the description of its important credentials. It’s done with the help of an
Image tagging
The most basic type of image classification algorithm is image tagging. The image
tag is a term or a phrase that describes the images and makes them easier to find.
This method is used by big companies like Facebook, Google, and Amazon. It is also
Visual Search
Furthermore, the visual search evaluates the image and searches for other photos
Recommender engines
Another field where image classification and object identification can be used is
make suggestions in the “you might also like” area. The presumption is based on the
user’s expressed behavior. The products are matched based on visual criteria, such
as red shoes and red lipstick for a red outfit. Pinterest employs CNN image
recognition in a novel way. The organization focuses on visual credentials matching,
Face recognition deserves its own section. This subset of image recognition deals
with more complex images. Such images could include human faces or other living
The distinction between straight image recognition and face recognition is based on
The shape of the face and its features are recognized first, followed by basic object
recognition.
The features of the face are then examined further to determine its essential
credentials. For example, It could be the shape of the nose, the skin tone, and
The sum of these credentials is then calculated into the image data perception of a
specific human being’s appearance. This procedure entails studying a large number
of samples that each present the subject in a different way. For instance, whether
The input image is then compared to the database, and the system recognizes a
specific face.
Face recognition is used in social media platforms such as Facebook for both social
of tagging people in photos. This feature is especially useful when you need to tag
through hundreds of images from a conference or when there are far too many faces
to tag. So, if you’re planning to build a social network, keep this feature in mind.
Facial detection in entertainment lays the groundwork for further transformations and
manipulations. The most notable examples are Facebook Messenger filters and
Snap chat Looksery filters. The filters depart from the face’s auto-generated basic
identification.
Face recognition cannot be used to verify a persona in the same way that
fingerprints and legal documents can. In cases where there is limited information,
face recognition can be useful in identifying the person. For instance, from
Healthcare is the industry where all of the cutting-edge technology is put to the test.
The most fascinating image recognition CNN use case is medical image computing.
The medical image includes a whole lot of further data analysis that arises from
These systems can display the series of photos as well as the differences between
them. This feature lays the groundwork for future predictive analytics.
Records. It serves as a training basis for the algorithms and patients’ confidential
data and test results. They work together to create an analytical platform that
In healthcare, saving lives is a top priority. And it is always advantageous to have the
ability to predict the future. Because when it comes to patient care, you must be
CNN uses a grid topology approach to process data, which is a set of spatial
correlations between data points. The grid is two-dimensional in the case of images.
The convolution algorithm is then used to identify some aspects of the input.
HRA is a predictive application that computes the likelihood of specific events. Based
on patient data, this use case includes disease progression or complications. It looks
for similar PHR, analyses the patient’s data, looks for patterns, and calculates
potential outcomes. This system can be used for routine health checks.
The framework can be expanded by including a treatment plan. In this case, the
The HRA system can also be used to investigate the specific environment and
identify potential hazards for those who work there. This method is used to as sess
dangerous situations. In Australia, for example, officials are studying sun activity to
Another major healthcare field that makes extensive use of CNNs is drug discover y.
It is also one of the most inventive uses of convolutional neural networks in general.
RNN (Recurrent Neural Network) and stock market prediction are examples of pure
The problem is that drug discovery and development is a time-consuming and costly
The process of developing new drugs lends itself well to the implementation of
neural networks. During the development of a new drug, there is a large amount of
data to consider.
The following stages are involved in the drug discovery process:
medical effects.
Machine learning anomaly detection may be useful in hit discovery. The algorithm
searches the compound database for new activities that can be used for specific
purposes.
Then, using the Hit to Lead process, the results are narrowed down to the most
relevant. That’s what dimensionality reduction and regression are all about.
Then there’s Lead Optimization, which is the process of combining and testing lead
compounds to find the best approaches to them. The stages involve the examination
Following that, the development shifts to live testing. Machine learning algorithms
were relegated to the background and were used to structure incoming data.
CNN optimizes and streamlines the drug discovery process at critical stages. It
allows for a reduction in the time required to develop cures for emerging diseases.
A similar approach can be used with existing drugs when developing a treatment
plan for patients. Precision medicine aims to find the most effective way to treat a
disease.
Supply chain management, predictive analytics, and user modeling are all part of
precision medicine.
The addition of variables (treatment types) has specific effects in both the short and
long term.
Each variable has its own set of statistics regarding its impact on a symptom.
Data is combined to form an assumption about the best course of action based on
The various outcomes and changes in the patient’s condition are then considered.
This is how the assumption is validated. This stage is handled by recurrent neural