-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix enumerate call #1049
fix enumerate call #1049
Conversation
fix tuple unpacking bug in PR roboflow#1035 Fix bug with detections with un-initialized tracker_ids
if i == 0: | ||
final_detections = detections[[idet]] | ||
final_detections.tracker_id[0] = int(tracks[itrack].track_id) | ||
if final_detections.tracker_id is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can tracker_id
be None
?
Hi @rolson24 👋🏻 I understand |
There was a second bug that I found. In my original testing I was
accidentally using model.track(frame) to get the detections from
ultralytics. Then when I called sv.from_ultralytics each detection would
already have a tracker ID so the supervision Detection class would have a
valid track_id. When I tested the change with just using model (frame), the
track_id array would be initialized to ‘None’ instead of a ‘np.array’. This
means that when I tried to assign an index of the track_id array to the new
track id in update_with_detections(), the code would throw an error. I
fixed this by initializing the track_id variable to a np.array
…On Tue, Mar 26, 2024 at 6:50 AM Piotr Skalski ***@***.***> wrote:
Hi @rolson24 <https://github.com/rolson24> 👋🏻 I understand for i,
(idet, itrack) in enumerate(matches): but what is the reason for rest of
the changes?
—
Reply to this email directly, view it on GitHub
<#1049 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AX2EJPGZ3O3VPBC6DWP53LTY2FAGFAVCNFSM6AAAAABFIBPAWGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRQGEYDKMJSGA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Hi @rolson24 👋🏻 I wonder if we didn't overcomplicate the def update_with_detections(self, detections: Detections) -> Detections:
tensors = detections2boxes(detections=detections)
tracks = self.update_with_tensors(tensors=tensors)
if len(tracks) > 0:
detection_bounding_boxes = np.asarray([det[:4] for det in tensors])
track_bounding_boxes = np.asarray([track.tlbr for track in tracks])
ious = box_iou_batch(detection_bounding_boxes, track_bounding_boxes)
iou_costs = 1 - ious
matches, _, _ = matching.linear_assignment(iou_costs, 0.5)
detections.tracker_id = np.full(len(detections), -1, dtype=int)
for i_detection, i_track in enumerate(matches):
detections.tracker_id[i_detection] = int(tracks[i_track].track_id)
return detections[detections.tracker_id != -1]
else:
detections.tracker_id = np.array([], dtype=int)
return detections |
Oh, that's a good point. It would fix both the issue of returning detections that never actually are tracked, and the minimum_consecutive_frames arguement. Would you like me to add this in a new branch from the current develop branch? |
|
…or the code. (had to change a few lines for bug fixes)
Hi @SkalskiP I agree with both of those, I updated my colab notebook to have more comprehensive tests, which should cover all of the different scenarios of detection objects being given to the tracker. |
Hi @rolson24 👋🏻 I left a comment regarding: invalid_tracks = [
i
for i in range(len(detections.tracker_id))
if detections.tracker_id[i] != -1
]
return detections[invalid_tracks] |
for i_detection, i_track in matches: | ||
detections.tracker_id[i_detection] = int(tracks[i_track].track_id) | ||
|
||
invalid_tracks = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup!
Also, I am wondering if we should add some unit tests for ByteTrack. I have some rudimentary one in a colab notebook. It would help when people need to test changes to ByteTrack and prevent bugs like this from happening again. |
@rolson24 I'm merging this PR. As for ByteTrack unit tests, I would love this! Feel free to open the next PR with tests. |
This is actually wrong. I forgot to test with low-confidence detections, and when that happens, the tracker_ids are -1, but the size of tracks returned from update_with_detections is none-zero, so it actually returns tracks that aren't actually tracked, but just with no track_id. I will submit a new PR with the needed change and will make sure the tests cover all of the possible cases. |
Description
I made a very silly mistake in my PR #1035. The enumerate returns and index and a tuple and I was unpacking that tuple incorrectly. I have since re-tested it with this change, and it works correctly now. I also had to fix a bug when there are no existing track_ids.
List any dependencies that are required for this change.
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?
This colab notebook https://colab.research.google.com/drive/1azgc_A-divM3Z5l0TyHW2SRHnw6EUlbO#scrollTo=J-lQUq30tUgD is what I used to test it.