Save PaddlePaddle Detections to CSV

Learn how to save model predictions to a file.

Overview

When you are working with computer vision models, you may want to save your detections to CSV or JSON for further processing. This is especially useful in testing and debugging scripts, or applications where you want to log all results from your model to a plain text file.

Using the supervision Python package, you can

Save PaddlePaddle Detections to CSV

predictions in a few lines of code. In this guide, we will show how to plot and visualize model predictions.

We will:

1. Install supervision
2. Load a model and save predictions with the supervision Sink API

Without further ado, let's get started!

and Image Annotation Resources

Explore these resources to enhance your understanding of and image annotation techniques.

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 save detections.

Save Data

First, we need to load our computer vision model. Then, we can load detections into the supervision Detections() API. With our detections in the Detections() API, we can use the

CSV

sink to save our data.

You can save data using the following code:


import supervision as sv
import paddle
from ppdet.engine import Trainer
from ppdet.core.workspace import load_config

weights = ()
config = ()

cfg = load_config(config)
trainer = Trainer(cfg, mode='test')
trainer.load_weights(weights)

csv_sink = sv.CSVSink("RESULT_CSV_FILE_PATH")
frames_generator = sv.get_video_frames_generator("SOURCE_VIDEO_PATH")

with csv_sink as sink:
    for frame in frames_generator:
    		paddledet_result = trainer.predict([images])[0]
				detections = sv.Detections.from_paddledet(paddledet_result)
        sink.append(detections, custom_data={'CUSTOM_LABEL':'CUSTOM_DATA'})

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.