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

Ensure videos are allocated into all specified splits #169

Merged
merged 10 commits into from
Dec 14, 2021
Merged

Conversation

ejm714
Copy link
Collaborator

@ejm714 ejm714 commented Dec 11, 2021

This PR fixes the issue that caused the following error:

RuntimeError: Early stopping conditioned on metric val_macro_f1 which is not available. Pass in or modify your EarlyStopping callback to use any of the following: train_loss

The issue has to do with the split column. When we don't provide it in the labels, we use a random split. But we don't guarantee that we have all of the values from the split_proportions dict (e.g. train and val ) in the split column. With a small number of videos and the default proportions, all videos getting assigned to train (see in splits.csv). Since there are no val videos, there is no val_f1_score.

I considered implementing this without the random draw and instead calculating the number of samples that need to go into each split based on the proportions provided. However, this gets tricky to ensure based on rounding. I instead went with the while loop that tries different seeds until it finds a draw that works. If someone specifies split proportions of train: 100, val: 1, and only provides say 5 videos, there is risk of an infinite loop. I'm not sure how important it is to catch such a situation since 1) we don't expect people to be training on so few videos and 2) it feels hard to accidentally end up in such a situation.

Bonus fix: fix bug in ModelCheckpoint which lets monitor be None if there is no early stopping. mode must either be min or max. I set it to min to match PTL's default but it doesn't get used if monitor is None.

Plus cleanup to set defaults in DummyTrainConfig to avoid repeated code.

@ejm714 ejm714 requested a review from pjbull December 11, 2021 03:40
@github-actions
Copy link
Contributor

github-actions bot commented Dec 11, 2021

@codecov
Copy link

codecov bot commented Dec 11, 2021

Codecov Report

Merging #169 (ad38de6) into master (62797d9) will increase coverage by 0.0%.
The diff coverage is 100.0%.

@@          Coverage Diff           @@
##           master    #169   +/-   ##
======================================
  Coverage    85.0%   85.0%           
======================================
  Files          30      30           
  Lines        1843    1851    +8     
======================================
+ Hits         1567    1575    +8     
  Misses        276     276           
Impacted Files Coverage Δ
zamba/models/model_manager.py 84.1% <ø> (ø)
zamba/models/config.py 97.1% <100.0%> (+<0.1%) ⬆️

zamba/models/config.py Outdated Show resolved Hide resolved
zamba/models/config.py Outdated Show resolved Hide resolved
@ejm714
Copy link
Collaborator Author

ejm714 commented Dec 14, 2021

@pjbull ready for another look. this now has the added benefit of doing split allocation within species which is something we had desired but hadn't yet implemented. this should help ensure better training results (in addition to fixing the bug)

@ejm714
Copy link
Collaborator Author

ejm714 commented Dec 14, 2021

@pjbull ready for reals this time!

list(values["split_proportions"].keys()),
weights=list(values["split_proportions"].values()),
k=len(species_df) - len(expected_splits),
)
Copy link
Member

Choose a reason for hiding this comment

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

This has one weird edge case that is likely rare, so just worth filing an issue for:

v0.mp4, antelope
v1.mp4, antelope  # v1 assigned test by antelope grouping
v1.mp4, cow       # subsequently v1 assigned train by cow grouping
v2.mp4, antelope
v4.mp4, cow
v5.mp4, cow

# test set is now missing antelope

@pjbull pjbull merged commit 9e2dad5 into master Dec 14, 2021
@pjbull pjbull deleted the ensure-splits branch December 14, 2021 02:52
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