SAHI: Slicing Aided Hyper Inference
Object detection and instance segmentation are by far the most important fields of applications in Computer Vision. However, detection of small objects and inference on large images are still major issues in practical usage. Here comes the SAHI to help developers overcome these real-world problems.
Check the official SAHI blog post.
- Install sahi using conda:
conda install -c obss sahi
- Install sahi using pip:
pip install sahi
- Install your desired version of pytorch and torchvision:
pip install torch torchvision
- Install your desired detection framework (such as mmdet):
pip install mmdet
- Sliced inference:
result = get_sliced_prediction( image, detection_model, slice_height = 256, slice_width = 256, overlap_height_ratio = 0.2, overlap_width_ratio = 0.2 )
Refer to inference notebook for detailed usage.
- Slice an image:
from sahi.slicing import slice_image slice_image_result, num_total_invalid_segmentation = slice_image( image=image_path, output_file_name=output_file_name, output_dir=output_dir, slice_height=256, slice_width=256, overlap_height_ratio=0.2, overlap_width_ratio=0.2, )
- Slice a coco formatted dataset:
from sahi.slicing import slice_coco coco_dict, coco_path = slice_coco( coco_annotation_file_path=coco_annotation_file_path, image_dir=image_dir, slice_height=256, slice_width=256, overlap_height_ratio=0.2, overlap_width_ratio=0.2, )