-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tracker_id=None
when merging a sequence of detections det_1
, det_2
, ..., starting with an initial empty Detection
#89
Comments
@zburq I assume that other |
@SkalskiP , yes have a |
@SkalskiP , I tried adding an empty det_initial = Detections.empty()
det_initial.tracker_id = np.empty(shape, dtype=np.int64) but this failed a validation. For now I have a hacky workaround: dets_all = None
for det in ...:
if dets_all is None:
dets_all = det
else:
dets_all = Detections.merge([dets_all, det]) |
What do you mean by |
Yes certainly. dets_all = Detections.empty()
dets_all.tracker_id = np.ndarray([]) I also tried results = volo_v8_model.track(source=my_vid.mp4,
tracker='bytetrack.yaml',
stream=True,
classes=
for result in results:
dets = Detections.from_yolov8(result)
if result.boxes.id is not None:
dets.tracker_id = result.boxes.id.cpu().numpy().astype(int)
dets_all = Detections.merge([dets_all, dets]) At the first call of ---> 33 dets_all = Detections.merge([dets_all, det])
34 print(dets_all.tracker_id)
35
/tmp/ipykernel_32267/3054824891.py in concat_detections(detections_list)
36 tracker_id = np.hstack(tracker_id) if all_not_none(tracker_id) else None
37
---> 38 return Detections(
39 xyxy=xyxy,
40 mask=mask,
~/anaconda3/envs/cvc_env/lib/python3.9/site-packages/supervision/detection/core.py in __init__(self, xyxy, mask, confidence, class_id, tracker_id)
~/anaconda3/envs/cvc_env/lib/python3.9/site-packages/supervision/detection/core.py in __post_init__(self)
72 _validate_class_id(class_id=self.class_id, n=n)
73 _validate_confidence(confidence=self.confidence, n=n)
---> 74 _validate_tracker_id(tracker_id=self.tracker_id, n=n)
75
76 def __len__(self):
~/anaconda3/envs/cvc_env/lib/python3.9/site-packages/supervision/detection/core.py in _validate_tracker_id(tracker_id, n)
45 )
46 if not is_valid:
---> 47 raise ValueError("tracker_id must be None or 1d np.ndarray with (n,) shape")
48
49
ValueError: tracker_id must be None or 1d np.ndarray with (n,) shape |
@zburq Would it be possible that you to create a reproducible example resulting in that |
Hi @SkalskiP - apologies, I got preoccupied with another aspect of the project. I made a fix to my local copy of supervision and got it working. The bug is in Here's a working example: det = Detections(xyxy=np.array([[146.8, 69.878, 198.65, 107.57],
[652.06, 81.007, 710.15, 122.01]], dtype=np.float32),
mask=None,
confidence=np.array([0.83976, 0.82391], dtype=np.float32),
class_id=np.array([2, 2]),
tracker_id=np.array([1, 2]))
e = Detections.empty()
Detections(xyxy=array([], shape=(0, 4), dtype=float32),
mask=None, confidence=array([], dtype=float32),
class_id=array([], dtype=int64),
tracker_id=None)
Detections(xyxy=array([[146.8, 69.878, 198.65, 107.57],
[652.06, 81.007, 710.15, 122.01]], dtype=float32),
mask=None,
confidence=array([0.83976, 0.82391], dtype=float32),
class_id=array([2, 2]),
tracker_id=None)
But if I modify e = Detections.empty()
e.tracker_id = np.array([], dtype=np.int64) |
Hi, @zburq 👋🏻! That's what I suspected. The problem was the interaction between @classmethod
def empty(
cls,
with_confidence: bool = False,
with_class_id: bool = False,
with_tracker_id: bool = False,
with_mask_wh: Optional[Tuple[int, int]] = None
) -> Detections:
xyxy = np.empty((0, 4), dtype=np.float32)
confidence = np.array([], dtype=np.float32) if with_confidence else None
class_id = np.array([], dtype=int) if with_class_id else None
tracker_id = np.array([], dtype=int) if with_tracker_id else None
mask = None
if with_mask_wh:
w, h = with_mask_wh
mask = np.empty((0, w, h), dtype=bool)
return cls(
xyxy=xyxy,
confidence=confidence,
class_id=class_id,
tracker_id=tracker_id,
mask=mask
) |
Yes - this works too. But feels slightly counterintuitive to me. Ideally, I'd expect The reason this would be desirable for me is that sometimes I want to extend For now, I'm creating two seperate But would still like to add Again, this is a patch based on my immediate needs. For optimal general design, I trust your judgement. 🖖 |
... which reminds me, it'd be nice to have an |
That one is definitely something I'd like to add. Could you create a separate issue (feature request) for that? 🙏🏻 |
First of all. In my mind, there is a difference between empty detection - where we expect, for example, masks, but we didn't find any and cases where we don't expect masks at all. But I know that complicates things... The alternative is that As for extending |
Makes sense. Thank you. |
The empty detection doesn't have a
tracker_id
:supervision/supervision/detection/core.py
Lines 345 to 364 in e16cca4
For all subsequent detections, when merged (concatenated is a better name),
tracker_id
seems to be getting set toNone
here:supervision/supervision/detection/core.py
Lines 366 to 413 in e16cca4
Originally posted by @zburq in #88 (comment)
The text was updated successfully, but these errors were encountered: