`sv.Detections.from_ultralytics()` can't handle segmentation results `ultralytics.engine.results.Results` from ultralytics `SAM()` when using `bboxes` or `points` arguments #1453
[X] I have searched the Supervision issues and found no similar bug report.
Bug
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/christoforos/Documents/supervision/supervision/detection/core.py", line 277, in from_ultralytics
class_id = ultralytics_results.boxes.cls.cpu().numpy().astype(int)
AttributeError: 'NoneType' object has no attribute 'cls'
Environment
Supervision: 0.22.0
Minimal Reproducible Example
import cv2
import supervision as sv
from ultralytics import SAM
image = cv2.imread("image.jpg")
model = SAM("mobile_sam.pt")
results = model(
image,
bboxes=[[100, 100, 200, 200]],
)
detections = sv.Detections.from_ultralytics(results[0])
Additional
When predicting with any model using SAM() class from ultralytics, if we don't specify bboxes or points arguments in the predict() function of SAM() model, it has expected behaviour.
The problem is when we pass bboxes or points arguments, which will results in ultralytics.engine.results.Results to contain None type for boxes, probs attributes (not sure if probs attribute affects the process but boxes does for sure).
As a results, mask annotators (polygon, halo, mask) also can't be used.
We could slightly modify sv.Detection.from_ultralytics() to handle this problem, by making an extra check and fill in required attributes of the class. I have implemented a fix of this issue, and I could submit a PR for review.
Search before asking
Bug
Environment
Minimal Reproducible Example
Additional
When predicting with any model using
SAM()
class fromultralytics
, if we don't specifybboxes
orpoints
arguments in thepredict()
function ofSAM()
model, it has expected behaviour.The problem is when we pass
bboxes
orpoints
arguments, which will results inultralytics.engine.results.Results
to containNone
type forboxes
,probs
attributes (not sure ifprobs
attribute affects the process butboxes
does for sure).As a results, mask annotators (polygon, halo, mask) also can't be used.
We could slightly modify
sv.Detection.from_ultralytics()
to handle this problem, by making an extra check and fill in required attributes of the class. I have implemented a fix of this issue, and I could submit a PR for review.Are you willing to submit a PR?