Skip to content

Conversation

@NicolasHug
Copy link
Contributor

@NicolasHug NicolasHug commented Oct 4, 2024

This PR adds an index-based sampler that returns equally-spaced clips.
It is a partial implementation, just like the random sampler in #221. In particular it is missing 2 key parts:

  • The implementation of a policy to deal with edge cases when the number of available frames is smaller than what is requested by the sampler
  • fast and efficient "sort and decode indices" strategy

Both these parts are left as TODO and are tracked in #239. I am hoping to merge this PR before we tackle those, because I want to make sure the solution we come up with will satisfy both samplers (and not just the existing random sampler).

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 4, 2024
@NicolasHug NicolasHug marked this pull request as draft October 4, 2024 11:00
@NicolasHug NicolasHug changed the title [WIP] Add clips_at_regular_indices() sampler Add clips_at_regular_indices() sampler Oct 4, 2024
@NicolasHug NicolasHug changed the title Add clips_at_regular_indices() sampler Add regular index-based sampler - part 1 Oct 4, 2024
@NicolasHug NicolasHug marked this pull request as ready for review October 4, 2024 12:18
def clips_at_regular_indices(
decoder: VideoDecoder,
*,
num_clips: int = 1,
Copy link
Contributor Author

@NicolasHug NicolasHug Oct 4, 2024

Choose a reason for hiding this comment

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

I feel like clips_at_regular_indices(num_clips=1) is an anti pattern. Same with 2. Maybe we should make 3 the default, and enforce num_clips>=3? Or not enforce, but still set the default to 3?

I don't feel too strongly about it either way - just being pedantic.

Copy link
Contributor

Choose a reason for hiding this comment

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

If this is what other libraries do we can do the same here.

I was thinking of sampling the middle of the video if num_clips=1 but that would make it slower than existing libraries

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. Other libs allow num_clips=1. Let's revisit if needed

def clips_at_regular_indices(
decoder: VideoDecoder,
*,
num_clips: int = 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is what other libraries do we can do the same here.

I was thinking of sampling the middle of the video if num_clips=1 but that would make it slower than existing libraries

assert len(torch.unique(clip_starts_seconds)) == sampling_range_size

# Assert clips starts are ordered, i.e. the start indices don't just "wrap
# around". They're duplicated *and* ordered.
Copy link
Contributor

Choose a reason for hiding this comment

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

Mention reason for not wrapping around?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no particular reason honestly, it's just an assertion of the behavior of torch.linspace. I'll add a comment near the Note to clarify that this is somewhat arbitrary.

@NicolasHug NicolasHug merged commit ab08788 into main Oct 4, 2024
@NicolasHug NicolasHug deleted the samplerzz branch October 4, 2024 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants