Deep Learning Starter · free course

Free course · Lesson 4 of 5

Transfer Learning & Pre-trained Models

In this lesson you will

  • Explain why transfer learning works
  • Describe feature extraction and fine-tuning

Transfer learning is one of the most powerful techniques in deep learning. Instead of training a massive model from scratch (which requires millions of images and weeks of GPU time), you take a pre-trained model — like ResNet50, MobileNet, or EfficientNet — that was already trained on millions of images (ImageNet). You remove the classification head and add your own custom layers for your specific task. This works even with very little data.

  • Pre-trained models have learned general visual features (edges, textures, shapes).
  • You "freeze" the early layers (they already know how to see) and only train the new head.
  • Perfect for custom tasks like detecting potholes, classifying crops, or mapping flooded areas.
  • Available in torchvision.models (PyTorch) and tf.keras.applications (TensorFlow).

💡 Practical Skill: Fine-tune MobileNet for a custom dataset of South Sudanese infrastructure (roads, bridges, markets). Use Google Colab with a free GPU — training takes minutes, not days.

Worked exampleLoad Pre-trained MobileNetV2 & Remove Head
Python
# Loading a pre-trained MobileNetV2 and customizing it for a new task# Install: pip install tensorflow import tensorflow as tf # Load MobileNetV2 pre-trained on ImageNet (1000 classes)# We exclude the top (classification head) to add our ownbase_model = tf.keras.applications.MobileNetV2(    input_shape=(224, 224, 3),   # standard image size    include_top=False,            # drop the classification head    weights='imagenet'            # use pre-trained ImageNet weights) # Freeze the base model layers (they already know how to "see")base_model.trainable = False # Add our own custom classification headmodel = tf.keras.Sequential([    base_model,                          # pre-trained feature extractor    tf.keras.layers.GlobalAveragePooling2D(),  # reduce dimensions    tf.keras.layers.Dense(128, activation='relu'),  # new learning layer    tf.keras.layers.Dropout(0.3),        # prevent overfitting    tf.keras.layers.Dense(1, activation='sigmoid')  # binary output (e.g., flooded/not flooded)]) # Compile — only the new head layers will trainmodel.compile(optimizer='adam',              loss='binary_crossentropy',              metrics=['accuracy']) print("\u2705 Pre-trained MobileNetV2 loaded with custom head!")print(f"   Base model layers: {len(base_model.layers)} (frozen)")print(f"   New head: GlobalAvgPool \u2192 Dense(128) \u2192 Dropout \u2192 Dense(1)")print("\nTrain with your own images:")print("   model.fit(train_images, train_labels, epochs=10)")print("   For fine-tuning later, set base_model.trainable = True")

Practice exercise

Write the steps you would follow to build a leaf disease classifier from a pre-trained model with only 300 labelled photos.

Key takeaways

  • Pre-trained models already know general visual features
  • Replace the head and train it first, then fine-tune gently
  • Check the licence and training data of any pre-trained model
In the full program Module 4: Transfer Learning with Pre-trained Models See how this topic is taught in depth, with practical activities and an assessment.

Free self-study lesson — no certificate. For the full instructor-led program, see registration options.