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
When you want Inception v3 to recognize new categories, you usually do not retrain the whole network from scratch. The standard approach is transfer learning: keep the pretrained convolutional base, replace the classifier head, train the new head on your dataset, and then fine-tune part of the base model if needed.
Start with a Dataset Organized by Class
The simplest workflow uses one directory per class. For example, a dataset could contain data/flowers/daisy, data/flowers/rose, and data/flowers/tulip. TensorFlow can read this structure directly and infer the class labels.
Inception v3 expects images resized to 299 x 299, so make sure the input pipeline uses that shape and applies the correct preprocessing function.
Replace the Original Classifier Head
The original Inception v3 top layers were trained for ImageNet classes. To add your own categories, load the pretrained base with include_top=False, then attach a new output layer sized for your dataset.
At this stage, only the new classification head trains. This lets the model learn the mapping from the pretrained visual features to your new categories without immediately disturbing the useful weights learned from ImageNet.
Fine-Tune After the Head Has Learned
If validation accuracy plateaus and you have enough data, unfreeze part of the base model and continue training with a much smaller learning rate.
The small learning rate is critical. Fine-tuning changes pretrained weights that already contain strong general-purpose image features. Updating them too aggressively often destroys useful representations and makes the model perform worse.
How This Relates to TensorFlow 1
Older TensorFlow 1 examples often retrained only the final layer using graph-based code or the original TensorFlow image retraining scripts. The training strategy was the same: keep most pretrained weights, add a new classifier, and optimize that classifier on your classes. The modern tf.keras API shown here is easier to maintain and is the recommended approach for current projects.
Common Pitfalls
The first common problem is using the wrong image size or skipping preprocess_input. Inception v3 was trained with a specific input pipeline, so mismatched preprocessing can noticeably reduce accuracy.
Another issue is unfreezing the entire model too early. If you start fine-tuning before the new head has learned anything useful, the base network may drift and training becomes unstable.
Small datasets can also create misleadingly high training accuracy with poor validation results. Data augmentation, class balancing, and early stopping often matter more than another extra epoch.
Finally, verify that the class folders are correct. A mislabeled directory name can silently train the model on the wrong labels and waste hours of debugging.
Summary
- Use transfer learning instead of training Inception v3 from scratch for a small custom dataset.
- Resize images to
299 x 299and apply Inception v3 preprocessing. - Load the pretrained base with
include_top=False, then add a new Dense layer for your categories. - Train the new classifier head first, then fine-tune upper layers with a very small learning rate.
- Check labels, preprocessing, and dataset quality before blaming the model architecture.
Related reading
- How do you create a boolean mask for a tensor in Keras?
- How do you edit an existing Tensorboard Training `Loss` summary?
- How do you pass video features from a CNN to an LSTM?
- How do you use freeze_graph.py 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 use Keras LeakyReLU in Python?
- How does a Neural Network calculate the sum of the weights?
.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 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.