Unit I
Unit I
School of Computing
Vel Tech Rangarajan Dr. Sagunthala R&D Institute of
Science and Technology
DEEP LEARNING
• Deep learning is a subset of machine learning that is
inspired by the structure and function of the human
brain.
• It uses large neural networks to process and learn
from data, enabling machines to make accurate
predictions and decisions.
DEEP LEARNING
• Deep learning has been used in a variety of
applications, from speech recognition and
natural language processing to image and
video recognition, and even self-driving cars.
• It has the ability to learn from vast amounts of
data, making it a powerful tool for solving
complex problems.
Unit – I Data Processing and Deep Learning Framework
It is the first step in data handling. Data is available from various sources, and the
analysts must collect them before they can use them.
Before they collect the data, experts must decide the desired outcome of data
analysis.
It will help them know the kind of information they must collect and where they will
be available.
The next step is deciding what methods will be used to collect and process the data.
The primary method is the first collection of data performed by researchers before
anyone has done any process. This method is expensive but more accurate.
In the secondary method, experts collect data that has already undergone processing.
This method is inexpensive but may need to be more accurate. It can be said to be
second-hand information.
2. Data Cleaning:
When observing the data, you may find details that don’t fit into the data
you are analysing. Removing such information will make your outcome
more accurate. Not all outliers are incorrect, and this makes it necessary to
make the right decision here.
iv. Taking Care Of Missing Data
Taking care of missing data is essential because most algorithms will not
accept missing values. One way to take care of this is to remove the
observation with missing values. The other way is to input the missing value
based on the other observations. It is also possible to alter the way you use
the data.
v. Validate And Quality Control
At this stage, it is necessary to see that you can answer some questions. You
must confirm that the data makes sense and follows the rules for its field. It
is also essential to see if the information proves or disproves your theory or
brings out any insight. You must also ensure that you can find trends in the
data.
3. Data Processing:
Data processing refers to the collection, manipulation, and analysis of raw data
to extract meaningful information and insights.
It involves a series of steps that transform data into a more usable and valuable
form. Data processing is a fundamental aspect of many industries, including
business, finance, healthcare, research, and more.
Stages of Data Processing are:
The goal of data processing is to prepare the data in a format that can be effectively
fed into a deep learning model for training or inference.
Here are some key steps involved in data processing for deep learning:
1. Data Cleaning: This step involves handling missing values, outliers, and any
noise in the data. It may include techniques like imputation for missing values or
removing outliers that could negatively impact the model's performance.
2. Data Preprocessing: Preprocessing steps depend on the type of data and the specific
requirements of the deep learning model. Common pre processing tasks include data
scaling, dimensionality reduction, handling categorical variables, and converting
data into a suitable format. Examples include normalizing numerical features, one-hot
encoding categorical variables, or applying text tokenization and vectorization.
3. Data Normalization: Normalizing the data brings the input features to a similar scale,
often between 0 and 1 or with a mean of 0 and standard deviation of 1.
Normalization helps in improving convergence and stability during training and
prevents certain features from dominating others.
6. Data Splitting: The dataset is typically split into training, validation, and test sets.
The training set is used to train the deep learning model, the validation set is used for
hyperparameter tuning and model evaluation during training, and the test set is used
for final model evaluation to assess its performance on unseen data.
Each step-in data processing plays a crucial role in preparing the data for deep
learning tasks. The specific data processing techniques applied depend on the nature
of the data, the problem domain, and the requirements of the deep learning model
Normalization
Normalization
Normalization in the context of deep learning techniques refers to the process of
scaling and standardizing input data to ensure that it falls within a specific range or
distribution.
Case2- If the value of X is maximum, then the value of the numerator is equal to the
denominator; hence Normalization will be 1.
Normalization
Case3- On the other hand, if the value of X is neither maximum nor minimum, then
values of normalization will also be between 0 and 1.
Hence, Normalization can be defined as a scaling method where values are shifted
and rescaled to maintain their ranges between 0 and 1, or in other words; it can be
referred to as Min-Max scaling technique.
iii. Batch normalization: Batch normalization is a technique specifically designed for deep
neural networks. It normalizes the activations of each layer by computing the mean
and standard deviation of a batch of training examples. It helps address the internal
covariate shift problem by stabilizing the distribution of the inputs to each layer,
leading to faster and more stable training.
It also helps prevent certain features from dominating the learning process due to
differences in scale or magnitude.
It's worth noting that the choice of normalization technique depends on the
specific requirements of the dataset and the characteristics of the deep learning
model being used.
import tensorflow as tf
# Assume you have input data 'x' with shape (batch_size, height, width, channels)
normalized_x = tf.keras.layers.BatchNormalization()(x)
2. Normalization in PyTorch:
PyTorch also offers different normalization options. One common approach is to use
the torchvision.transforms.Normalize class, which can be applied to input tensors.
Here's an example:
import torch
import torchvision.transforms as transforms
# Assume you have input data 'x' as a PyTorch tensor
mean = [0.5, 0.5, 0.5] # Mean values for each channel
std = [0.5, 0.5, 0.5] # Standard deviation for each channel
transform = transforms.Compose([
transforms.ToTensor(), # Convert to tensor
transforms.Normalize(mean=mean, std=std) # Normalize
])
normalized_x = transform(x)
Data Augmentation
Data augmentation techniques are used to increase the diversity and size of the training
dataset by applying various transformations to the input data. The goal of data
augmentation is to enhance the model's ability to generalize and improve its
performance by exposing it to a wider range of variations and scenarios.
Image Augmentation: For image datasets, data augmentation techniques can include
operations
1. Random Flips: Horizontally or vertically flipping the image.
2. Random Rotations: Rotating the image by a random angle.
3. Random Crop: Cropping a random portion of the image.
4. Random Zoom: Zooming in or out on the image.
5. Random Brightness/Contrast: Adjusting the brightness or contrast of the image.
6. Random Hue/Saturation: Modifying the hue or saturation of the image.
7. Random Gaussian Noise: Adding Gaussian noise to the image
Geometric Transformations:
1. Translation: Shifting the image in the x and y directions.
2. Rotation: Rotating the image by a specific angle.
3. Scaling: Rescaling the image by a factor.
4. Shearing: Distorting the image by shearing it along the x or y-axis.
There are several popular deep learning frameworks available that provide tools and
libraries to build and train deep neural networks. Some of the commonly used deep
learning frameworks are:
1. TensorFlow
Developed by Google Brain, Tensorflow is by far, one of the most used deep
learning frameworks. Tensorflow provided a wide range of APIs(application
programming language) from preprocessing to the modelling of data.
It is written in Python, C++ and CUDA. Runs on almost all platforms – Linux,
Windows, macOS, iOS and Android. For Android and iOS, Tensorflow provides
the TensorflowLite version.
PyTorch is built on top of the Torch library. PyTorch has similarities with
Tensorflow and thus in major competition with it. PyTorch was mainly developed
for research and production deployment purpose.
Using TorchServe, PyTorch faster speed and ease of access to deploy models.
Keras best runs on GPUs and TPUs. Keras models can easily be deployed to the
web, iOS and Android. Keras is known for its fast computation, user-friendliness
and ease of access. Keras has an active community and thus under constant
development.
1. Epoch:
An epoch represents a complete pass through the entire training dataset during the
training process.
In other words, it indicates the number of times the model sees and learns from the entire
training data. Increasing the number of epochs allows the model to potentially converge
to a better solution.
However, setting too many epochs may result in overfitting, where the model memorizes
the training data instead of learning generalizable patterns.
The optimal number of epochs depends on the complexity of the problem and the size of
the dataset and is typically determined through experimentation.
Deep Learning Parameters
2. Batch Size:
During training, the dataset is divided into smaller subsets called batches. The batch size
refers to the number of samples in each batch. The choice of batch size affects both
computational efficiency and the quality of the model's parameter updates.
Larger batch sizes tend to provide more stable gradient estimates, leading to smoother
convergence. They also offer better utilization of hardware resources, especially when
training on GPUs. However, larger batch sizes require more memory and may lead to
slower convergence or difficulties in reaching sharp minima.
Smaller batch sizes introduce more noise into the parameter updates, but they can help the
model generalize better as they provide more diverse examples in each update. Smaller
batches also consume less memory but may result in longer training times due to
increased computational overhead.
Selecting an appropriate batch size often involves a trade-off between convergence
speed, memory usage, and generalization performance. Common choices range from
small values (e.g., 32 or 64) to larger values (e.g., 256 or 512).
Deep Learning Parameters
3. Learning Rate:
The learning rate determines the step size at which the model's parameters are updated
during the optimization process. It is a critical hyperparameter as it affects the
convergence speed and the quality of the learned solution.
A high learning rate may cause the optimization algorithm to overshoot the optimal
solution, leading to unstable or divergent behavior.
A low learning rate may result in slow convergence or getting stuck in suboptimal
solutions.
The choice of an appropriate learning rate depends on the problem and the model
architecture. It is often set based on a combination of intuition and empirical
experimentation.
Hyperparameter tuning, including finding the optimal number of epochs, batch size, and
learning rate, is often an iterative process. It requires experimentation, monitoring the
model's performance on validation data, and making adjustments based on observed
results.
Open Source Deep Learning Tools