TensorFlow Object Detection API Weird Behavior
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 the TensorFlow Object Detection API behaves strangely, the root cause is often not the detector itself but a mismatch somewhere in preprocessing, label mapping, checkpoint loading, or post-processing. The fastest way to debug it is to treat the pipeline as a sequence of contracts and verify each contract separately.
Start With the Usual Symptoms
"Weird behavior" in object detection usually means one of these:
- boxes appear in the wrong location
- scores are unexpectedly low or unstable
- classes do not match the objects on screen
- inference returns almost no detections
- training metrics improve, but inference looks wrong
Those symptoms point to different failure points. If you debug the entire stack at once, you waste time. Start by isolating where the numbers first stop making sense.
Verify Input Shape and Preprocessing First
A detection model is sensitive to image shape, channel order, and numeric range. Before blaming the model, print the tensor you actually pass into inference.
That simple check catches a surprising number of mistakes. If the model expects a batch dimension and you forget it, the rest of the pipeline becomes misleading. If the preprocessing function expects normalized floats but receives raw integers, scores can look erratic.
Keep the training and inference preprocessing paths aligned. If training resized or normalized images one way and inference does it another way, apparent model instability is often just input mismatch.
Make Sure You Interpret Boxes Correctly
Many models return normalized bounding boxes in the order (ymin, xmin, ymax, xmax). If you treat them as pixel values or swap the coordinate order, the output looks broken even when the detector is correct.
If your boxes are shifted, inverted, or drawn outside the image, verify the coordinate convention before changing the model.
Check Label Maps and Class Offsets
Another common source of confusion is label mismatch. The detector may be producing the correct class ID, but your application maps that ID to the wrong label.
Print the raw class IDs and scores before converting them into display names.
If the dataset label map and the inference-time label map differ, the model can look nonsensical even though the raw predictions are internally consistent.
Separate Training Problems From Inference Problems
If training loss looks reasonable but inference is wrong, the model may be fine and the export or serving path may be broken. Conversely, if inference is noisy on both training and validation examples, the problem is likely earlier.
A practical check is to run inference on one image from the training set that the model should recognize easily. If that still looks wrong, inspect:
- checkpoint loading
- label map alignment
- preprocessing parity
- score threshold and non-max suppression settings
If training truly never converged, then start looking at learning rate, bad annotations, class imbalance, or data pipeline errors.
Use Deterministic Sanity Checks
Randomness makes debugging detection models harder than it needs to be. During investigation, make the setup repeatable.
This will not eliminate every source of nondeterminism in every environment, but it reduces noise while you isolate the actual bug.
Common Pitfalls
The most common mistake is debugging rendered boxes instead of the raw tensors. Look at class IDs, scores, and normalized boxes before you touch visualization code.
Another mistake is mixing training and inference preprocessing. A tiny resize or normalization mismatch can look like a model failure.
A third issue is using the wrong label map or an off-by-one class index.
Finally, do not call the behavior "weird" until you have checked the boring explanations first. In detection systems, the boring explanations win most of the time.
Summary
- Debug object detection pipelines one contract at a time: input, model output, label mapping, and rendering.
- Verify tensor shape, dtype, and preprocessing before changing the model.
- Confirm whether boxes are normalized and in
(ymin, xmin, ymax, xmax)order. - Print raw class IDs and scores to validate label-map alignment.
- Compare behavior on an easy training image to separate training issues from inference issues.
- Use deterministic seeds during debugging so the real failure is easier to isolate.
Related reading
- TensorFlow Object Detection API Weird Behavior
- Tensorflow object detection config files documentation
- Tensorflow object detection evaluation pycocotools missing
- tensorflow object detection Fine-tuning a model from an existing checkpoint
- Tensorflow object detection ImportError No module named nets
- Tensorflow object detection mask rcnn uses too much memory
- Tensorflow Object detection model evaluation on Test Dataset
- TensorFlow object detection TF-TRT Warning Could not find TensorRT

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the 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.