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

feature: labeledvideodataset returns clip start and end #78

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
22 changes: 7 additions & 15 deletions pytorchvideo/data/labeled_video_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ def __init__(
self._video_random_generator = None
if video_sampler == torch.utils.data.RandomSampler:
self._video_random_generator = torch.Generator()
self._video_sampler = video_sampler(
self._labeled_videos, generator=self._video_random_generator
)
self._video_sampler = video_sampler(self._labeled_videos, generator=self._video_random_generator)
else:
self._video_sampler = video_sampler(self._labeled_videos)

Expand Down Expand Up @@ -153,9 +151,7 @@ def __next__(self) -> dict:
clip_index,
aug_index,
is_last_clip,
) = self._clip_sampler(
self._next_clip_start_time, video.duration, info_dict
)
) = self._clip_sampler(self._next_clip_start_time, video.duration, info_dict)

# Only load the clip once and reuse previously stored clip if there are multiple
# views for augmentations to perform on the same clip.
Expand All @@ -164,9 +160,7 @@ def __next__(self) -> dict:

self._next_clip_start_time = clip_end

video_is_null = (
self._loaded_clip is None or self._loaded_clip["video"] is None
)
video_is_null = self._loaded_clip is None or self._loaded_clip["video"] is None
if is_last_clip or video_is_null:
# Close the loaded encoded video and reset the last sampled clip time ready
# to sample a new video on the next iteration.
Expand All @@ -175,9 +169,7 @@ def __next__(self) -> dict:
self._next_clip_start_time = 0.0

if video_is_null:
logger.debug(
"Failed to load clip {}; trial {}".format(video.name, i_try)
)
logger.debug("Failed to load clip {}; trial {}".format(video.name, i_try))
continue

frames = self._loaded_clip["video"]
Expand All @@ -187,6 +179,8 @@ def __next__(self) -> dict:
"video_name": video.name,
"video_index": video_index,
"clip_index": clip_index,
"clip_start": clip_start,
"clip_end": clip_end,
"aug_index": aug_index,
**info_dict,
**({"audio": audio_samples} if audio_samples is not None else {}),
Expand All @@ -200,9 +194,7 @@ def __next__(self) -> dict:

return sample_dict
else:
raise RuntimeError(
f"Failed to load video after {self._MAX_CONSECUTIVE_FAILURES} retries."
)
raise RuntimeError(f"Failed to load video after {self._MAX_CONSECUTIVE_FAILURES} retries.")

def __iter__(self):
self._video_sampler_iter = None # Reset video sampler
Expand Down