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

Generate suggestions for videos with less frames than samples per video #781

Merged
merged 5 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions sleap/gui/suggestions.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ def basic_sample_suggestion_method(

for video in labels.videos:
if sampling_method == "stride":
vid_suggestions = list(
range(0, video.frames, video.frames // per_video)
)[:per_video]
frame_increment = video.frames // per_video
frame_increment = per_video if frame_increment == 0 else frame_increment
vid_suggestions = list(range(0, video.frames, frame_increment))[
:per_video
]
else:
# random sampling
vid_suggestions = random.sample(range(video.frames), per_video)
Expand Down
31 changes: 31 additions & 0 deletions tests/gui/test_suggestions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from sleap.gui.suggestions import VideoFrameSuggestions
from sleap.io.dataset import Labels


def test_velocity_suggestions(centered_pair_predictions):
Expand All @@ -9,3 +10,33 @@ def test_velocity_suggestions(centered_pair_predictions):
assert len(suggestions) == 45
assert suggestions[0].frame_idx == 21
assert suggestions[1].frame_idx == 45


def test_frame_increment(centered_pair_predictions: Labels):

# Testing videos that have less frames than desired Samples per Video value using stride method.
# Expected result is one suggested frame.

vid_frames = centered_pair_predictions.video.num_frames
suggestions = VideoFrameSuggestions.suggest(
labels=centered_pair_predictions,
params={
"method": "sample",
"per_video": 2 * vid_frames,
"sampling_method": "stride",
},
)
assert len(suggestions) == 1

# Testing typical videos that have more frames than desired Samples per Video value using stride method.
# Expected result is the desired Samples per Video number of frames.

suggestions = VideoFrameSuggestions.suggest(
labels=centered_pair_predictions,
params={
"method": "sample",
"per_video": 20,
"sampling_method": "stride",
},
)
assert len(suggestions) == 20