Retraining the last layer of Inception-ResNet-v2
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
Retraining only the last layer of Inception-ResNet-v2 is a standard transfer-learning workflow when you have a pretrained ImageNet model and a new classification problem with different classes. The idea is to keep the convolutional backbone fixed, replace the classifier head, and train only that final part on your dataset.
Why Retrain Only the Last Layer
The earlier layers of Inception-ResNet-v2 learn broadly useful visual features such as edges, textures, shapes, and part-level patterns. If your new dataset is not huge, reusing those features is usually better than training the full network from scratch.
Retraining only the classifier head gives you:
- much faster training
- lower GPU memory pressure
- less risk of overfitting on a small dataset
It is usually the first transfer-learning step before considering deeper fine-tuning.
Building the Model in Keras
With tf.keras.applications.InceptionResNetV2, the common pattern is to load the pretrained base without the top classification layer, freeze it, and add a new dense output layer for your class count.
The include_top=False setting removes the original ImageNet classifier, and the new dense layer becomes the only trainable classification head.
Input Size and Preprocessing Matter
Inception-ResNet-v2 expects images resized to 299 x 299, and you should use the matching preprocessing function. Skipping the model-specific preprocessing or feeding the wrong input size can hurt accuracy enough that the transfer-learning setup appears broken.
If your dataset pipeline is built with tf.data, the preprocessing step can be integrated cleanly:
The actual normalization still happens in the model through preprocess_input in the earlier example.
Training the New Head
Once the base is frozen, training updates only the last layer's weights.
If the dataset is small, data augmentation is often more valuable than trying to unfreeze deeper layers immediately.
When to Fine-Tune More Than the Last Layer
Retraining only the final layer is a strong baseline, but it may plateau if your target dataset is visually very different from ImageNet. In that case, unfreezing a small portion of the upper backbone can help.
The key is to lower the learning rate when fine-tuning deeper layers. Otherwise, you can quickly damage the pretrained weights.
Common Pitfalls
The biggest pitfall is forgetting to freeze the base model before the first training phase. If everything is trainable immediately, training becomes slower and the pretrained representation can drift too aggressively.
Another issue is skipping the model-specific preprocessing. Inception-style models are sensitive to input scaling conventions.
Developers also sometimes replace only the very last dense layer but keep a mismatch between the label format and the loss function. For example, one-hot labels and integer labels need different loss choices.
Finally, when you later unfreeze layers for fine-tuning, always recompile the model. Keras needs a fresh compiled training graph after trainable flags change.
Summary
- Retraining the last layer of Inception-ResNet-v2 is a standard transfer-learning baseline.
- Load the pretrained backbone with
include_top=False, freeze it, and add a new classifier head. - Use the correct
299 x 299input size and the matching preprocessing function. - Start with only the last layer trainable, then fine-tune upper layers later if needed.
- Lower the learning rate significantly before unfreezing part of the backbone.
Related reading
- Return number of epochs for EarlyStopping callback in Keras
- Return number of epochs for EarlyStopping callback in Keras
- return_sequences False equivalent in pytorch LSTM
- Reusing a group of Keras layers
- Retrieve cross validation performance AUC on h2o AutoML for holdout dataset
- retrieve misclassified documents using scikitlearn
- \`RNN\` in Tensorflow vs Keras, depreciation of tf.nn.dynamic_rnn
- `RNN` model GRU of word2vec to regression not learning
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.