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.4.tar.gz (6.3 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.4-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sahi_processor-0.0.4.tar.gz
  • Upload date:
  • Size: 6.3 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.4.tar.gz
Algorithm Hash digest
SHA256 9655b1975173187c7df8778d243f641227e0771c5cbae5c1174525d04ecc42d8
MD5 9d14bf6a5571483c74b48683b2d814d8
BLAKE2b-256 8b2a88a45366ec726d7af4eb42ecf006eb611b6f0b38cc99baf4134794c8461e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sahi_processor-0.0.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ad7ccb43610c80bfe4b17abc1893d69b8ab4bde2cd25afcde86ad0ca1aa4392d
MD5 6049986b0f9e4203a1f04b201e98550f
BLAKE2b-256 866baaa3285ffe31c5517599df34b19937aaeb5090c96fb756ece850b603b2b4

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