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

Load bboxes dataset from VIA tracks file (3/4) #229

Merged
merged 50 commits into from
Jul 31, 2024

Conversation

sfmig
Copy link
Contributor

@sfmig sfmig commented Jun 19, 2024

Rebase after #234

Description

What is this PR

  • Bug fix
  • Addition of a new feature
  • Other

Why is this PR needed?
To be able to load a VIA tracks file with bounding boxes into a movement dataset.

What does this PR do?

  • Adds a movement.io.load_bboxes module, which follows the equivalent poses one as much as possible.
  • Adds corresponding unit tests in tests_load_bboxes.

Question: how to make mypy aware of the type transformations that take place in __attrs_post_init__?
For example, the confidence array passed to ValidBboxesDataset can be None, and mypy flags that a .shape attribute is used later which None doesn't have. But mypy seems to be missing that the confidence array is populated with nans in __attrs_post_init__ if None is passed as input. Is there a nice way to fix this?

References

This PR would close #167

How has this PR been tested?

Tests pass locally and on CI.

Is this a breaking change?

No.

Does this PR require an update to the documentation?

I updated api_index.rst.

Checklist:

  • The code has been tested locally
  • Tests have been added to cover all new functionality
  • The documentation has been updated to reflect any changes
  • The code has been formatted with pre-commit

Copy link

codecov bot commented Jun 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.76%. Comparing base (d10ec20) to head (7c260b3).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #229      +/-   ##
==========================================
+ Coverage   99.74%   99.76%   +0.02%     
==========================================
  Files          13       14       +1     
  Lines         771      854      +83     
==========================================
+ Hits          769      852      +83     
  Misses          2        2              

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

@sfmig sfmig force-pushed the smg/read-via-file-as-bbox-ds branch from 511b3de to 161bf67 Compare June 19, 2024 17:27
This was referenced Jun 20, 2024
@sfmig sfmig changed the title Load VIA data as bboxes dataset Load bboxes dataset from VIA tracks file Jun 20, 2024
@sfmig sfmig changed the title Load bboxes dataset from VIA tracks file Load bboxes dataset from VIA tracks file (4/4) Jun 20, 2024
@sfmig sfmig marked this pull request as ready for review June 21, 2024 12:57
@sfmig sfmig force-pushed the smg/read-via-file-as-bbox-ds branch from 111e599 to 2cf6c80 Compare June 21, 2024 13:13
Copy link

@sfmig sfmig requested a review from niksirbi June 21, 2024 15:42
@sfmig sfmig changed the title Load bboxes dataset from VIA tracks file (4/4) Load bboxes dataset from VIA tracks file (3/4) Jun 27, 2024
Copy link
Member

@niksirbi niksirbi left a comment

Choose a reason for hiding this comment

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

Thanks a lot @sfmig and well done on closely following the code architecture for loading poses. This makes me hopeful that we will be able to refactor them in future, such that we abstract away there common bits (to reduce repetition in validators and tests between poses and bboxes). But this shouldn't worry us right now.

I have two substantial comments apart form the cosmetic/trivial issues I've highlighted in specific comments.

  • I don't fully understand what frame_array is needed for and how it is handled. See my specific comment about this. Perhaps we can discuss it in person together?
  • The documentaiton pages for input_output.md and movement_dataset.md need to be updated. Specifically:
    • the new format has to be aded in the "Supported formats" section of Input/Output.
    • A new "Loading tracks of bounding boxes" section has to be added to Input/Output.
    • The "Movement Dataset" page has to also include information about the bboxes dataset format, especially where it differs from the poses format

I'm happy for you to leave the documentation changes for a future PR (just open an issue in that case).

EDIT

Another thought that just came to mind: have you tested whether the existing filtering and kinematics functions work on the new bboxes datasets?

You could define a valid_bboxes_dataset pytest fixture (similar to valid_poses_dataset) and add it to all relevant tests in:

  • test_integration/test_filtering.py
  • test_unit/test_filtering.py
  • test_unit/test_kinematics.py
  • test_unit/test_move_accessor.py

It's crucial to determine if our existing features work on the new type of dataset.

@sfmig
Copy link
Contributor Author

sfmig commented Jul 19, 2024

From chats with @niksirbi:
We agreed to take the frame numbers as specified in the csv file for now (that is, not necessarily starting from 0), but to make the time coordinate have the same origin as the frame number.

@sfmig sfmig force-pushed the smg/read-via-file-as-bbox-ds branch 4 times, most recently from 089a7d1 to 2d9b330 Compare July 24, 2024 09:17
@sfmig sfmig force-pushed the smg/read-via-file-as-bbox-ds branch from ec714db to 3f7aadf Compare July 25, 2024 17:31
@sfmig
Copy link
Contributor Author

sfmig commented Jul 26, 2024

Thanks @niksirbi for the feedback!

I think I addressed all the comments, let me know if something is missing.

frame_array and frame numbers

I did some changes to hopefully make more understandable the behaviour of keeping / resetting the frame numbers:

  • In all the loaders of bboxes data (from_file, from_via_tracks_file, from numpy), the default behaviour is that the origin of the time dimension is the first loaded (aka tracked) frame, which would be frame number 0 captured at t = 0 seconds. This is to stay consistent with the pose data, and it is likely the most natural for our users.

  • In the from_file and the from_via_tracks_file I added a use_frame_numbers_from_file option, that is False by default. If True, it will take the frame numbers from the input file, with whatever assumption for the time origin they have (they may assume for example the first frame is 0, or 1).

    • The caveat is that if you take the frame number from the file, and later transform it to seconds, then the time origin is assumed to be at frame number 0 and time = 0 seconds. This is because we simply transform to seconds as frame_number/fps.
    • Another option could be to add an extra attribute / argument to set the time origin manually, but I didn't want to complicate it too much. Let me know if it is clear as is, if not I am happy to give it another go.
    • If users want to keep track of the frame relative to the full video at which the analysed clip starts, they could assign a custom attribute. I sneakily added this in PR Getting started docs update for bboxes #245 - let me know thoughts.
  • For the from_numpy loader, this is simply done via the frame_array input. If passed, those frame numbers are used, but the input is None by default, which means the frame numbers are assigned from 0 to N-1, with N being the first dimension of the position array.

Update Getting started documentation

Extend tests to ensure postprocessing methods work with bboxes datasets

Question

How do you think we should merge these PRs?
I have never done this but I'm wondering if we should merge PR #245 and #246 into this PR's branch, before merging this into main. Or should we use a dev branch?

@sfmig sfmig requested a review from niksirbi July 26, 2024 12:17
Copy link
Member

@niksirbi niksirbi left a comment

Choose a reason for hiding this comment

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

Thanks @sfmig, I'm happy with how you've handled things, and the updated docstrings make it super clear what happens to time and frames.

I've only left very few suggestions re docstrings, feel free to adopt or not.

@niksirbi
Copy link
Member

How do you think we should merge these PRs?
I have never done this but I'm wondering if we should merge PR #245 and #246 into this PR's branch, before merging this into main. Or should we use a dev branch?

I've never done this as well. Maybe we should consult with Alessandro or Joe who have more experience with complex merges.
How about merging each of these 3 PRs separately (and sequentially) to main (with rebases in-between)? Is that not an option? It would be nice to have them as 3 separate commits in main, but if that' painful, feel free to merge any way that's convenient.

@sfmig sfmig force-pushed the smg/read-via-file-as-bbox-ds branch from d0f2326 to d9cf96b Compare July 30, 2024 13:28
@sfmig sfmig force-pushed the smg/read-via-file-as-bbox-ds branch from d9cf96b to 6e5420d Compare July 31, 2024 10:19
Copy link

@sfmig sfmig added this pull request to the merge queue Jul 31, 2024
Merged via the queue into main with commit 01c3cf6 Jul 31, 2024
17 checks passed
@lochhh lochhh deleted the smg/read-via-file-as-bbox-ds branch October 25, 2024 16:36
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.

Support reading trajectories from tracked bounding boxes in VGG annotator format
3 participants