def predict(model, img, size=768, augment=False, use_sahi=False):
    if use_sahi:
        from sahi.predict import get_sliced_prediction
        results = get_sliced_prediction(img, model, slice_height=512, slice_width=512, overlap_height_ratio=0.2, overlap_width_ratio=0.2)
        preds = results.object_prediction_list
        bboxes = np.array([pred.bbox.to_voc_bbox() for pred in preds])
    else:
        results = model(img, size=size, augment=augment)
        preds = results.pandas().xyxy[0]
        bboxes = preds[['xmin', 'ymin', 'xmax', 'ymax']].values
    if len(bboxes):
        (height, width) = img.shape[:2]
        bboxes = voc2coco(bboxes, height, width).astype(int)
        if use_sahi:
            confs = np.array([pred.score.value for pred in preds])
        else:
            confs = preds.confidence.values
        return (bboxes, confs)
    else:
        return (np.array([]), [])
def predict(model, img, size=768, augment=False, use_sahi=False):
    if use_sahi:
        from sahi.predict import get_sliced_prediction
        results = get_sliced_prediction(img, model, slice_height=512, slice_width=512, overlap_height_ratio=0.2, overlap_width_ratio=0.2)
        preds = results.object_prediction_list
        bboxes = np.array([pred.bbox.to_voc_bbox() for pred in preds])
    else:
        results = model(img, size=size, augment=augment)
        preds = results.pandas().xyxy[0]
        bboxes = preds[['xmin', 'ymin', 'xmax', 'ymax']].values
    if len(bboxes):
        (height, width) = img.shape[:2]
        bboxes = voc2coco(bboxes, height, width).astype(int)
        if use_sahi:
            confs = np.array([pred.score.value for pred in preds])
        else:
            confs = preds.confidence.values
        return (bboxes, confs)
    else:
        return (np.array([]), [])