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.
1. Install supervision
2. Load data
3. Plot and blur predictions with a supervision BlurAnnotator
Without further ado, let's get started!
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.
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
You can load data using the following code:
from deepsparse import Pipeline import supervision as sv yolo_pipeline = Pipeline.create( task="yolo", model_path="zoo:cv/detection/yolov5-l/pytorch/ultralytics/coco/pruned80_quant-none" ) pipeline_outputs = yolo_pipeline(SOURCE_IMAGE_PATH, iou_thres=0.6, conf_thres=0.001) detections = sv.Detections.from_deepsparse(pipeline_outputs)
Replace the ... with the response object from your model.
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( scene=image.copy(), detections=detections ) 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.
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.