supervision icon indicating copy to clipboard operation
supervision copied to clipboard

Allow ByteTrack to track detections without IDs

Open LinasKo opened this issue 1 year ago • 12 comments

Allow ByteTrack to track detections without IDs

[!TIP] Hacktoberfest is calling! Whether it's your first PR or your 50th, you’re helping shape the future of open source. Help us build the most reliable and user-friendly computer vision library out there! 🌱

For a long time, all of models we support would return a class_id which we set inside Detections (class_id is an array of N integers). However, we've seen more and more models where that isn't provided.

ByteTrack allows you to track objects in the scene. It uses the class and location of the detection to figure out where it is. It can track objects where all class IDs are the same. However, if you try passing something without an ID, it will fail. See this Colab.

Let's change ByteTrack so it can track detections, even if they didn't have a class_id. I see two ways of doing this:

  1. Change the algorithm such that class_ids are not required
  2. Set an internal class ID such as -1.

As a result, I expect the videos produced in the Colab to be visually indistinguishable.

It would also be useful to test on a video where some frames feature no detections (you can simulate with detections = sv.Detections.empty())

Also, check what happens when some detections have class_id and some do not.


Helpful links:

LinasKo avatar Oct 09 '24 11:10 LinasKo

Contribution guidelines

If you would like to make a contribution, please check that no one else is assigned already. Then leave a comment such as "Hi, I would like to work on this issue". We're happy to answer any questions about the task even if you choose not to contribute.

Testing

Please share a Google Colab with minimal code to test the new feature. We know it's additional work, but it will speed up the review process. You may use the Starter Template. The reviewer must test each change. Setting up a local environment to do this is time-consuming. Please ensure that Google Colab can be accessed without any issues (make it public). Thank you! :pray:

LinasKo avatar Oct 09 '24 11:10 LinasKo

Hi, I would like to work on this issue. :)

Kadermiyanyedi avatar Oct 09 '24 12:10 Kadermiyanyedi

@Kadermiyanyedi task is yours, good luck ;)

onuralpszr avatar Oct 09 '24 13:10 onuralpszr

Hi,

I apologize for the delay. I couldn't work on the issue last week due to a busy schedule, but I've started it now. I'll submit a PR in a few days.

Thank you for your patience!

Kadermiyanyedi avatar Oct 14 '24 07:10 Kadermiyanyedi

Hi @Kadermiyanyedi :wave:

Thanks for letting me know! Feel free to take your time.

Your submissions are always of a very high quality so I'm happy either way, even if it takes longer :)

LinasKo avatar Oct 14 '24 08:10 LinasKo

Hi, I would like to work on this issue

AyuK03 avatar Oct 16 '24 02:10 AyuK03

Hi, I would like to work on this issue

This issue has taken already and if something changed we can but for now @Kadermiyanyedi is going the task, thank you for understanding

onuralpszr avatar Oct 16 '24 02:10 onuralpszr

Hi @Kadermiyanyedi,

Quick note, there's been a few updates on the tracker today:

  • I merged #1528, which changes the behaviour when more than one ByteTrack is used simultaneously.
  • I opened #1603 which involves some hefty refactoring, but the behaviour is the same.

I expect some merge conflicts; I'l leave it up to you if you want to handle them. If it proves beyond what you planned for this PR - feel free to complete the task with the current base, and I'll resolve any clashes.

LinasKo avatar Oct 18 '24 00:10 LinasKo

Another update: It may be possible to just remove class_ids from STracks entirely. I didn't see it being used anywhere, nor does it appear in the original ByteTrack implementation.

LinasKo avatar Oct 18 '24 10:10 LinasKo

If it's not used anywhere, we can remove it.

I initialized a new NumPy array filled with -1 values in case the detections.class_id is None. The new array has the same length as detections.xyxy. The code runs correctly, but I'm not seeing the detected objects in the output, and I'm currently investigating this issue.

If we don't need the class id, I will remove and open PR quickly.

def detections2boxes(detections: Detections) -> np.ndarray:
    num_rows = detections.xyxy.shape[0]

    class_ids = np.full(num_rows, -1)
    if detections.class_id is not None:
        class_ids = detections.class_id
    return np.hstack(
        (
            detections.xyxy,
            detections.confidence[:, np.newaxis],
            class_ids[:, np.newaxis],
        )
    )

Kadermiyanyedi avatar Oct 18 '24 11:10 Kadermiyanyedi

I recall seeing -1 as a special temporary value somewhere. Are detections also gone when you use -2, or some large positive integer?

LinasKo avatar Oct 18 '24 11:10 LinasKo

I recall seeing -1 as a special temporary value somewhere. Are detections also gone when you use -2, or some large positive integer?

unfortunately it is same

Kadermiyanyedi avatar Oct 18 '24 11:10 Kadermiyanyedi

@LinasKo Hi, I hope you're doing well.

The changes I made worked. I noticed an error in the test code later and confirmed the changes were working before opening the PR. I also fixed the code conflicts.

I was excitedly waiting for your feedback!

Kadermiyanyedi avatar Oct 23 '24 19:10 Kadermiyanyedi

Thank you @Kadermiyanyedi!

I'm away at the moment and will be back around next Wednesday; I'll review it then.

Thank you for your contribution!

LinasKo avatar Oct 23 '24 19:10 LinasKo

This is now completed. Thanks @Kadermiyanyedi!

LinasKo avatar Nov 04 '24 11:11 LinasKo