Elena' s AI Blog

TensorFlow: Transfer Learning (Fine-Tuning) in Image Classification

06 Apr 2022 (updated: 24 Aug 2026) / 56 minutes to read

Elena Daehnhardt

Jasper AI-generated art, January 2023


TL;DR:
  • Fine-tune EfficientNetB0: unfreeze top layers, use lower learning rate (10x smaller), add data augmentation. Achieves 98.5% accuracy vs 50% from scratch—transfer learning wins.

Previous: Part 12 — TensorFlow: Transfer Learning (Feature Extraction) in Image Classification

Next: Part 14 — TensorFlow: Evaluating the Saved Bird Species Prediction Model

Fine-Tuning EfficientNetB0 for Bird Species Image Classification

Transfer learning is a machine learning technique that reuses patterns learned by a pre-trained model on a new dataset and task. In my previous post “TensorFlow: Transfer Learning (Feature Extraction) in Image Classification”, I wrote about employing pre-trained models such as EfficientNet — trained on the [ImageNet][3] dataset and available in [the TensorFlow Hub][4] — for the task of bird species prediction. That earlier post covered the feature extraction approach. This post applies the fine-tuning approach I learned in the Udemy course on TensorFlow, describing transfer learning experiments that fine-tune a bird species prediction model. The code uses [the Keras EfficientNet API][6] for building EfficientNetB0-based models.

What Is Fine-Tuning in Transfer Learning?

Fine-tuning is a transfer learning method that unfreezes some layers of a pre-trained model and retrains them at a low learning rate to adapt learned features to a new dataset. In transfer learning, we reuse features learned on a different dataset for a different problem — useful when training data is limited and a state-of-the-art, well-tested model such as EfficientNet [5] is available. Transfer learning thus reuses features extracted from an existing model for predictions on a new dataset.

Figure 1 schematically shows the difference between feature extraction (see my post on feature extraction) and fine-tuning in transfer learning. I have drawn it to outline the process of using the trained on ImageNet model, in which layers are frozen during the feature extraction step. After the model is converged with the use of the birds’ dataset, we unfreeze some unfrozen layers while performing fine-tuning wherein the model is retrained with new data using the bird species dataset [2].

Transfer Learning: feature extraction vs fine-tuning

Figure 1. Transfer Learning: feature extraction vs fine-tuning

The fine-tuning is done by unfreezing the frozen layers, partially or entirely, and retraining the model with a meager learning rate. This way, we adapt the trained features to our new (birds species) dataset while (potentially) achieving better prediction results.

Would fine-tuning be beneficial to our bird species prediction task? Let’s run some experiments on feature extraction with fine-tuning and comparing their results with the feature extraction without fine-tuning (the model described and evaluated in my previous post on feature extraction).

Retrieving and Preparing the 400 Bird Species Dataset

I have described the data loading and preprocessing in my previous post “TensorFlow: Transfer Learning (Feature Extraction) in Image Classification” in detail. You could read it if you did not do it yet. I also moved the code that I will further reuse it in the GiHub repository, helpers.py. You can check it out and use it for your own convenience. This code is adapted from the Udemy course and includes getting and unzipping the dataset, preprocessing, plotting images, and loss functions, model creation and callbacks for TensorBoard and saving of checkpoints
for deep learning experiments with TensorFlow. You can use this code directly in Colab with:

Model Creation: Four EfficientNetB0 Transfer Learning Variants

🔒 Subscribe to keep reading.

Saving Model Checkpoints with ModelCheckpoint Callbacks

🔒 Subscribe to keep reading.

1. Baseline EfficientNetB0 Feature Extraction Model

🔒 Subscribe to keep reading.

2. EfficientNetB0 Model with Data Augmentation

🔒 Subscribe to keep reading.

3. Fine-Tuning Model 2 by Unfreezing the Top 10 Layers

🔒 Subscribe to keep reading.

4. Final Model 4: No Augmentation, Top 100 Layers Unfrozen

🔒 Subscribe to keep reading.

Comparing the Four Transfer Learning Models by Accuracy

🔒 Subscribe to keep reading.

Bird Species Predictions with the Saved EfficientNetB0 Model

🔒 Subscribe to keep reading.

Conclusion: Fine-Tuning vs. Feature Extraction Results

🔒 Subscribe to keep reading.

References

🔒 Subscribe to keep reading.

You've hit a Deep Dive tutorial.

I spend dozens of hours researching, coding, and breaking things to write these guides. This content is free, but reserved for my subscriber community. Drop your email below to unlock this guide (and all past/future deep dives):

Already a subscriber? Use the magic link from your last newsletter, or reset your password.

New subscribers get an inbox mail: Set a password to unlock articles. The form does not log you in — use the same email afterwards.

desktop bg dark

About Elena

Elena, a PhD in Computer Science, simplifies AI concepts and helps you use machine learning.

Citation
Elena Daehnhardt. (2022) 'TensorFlow: Transfer Learning (Fine-Tuning) in Image Classification', daehnhardt.com, 06 April 2022. Available at: https://daehnhardt.com/blog/2022/04/06/tensorflow-transfer-learning-image-classification-fine-tuning-data-augmentation-predictive-modeling-image-classification/
All Posts