Skip to main content

Using SAHI as a pre and post processing step

Project description

SAHI_processor

Using SAHI as a pre and post processing step

Link to original repo, SAHI: Slicing Aided Hyper Inference

Impetus

To make it easier to use sahi without changes to the your model inference code. Also allow for batched inference which is something that is not provided in the official repo.

How to use

Install package with

pip install sahi_processor

Sample usage

from sahi_processor.sahi_processor import SAHIProcessor

processor = SAHIProcessor()
batched_images = processor.get_slice_batches(list_of_images, model_batchsize=batchsize)

# run batched_images through your model and output predictions
# combine all batches of predictions into  List[List[l, t, r, b, score, class_id]]

merged_predictions = processor.run_sahi_algo(list_of_images, predictions)

A sample test script can be ran via python tests/test.py

Parameters and defaults for SAHIProcesor

# image_height_threshold: int
#     only do sahi if the height of the image exceeds this
# image_width_threshold: int
#     only do sahi if the width of the image exceeds this
#     The rationale for these 2 parameters is that since this repo is meant to batch multiple images,
#     there could be a case where we have images of different size in a batch. For image that may be
#     around the size of a single slice, there may not be a point to slice them
# resize_full_frame: bool
#     to resize images that has not been sliced size to the slice size if True else no resizing

image_height_threshold: int = 600 
image_width_threshold: int = 600
resize_full_frame: bool = True

# the variables below are from the default sahi repo: https://github.com/obss/sahi/blob/main/sahi/predict.py#L125
sahi_slice_height: int = 400
sahi_slice_width: int = 400
sahi_overlap_height_ratio: float = 0.3
sahi_overlap_width_ratio: float = 0.3
sahi_perform_standard_pred: bool = True
sahi_postprocess_type: str = "GREEDYNMM"
sahi_postprocess_match_metric: str = "IOS"
sahi_postprocess_match_threshold: float = 0.5
sahi_postprocess_class_agnostic: bool = True
sahi_auto_slice_resolution: bool = True

Formats to note

list_of_images is a list of cv2 images in (H, W, C)

predictions is a list of predictions for each image. Below is a sample:

[
    [ 
        [l, t, r, b, score, class_id],
        [l, t, r, b, score, class_id], ...
    ],...
]

Project details


Download files

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

Source Distribution

sahi_processor-0.0.3.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sahi_processor-0.0.3-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file sahi_processor-0.0.3.tar.gz.

File metadata

  • Download URL: sahi_processor-0.0.3.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.10

File hashes

Hashes for sahi_processor-0.0.3.tar.gz
Algorithm Hash digest
SHA256 a9052ecb9d51fab0a068e6151201f4b25e76f58356486f08f1bdb428f167835e
MD5 52307d621b0792c4f5f020bddbf131cd
BLAKE2b-256 ed11e2cd5c470b356b4b712cc1aaec5645b864aad7c24b1aea3ce16f226d5d5a

See more details on using hashes here.

File details

Details for the file sahi_processor-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: sahi_processor-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.10

File hashes

Hashes for sahi_processor-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0687b9cf70a8187acb67dc462d81de6201880835fe9afc688a2913740f5df3eb
MD5 64de91e6840b4d60cf7d44170bd5c5c0
BLAKE2b-256 f8fa90706807a424c0ba2bc791cdefe3c7082d96dbcde5c48459f0137ed5eceb

See more details on using hashes here.

Supported by

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