Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit c5bceb2

Browse files
Merge pull request #56 from bruefire/folder_dataset_bug_with_short_video
Fixed an error with short video on 'folder' dataset.
2 parents 720117b + 0d01123 commit c5bceb2

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

utils/dataset.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -505,20 +505,18 @@ def get_frame_buckets(self, vr):
505505
return resize
506506

507507
def get_frame_batch(self, vr, resize=None):
508+
n_sample_frames = self.n_sample_frames
508509
native_fps = vr.get_avg_fps()
510+
509511
every_nth_frame = max(1, round(native_fps / self.fps))
510-
512+
every_nth_frame = min(len(vr), every_nth_frame)
513+
511514
effective_length = len(vr) // every_nth_frame
515+
if effective_length < n_sample_frames:
516+
n_sample_frames = effective_length
512517

513-
if effective_length < self.n_sample_frames:
514-
raise ValueError(
515-
f"Video is too short to sample {self.n_sample_frames} frames at {self.fps} fps. "
516-
f"Native video framerate is {native_fps} with length {len(vr)} frames."
517-
)
518-
519-
effective_idx = random.randint(1, effective_length - self.n_sample_frames)
520-
521-
idxs = every_nth_frame * np.arange(effective_idx, effective_idx + self.n_sample_frames)
518+
effective_idx = random.randint(0, (effective_length - n_sample_frames))
519+
idxs = every_nth_frame * np.arange(effective_idx, effective_idx + n_sample_frames)
522520

523521
video = vr.get_batch(idxs)
524522
video = rearrange(video, "f h w c -> f c h w")

0 commit comments

Comments
 (0)