Uniform clip sampling + multi-clip sampling function#57
Uniform clip sampling + multi-clip sampling function#57themattinthehatt wants to merge 20 commits into
Conversation
sfmig
left a comment
There was a problem hiding this comment.
Hi @themattinthehatt, thanks for this!
I made a few suggestions: two of them are two options to try to keep the kwargs within static type checking; the other one is a decoupling suggestion that I think can help simplify tests and has other benefits too.
I think the decoupled approach would be my preferred one in terms of clarity, but it may be a personal preference too. I leave you all the options, let me know what you think. I requested changes in case you want to go for any one of them, I'd be happy to have another look. I haven't checked the tests in detail for the same reason.
|
@sfmig thanks for the great feedback! I incorporated many of you suggestions. I also imagine at some point we'll build a proper CLI module and move I have one test failing: https://github.com/neuroinformatics-unit/poseinterface/actions/runs/27362615831/job/80853717159?pr=57. Do you know why this is the case? I didn't touch this module on my side, is this related to some update in |
Ah yeah, that's because of the breaking change of dimension names in movement v0.17.0. To unblock the ongoing PRs, we could temporarily pin movement to v0.16.0 here and then we can follow up with a separate PR bringing the codebase up-to-speed with |
|
@themattinthehatt, I've quickly fixed the If you give #59 a quick approval, we can merge that first and then rebase your 2 PRs to |
…lips when shared (both are public API). Small suggested edit for extract_clips_uniform one-line summary
* Use explicit kwargs to avoid confusion where possible. Parametrise `test_validate_clip_request_valid`. * Include `test_parse_args_invalid_sampling` as a parametrised case of `test_parse_args_missing_required`, and rename to `test_parse_args_invalid_inputs`. * Define variables for inputs to tested functions, to have a single point of data entry (nice if it ever gets modified) * Spell out the error message for clarity in `test_main_uniform_missing_num_clips` and `test_main_manual_missing_start_frames`
…ing test assertions edits
sfmig
left a comment
There was a problem hiding this comment.
Hi @themattinthehatt, thanks for having a second look!
I pushed some small edits myself, hope that is ok. I contained them in separate commits in case you'd like to revert any/all of them. We can discuss any of these in the meeting tomorrow.
The smaller changes are:
- Moving the guidelines on contributing sampling strategies from the
clips.pymodule description to thecontributing.md(this will make it more findable I think). [commit] - Make the order of the input arguments in
extract_single_clipfollowextract_clipswhen arguments are shared (mainly for clarity because both are public API). [commit] - Fix tests accordingly, and other small edits to tests: parametrise one test, include one tests into the parametrisation of the previous one, etc ([commit])
A more substantial change is about _uniform_start_frames. Right now, the duration parameter is only used to check if a single clip fits in the whole video. I found this a bit surprising. I think I would either:
- drop
durationand say clearly in the docstring that clips are not guaranteed to be non-overlapping or fully in-bounds (i.e. the last clip may be shorter), OR - keep
duration, but use it to spread the start frames uniformly over the range[0, n_frames - duration]so we guarantee clips are fully in-bounds and are of same duration (even if they can still have overlaps between them).
I had a go at that second option in this commit in case you want to have a look. It includes edits in the tests too (but again we can revert it, if you had something else in mind).
| @patch("poseinterface.clips.sio.save_video") | ||
| @patch("poseinterface.clips.sio.load_video") | ||
| def test_extract_clip_clamped( | ||
| def test_extract_single_clip_no_labels( |
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def test_validate_clip_request_valid(): |
There was a problem hiding this comment.
This repeated call in the test can be parametrized
| @patch( | ||
| "poseinterface.clips.extract_clips", side_effect=ValueError("bad frame") | ||
| ) | ||
| def test_main_propagates_value_error(mock_extract_single_clips): |
There was a problem hiding this comment.
| def test_main_propagates_value_error(mock_extract_single_clips): | |
| def test_main_propagates_value_error(mock_extract_clips): |
|
|
||
|
|
||
| @patch("poseinterface.clips.extract_clips") | ||
| def test_main_manual(mock_extract_single_clips): |
There was a problem hiding this comment.
| def test_main_manual(mock_extract_single_clips): | |
| def test_main_manual(mock_extract_clips): |
| @patch("poseinterface.clips.extract_clip") | ||
| def test_main(mock_extract_clip): | ||
| """Test main calls extract_clip with parsed arguments.""" | ||
| def test_parse_args_invalid_sampling(): |
There was a problem hiding this comment.
This test could be included in the parametrisation of the one just above
Description
What is this PR
Why is this PR needed?
Current repo only has a single clip selection strategy (
manual).What does this PR do?
Adds a
uniformclip sampling strategy option, and updates the CLI to take sampling strategy as input.References
Builds on #39.
How has this PR been tested?
Added new unit tests, checked all tests are passing locally before making PR.
Is this a breaking change?
Yes; the previous clip extraction entry point was
extract-clip; this has been updated toextract-clipsto work with multiple clips; in addition, the command line args changed to allow for multiple clip sampling strategies.Does this PR require an update to the documentation?
Minor update renaming the clip extraction entrypoint from
extract-cliptoextract-clips.Checklist: