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 validation and test split not being reproducible #218

Merged
merged 18 commits into from
Oct 28, 2024

Conversation

sfmig
Copy link
Collaborator

@sfmig sfmig commented Jul 8, 2024

Why is this PR needed?

Currently when we create the test and validation splits we don't pass a generator. We do pass one when we create the training split.

This means that given a seed, the splitting of the dataset into train and test-val sets is reproducible, but the subsequent splitting of the test-val set into a test set and a val set is not.

What does this PR do?

This PR:

  • passes a new generator to the second split of the data
  • adds tests for the splits generation.

Smaller bits

  • adds short docstrings to existing datamodule tests.
  • adds a utility function that converts a tensor of bboxes into a COCO-style dictionary for a crab dataset.

Notes

I decided to pass a different generator for each call to random_split to try to make it a bit "future-proof". That way we guarantee the splits are repeatable even if some randomisation code is added in between the two calls to random_split.

@codecov-commenter
Copy link

codecov-commenter commented Jul 8, 2024

Codecov Report

Attention: Patch coverage is 95.23810% with 1 line in your changes missing coverage. Please review.

Project coverage is 47.75%. Comparing base (a21d4f1) to head (c678df6).

Files with missing lines Patch % Lines
crabs/detector/datamodules.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #218      +/-   ##
==========================================
+ Coverage   46.68%   47.75%   +1.07%     
==========================================
  Files          24       24              
  Lines        1476     1493      +17     
==========================================
+ Hits          689      713      +24     
+ Misses        787      780       -7     

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

@sfmig sfmig requested a review from nikk-nikaznan July 8, 2024 16:12
Copy link
Collaborator

@nikk-nikaznan nikk-nikaznan left a comment

Choose a reason for hiding this comment

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

Well done for spotting this. I leave a comment, as I am not sure myself if we need two generators.

Other option, can we just use seed_everything?

crabs/detector/datamodules.py Outdated Show resolved Hide resolved
@sfmig
Copy link
Collaborator Author

sfmig commented Jul 9, 2024

Other option, can we just use seed_everything?

Cool, I didn't know about this!

I think for now I'd prefer to constraint the seeding to the dataset creation, because that is the part I need to be reproducible. But good to have this in the radar.

Copy link
Collaborator

@nikk-nikaznan nikk-nikaznan 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 to me! I think having separate generators is a good move. Nice test as well! Just some small comments below.

crabs/detector/utils/detection.py Outdated Show resolved Hide resolved
crabs/detector/utils/detection.py Show resolved Hide resolved
tests/test_unit/test_datamodules.py Outdated Show resolved Hide resolved
@sfmig sfmig force-pushed the smg/fix-reproducible-val-test-split branch from 65d1084 to fb1ad06 Compare October 28, 2024 15:28
@sfmig
Copy link
Collaborator Author

sfmig commented Oct 28, 2024

thanks for the help Nik! 🌟

@sfmig sfmig merged commit 5d58d85 into main Oct 28, 2024
6 checks passed
@sfmig sfmig deleted the smg/fix-reproducible-val-test-split branch October 28, 2024 15:38
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