TensorFlow Object Detection API print objects found on image to console
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
If you only need to print the detected object names to the console, the TensorFlow object detector output is already enough. The essential workflow is: load the model, run inference on the image, read the class IDs and scores, map those IDs to labels, and print the detections above a confidence threshold.
Run the Detector and Inspect the Output Tensors
Exported TensorFlow detection models typically return a dictionary containing keys such as detection_classes, detection_scores, detection_boxes, and num_detections.
A minimal inference script looks like this:
At this point you already have the raw predictions. The only thing missing is label decoding and thresholding.
Map Class IDs to Human-Readable Labels
The model returns numeric class IDs, not names. For a quick example, a small label map dictionary is enough:
Then print detections above a score cutoff:
That is the core answer to the question. You do not need to draw bounding boxes if your goal is only console output.
A Complete Runnable Example
Putting it together:
If the model sees a person and a dog, the console output might look like:
If You Use a Full Label Map File
Real projects often load a label map from the model's metadata or a .pbtxt file rather than hardcoding a dictionary. That is the right move once you support many classes, but the logic stays the same: class ID in, display name out.
So the actual detection-printing path is always:
- run inference
- read class IDs and scores
- map IDs to labels
- print labels above the threshold
Modern vs Legacy TensorFlow Code
Older TensorFlow Object Detection API examples often used TensorFlow 1.x sessions, graphs, and utility helpers from notebook code. Modern exported models are more commonly run through tf.saved_model.load, which is much simpler if all you need is inference and console output.
That means you do not need to copy a large notebook pipeline just to print object names.
Common Pitfalls
The biggest pitfall is forgetting to convert detection_classes to integers before using them as label-map keys.
Another common issue is printing every detection regardless of score. Low-confidence predictions create noisy console output, so always apply a threshold.
People also mix the wrong label map with the wrong model. If class IDs and labels do not belong to the same model family, the console output is misleading even though the code runs.
Summary
- Run the detector and read
detection_classes,detection_scores, andnum_detections. - Convert class IDs to integers and map them to human-readable labels.
- Print only detections above a sensible confidence threshold.
- Use
tf.saved_model.loadfor a simple modern inference path. - Make sure the label map matches the model you exported.

