Improve your Object Detection and Instance Segmentation Results for Detection of Small Objects

One of the important tasks of computer vision is to identify objects in real-time, what if we have large image of large size and the objects we need to identify are small? Now one of the methods we can can rely is SAHI.

They call it Slicing Aided Hyper Inference (SAHI) , it provides a generic slicing aided inference and finetuning pipeline for small object detection.

Try SAHI on Huggingface:

Installation of SAHI :

Dependencies :

  • On Windows, needs to be installed via Conda:

That’s it, now you can import and use any SAHI function in Python:

Detecting Smaller Objects using Sliced Inference with SAHI:

Concept of sliced inference is basically; performing inference over smaller slices of the original image and then merging the sliced predictions on the original image.

will perform sliced inference on default parameters and export the prediction visuals to runs/predict/exp folder.

  • Specify detection framework as for MMDetection or for YOLOv5, to match with your model weight
  • Specify postprocess type as or to be applied over sliced predictions
  • Specify postprocess match metric as for intersection over smaller area or for intersection over union
  • Specify postprocess match threshold as
  • Add argument to ignore category ids of the predictions during postprocess (merging/nms)
  • If you want to export prediction pickles and cropped predictions add and arguments. If you want to change crop extension type, set it as .
  • If you want to export prediction visuals, add argument.
  • By default, scripts apply both standard and sliced prediction (multi-stage inference). If you don’t want to perform sliced prediction add argument. If you don't want to perform standard prediction add argument.
  • If you want to perform prediction using a COCO annotation file, provide COCO json path as add and coco image folder as , predictions will be exported as a coco json file to runs/predict/exp/results.json. Then you can use coco_evaluation command to calculate COCO evaluation results or coco_error_analysis command to calculate detailed COCO error plots.

check here more SAHI CLI commands :

You can have the flexibility to choose different models to inference with SAHI:

Slicing Operation

  • Slice an image:
  • Slice a COCO formatted dataset:

Inference between Normal and Sliced Inference:

Instance Segmentation result with SAHI :

We could spot some far away objects been detected. That is awesome !

For Error Analysis Plot and Interactive Result Visualization , refer below links:

Reference :

Paper :

Hope you learned something new today, Happy Learning!



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