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.37k stars 129 forks source link

Include `class_id` and `class_list` in inference response #5

Closed SkalskiP closed 1 year ago

SkalskiP commented 1 year ago

Adding the class_id value to the inference response would help simplify the API between supervision and inference. sv.Detections requires int value representing class_id. Currently, we force users to provide class_list as one of the arguments of sv.Detections.from_roboflow method to perform the mapping. We could drop that requirement if class_id was provided.

sv.Detections.from_roboflow is the only connector that requires an additional class_list argument. All other connectors: from_detectron2, from_mmdetection, from_paddledet, from_sam, from_transformers, from_ultralytics, from_yolo_nas, from_yolov5 and from_yolov8 can retrieve class_id from inference result object. It is a common standard in computer vision.

Before

>>> import supervision as sv

>>> roboflow_result = {
...     "predictions": [
...         {
...             "x": 0.5,
...             "y": 0.5,
...             "width": 0.2,
...             "height": 0.3,
...             "class": "person",
...             "confidence": 0.9
...         },
...         # ... more predictions ...
...     ]
... }
>>> class_list = ["person", "car", "dog"]

>>> detections = sv.Detections.from_roboflow(roboflow_result, class_list)

After

>>> import supervision as sv

>>> roboflow_result = {
...     "predictions": [
...         {
...             "x": 0.5,
...             "y": 0.5,
...             "width": 0.2,
...             "height": 0.3,
...             "class": "person",
...             "class_id": 0,
...             "confidence": 0.9
...         },
...         # ... more predictions ...
...     ]
... }

>>> detections = sv.Detections.from_roboflow(roboflow_result)

🙋🏻 I would love to work on the implementation of this feature.

paulguerrie commented 1 year ago

Great feedback! I'll definitely add this!