Skip to content
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

Merged
merged 5 commits into from
Mar 28, 2024
Merged

fix enumerate call #1049

merged 5 commits into from
Mar 28, 2024

Conversation

rolson24
Copy link
Contributor

@rolson24 rolson24 commented Mar 26, 2024

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.

  • Bug fix (non-breaking change which fixes an issue)

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.

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:
Copy link
Collaborator

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?

@SkalskiP
Copy link
Collaborator

Hi @rolson24 👋🏻 I understand for i, (idet, itrack) in enumerate(matches): but what is the reason for rest of the changes?

@rolson24
Copy link
Contributor Author

rolson24 commented Mar 26, 2024 via email

@SkalskiP
Copy link
Collaborator

Hi @rolson24 👋🏻 I wonder if we didn't overcomplicate the update_with_detections implementation. Take a look at the code below. What do you think?

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

@rolson24
Copy link
Contributor Author

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?

@SkalskiP
Copy link
Collaborator

@rolson24

  1. I think we should solve this issue first and then merge the minimum_consecutive_frames PR. Let's keep those two separate.
  2. I'd like to ask you to thoroughly test if we do not introduce any bugs with that change. I'm always super worried about making any changes in trackers.

@rolson24
Copy link
Contributor Author

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.

@SkalskiP
Copy link
Collaborator

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 = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rolson24 I assume that after #1062 we can change this into return detections[detections.tracker_id != =1] ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup!

@rolson24
Copy link
Contributor Author

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.

@SkalskiP SkalskiP merged commit 908a1b4 into roboflow:develop Mar 28, 2024
9 checks passed
@SkalskiP
Copy link
Collaborator

SkalskiP commented Mar 28, 2024

@rolson24 I'm merging this PR. As for ByteTrack unit tests, I would love this! Feel free to open the next PR with tests.

@rolson24
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants