Program 5n6 DL
Program 5n6 DL
AIM-Introduction to Transfer Learning and Fine Tuning in Deep CNN. Also, discuss
various Pre-trained networks with their advantage and drawbacks.
THEORY-
1. Introduction to Transfer Learning: Transfer learning is a machine learning technique
where a model developed for one task is reused as the starting point for a model on a second
task. In deep learning, particularly with Convolutional Neural Networks (CNNs), transfer
learning has proven highly effective because CNNs trained on large datasets like ImageNet
have already learned useful features such as edge detection, shape recognition, and texture
identification. These features can be generalized across many different types of image
recognition tasks.
Instead of training a deep learning model from scratch (which can be computationally
expensive and time-consuming, requiring large datasets), transfer learning allows us to
leverage the knowledge learned by a pre-trained model.
2. Concept of Transfer Learning in Deep CNN: In deep CNNs, lower layers learn general
features like edges and textures, while higher layers learn more task-specific features. In
transfer learning, we use the lower layers of a pre-trained network as a feature extractor and
modify the higher layers to suit the new task.
Transfer learning in CNNs typically follows these steps:
• Using a Pre-trained Model: Load a model that has already been trained on a large
dataset, like ImageNet.
• Modifying the Architecture: Replace the output layer (classifier) of the model to suit
the new dataset's classes.
• Freezing Some Layers: Freeze the initial layers of the model to retain the learned
features.
• Training on New Data: Train the remaining layers and the new classifier on the new
dataset.
This significantly reduces training time and provides better performance, especially when the
new dataset is smaller.
3. Fine-Tuning: Fine-tuning is a specific type of transfer learning where you not only replace
the output layer but also allow some (or all) of the pre-trained model's layers to be updated
during training.
In typical transfer learning:
• The pre-trained model's layers are frozen (i.e., their weights are not updated).
• Only the newly added classifier (top layer) is trained on the new dataset.
In fine-tuning:
VIVA QUESTIONS
1. What is transfer learning?
o Transfer learning refers to using a model trained on one task as the starting
point for a model on another related task.
2. Why do we use transfer learning in CNNs?
o It is used to leverage the learned features from large datasets to reduce training
time and improve performance on tasks with smaller datasets.
3. What is fine-tuning in CNNs?
o Fine-tuning is the process of retraining some or all layers of a pre-trained
network on a new dataset to adapt it to the new task.
4. What is the difference between transfer learning and fine-tuning?
o In transfer learning, the pre-trained model is used without changing the
weights. In fine-tuning, we adjust some or all of the weights based on the new
dataset.
5. Give an example of a pre-trained CNN model.
o Examples include VGG16, ResNet, InceptionNet.
THEORY-
Introduction to Transfer Learning:
Transfer learning is a machine learning technique where a model trained on one task is
repurposed to solve another related task. In deep learning, especially with Convolutional
Neural Networks (CNNs), transfer learning is commonly used to leverage models pre-trained
on large datasets such as ImageNet for smaller and more specific tasks. This saves time and
computational resources and can often result in higher accuracy than training a model from
scratch, particularly when the new task has limited data.
MobileNetV2:
MobileNetV2 is a lightweight deep neural network architecture designed by Google for
mobile and embedded vision applications. It is optimized to perform well even on devices
with limited computational power, such as smartphones. The architecture is based on
depthwise separable convolutions, which significantly reduce the number of parameters and
computational cost while retaining model accuracy.
MobileNetV2 is particularly suitable for transfer learning and fine-tuning because it balances
performance and efficiency, making it an excellent choice for real-time applications or
resource-constrained environments.
MobileNetV2 Architecture:
MobileNetV2 builds on its predecessor, MobileNetV1, and introduces several key
improvements:
• Depthwise Separable Convolutions: This technique separates convolution into two
operations:
o Depthwise convolution: Applies a single filter to each input channel.
o Pointwise convolution: Applies a 1x1 convolution to combine the outputs of
the depthwise convolution. This reduces the number of computations and
parameters, making the model lighter.
base_model.trainable = False
model = tf.keras.Sequential([
base_model,
tf.keras.layers.GlobalAveragePooling2D(),
tf.keras.layers.Dense(10, activation='softmax') # Adjust the output units to match the
number of classes
])
model.compile(optimizer=tf.keras.optimizers.Adam(),
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
# early_stopping=EarlyStopping(patience=3)