Koldim2001/YOLO-Patch-Based-Inference
Python library for YOLO small object detection and instance segmentation
What it solves
This library addresses the challenge of detecting small objects in high-resolution images, which often get lost or downsampled when passed through standard neural networks. It simplifies the process of "patch-based inference" (similar to SAHI), where an image is split into smaller, overlapping crops to ensure small objects are captured at a higher relative scale.
How it works
The library implements a two-step pipeline for object detection and instance segmentation:
- Cropping: The
MakeCropsDetectThemclass divides an image into patches based on user-defined sizes and overlap percentages, then runs a supported YOLO model on each patch. - Consolidation: The
CombineDetectionsclass merges the results from all overlapping crops and applies Non-Maximum Suppression (NMS) to remove duplicate detections, using either IoU or IoS metrics.
It supports a wide range of Ultralytics models, including YOLOv8, v9, v10, v11, v12, FastSAM, and RTDETR.
Who it’s for
Computer vision developers and researchers who need to detect small objects in large images using YOLO-based models and want a streamlined way to handle tiling and result merging.
Highlights
- Broad Model Support: Compatible with nearly all recent Ultralytics models for both detection and segmentation.
- Flexible Tiling: Customizable crop dimensions and overlap percentages to optimize detection accuracy.
- Advanced NMS: Features an "intelligent sorter" and class-agnostic NMS options to better handle duplicate suppression.
- Custom Visualization: Includes a dedicated
visualize_resultsfunction for sleek, customizable rendering of bounding boxes and segmentation masks. - Performance Options: Supports batch inference for faster processing and a
memory_optimizetoggle to balance RAM usage against segmentation accuracy.