# SAHI

> Slicing-aided inference that catches small objects in large images

- Category: Multimodal Generation / Vision & Understanding
- Language: Python
- Licence: MIT
- Repository: https://github.com/obss/sahi
- Canonical page: https://ai-tldr.dev/tools/sahi/

## In short

SAHI (Slicing Aided Hyper Inference) is a Python library for large-scale object detection and instance segmentation. Instead of feeding a whole high-resolution image to a model at once, it cuts the image into overlapping tiles, runs detection on each tile, and merges the results back together. It sits in the Vision & Understanding category of the Multimodal Generation tools and is open-source, written in Python and licensed MIT.

## Overview

SAHI (Slicing Aided Hyper Inference) is a Python library for large-scale object detection and instance segmentation. Instead of feeding a whole high-resolution image to a model at once, it cuts the image into overlapping tiles, runs detection on each tile, and merges the results back together. This makes small objects much easier to find than running standard inference on a downscaled full frame.

It is aimed at computer-vision developers who already work with detection models and need better recall on tiny objects in big images, such as aerial, satellite, or surveillance footage. SAHI does not replace your model; it wraps one through a common interface and adds the slicing and merging logic around it.

It supports popular detection frameworks, including Ultralytics YOLO, MMDetection, Hugging Face, and TorchVision models, and offers both a Python API and a command-line tool. It also includes utilities for slicing COCO datasets and exploring predictions in FiftyOne.

## What it does

- Sliced inference: splits large images into overlapping tiles so small objects are detected at full resolution
- Works with multiple model backends: Ultralytics YOLO, MMDetection, Hugging Face, and TorchVision
- Command-line predict tool for sliced or standard inference on images and video
- COCO slicing utilities to cut annotation and image files into tiles
- FiftyOne integration to visualize and compare prediction results
- Common AutoDetectionModel interface so you can swap models without rewriting the inference code

## Getting started

Install SAHI from PyPI, then run sliced prediction from Python or the command line with any supported detection model.

1. Install

   Install SAHI with pip. Add the model framework you plan to use (for example, Ultralytics) separately.

```bash
pip install sahi
```

2. Run sliced prediction in Python

   Load a model through AutoDetectionModel, then call get_sliced_prediction with your tile size and overlap ratios.

```python
from sahi.predict import get_sliced_prediction
from sahi import AutoDetectionModel

# init any model
detection_model = AutoDetectionModel.from_pretrained(model_type='ultralytics',...)

# get sliced prediction result
result = get_sliced_prediction(
    image,
    detection_model,
    slice_height = 256,
    slice_width = 256,
    overlap_height_ratio = 0.2,
    overlap_width_ratio = 0.2
)
```

3. Or use the CLI

   The sahi predict command runs sliced or standard inference on an image, folder, or video using your chosen model_type and model_path.

```bash
sahi predict --model_path yolo26s.pt --model_type ultralytics --source video.mp4
```

## When to use it

- Detecting small objects in aerial or satellite imagery where targets are tiny relative to the full frame
- Improving recall on high-resolution surveillance or traffic footage without retraining the model
- Slicing a COCO dataset into tiles to train or evaluate detection models on smaller crops
- Comparing prediction results across models in FiftyOne, ordered by misdetections
