Skip to content

Transfer learning in TensorFlow/Keras using ImageNet-pretrained CNNs (e.g., VGG16, ResNet50) for CIFAR-10 classification. Demonstrates feature extraction, custom classifier heads, and fine-tuning workflows.

License

Notifications You must be signed in to change notification settings

imehranasgari/DL_TF_TransferLearning_CIFAR10

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

1) Project Title

Transfer Learning with TensorFlow/Keras — CIFAR-10 Classification Using Pretrained CNNs


2) Problem Statement and Goal of Project

This project demonstrates transfer learning in TensorFlow/Keras by adapting a pretrained convolutional neural network (CNN) for CIFAR-10 image classification. The goals are to:

  • Leverage ImageNet-trained models (e.g., VGG16, ResNet50) as feature extractors.
  • Implement both frozen-base feature extraction and fine-tuning strategies.
  • Showcase best practices for efficiently adapting large models to smaller datasets.

3) Solution Approach

  1. Dataset Loading & Preprocessing

    • CIFAR-10 loaded from tf.keras.datasets.
    • Pixel values normalized to [0, 1].
    • Labels one-hot encoded with tf.keras.utils.to_categorical.
  2. Base Model Selection

    • Pretrained model from tf.keras.applications with imagenet weights.
    • include_top=False to remove the original classifier.
    • Input resized to match the base model requirements.
  3. Custom Classifier Head

    • GlobalAveragePooling2D → Dense(256, relu) → Dense(10, softmax).
    • Designed to adapt ImageNet features to CIFAR-10 classes.
  4. Training Phases

    • Feature Extraction: Base layers frozen, only new classifier layers trained.
    • Fine-Tuning (optional): Top layers of base model unfrozen, trained with a lower LR.
  5. Evaluation & Visualization

    • Model summary printed to verify architecture and trainable parameters.
    • Optional plots for training history.

4) Technologies & Libraries

  • Python 3.x
  • TensorFlow / Keras
  • NumPy
  • Matplotlib (for visualizations)

5) Description about Dataset

  • CIFAR-10:

    • 60,000 images (32×32 RGB), 10 classes.
    • Train: 50,000 images | Test: 10,000 images.
    • Classes: airplane, automobile, bird, cat, deer, dog, frog, horse, ship, truck.
  • Preprocessing: normalization + one-hot encoding.


6) Installation & Execution Guide

Prerequisites

  • Python 3.x
  • TensorFlow (GPU optional)

Install

pip install tensorflow numpy matplotlib

Run

  1. Open Transfer Learning_me.ipynb in Jupyter/Colab/VS Code.

  2. Execute cells sequentially.

  3. The notebook will:

    • Load and preprocess CIFAR-10.
    • Load the pretrained model and build a custom head.
    • Train in feature extraction and/or fine-tuning modes.

7) Key Results / Performance

  • Not provided — The notebook focuses on demonstrating the transfer learning process, not maximizing accuracy.

8) Screenshots / Sample Output

Example: Model Summary Output

Model: "sequential"
_________________________________________________________________
vgg16 (Functional)           (None, 7, 7, 512)         14714688
global_average_pooling2d     (None, 512)               0
dense                        (None, 10)                5130
=================================================================
Total params: 14,719,818
Trainable params: 5,130
Non-trainable params: 14,714,688
_________________________________________________________________

9) Additional Learnings / Reflections

  • Freezing pretrained layers preserves valuable learned features.
  • Fine-tuning selectively can further improve domain adaptation.
  • Transfer learning enables strong performance on small datasets with reduced compute cost.
  • This workflow is adaptable to any image classification task.

👤 Author

Mehran Asgari Email: imehranasgari@gmail.com GitHub: https://github.com/imehranasgari


📄 License

This project is licensed under the Apache 2.0 License – see the LICENSE file for details.


💡 Some interactive outputs (e.g., plots, widgets) may not display correctly on GitHub. If so, please view this notebook via nbviewer.org for full rendering.


About

Transfer learning in TensorFlow/Keras using ImageNet-pretrained CNNs (e.g., VGG16, ResNet50) for CIFAR-10 classification. Demonstrates feature extraction, custom classifier heads, and fine-tuning workflows.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published