File size: 1,035 Bytes
11d0e57
 
 
 
 
 
 
 
 
 
 
b113de0
 
ee620ac
 
b113de0
 
11d0e57
 
d62b128
7bb89fc
11d0e57
 
 
 
 
 
 
 
7bb89fc
11d0e57
7bb89fc
a16a11f
43c365e
11d0e57
 
7bb89fc
11d0e57
7bb89fc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import numpy
import sahi.predict
import sahi.utils
from PIL import Image

TEMP_DIR = "temp"


def sahi_yolov8m_inference(
    image,
    detection_model,
    slice_height=1240,
    slice_width=1240,
    overlap_height_ratio=0.1,
    overlap_width_ratio=0.1,
    image_size=4960,
    postprocess_match_threshold=0.8,
):
    # sliced inference
    detection_model.image_size = image_size
    prediction_result = sahi.predict.get_sliced_prediction(
        image=image,
        detection_model=detection_model,
        slice_height=slice_height,
        slice_width=slice_width,
        overlap_height_ratio=overlap_height_ratio,
        overlap_width_ratio=overlap_width_ratio,
        postprocess_match_threshold=postprocess_match_threshold,
    )
    visual_result = sahi.utils.cv.visualize_object_predictions(
        image=numpy.array(image),
        object_prediction_list=prediction_result.object_prediction_list,
        rect_th=3,
        text_size=3
    )

    output = Image.fromarray(visual_result["image"])

    return output