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

Add track ids if present for ultralytics models #4569

Merged
merged 2 commits into from
Jul 12, 2024

Conversation

Rusteam
Copy link
Contributor

@Rusteam Rusteam commented Jul 12, 2024

What changes are proposed in this pull request?

If running track method from ultralytics.YOLO model, then track ids will be available video files.
If track ids are present, we add then to fiftyone.Detection(index=track_id) and other labels.

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

Works with detection and pose estimation models for the ultralytics integration.

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.

When running ultralytics models on video files, track ids will be internally added to label fields with a instance index.

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 tracking capabilities by including track IDs in detection, instance, polyline, and keypoint results.

Copy link
Contributor

coderabbitai bot commented Jul 12, 2024

Walkthrough

This update introduces functions to extract track IDs from Ultralytics results and modifies existing functions to include track ID processing. The changes enhance the ability to keep track of object identities across frames, crucial for tasks like object tracking in video analysis.

Changes

File Change Summary
.../ultralytics.py Added _extract_track_ids function to extract track IDs from results
.../ultralytics.py Modified _to_detections, _to_instances, _to_polylines, _to_keypoints to include track IDs

Sequence Diagram(s)

sequenceDiagram
    participant Ultralytics as Ultralytics Model
    participant FOUtils as fiftyone.utils.ultralytics
    participant Result as Ultralytics Result

    Ultralytics->>Result: Generate Results
    Result->>FOUtils: Pass Results
    FOUtils->>+FOUtils: _extract_track_ids(result)
    FOUtils->>-FOUtils: Return Track IDs
    FOUtils->>Result: Process Results with Track IDs
Loading

Poem

In fields of code where changes flow,
Track IDs now we aptly show.
Detections, instances, all enhanced,
With every frame, our data danced.
A rabbit's joy in lines so fine,
For tracking paths, a new design.
🐇✨


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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
fiftyone/utils/ultralytics.py (1)

56-62: Add a comment explaining the function logic.

The function _extract_track_ids handles the presence and absence of track IDs. Adding a comment will improve code readability.

def _extract_track_ids(result):
    """Get ultralytics track ids if present, else use Nones"""
    # Extract track IDs if they are present; otherwise, return a list of None
    return (
        result.boxes.id.detach().cpu().numpy().astype(int)
        if result.boxes.is_track
        else [None] * len(result.boxes.conf.size(0))
    )
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ea8774b and d3731be.

Files selected for processing (1)
  • fiftyone/utils/ultralytics.py (10 hunks)
Additional comments not posted (4)
fiftyone/utils/ultralytics.py (4)

Line range hint 95-110:
LGTM! The changes correctly incorporate track IDs into detections.

The track IDs are correctly added to the fol.Detection objects.


Line range hint 149-180:
LGTM! The changes correctly incorporate track IDs into instances.

The track IDs are correctly added to the fol.Detection objects within instance segmentations.


Line range hint 276-305:
LGTM! The changes correctly incorporate track IDs into polylines.

The track IDs are correctly added to the fol.Polyline objects.


Line range hint 346-360:
LGTM! The changes correctly incorporate track IDs into keypoints.

The track IDs are correctly added to the fol.Keypoint objects.

Copy link
Contributor

@brimoor brimoor left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! 💪

Copy link

codecov bot commented Jul 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 28.77%. Comparing base (8b225c4) to head (d3731be).
Report is 215 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff              @@
##           develop    #4569       +/-   ##
============================================
- Coverage    99.27%   28.77%   -70.50%     
============================================
  Files           47      857      +810     
  Lines        16212   106376    +90164     
  Branches         0     1374     +1374     
============================================
+ Hits         16095    30614    +14519     
- Misses         117    75762    +75645     
Flag Coverage Δ
app 16.00% <ø> (?)
python 99.11% <ø> (-0.17%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@benjaminpkane benjaminpkane merged commit 61afb2d into voxel51:develop Jul 12, 2024
12 of 13 checks passed
@swheaton swheaton mentioned this pull request Aug 23, 2024
2 tasks
@coderabbitai coderabbitai bot mentioned this pull request Oct 5, 2024
7 tasks
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.

3 participants