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

Adding DeepSort object tracking utility #4296

Merged
merged 5 commits into from
May 6, 2024
Merged

Conversation

rohis06
Copy link
Contributor

@rohis06 rohis06 commented Apr 19, 2024

What changes are proposed in this pull request?

Adds DeepSort object tracking utility to FiftyOne 🎊

It can be used as follows:

!pip3 install deep-sort-realtime

import fiftyone as fo
import fiftyone.zoo as foz
from fiftyone import ViewField as F
from fiftyone.utils.tracking import DeepSort
from ultralytics import YOLO

model = YOLO('yolov8n.pt')

dataset = foz.load_zoo_dataset("quickstart-video", dataset_name="qv", max_samples=3)

dataset.ensure_frames()

dataset.apply_model(model, label_field="frames.detections")

DeepSort.track(dataset=dataset, in_field="frames.detections", max_age=15, progress=True)

session = fo.launch_app(dataset)

trajectories = (
    dataset
    .filter_labels("frames.ds_tracks", F("label") == "car")
    .to_trajectories("frames.ds_tracks")
)

session = fo.launch_app(view=trajectories)

How is this patch tested? If it is not, please explain why.

It has been thoroughly tested using the above code snippet.

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

Adds DeepSort object tracking utility to FiftyOne.

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • New Features
    • Enhanced object tracking in video datasets with the new DeepSort class, utilizing advanced deep learning techniques for improved accuracy and efficiency.

Copy link
Contributor

coderabbitai bot commented Apr 19, 2024

Walkthrough

The update introduces a new tracking utility for video datasets, leveraging the DeepSort algorithm. This enhancement involves the creation of a DeepSort class that facilitates object tracking across video frames, managing object persistence and bounding box associations effectively.

Changes

File Path Change Summary
.../tracking/__init__.py Introduced tracking utilities related to the DeepSort functionality.
.../tracking/deepsort.py Added DeepSort class for object tracking in videos, with methods for setting track lifespan and more.

Poem

🐇💻
In the land of code and byte,
A rabbit hopped through the night.
Tracking objects, bounding free,
With DeepSort magic, joyous spree!
Watch them go, frame by frame,
Each object tagged, none the same.


Recent Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 16eb245 and 757d22e.
Files selected for processing (1)
  • fiftyone/utils/tracking/deepsort.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • fiftyone/utils/tracking/deepsort.py

Warning

Following problems were encountered

  • Git: Failed to clone repository. Please contact CodeRabbit support.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jacobmarks
Copy link
Contributor

This is awesome @rohis06 !!! I love the simplicity of your implementation, and this is a huge upgrade for FiftyOne 💪. The way you laid the structure out to accommodate others trackers in the future is perfect. The implementation works for me!!!

Just one very minor question/note: the tracks have index numbers that are pretty high — it looks like a lot of the tracks got cut and the index is never reset. This means that the cars have labels like "car 14", "car 18", ... as opposed to "car 0", "car 1", ... etc. Is this the convention, if not, it might be nice to parse through the index numbers and reassign numbers starting from 0. What do you think?

Also, I LOVE the illustration of trajectories. Thank you for making this by far more useful than ever before!!

@rohis06
Copy link
Contributor Author

rohis06 commented Apr 19, 2024

Thanks for reviewing and providing your feedback, @jacobmarks! 😄
I am glad that it met the expectations 😊

Just one very minor question/note: the tracks have index numbers that are pretty high — it looks like a lot of the tracks got cut and the index is never reset. This means that the cars have labels like "car 14", "car 18", ... as opposed to "car 0", "car 1", ... etc. Is this the convention, if not, it might be nice to parse through the index numbers and reassign numbers starting from 0. What do you think?

That's actually correct since the DeepSort algorithm outputs the global tracking IDs. So, "car 14" doesn't essentially translate to the 14th car. Instead, it's the 14th object detected and tracked across all the frames of the input video. Even I felt it to be a little misleading. So, do you think it would be better to update the code so that the out_field only contains the bounding_box and index (tracking_id) of the detection and not include the labels and confidence?

I can update the lines 112-119 to:

                    tracked_detections.append(
                        fo.Detection(
                            bounding_box=[rel_x, rel_y, rel_w, rel_h],
                            index=track.track_id,
                        )
                    )

Let me know what you think about this approach.

@jacobmarks
Copy link
Contributor

Thanks for reviewing and providing your feedback, @jacobmarks! 😄 I am glad that it met the expectations 😊

Just one very minor question/note: the tracks have index numbers that are pretty high — it looks like a lot of the tracks got cut and the index is never reset. This means that the cars have labels like "car 14", "car 18", ... as opposed to "car 0", "car 1", ... etc. Is this the convention, if not, it might be nice to parse through the index numbers and reassign numbers starting from 0. What do you think?

That's actually correct since the DeepSort algorithm outputs the global tracking IDs. So, "car 14" doesn't essentially translate to the 14th car. Instead, it's the 14th object detected and tracked across all the frames of the input video. Even I felt it to be a little misleading. So, do you think it would be better to update the code so that the out_field only contains the bounding_box and index (tracking_id) of the detection and not include the labels and confidence?

I can update the lines 112-119 to:

                    tracked_detections.append(
                        fo.Detection(
                            bounding_box=[rel_x, rel_y, rel_w, rel_h],
                            index=track.track_id,
                        )
                    )

Let me know what you think about this approach.

Hmm I see. I think the best thing to do would be to add an argument to the tracker like keep_confidence=False which allows the user to decide whether they want this. What do you think?

@jacobmarks
Copy link
Contributor

@rohis06 I'm also seeing some small issues with bounding boxes/tracks.
Screenshot 2024-04-20 at 11 13 07 AM

  1. It looks like the tracks don't start until frame 3 for each sample.
  2. Looks like some of the tracks from sample 1 and propagating through to sample 2. Screenshot attached. This might be user error though!

@rohis06
Copy link
Contributor Author

rohis06 commented Apr 21, 2024

Thanks for reviewing and providing your feedback, @jacobmarks! 😄 I am glad that it met the expectations 😊

Just one very minor question/note: the tracks have index numbers that are pretty high — it looks like a lot of the tracks got cut and the index is never reset. This means that the cars have labels like "car 14", "car 18", ... as opposed to "car 0", "car 1", ... etc. Is this the convention, if not, it might be nice to parse through the index numbers and reassign numbers starting from 0. What do you think?

That's actually correct since the DeepSort algorithm outputs the global tracking IDs. So, "car 14" doesn't essentially translate to the 14th car. Instead, it's the 14th object detected and tracked across all the frames of the input video. Even I felt it to be a little misleading. So, do you think it would be better to update the code so that the out_field only contains the bounding_box and index (tracking_id) of the detection and not include the labels and confidence?
I can update the lines 112-119 to:

                    tracked_detections.append(
                        fo.Detection(
                            bounding_box=[rel_x, rel_y, rel_w, rel_h],
                            index=track.track_id,
                        )
                    )

Let me know what you think about this approach.

Hmm I see. I think the best thing to do would be to add an argument to the tracker like keep_confidence=False which allows the user to decide whether they want this. What do you think?

Yeah, this sounds like a great approach. I will update the code to include the keep_confidence=False argument.

@rohis06
Copy link
Contributor Author

rohis06 commented Apr 21, 2024

@rohis06 I'm also seeing some small issues with bounding boxes/tracks. Screenshot 2024-04-20 at 11 13 07 AM

  1. It looks like the tracks don't start until frame 3 for each sample.
  2. Looks like some of the tracks from sample 1 and propagating through to sample 2. Screenshot attached. This might be user error though!

Hmm, I see. Could you please share the code snippet that resulted in this issue? I will try to reproduce it at my end and debug it further.

@jacobmarks
Copy link
Contributor

@rohis06 I'm also seeing some small issues with bounding boxes/tracks. Screenshot 2024-04-20 at 11 13 07 AM

  1. It looks like the tracks don't start until frame 3 for each sample.
  2. Looks like some of the tracks from sample 1 and propagating through to sample 2. Screenshot attached. This might be user error though!

Hmm, I see. Could you please share the code snippet that resulted in this issue? I will try to reproduce it at my end and debug it further.

Thanks for looking into this!

I just used this code snippet:

import fiftyone as fo
import fiftyone.zoo as foz
import fiftyone.brain as fob
from fiftyone import ViewField as F
from fiftyone.utils.tracking import DeepSort

dataset = foz.load_zoo_dataset("quickstart-video", max_samples=3)
model = foz.load_zoo_model("yolov8n-coco-torch")

dataset.ensure_frames()
dataset.apply_model(model, label_field="frames.yolo_detection")

DeepSort.track(dataset=dataset, in_field="frames.yolo_detection", max_age=15, progress=True)

@rohis06
Copy link
Contributor Author

rohis06 commented Apr 24, 2024

@rohis06 I'm also seeing some small issues with bounding boxes/tracks. Screenshot 2024-04-20 at 11 13 07 AM

  1. It looks like the tracks don't start until frame 3 for each sample.

So, according to the official implementation of the deep sort algorithm, tracks have three states: Tentative, Confirmed, and Deleted. If we look at line 102 in our code, we can see that we ignore the tracks that aren't "confirmed" yet, which means not enough evidence has been collected for these tracks yet. In this specific dataset that we are testing, it looks like only when the 3rd frame is seen the tracks change their state from "tentative" to "confirmed". However, it doesn't always have to be the 3rd frame.

  1. Looks like some of the tracks from sample 1 and propagating through to sample 2. Screenshot attached. This might be user error though!

Thanks for pointing this out, @jacobmarks. I have addressed this issue.

@jacobmarks
Copy link
Contributor

Awesome job @rohis06 , just ran the latest and it works swimmingly :) Massive kudos 🚀

@jacobmarks jacobmarks self-requested a review April 26, 2024 01:05
Copy link
Contributor

@jacobmarks jacobmarks left a comment

Choose a reason for hiding this comment

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

👍 LGTM!!!

@rohis06
Copy link
Contributor Author

rohis06 commented Apr 26, 2024

Awesome job @rohis06 , just ran the latest and it works swimmingly :) Massive kudos 🚀

Thanks so much! Glad to hear it's working well! 🚀

@jacobmarks jacobmarks merged commit 827daa2 into voxel51:develop May 6, 2024
9 of 10 checks passed
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