YOLO-Patch-Based-Inference: SAHI-style slicing for small object detection
Python library for YOLO small object detection and instance segmentation
At a glance
- What is it?
- A Python library that slices images into overlapping patches, runs Ultralytics YOLO models on each, and merges the results, so small objects survive detection and segmentation.
- Who is it for?
- YOLO-Patch-Based-Inference fits Ultralytics users whose small objects vanish at full-image inference and who want SAHI-style slicing behind a two-class Python API, with segmentation support and clean result attributes. Skip it if your objects are already detected reliably, if you need a framework-agnostic tiler with a large community, or if AGPL obligations do not fit your product.
- Can I use it commercially?
- Yes, with strict conditions. AGPL-3.0 is a network copyleft licence: if people use a modified version over a network, for example as a hosted service, you must offer them its source code under the same licence.
- Is it still maintained?
- Activity is slowing. The repository last received commits 7 months ago.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- Koldim2001/YOLO-Patch-Based-Inference562 ★ · +5
| Repository | 2026-09-18 | 2026-11-25 |
|---|---|---|
| Koldim2001/YOLO-Patch-Based-Inference | 557 | 562 |
5 Stars in the last 68 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Why small objects break plain YOLO inference
A drone shot of a parking lot, a histology slide, a herd counted from the air: feed any of these through a YOLO model at standard resolution and the small objects quietly vanish. Downsampling inside the network gives every object a minimum viable pixel count, and anything below it never becomes a detection. The established remedy is slicing-aided inference, the approach the SAHI project popularized, and YOLO-Patch-Based-Inference by koldim2001 is a Python library in that tradition, built specifically around Ultralytics models.
The pitch is in the first line of the README: simplified SAHI-like inference for detection and instance segmentation of small objects. The audience is anyone already in the Ultralytics ecosystem, YOLOv8 through YOLO12, FastSAM, RTDETR, who needs those small targets back without building a tiling pipeline from scratch.
Installing patched-yolo-infer
The library ships on PyPI as patched-yolo-infer, and installation is one command:
pip install patched_yolo_inferThe dependency list is short and readable in requirements.txt: tqdm, opencv-python, matplotlib and ultralytics. The README includes one operational note that matters on GPUs: if CUDA is available, pre-install a CUDA-enabled PyTorch before installing the library, otherwise the CPU build lands by default, and that default is the difference between seconds and minutes per image at patch counts worth using.
The project sits at version 1.3.10 per setup.py, with three releases published and the last push on 2026-04-22, roughly five months back. Treat it as stable-but-slow-moving rather than abandoned; the API surface it wraps, Ultralytics, changes on its own schedule.
A two-class pipeline
The whole workflow runs through two classes, and the README's example shows the contract. MakeCropsDetectThem takes the image and every parameter that governs slicing and inference; CombineDetections merges the per-crop predictions and suppresses duplicates:
element_crops = MakeCropsDetectThem(
image=img,
model_path="yolo11m.pt",
segment=False,
shape_x=640,
shape_y=640,
overlap_x=25,
overlap_y=25,
conf=0.5,
iou=0.7,
)
result = CombineDetections(element_crops, nms_threshold=0.25)The image is a NumPy array loaded beforehand, for example with cv2.imread, and the imports pull the two classes from patched_yolo_infer. The four-line core of the idea sits in the arguments: 640-pixel crops with 25 percent overlap in each axis, so no object straddling a boundary is lost, and per-crop confidence and IoU thresholds feeding a final NMS pass at 0.25 across everything the crops produced.
What the result object gives you
After the merge, the result object exposes per-image attributes the README enumerates: the original image, confidence scores, bounding boxes as x_min, y_min, x_max, y_max lists, class IDs and human-readable class names. For segmentation runs, polygons arrive as NumPy arrays of coordinates tracing each mask, which is what makes downstream measurement, area, shape, overlap, practical without re-running anything.
The filtered variants, filtered_confidences, filtered_boxes, filtered_polygons and their siblings, are the post-NMS versions, and those are the ones normal pipelines consume. The design keeps the pre-merge crop-level predictions available too, which matters when you are debugging why a duplicate survived or a thin object split across two crops: you can inspect the raw per-crop detections before the suppression decided.
The knobs that actually matter
The README's argument tables expose the tuning surface, and three groups decide results in practice. Crop geometry is shape_x and shape_y against imgsz, the inference size, with overlap_x and overlap_y controlling the safety margin between tiles; larger overlaps cost more inference calls and catch more boundary-straddling objects. Thresholds split across stages: the per-crop conf and iou govern what each patch reports, while CombineDetections' nms_threshold governs how aggressively overlapping detections from neighboring crops collapse into one.
Model selection is a path or a pre-initialized model object, so a custom-trained checkpoint drops in without ceremony, and the segment flag flips the pipeline between detection and instance segmentation. The supported model list is wide, YOLOv8 and its seg variant through YOLOv9, YOLOv10, YOLO11, YOLO12, plus FastSAM and RTDETR, all from the Ultralytics family, pretrained or your own.
Learning paths, and the licence question
The project teaches itself unusually well. Colab notebooks cover patch-based batch inference and custom visualization of results, each paired with a YouTube tutorial, and there is a Russian-language conference presentation from AiConf 2024 for anyone who prefers it. For a library whose value is a workflow rather than a model, worked examples are most of the documentation that matters.
One decision deserves attention before commercial use: the licence is AGPL-3.0, matching the Ultralytics ecosystem it extends. Wrapping this library in a networked service triggers AGPL source obligations for that service, which is a business decision, not a technical one; teams with SaaS intentions should read the terms with that in mind. With the last push on 2026-04-22 and three releases behind it, the project's cadence is quiet, so pin your versions and expect to maintain your own fork of anything you patch.
Against SAHI, plain Ultralytics, and DIY tiling
The obvious relative is SAHI itself, the slicing-aided inference framework that named the technique. SAHI is framework-agnostic with broader model support and a larger community; this library trades that generality for a tighter, simpler API tuned to the Ultralytics family, with the two-class flow and ready-made result attributes covering the common cases in a few lines. For detection-only and segmentation-only pipelines on YOLO models, the smaller surface is a feature.
The do-nothing alternative, running the model directly at full resolution, remains correct whenever your objects are large enough to survive downsampling, and it is the first thing to check before adopting any tiling pipeline. The roll-your-own route, hand-written crop loops plus NMS merging, teaches you the failure modes but hands you the edge cases this library has already absorbed, boundary duplicates and partial-object merging chief among them. Measure your miss rate on small objects first; adopt tiling when the number, not the worry, justifies it.
Editorial conclusion
YOLO-Patch-Based-Inference fits Ultralytics users whose small objects vanish at full-image inference and who want SAHI-style slicing behind a two-class Python API, with segmentation support and clean result attributes. Skip it if your objects are already detected reliably, if you need a framework-agnostic tiler with a large community, or if AGPL obligations do not fit your product. Verify the win on your own data: run one image through plain inference and one through the MakeCropsDetectThem example with 25 percent overlap, and compare the small-object miss count before wiring the pipeline in anywhere.
Frequently asked questions
Which YOLO models does patched-yolo-infer support?
Ultralytics models: YOLOv8 and YOLOv8-seg, YOLOv9 and v9-seg, YOLOv10, YOLO11 and 11-seg, YOLO12 and 12-seg, FastSAM and RTDETR, either pretrained or your own custom-trained checkpoints.
How does patch-based inference improve small object detection?
The image is cut into overlapping patches, each patch runs through the YOLO model at full resolution, and the per-crop detections are consolidated with duplicate suppression. Small objects that disappear at whole-image scale keep enough pixels inside their own crop to be detected.
Can patched-yolo-infer do instance segmentation?
Yes. Set segment to true or use one of the seg model variants such as YOLOv8-seg or YOLO11-seg, and the results include polygon coordinates for each object mask as NumPy arrays.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/koldim2001-yolo-patch-based-inference)Star history chart for your README
[](https://hysenlabs.com/projects/koldim2001-yolo-patch-based-inference)Was this useful?