Skip to main content

A vision library for performing sliced inference on large images/small objects

Project description

SAHI: Slicing Aided Hyper Inference

A vision library for performing sliced inference on large images/small objects.

teaser

downloads pypi version conda version ci

Overview

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.

Getting started

Blogpost

Check the official SAHI blog post.

Installation

  • Install sahi using pip:
pip install sahi
  • On Windows, Shapely needs to be installed via Conda:
conda install -c conda-forge shapely
  • Install your desired version of pytorch and torchvision:
pip install torch torchvision
  • Install your desired detection framework (such as mmdet or yolov5):
pip install mmdet mmcv
pip install yolov5

Usage

  • 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 YOLOv5 Inference Notebook or MMDetection 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,
)

Refer to slicing notebook for detailed usage.

Scripts

Find detailed info on script usage (predict, coco2yolov5, coco_error_analysis) at SCRIPTS.md.

COCO Utilities

Find detailed info on COCO utilities (yolov5 conversion, slicing, subsampling, filtering, merging, splitting) at COCO.md.

Adding new detection framework support

sahi library currently supports all YOLOv5 models and MMDetection models. Moreover, it is easy to add new frameworks.

All you need to do is, creating a new class in model.py that implements DetectionModel class. You can take the MMDetection wrapper or YOLOv5 wrapper as a reference.

Contributers

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sahi-0.4.5.tar.gz (46.8 kB view details)

Uploaded Source

Built Distribution

sahi-0.4.5-py3-none-any.whl (52.2 kB view details)

Uploaded Python 3

File details

Details for the file sahi-0.4.5.tar.gz.

File metadata

  • Download URL: sahi-0.4.5.tar.gz
  • Upload date:
  • Size: 46.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for sahi-0.4.5.tar.gz
Algorithm Hash digest
SHA256 9f3381fdcc8a3b8e11728e9857dda38f5fa57c5570bb19498bb4f3ec38205f04
MD5 3a6459fb6f46a566132b02212f8cb7ae
BLAKE2b-256 758f4d3f4fee774b09f4237497bd55fa32e22b247fea08b19b4bc2dd6bd42103

See more details on using hashes here.

File details

Details for the file sahi-0.4.5-py3-none-any.whl.

File metadata

  • Download URL: sahi-0.4.5-py3-none-any.whl
  • Upload date:
  • Size: 52.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for sahi-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1cb2d1ffd6b5780a79de3496b8b5dbeba33761606b00834cca1a47baf43e38c7
MD5 e12216c5f76b8c03c48420ba311c6298
BLAKE2b-256 a0c82ac86705682cedb44b1ae498ca04c68e2df9e13d69f23966b9188d1bbaf5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page