obss/sahi
Framework agnostic sliced/tiled inference + interactive ui + error analysis plots
What is SAHI?
SAHI ( Slicing‑Aided Hyper Inference ) is a lightweight Python library that makes it easy to run object‑detection and instance‑segmentation models on very large images or videos. The core idea is sliced inference: the input image is automatically cut into overlapping tiles, each tile is fed to a standard detector, and the results are merged back together. This solves the common problem of missing tiny objects when a model sees only a low‑resolution whole image.
Key Features (as described in the README)
| Feature | What it does |
|---|---|
| Sliced inference | Automatically tiles large images, runs any supported detector on each tile, and stitches detections back together. |
| Framework‑agnostic | Works with Ultralytics YOLO (v5, v8, YOLO‑X, YOLO‑E, etc.), MMDetection, Detectron2, HuggingFace 🤗 Transformers, TorchVision, Roboflow / RF‑DETR, and GroundingDINO. |
| CLI tools | sahi predict, predict‑fiftyone, coco slice, coco evaluate, coco analyse, coco yolo, etc., for quick command‑line usage and dataset handling. |
| FiftyOne integration | Visualise predictions and error analysis in the FiftyOne app. |
| COCO utilities | Slice COCO datasets, convert between formats, evaluate AP/AR, and generate error‑analysis plots. |
| Video support | Same slicing logic works on video frames for real‑time or batch inference. |
| Pre‑trained model support | No extra code needed – just point SAHI at a model checkpoint from any of the supported libraries. |
| Extensive docs & notebooks | Colab notebooks for every major detector, a full documentation site, and a paper (ICIP 2022) describing the method. |
Installation (quick)
pip install sahi # core library
# optional – install the detector you want to use, e.g.:
# pip install ultralytics>=8.3 # YOLO family
# pip install torch torchvision # for torchvision models
# pip install transformers timm # HuggingFace models
# pip install yolov5==7.0.14 # YOLOv5
# pip install mim && mim install mmdet==3.3.0 # MMDetection
The README also provides detailed version‑matching instructions for PyTorch, CUDA, and each detection framework.
Quick‑Start Example (from the docs)
from sahi import AutoDetectionModel, get_sliced_prediction
# Choose any supported model – here we use YOLOv8 from ultralytics
model = AutoDetectionModel.from_pretrained(
model_type="yolov8",
model_path="yolov8n.pt",
confidence_threshold=0.3,
device="cuda:0",
)
result = get_sliced_prediction(
"large_image.jpg",
detection_model=model,
slice_height=512,
slice_width=512,
overlap_height_ratio=0.2,
overlap_width_ratio=0.2,
)
# Visualise or export the merged detections
result.save("output.jpg")
The same workflow works for video (get_sliced_prediction on each frame) and for any of the other supported back‑ends.
When Would You Use SAHI?
- Satellite or aerial imagery where a single image can be tens of thousands of pixels wide and small objects (cars, ships, animals) are easy to miss.
- Medical imaging (e.g., whole‑slide pathology) where high‑resolution scans need to be processed without down‑sampling.
- Surveillance video where you want to detect tiny objects across many frames efficiently.
- Benchmarking / research – the library includes tools to slice COCO datasets, evaluate AP/AR, and generate error‑analysis plots.
- Rapid prototyping – no need to rewrite your existing detector code; just wrap it with SAHI’s CLI or Python API.
Resources
- Paper: Slicing Aided Hyper Inference (ICIP 2022) – DOI 10.1109/ICIP46576.2022.9897990
- Docs: https://github.com/obss/sahi/tree/main/docs
- Colab notebooks for every major detector (links in the README).
- HuggingFace Space demo – https://huggingface.co/spaces/fcakyon/sahi-yolox
- Community: 600+ citations, competition winners, and a discussion forum for error analysis.
Bottom line: SAHI is a real, actively maintained open‑source library that lets you apply any mainstream object‑detection model to huge images or video streams by automatically slicing, predicting, and merging results. It is squarely in the AI/ML domain (computer vision) and provides both CLI convenience and a Python API for developers.
Related
- Project
- Project
- Project
- Project
- Project