How do you add new categories and training to a pretrained Inception v3 model in TensorFlow?
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
Adding new categories to a pretrained Inception v3 model is a standard transfer-learning task. Instead of training a deep image classifier from scratch, you reuse the convolutional backbone learned on ImageNet and replace the final classification head. This gives faster training, lower data requirements, and usually better results for small or medium custom datasets.
Load Inception v3 Without the Original Classifier
The pretrained top layer predicts ImageNet classes, so the first step is removing it and attaching a new head for your categories.
This builds a new classifier while keeping pretrained feature extraction frozen.
Prepare the Dataset Correctly
Transfer learning works best when input size, label structure, and preprocessing are consistent.
Keep class folder order stable and record train_ds.class_names, because Android apps, APIs, or reports often depend on the same label ordering later.
Train the New Classification Head First
Freeze the base model initially and train only the new head. This stabilizes optimization and prevents early destruction of pretrained features.
If you have very little data, add augmentation before the base model to improve generalization.
Then apply augment(inputs) before preprocess_input.
Fine-Tune the Upper Layers
Once the new head learns the task, unfreeze part of the pretrained model and continue with a lower learning rate.
This allows the upper visual features to adapt to your categories without destabilizing the entire network.
Save the Model and Label Mapping
After training, save the model and the label list together.
Saving the label mapping is essential. If label order changes later, predictions can become semantically wrong even when accuracy seems fine.
Practical Training Guidance
Transfer learning quality depends on:
- dataset cleanliness
- label balance
- enough validation data
- matching preprocessing in training and inference
Inception v3 expects 299 by 299 RGB images and its specific preprocessing function. If you skip that or use another model’s normalization, training can look normal but underperform badly.
Also monitor validation loss, not just training accuracy. A pretrained backbone can overfit small datasets quickly once fine-tuning begins.
Common Pitfalls
One common mistake is leaving the original ImageNet classifier attached instead of replacing it. Another is fine-tuning the entire model immediately with a high learning rate, which often destroys pretrained features. Developers also forget to use preprocess_input for Inception v3 specifically. Label-order drift between training and inference is another frequent production bug. Finally, people often evaluate only accuracy and miss class imbalance problems that require precision and recall checks.
Summary
- Load Inception v3 without the original top classifier.
- Add a new dense head sized for your custom categories.
- Freeze the base model first and train the new head.
- Fine-tune upper layers later with a much smaller learning rate.
- Keep preprocessing and label mapping identical across environments.
- Save both the trained model and the class-name order for deployment.
Related reading
- How do you add new categories and training to a pretrained Inception v3 model in TensorFlow?
- How do you compute accuracy in a regression model, after rounding predictions to classes, in keras?
- How do you compute accuracy in a regression model, after rounding predictions to classes, in keras?
- How do you create a boolean mask for a tensor in Keras?
- How do you alter the size of a Pytorch Dataset?
- How do you convert a .onnx to tflite?
- How do you decode one-hot labels in Tensorflow?
- How do you decode one-hot labels in Tensorflow?
.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 courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.