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

Fix Kinetics dataset docstring #8121

Merged
merged 2 commits into from
Nov 20, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions torchvision/datasets/kinetics.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ class Kinetics(VisionDataset):
root/
├── split
│ ├── class1
│ │ ├── clip1.mp4
│ │ ├── clip2.mp4
│ │ ├── clip3.mp4
│ │ ├── vid1.mp4
│ │ ├── vid2.mp4
│ │ ├── vid3.mp4
│ │ ├── ...
│ ├── class2
│ │ ├── clipx.mp4
│ │ ├── vidx.mp4
│ │ └── ...

Note: split is appended automatically using the split argument.
Expand Down
12 changes: 6 additions & 6 deletions torchvision/datasets/video_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ def __init__(
self.compute_clips(clip_length_in_frames, frames_between_clips, frame_rate)

def _compute_frame_pts(self) -> None:
self.video_pts = []
self.video_fps: List[int] = []
self.video_pts = [] # len = num_videos. Each entry is a tensor of shape (num_frames_in_video,)
self.video_fps: List[int] = [] # len = num_videos

# strategy: use a DataLoader to parallelize read_video_timestamps
# so need to create a dummy dataset first
Expand All @@ -152,13 +152,13 @@ def _compute_frame_pts(self) -> None:
with tqdm(total=len(dl)) as pbar:
for batch in dl:
pbar.update(1)
clips, fps = list(zip(*batch))
batch_pts, batch_fps = list(zip(*batch))
Copy link
Member Author

Choose a reason for hiding this comment

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

This is just renaming of local variables. The main thing is: the variable that used to be called clips really really should not have been called clips. These are pts (presentation time stamps) for each frame in the videos. Nothing to do with a clip in this VideoClips context.

# we need to specify dtype=torch.long because for empty list,
# torch.as_tensor will use torch.float as default dtype. This
# happens when decoding fails and no pts is returned in the list.
clips = [torch.as_tensor(c, dtype=torch.long) for c in clips]
self.video_pts.extend(clips)
self.video_fps.extend(fps)
batch_pts = [torch.as_tensor(pts, dtype=torch.long) for pts in batch_pts]
self.video_pts.extend(batch_pts)
self.video_fps.extend(batch_fps)

def _init_from_metadata(self, metadata: Dict[str, Any]) -> None:
self.video_paths = metadata["video_paths"]
Expand Down