roboflow / inference

A fast, easy-to-use, production-ready inference server for computer vision supporting deployment of many popular model architectures and fine-tuned models.
https://inference.roboflow.com
Other
1.12k stars 84 forks source link

Fix undo image padding for predicted boxes #495

Closed grzegorz-roboflow closed 4 days ago

grzegorz-roboflow commented 1 week ago

Description

Fix - infer_shape was passed as (height, width), and used both as (height, width) and (width, height) in undo_image_padding_for_predicted_boxes. Add correction where it was used as (width, height).

Type of change

Please delete options that are not relevant.

How has this change been tested, please provide a testcase or example of how you tested the change?

Model had training images shape width: 1000 and height: 1333 Image had width: 720, height: 1280 Bug was not observable after adding fix.

from typing import List

import cv2 as cv
import supervision as sv

from inference import get_model
from inference.core.entities.responses.inference import ObjectDetectionInferenceResponse

model = get_model(model_id="<custom model ID that had training widthxheight as 1000x1333>")
img_path = "/path/to/image/width_720_height_1280.jpg"
results: List[ObjectDetectionInferenceResponse] = model.infer(img_path)

img = cv.imread(img_path)
h, w, _ = img.shape

results = [r.model_dump() for r in results]
preds = results[0]
for p in preds["predictions"]:
    p["class"] = p["class_name"]
    del p["tracker_id"]
preds["image"] = {"width": w, "height": h}
print(preds)
dets = sv.Detections.from_inference(preds)

bbox_annotator = sv.BoundingBoxAnnotator()
bbox_annotator.annotate(img, dets)

cv.imshow("localhost script", img)
cv.waitKey(0)

print(dets)

Any specific deployment considerations

N/A

Docs

N/A

grzegorz-roboflow commented 4 days ago

Tested on staging, confirm no regression on hosted platform.