How to blur MMDetection predictions

There are many scenarios in which you may want to blur detections from an object detection model. For example, consider a scenario where you are counting the number of cars going through a drive-through. With computer vision, you can both count the number of cars while blurring any faces that are present.

In this guide, we are going to walk you through how to blur predictions from a

model in a few lines of code using the open source supervision Python package.

We will:

1. Install supervision
2. Load data
3. Plot and blur predictions with a supervision BlurAnnotator

Without further ado, let's get started!

Step #1: Install supervision

First, install the supervision pip package:

pip install supervision

Once you have installed supervision, you are ready to load your data and start writing logic to filter detections.

Step #2: Load Data

First, we are going to load our dataset into a supervision.DetectionDataset() object. This object will contain information about all the images in a dataset. You can load datasets from many different model types, from YOLO to MMDetection. For this guide, we will use the

data loader.

You can load data using the following code:

import cv2
import supervision as sv
from mmdet.apis import DetInferencer

inferencer = DetInferencer(model_name, checkpoint, device)
mmdet_result = inferencer(SOURCE_IMAGE_PATH, out_dir='./output',
detections = sv.Detections.from_mmdet(mmdet_result)

Replace the ... with the response object from your model.

Step #3: Plot Detections with the BlurAnnotator

Supervision has a range of annotators that let you visualize detections from a computer vision model. For this guide, we are going to use the BlurAnnotator, which allows you to plot bounding boxes and blur their contents.

You can use the following code to plot predictions and blur their contents:

blur_annotator = sv.BlurAnnotator()

annotated_frame = blur_annotator.annotate(

sv.plot_image(image=annotated_frame, size=(16, 16))

Here is an example of an image on which the BlurAnnotator has been applied:

All of the people found by the model have been blurred. Some people have not been blurred, but this could be fixed by improving the accuracy of the underlying model.

Next steps

supervision provides an extensive range of functionalities for working with computer vision models. With supervision, you can:

1. Process and filter detections and segmentation masks from a range of popular models (YOLOv5, Ultralytics YOLOv8, MMDetection, and more).
2. Process and filter classifications.
3. Compute confusion matrices.

And more! To learn about the full range of functionality in supervision, check out the supervision documentation.