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 and relax bboxes requirements #313

Merged
merged 33 commits into from
Dec 5, 2024
Merged

Conversation

sfmig
Copy link
Contributor

@sfmig sfmig commented Sep 17, 2024

Description

What is this PR

  • Bug fix
  • Addition of a new feature
  • Other

Why is this PR needed?
The current implementation gives an error when loading a dataset with a single individual.

It also has some inconveniences that I realised were a bit too strict when I started using it more. Mainly:

  • the requirement for the encoding of the frames number in the filename - right now we expect the number to be prefixed by frame_, but often the filename is simply the frame number, so I removed this.
  • when loading the frames as specified in the input file, it may be that the frames are not regularly spaced.
    • Currently this would throw an error because we check the frames are separated by exactly 1.
    • I relaxed this requirement to simply require the frame numbers increase.
    • If we extract them from the VIA file they are sorted before creating the dataset, but if the frame array is passed using from_numpy it is up to the user to sort it.

What does this PR do?

  • Adds fix to load a bounding boxes' dataset of a single animal
    • fixes issue with squeezing
    • extends existing tests to a file with a single animal
  • Relaxes the requirement for extracting the frame number from the filename
    • before we required a frame_ prefix
  • Relaxes the requirement on the loaded frames being continuous
    • continuous: frames increase exactly by one number
    • instead we just check the frame numbers always increase
    • two fixtures are added to test_datasets_validators/test_bboxes_dataset_validator_frame_array to check this behaves as expected.
  • Simplifies the fixtures for the load_bboxes tests
    • Uses fixture "factories" to reduce the number of predefined fixtures
    • Adapts existing tests to use those fixtures

References

Many of these issues were identified while working on #312

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?

The relevant docstrings have been updated.

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

@sfmig sfmig force-pushed the smg/fix-and-relax-reqs-bboxes branch from 71bf499 to 64eb1de Compare September 17, 2024 15:47
Copy link

codecov bot commented Sep 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.78%. Comparing base (4de4963) to head (489cba1).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #313   +/-   ##
=======================================
  Coverage   99.78%   99.78%           
=======================================
  Files          14       14           
  Lines         912      927   +15     
=======================================
+ Hits          910      925   +15     
  Misses          2        2           

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

Copy link

sonarqubecloud bot commented Oct 3, 2024

@sfmig sfmig force-pushed the smg/fix-and-relax-reqs-bboxes branch from 5c27794 to 1413167 Compare November 19, 2024 15:56
@sfmig sfmig force-pushed the smg/fix-and-relax-reqs-bboxes branch from 4736595 to b5b7046 Compare November 29, 2024 14:10
@sfmig sfmig marked this pull request as ready for review November 29, 2024 17:20
@sfmig sfmig requested a review from niksirbi November 29, 2024 17:21
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.

Looks good @sfmig! That's some fixture factory extravaganza right there!

I only left very few clarifying comments/questions.

I also think you may have forgotten to update the docstring of the from_numpy() functions. It currently says:

frame_array : np.ndarray, optional
        Array of shape (n_frames, 1) containing the frame numbers for which
        bounding boxes are defined. If None (default), frame numbers will
        be assigned based on the first dimension of the ``position_array``,
        starting from 0. If a specific array of frame numbers is provided,
        these need to be consecutive integers.

I think they no longer need to be consecutive, right?

movement/validators/files.py Show resolved Hide resolved
movement/validators/files.py Outdated Show resolved Hide resolved
tests/test_unit/test_load_bboxes.py Outdated Show resolved Hide resolved
movement/io/load_bboxes.py Show resolved Hide resolved
tests/test_unit/test_load_bboxes.py Outdated Show resolved Hide resolved
@sfmig sfmig force-pushed the smg/fix-and-relax-reqs-bboxes branch from 8cd94c1 to 63cdb0e Compare December 4, 2024 14:09
@sfmig sfmig requested a review from niksirbi December 4, 2024 18:55
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.

Just a few more comments

movement/io/load_bboxes.py Show resolved Hide resolved
movement/io/load_bboxes.py Show resolved Hide resolved
movement/validators/files.py Outdated Show resolved Hide resolved
movement/validators/files.py Outdated Show resolved Hide resolved
Copy link

sonarqubecloud bot commented Dec 5, 2024

@sfmig sfmig enabled auto-merge December 5, 2024 10:44
@sfmig sfmig added this pull request to the merge queue Dec 5, 2024
Merged via the queue into main with commit f7539b9 Dec 5, 2024
18 checks passed
@niksirbi niksirbi deleted the smg/fix-and-relax-reqs-bboxes branch December 5, 2024 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

2 participants