Implementation:Cleanlab Cleanlab OD Visualize
| API | object_detection.summary.visualize
|
|---|---|
| Source | cleanlab/object_detection/summary.py:L335-346
|
| Domains | Machine_Learning, Data_Quality, Object_Detection |
| Last Updated | 2026-02-09 |
Overview
Implementation of bounding box visualization for object detection label quality review. Renders ground truth labels and model predictions on images with color-coded overlays, supporting both interactive display and file export.
Description
This function renders an annotated image showing ground truth bounding boxes and/or model predictions. It supports:
- Multiple image input formats: file path (str), numpy array, or PIL Image.
- Optional ground truth label overlay with class names.
- Optional prediction overlay filtered by a confidence threshold.
- Overlay mode that composites both sets of boxes on a single image.
- Configurable figure size and the ability to save to disk.
- Class name mapping for human-readable labels on boxes.
The function uses matplotlib for rendering and can display the result inline (e.g., in Jupyter notebooks) or save it to a specified file path.
Usage
This function is used after identifying images with label issues to visually inspect and confirm detected errors. It is typically called in a notebook environment for interactive exploration or in a script to batch-generate annotated images for review.
Code Reference
Source Location
cleanlab/object_detection/summary.py, lines 335-346.
Signature
def visualize(
image: Union[str, np.ndarray, "Image.Image"],
*,
label: Optional[Dict[str, Any]] = None,
prediction: Optional[np.ndarray] = None,
prediction_threshold: Optional[float] = None,
overlay: bool = True,
class_names: Optional[Dict] = None,
figsize: Optional[Tuple[int, int]] = None,
save_path: Optional[str] = None,
**kwargs,
) -> None
Import
from cleanlab.object_detection.summary import visualize
I/O Contract
Inputs
| Parameter | Type | Description |
|---|---|---|
image |
Union[str, np.ndarray, Image.Image] |
The image to visualize. Can be a file path string, a numpy array (H,W,C), or a PIL Image object. |
label |
Optional[Dict[str, Any]] |
Ground truth annotation dictionary with "bboxes" (np.ndarray M,4 in xyxy format) and "labels" (np.ndarray M,). If None, no ground truth boxes are drawn.
|
prediction |
Optional[np.ndarray] |
Model predictions array of shape (P, K+5). If None, no prediction boxes are drawn. |
prediction_threshold |
Optional[float] |
Minimum confidence score for displaying predicted boxes. Predictions below this threshold are hidden. If None, all predictions are shown. |
overlay |
bool |
If True, renders both ground truth and predictions on the same image. If False, renders them side by side. Defaults to True. |
class_names |
Optional[Dict] |
Mapping from integer class indices to human-readable class names. Used to annotate boxes with class labels. |
figsize |
Optional[Tuple[int, int]] |
Figure size in inches as (width, height). If None, matplotlib defaults are used. |
save_path |
Optional[str] |
File path to save the rendered image. If None, the image is only displayed. |
**kwargs |
Additional keyword arguments passed to the underlying rendering functions. |
Outputs
| Type | Description |
|---|---|
None |
The function does not return a value. It displays a matplotlib figure and/or saves the rendered image to disk. |
Usage Examples
import numpy as np
from cleanlab.object_detection.summary import visualize
# Visualize an image with ground truth labels only
label = {
"bboxes": np.array([[10, 20, 50, 60], [100, 110, 200, 210]]),
"labels": np.array([0, 1]),
}
visualize("path/to/image.jpg", label=label)
# Visualize with both ground truth and predictions
prediction = np.array([
[10, 20, 50, 60, 0.9, 0.85, 0.10, 0.05],
[100, 110, 200, 210, 0.8, 0.05, 0.90, 0.05],
[150, 150, 250, 250, 0.3, 0.70, 0.20, 0.10],
])
class_names = {0: "cat", 1: "dog", 2: "bird"}
visualize(
"path/to/image.jpg",
label=label,
prediction=prediction,
prediction_threshold=0.5,
overlay=True,
class_names=class_names,
figsize=(12, 8),
)
# Save the visualization to a file
visualize(
"path/to/image.jpg",
label=label,
prediction=prediction,
class_names=class_names,
save_path="output/annotated_image.png",
)