TensorFlow Adding Class to Pre-trained Inception Model Outputting Full Image Hierarchy
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Adding your own classes to a pre-trained Inception model is really a transfer-learning problem, not a matter of appending one extra label to the existing softmax and hoping the model understands it. If you want custom classes while still keeping the original ImageNet predictions, the clean solution is usually to reuse the Inception feature extractor and attach a separate custom classification head.
What the Pre-trained Inception Model Actually Gives You
A pre-trained Inception network has learned rich visual features from ImageNet. Those features are useful beyond the original thousand classes, which is why transfer learning works so well.
What the original top layer does not give you is a true semantic hierarchy you can extend cleanly. The ImageNet output is a flat probability distribution over the model's trained classes. If your application needs:
- original ImageNet predictions
- new custom classes
- some higher-level grouping of results
then it is usually better to separate those concerns instead of trying to force one old classifier head to do everything.
Reusing the Inception Base for New Classes
In TensorFlow Keras, the standard pattern is to load the pre-trained base without the old classifier, then add your own head.
This gives you a new classifier for your own three classes while keeping the pre-trained convolutional features.
Keeping the Original ImageNet Predictions Too
If you also want the original ImageNet output, treat it as a separate branch or separate model. One practical approach is to keep an off-the-shelf Inception model with include_top=True for ImageNet predictions and a second transfer-learning model for your custom classes.
Conceptually, the workflow is:
- use one model for the original ImageNet label distribution
- use a second head, or a second model, for your project-specific classes
- map those outputs into your own application hierarchy if needed
That is much easier to reason about than trying to add one new class into the old thousand-way classifier without retraining the original label space thoroughly.
Fine-Tuning After the New Head Learns
A common training sequence is:
- freeze the pre-trained Inception base
- train the new classification head
- unfreeze some of the upper convolutional layers
- continue training with a smaller learning rate
This gives the new head a chance to stabilize before you start adjusting the shared visual features.
Building a Hierarchy Outside the Softmax
If by "full image hierarchy" you mean broader categories such as animal, vehicle, and furniture, that hierarchy usually belongs in your application logic or label taxonomy, not inside the original flat softmax layer itself.
For example, you can map predicted labels into parent categories after inference:
That is a cleaner representation of hierarchy than trying to reinterpret the dense output layer as a tree.
Common Pitfalls
The biggest pitfall is thinking you can append a single class to the old Inception classifier and keep the original behavior without retraining the output layer carefully. The classifier weights were learned for a fixed label space, so changing that space changes the task.
Another mistake is forgetting the required image size and preprocessing for Inception. Feeding the wrong input shape or skipping preprocess_input often hurts performance more than the transfer-learning code itself.
Developers also blur together "ImageNet classes" and "hierarchical categories." The original model predicts flat classes. If you need a hierarchy, define one separately and map predictions into it.
Summary
- Reuse the pre-trained Inception base as a feature extractor and add a new classifier head for your custom classes.
- Do not treat the original ImageNet softmax as something you can casually extend by one class.
- Keep original ImageNet predictions and custom predictions as separate outputs if you need both.
- Fine-tune only after the new head has learned the task reasonably well.
- Build semantic hierarchies in your label mapping layer rather than forcing them into the old classifier head.

