Class filtering

Learn how to filter model outputs by class to reduce clutter, streamline downstream logic, and focus on what matters to your application.

Estimated read time: 4 minutes

Models are often trained on many labels (e.g., COCO’s 80), but your application may only need a subset.

Use model.label_dictionary to see exactly which labels a model predicts (for detection, classification, or segmentation). Then, optionally restrict outputs to the classes you care about using output_class_set—reducing clutter and simplifying downstream logic.

Inspect labels without filtering

Two people sitting on a bench next to two bicycles. The people, bench, and bicycles are labeled.
Two people sitting on a bench next to two bicycles. The people, bench, and bicycles are labeled.

Use this baseline run to confirm label names before filtering. Knowing the exact strings ensures you pass the right values to output_class_set later.

Example

Expect console output similar to the snippet below.

Example

Filter to a subset of classes

Two people sitting on a bench next to two bicycles. The bicycles are labeled.
Two people sitting on a bench next to two bicycles. The bicycles are labeled.

Apply class filtering to focus overlays and downstream logic on just the labels you need. Adjust the set before loading the model so every result reports only the chosen classes.

Example

  • model.label_dictionary lists the label names the model can predict—use it to confirm exact strings (e.g., "bicycle" vs "bike").

  • output_class_set accepts a set or list of label strings. Omit it (or set to None) to return all classes.

  • Works the same for detection and segmentation models: non-selected classes are removed from boxes, masks, and overlays.

Last updated

Was this helpful?