How to set max_detections_per_class and max_total_detections when training for unique objects using Tensorflow Object Detection API
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
When training object detection models using the TensorFlow Object Detection API, parameter tuning is a crucial aspect that can significantly influence the quality of the results. Two such important parameters are max_detections_per_class
and max_total_detections
. Understanding and setting these correctly can help to improve the performance of models, especially when dealing with unique object detection tasks.
Understanding the Parameters
1. max_detections_per_class
- This parameter indicates the maximum number of detections the model should output per class.
- It is particularly useful in scenarios where each class has a known upper limit on the number of instances visible within an image.
- For example, if a specific class, such as "stop signs", never appears more than four times in an image, setting
max_detections_per_classto four helps reduce false positives.
2. max_total_detections
- This parameter defines the overall limit on the number of detections across all classes.
- This is critical in cases where you want to limit computational cost, especially during inference on large images or videos.
- For instance, in a case where resource constraints are significant, you might prioritize
max_total_detectionsto ensure processing remains efficient.
Technical Considerations
Detection Process
The detection process in object detection models involves the generation of multiple bounding boxes and scores for every class. To refine these predictions, Non-Maximum Suppression (NMS) is typically applied. NMS eliminates redundant boxes by comparing detection scores and coordinates. Here, the max_detections_per_class
and max_total_detections
influence the final output by filtering top predictions.
- High Values: Good for classes with many distinct objects, but may increase false positives.
- Low Values: Reduces false positives but might miss objects.
- High Values: Can capture more scene details but may slow down inference.
- Low Values: Ensures faster inference and avoids overloading systems with excessive data.
- Unique classes: E.g., elephants, each distinct and less frequent.
- Sparse scenes: Images typically contain few objects per class.
- Set
max_detections_per_classaccording to expected animal groups (e.g., max 20 zebras). - Limit
max_total_detectionsto save processing resources (e.g., max 100 across all classes). - Perform iterative testing to find an optimal balance.
- Use profiling tools available with TensorFlow to assess computational load.

