TensorFlow Adding Class to Pre-trained Inception Model Outputting Full Image Hierarchy
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
If you want a pretrained Inception model to recognize a new class, the normal solution is transfer learning: keep the convolutional base, replace the classification head, and train a new output layer for your target labels. What you usually cannot do cleanly is bolt one extra class onto the old ImageNet softmax and expect TensorFlow to preserve some built-in "full hierarchy" of original classes plus your custom class automatically.
Understand What The Pretrained Head Actually Does
A pretrained Inception model such as InceptionV3 with include_top=True ends in a classifier trained on the original ImageNet label set. Those logits correspond to the training classes used for that model.
That means the final layer is not a generic expandable taxonomy. It is a fixed classifier head.
If your goal is custom classification, the standard TensorFlow guidance is to remove the top layer and attach a new one for your own classes.
Replace The Top Layer
Here is the standard Keras pattern.
Here, the new output layer has 5 classes because the task is now defined by your dataset, not by ImageNet's original classifier.
If You Need Original Classes Too
This is where people often get stuck. If you need the original ImageNet predictions and your new label at the same time, you have to define what that means operationally.
Common choices are:
- keep two separate models, one for ImageNet labels and one for your custom labels
- build a new classifier head that predicts a new combined label space and retrain it accordingly
- use the pretrained model only as a feature extractor and train your own downstream classifier
There is no free way to append a new label to the existing softmax without providing training data and defining how the new output relates to the old outputs.
About The "Full Image Hierarchy"
ImageNet labels are related to WordNet concepts, but the neural network's output is still just a vector of class scores. The model does not automatically reason over a symbolic hierarchy during ordinary inference.
So if you want hierarchical output, you usually implement it in post-processing or in a custom label structure. It is not something that appears automatically just because the original dataset had a taxonomy behind it.
Fine-Tune Later If Needed
After training the new head, you can optionally unfreeze part of the backbone and fine-tune with a low learning rate.
This can improve accuracy when the new image domain is meaningfully different from ImageNet.
Common Pitfalls
A common mistake is keeping include_top=True and trying to add one more class after the existing 1000-way softmax. That usually does not reflect a coherent training objective.
Another mistake is assuming the ImageNet hierarchy is built directly into inference output semantics. The model predicts class scores, not a rich symbolic tree.
It is also easy to forget preprocessing. Inception models expect a particular input size and preprocessing function, so custom data must follow the same conventions.
Summary
- To add custom classes to Inception, remove the pretrained top layer and train a new classifier head.
- The original ImageNet softmax is a fixed classifier, not a plug-and-play expandable taxonomy.
- If you need both original and custom labels, define an explicit multi-model or combined-label strategy.
- Hierarchical output usually has to be implemented outside the raw softmax layer.
- Fine-tuning the backbone later can help once the new head is working.
Related reading
- TensorFlow Adding Class to Pre-trained Inception Model Outputting Full Image Hierarchy
- Tensorflow after 1.15 - No need to install tensorflow-gpu package
- Tensorflow aggregation_method for optimizers
- Tensorflow allocating GPU memory when using tf.device'/cpu0
- Tensorflow and cifar 10, testing single images
- Tensorflow Android demo Detection using Front Camera
- Tensorflow Allocation Memory Allocation of 38535168 exceeds 10 of system memory
- Tensorflow always predict the same output
.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.