Published in


Perform Sliced (Tiled) Inference and Detailed Error Analysis using YOLOv5 Models

  • Do you need sliced (tiled) inference for small object detection on satellite images or high-resolution images?
  • Do you need explainable metrics for your detection model (insights on possible improvements)?
  • Do you need an interactive UI to visualize faulty predictions?
  • Do you rely on YOLOv5 models?

All of them is possible with the YOLOv5 integration of SAHI 🚀

This post will walk you through installation, sliced inference, error analysis, and interactive visualization steps for your YOLOv5 models.


✔️ Install Pytorch:

conda install pytorch=1.10.0 torchvision=0.11.1 cudatoolkit=11.3 -c pytorch

✔️ Install SAHI:

conda install sahi -c conda-forge
pip install -U sahi

✔️ Install YOLOv5:

pip install -U yolov5

Sliced Prediction

Gif showing sliced prediction capabilities of SAHI.

✔️ Use your weight path to perform inference:

sahi predict --source image_dir/ --model_type yolov5 --model_path --slice_height 512 --slice_width 512

Error Analysis Plots/Metrics

✔️ Create COCO formatted prediction results using COCO formatted dataset:

Gif showing COCO formatted dataset prediction capabilities of SAHI.
sahi predict --source image_dir/ --dataset_json_path dataset.json --model_type yolov5 --model_path --no_sliced_prediction

✔️ Create error analysis plots using the created result.json:

Gif showing error analysis capabilities of SAHI.
sahi coco analyse --dataset_json_path dataset.json --result_json_path result.json

🎯 Meaning of the metrics:

C75: Results at 0.75 IOU threshold
C50: Results at 0.50 IOU threshold
Loc: Results after ignoring localization errors
Sim: Results after ignoring supercategory false positives
Oth: Results after ignoring all category confusions
BG: Results after ignoring all false positives
FN: Results after ignoring all false negatives

📈 Possible model improvements:

C75-C50 and C50-Loc=Potential gain with more accurate bounding box prediction
Loc-Sim=Potential gain after fixing supercategory confusions
Loc-Oth=Potential gain after fixing category confusions
Oth-BG=Potential gain after fixing all false positives
BG-FN=Potential gain after fixing all false negatives

Interactive Visualization

✔️ Install fiftyone:

pip install -U fiftyone

✔️ Start a fiftyone web app with your prediction results:

Gif showing interactive visualization capabilities of SAHI.
sahi coco fiftyone --dataset_json_path dataset.json --image_dir image_dir/ result.json



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store