Shortcuts

Video API

This example illustrates some of the APIs that torchvision offers for videos, together with the examples on how to build datasets and more.

1. Introduction: building a new video object and examining the properties

First we select a video to test the object out. For the sake of argument we’re using one from kinetics400 dataset. To create it, we need to define the path and the stream we want to use.

Chosen video statistics:

  • WUzgd7C1pWA.mp4
    • source:
      • kinetics-400

    • video:
      • H-264

      • MPEG-4 AVC (part 10) (avc1)

      • fps: 29.97

    • audio:
      • MPEG AAC audio (mp4a)

      • sample rate: 48K Hz

import torch
import torchvision
from torchvision.datasets.utils import download_url

# Download the sample video
download_url(
    "https://github.com/pytorch/vision/blob/main/test/assets/videos/WUzgd7C1pWA.mp4?raw=true",
    ".",
    "WUzgd7C1pWA.mp4"
)
video_path = "./WUzgd7C1pWA.mp4"

Out:

Downloading https://raw.githubusercontent.com/pytorch/vision/main/test/assets/videos/WUzgd7C1pWA.mp4 to ./WUzgd7C1pWA.mp4

0.1%
0.2%
0.3%
0.5%
0.6%
0.7%
0.8%
0.9%
1.0%
1.2%
1.3%
1.4%
1.5%
1.6%
1.7%
1.8%
2.0%
2.1%
2.2%
2.3%
2.4%
2.5%
2.6%
2.8%
2.9%
3.0%
3.1%
3.2%
3.3%
3.5%
3.6%
3.7%
3.8%
3.9%
4.0%
4.1%
4.3%
4.4%
4.5%
4.6%
4.7%
4.8%
4.9%
5.1%
5.2%
5.3%
5.4%
5.5%
5.6%
5.8%
5.9%
6.0%
6.1%
6.2%
6.3%
6.4%
6.6%
6.7%
6.8%
6.9%
7.0%
7.1%
7.3%
7.4%
7.5%
7.6%
7.7%
7.8%
7.9%
8.1%
8.2%
8.3%
8.4%
8.5%
8.6%
8.7%
8.9%
9.0%
9.1%
9.2%
9.3%
9.4%
9.6%
9.7%
9.8%
9.9%
10.0%
10.1%
10.2%
10.4%
10.5%
10.6%
10.7%
10.8%
10.9%
11.1%
11.2%
11.3%
11.4%
11.5%
11.6%
11.7%
11.9%
12.0%
12.1%
12.2%
12.3%
12.4%
12.5%
12.7%
12.8%
12.9%
13.0%
13.1%
13.2%
13.4%
13.5%
13.6%
13.7%
13.8%
13.9%
14.0%
14.2%
14.3%
14.4%
14.5%
14.6%
14.7%
14.8%
15.0%
15.1%
15.2%
15.3%
15.4%
15.5%
15.7%
15.8%
15.9%
16.0%
16.1%
16.2%
16.3%
16.5%
16.6%
16.7%
16.8%
16.9%
17.0%
17.2%
17.3%
17.4%
17.5%
17.6%
17.7%
17.8%
18.0%
18.1%
18.2%
18.3%
18.4%
18.5%
18.6%
18.8%
18.9%
19.0%
19.1%
19.2%
19.3%
19.5%
19.6%
19.7%
19.8%
19.9%
20.0%
20.1%
20.3%
20.4%
20.5%
20.6%
20.7%
20.8%
20.9%
21.1%
21.2%
21.3%
21.4%
21.5%
21.6%
21.8%
21.9%
22.0%
22.1%
22.2%
22.3%
22.4%
22.6%
22.7%
22.8%
22.9%
23.0%
23.1%
23.3%
23.4%
23.5%
23.6%
23.7%
23.8%
23.9%
24.1%
24.2%
24.3%
24.4%
24.5%
24.6%
24.7%
24.9%
25.0%
25.1%
25.2%
25.3%
25.4%
25.6%
25.7%
25.8%
25.9%
26.0%
26.1%
26.2%
26.4%
26.5%
26.6%
26.7%
26.8%
26.9%
27.0%
27.2%
27.3%
27.4%
27.5%
27.6%
27.7%
27.9%
28.0%
28.1%
28.2%
28.3%
28.4%
28.5%
28.7%
28.8%
28.9%
29.0%
29.1%
29.2%
29.4%
29.5%
29.6%
29.7%
29.8%
29.9%
30.0%
30.2%
30.3%
30.4%
30.5%
30.6%
30.7%
30.8%
31.0%
31.1%
31.2%
31.3%
31.4%
31.5%
31.7%
31.8%
31.9%
32.0%
32.1%
32.2%
32.3%
32.5%
32.6%
32.7%
32.8%
32.9%
33.0%
33.2%
33.3%
33.4%
33.5%
33.6%
33.7%
33.8%
34.0%
34.1%
34.2%
34.3%
34.4%
34.5%
34.6%
34.8%
34.9%
35.0%
35.1%
35.2%
35.3%
35.5%
35.6%
35.7%
35.8%
35.9%
36.0%
36.1%
36.3%
36.4%
36.5%
36.6%
36.7%
36.8%
36.9%
37.1%
37.2%
37.3%
37.4%
37.5%
37.6%
37.8%
37.9%
38.0%
38.1%
38.2%
38.3%
38.4%
38.6%
38.7%
38.8%
38.9%
39.0%
39.1%
39.3%
39.4%
39.5%
39.6%
39.7%
39.8%
39.9%
40.1%
40.2%
40.3%
40.4%
40.5%
40.6%
40.7%
40.9%
41.0%
41.1%
41.2%
41.3%
41.4%
41.6%
41.7%
41.8%
41.9%
42.0%
42.1%
42.2%
42.4%
42.5%
42.6%
42.7%
42.8%
42.9%
43.0%
43.2%
43.3%
43.4%
43.5%
43.6%
43.7%
43.9%
44.0%
44.1%
44.2%
44.3%
44.4%
44.5%
44.7%
44.8%
44.9%
45.0%
45.1%
45.2%
45.4%
45.5%
45.6%
45.7%
45.8%
45.9%
46.0%
46.2%
46.3%
46.4%
46.5%
46.6%
46.7%
46.8%
47.0%
47.1%
47.2%
47.3%
47.4%
47.5%
47.7%
47.8%
47.9%
48.0%
48.1%
48.2%
48.3%
48.5%
48.6%
48.7%
48.8%
48.9%
49.0%
49.2%
49.3%
49.4%
49.5%
49.6%
49.7%
49.8%
50.0%
50.1%
50.2%
50.3%
50.4%
50.5%
50.6%
50.8%
50.9%
51.0%
51.1%
51.2%
51.3%
51.5%
51.6%
51.7%
51.8%
51.9%
52.0%
52.1%
52.3%
52.4%
52.5%
52.6%
52.7%
52.8%
52.9%
53.1%
53.2%
53.3%
53.4%
53.5%
53.6%
53.8%
53.9%
54.0%
54.1%
54.2%
54.3%
54.4%
54.6%
54.7%
54.8%
54.9%
55.0%
55.1%
55.3%
55.4%
55.5%
55.6%
55.7%
55.8%
55.9%
56.1%
56.2%
56.3%
56.4%
56.5%
56.6%
56.7%
56.9%
57.0%
57.1%
57.2%
57.3%
57.4%
57.6%
57.7%
57.8%
57.9%
58.0%
58.1%
58.2%
58.4%
58.5%
58.6%
58.7%
58.8%
58.9%
59.0%
59.2%
59.3%
59.4%
59.5%
59.6%
59.7%
59.9%
60.0%
60.1%
60.2%
60.3%
60.4%
60.5%
60.7%
60.8%
60.9%
61.0%
61.1%
61.2%
61.4%
61.5%
61.6%
61.7%
61.8%
61.9%
62.0%
62.2%
62.3%
62.4%
62.5%
62.6%
62.7%
62.8%
63.0%
63.1%
63.2%
63.3%
63.4%
63.5%
63.7%
63.8%
63.9%
64.0%
64.1%
64.2%
64.3%
64.5%
64.6%
64.7%
64.8%
64.9%
65.0%
65.1%
65.3%
65.4%
65.5%
65.6%
65.7%
65.8%
66.0%
66.1%
66.2%
66.3%
66.4%
66.5%
66.6%
66.8%
66.9%
67.0%
67.1%
67.2%
67.3%
67.5%
67.6%
67.7%
67.8%
67.9%
68.0%
68.1%
68.3%
68.4%
68.5%
68.6%
68.7%
68.8%
68.9%
69.1%
69.2%
69.3%
69.4%
69.5%
69.6%
69.8%
69.9%
70.0%
70.1%
70.2%
70.3%
70.4%
70.6%
70.7%
70.8%
70.9%
71.0%
71.1%
71.3%
71.4%
71.5%
71.6%
71.7%
71.8%
71.9%
72.1%
72.2%
72.3%
72.4%
72.5%
72.6%
72.7%
72.9%
73.0%
73.1%
73.2%
73.3%
73.4%
73.6%
73.7%
73.8%
73.9%
74.0%
74.1%
74.2%
74.4%
74.5%
74.6%
74.7%
74.8%
74.9%
75.0%
75.2%
75.3%
75.4%
75.5%
75.6%
75.7%
75.9%
76.0%
76.1%
76.2%
76.3%
76.4%
76.5%
76.7%
76.8%
76.9%
77.0%
77.1%
77.2%
77.4%
77.5%
77.6%
77.7%
77.8%
77.9%
78.0%
78.2%
78.3%
78.4%
78.5%
78.6%
78.7%
78.8%
79.0%
79.1%
79.2%
79.3%
79.4%
79.5%
79.7%
79.8%
79.9%
80.0%
80.1%
80.2%
80.3%
80.5%
80.6%
80.7%
80.8%
80.9%
81.0%
81.1%
81.3%
81.4%
81.5%
81.6%
81.7%
81.8%
82.0%
82.1%
82.2%
82.3%
82.4%
82.5%
82.6%
82.8%
82.9%
83.0%
83.1%
83.2%
83.3%
83.5%
83.6%
83.7%
83.8%
83.9%
84.0%
84.1%
84.3%
84.4%
84.5%
84.6%
84.7%
84.8%
84.9%
85.1%
85.2%
85.3%
85.4%
85.5%
85.6%
85.8%
85.9%
86.0%
86.1%
86.2%
86.3%
86.4%
86.6%
86.7%
86.8%
86.9%
87.0%
87.1%
87.2%
87.4%
87.5%
87.6%
87.7%
87.8%
87.9%
88.1%
88.2%
88.3%
88.4%
88.5%
88.6%
88.7%
88.9%
89.0%
89.1%
89.2%
89.3%
89.4%
89.6%
89.7%
89.8%
89.9%
90.0%
90.1%
90.2%
90.4%
90.5%
90.6%
90.7%
90.8%
90.9%
91.0%
91.2%
91.3%
91.4%
91.5%
91.6%
91.7%
91.9%
92.0%
92.1%
92.2%
92.3%
92.4%
92.5%
92.7%
92.8%
92.9%
93.0%
93.1%
93.2%
93.4%
93.5%
93.6%
93.7%
93.8%
93.9%
94.0%
94.2%
94.3%
94.4%
94.5%
94.6%
94.7%
94.8%
95.0%
95.1%
95.2%
95.3%
95.4%
95.5%
95.7%
95.8%
95.9%
96.0%
96.1%
96.2%
96.3%
96.5%
96.6%
96.7%
96.8%
96.9%
97.0%
97.1%
97.3%
97.4%
97.5%
97.6%
97.7%
97.8%
98.0%
98.1%
98.2%
98.3%
98.4%
98.5%
98.6%
98.8%
98.9%
99.0%
99.1%
99.2%
99.3%
99.5%
99.6%
99.7%
99.8%
99.9%
100.0%

Streams are defined in a similar fashion as torch devices. We encode them as strings in a form of stream_type:stream_id where stream_type is a string and stream_id a long int. The constructor accepts passing a stream_type only, in which case the stream is auto-discovered. Firstly, let’s get the metadata for our particular video:

stream = "video"
video = torchvision.io.VideoReader(video_path, stream)
video.get_metadata()

Out:

{'video': {'duration': [10.9109], 'fps': [29.97002997002997]}, 'audio': {'duration': [10.9], 'framerate': [48000.0]}, 'subtitles': {'duration': []}, 'cc': {'duration': []}}

Here we can see that video has two streams - a video and an audio stream. Currently available stream types include [‘video’, ‘audio’]. Each descriptor consists of two parts: stream type (e.g. ‘video’) and a unique stream id (which are determined by video encoding). In this way, if the video container contains multiple streams of the same type, users can access the one they want. If only stream type is passed, the decoder auto-detects first stream of that type and returns it.

Let’s read all the frames from the video stream. By default, the return value of next(video_reader) is a dict containing the following fields.

The return fields are:

  • data: containing a torch.tensor

  • pts: containing a float timestamp of this particular frame

metadata = video.get_metadata()
video.set_current_stream("audio")

frames = []  # we are going to save the frames here.
ptss = []  # pts is a presentation timestamp in seconds (float) of each frame
for frame in video:
    frames.append(frame['data'])
    ptss.append(frame['pts'])

print("PTS for first five frames ", ptss[:5])
print("Total number of frames: ", len(frames))
approx_nf = metadata['audio']['duration'][0] * metadata['audio']['framerate'][0]
print("Approx total number of datapoints we can expect: ", approx_nf)
print("Read data size: ", frames[0].size(0) * len(frames))

Out:

PTS for first five frames  [0.0, 0.021332999999999998, 0.042667, 0.064, 0.08533299999999999]
Total number of frames:  511
Approx total number of datapoints we can expect:  523200.0
Read data size:  523264

But what if we only want to read certain time segment of the video? That can be done easily using the combination of our seek function, and the fact that each call to next returns the presentation timestamp of the returned frame in seconds.

Given that our implementation relies on python iterators, we can leverage itertools to simplify the process and make it more pythonic.

For example, if we wanted to read ten frames from second second:

import itertools
video.set_current_stream("video")

frames = []  # we are going to save the frames here.

# We seek into a second second of the video and use islice to get 10 frames since
for frame, pts in itertools.islice(video.seek(2), 10):
    frames.append(frame)

print("Total number of frames: ", len(frames))

Out:

Total number of frames:  10

Or if we wanted to read from 2nd to 5th second, We seek into a second second of the video, then we utilize the itertools takewhile to get the correct number of frames:

video.set_current_stream("video")
frames = []  # we are going to save the frames here.
video = video.seek(2)

for frame in itertools.takewhile(lambda x: x['pts'] <= 5, video):
    frames.append(frame['data'])

print("Total number of frames: ", len(frames))
approx_nf = (5 - 2) * video.get_metadata()['video']['fps'][0]
print("We can expect approx: ", approx_nf)
print("Tensor size: ", frames[0].size())

Out:

Total number of frames:  90
We can expect approx:  89.91008991008991
Tensor size:  torch.Size([3, 256, 340])

2. Building a sample read_video function

We can utilize the methods above to build the read video function that follows the same API to the existing read_video function.

def example_read_video(video_object, start=0, end=None, read_video=True, read_audio=True):
    if end is None:
        end = float("inf")
    if end < start:
        raise ValueError(
            "end time should be larger than start time, got "
            f"start time={start} and end time={end}"
        )

    video_frames = torch.empty(0)
    video_pts = []
    if read_video:
        video_object.set_current_stream("video")
        frames = []
        for frame in itertools.takewhile(lambda x: x['pts'] <= end, video_object.seek(start)):
            frames.append(frame['data'])
            video_pts.append(frame['pts'])
        if len(frames) > 0:
            video_frames = torch.stack(frames, 0)

    audio_frames = torch.empty(0)
    audio_pts = []
    if read_audio:
        video_object.set_current_stream("audio")
        frames = []
        for frame in itertools.takewhile(lambda x: x['pts'] <= end, video_object.seek(start)):
            frames.append(frame['data'])
            video_pts.append(frame['pts'])
        if len(frames) > 0:
            audio_frames = torch.cat(frames, 0)

    return video_frames, audio_frames, (video_pts, audio_pts), video_object.get_metadata()


# Total number of frames should be 327 for video and 523264 datapoints for audio
vf, af, info, meta = example_read_video(video)
print(vf.size(), af.size())

Out:

torch.Size([327, 3, 256, 340]) torch.Size([523264, 1])

3. Building an example randomly sampled dataset (can be applied to training dataest of kinetics400)

Cool, so now we can use the same principle to make the sample dataset. We suggest trying out iterable dataset for this purpose. Here, we are going to build an example dataset that reads randomly selected 10 frames of video.

Make sample dataset

import os
os.makedirs("./dataset", exist_ok=True)
os.makedirs("./dataset/1", exist_ok=True)
os.makedirs("./dataset/2", exist_ok=True)

Download the videos

from torchvision.datasets.utils import download_url
download_url(
    "https://github.com/pytorch/vision/blob/main/test/assets/videos/WUzgd7C1pWA.mp4?raw=true",
    "./dataset/1", "WUzgd7C1pWA.mp4"
)
download_url(
    "https://github.com/pytorch/vision/blob/main/test/assets/videos/RATRACE_wave_f_nm_np1_fr_goo_37.avi?raw=true",
    "./dataset/1",
    "RATRACE_wave_f_nm_np1_fr_goo_37.avi"
)
download_url(
    "https://github.com/pytorch/vision/blob/main/test/assets/videos/SOX5yA1l24A.mp4?raw=true",
    "./dataset/2",
    "SOX5yA1l24A.mp4"
)
download_url(
    "https://github.com/pytorch/vision/blob/main/test/assets/videos/v_SoccerJuggling_g23_c01.avi?raw=true",
    "./dataset/2",
    "v_SoccerJuggling_g23_c01.avi"
)
download_url(
    "https://github.com/pytorch/vision/blob/main/test/assets/videos/v_SoccerJuggling_g24_c01.avi?raw=true",
    "./dataset/2",
    "v_SoccerJuggling_g24_c01.avi"
)

Out:

Downloading https://raw.githubusercontent.com/pytorch/vision/main/test/assets/videos/WUzgd7C1pWA.mp4 to ./dataset/1/WUzgd7C1pWA.mp4

0.1%
0.2%
0.3%
0.5%
0.6%
0.7%
0.8%
0.9%
1.0%
1.2%
1.3%
1.4%
1.5%
1.6%
1.7%
1.8%
2.0%
2.1%
2.2%
2.3%
2.4%
2.5%
2.6%
2.8%
2.9%
3.0%
3.1%
3.2%
3.3%
3.5%
3.6%
3.7%
3.8%
3.9%
4.0%
4.1%
4.3%
4.4%
4.5%
4.6%
4.7%
4.8%
4.9%
5.1%
5.2%
5.3%
5.4%
5.5%
5.6%
5.8%
5.9%
6.0%
6.1%
6.2%
6.3%
6.4%
6.6%
6.7%
6.8%
6.9%
7.0%
7.1%
7.3%
7.4%
7.5%
7.6%
7.7%
7.8%
7.9%
8.1%
8.2%
8.3%
8.4%
8.5%
8.6%
8.7%
8.9%
9.0%
9.1%
9.2%
9.3%
9.4%
9.6%
9.7%
9.8%
9.9%
10.0%
10.1%
10.2%
10.4%
10.5%
10.6%
10.7%
10.8%
10.9%
11.1%
11.2%
11.3%
11.4%
11.5%
11.6%
11.7%
11.9%
12.0%
12.1%
12.2%
12.3%
12.4%
12.5%
12.7%
12.8%
12.9%
13.0%
13.1%
13.2%
13.4%
13.5%
13.6%
13.7%
13.8%
13.9%
14.0%
14.2%
14.3%
14.4%
14.5%
14.6%
14.7%
14.8%
15.0%
15.1%
15.2%
15.3%
15.4%
15.5%
15.7%
15.8%
15.9%
16.0%
16.1%
16.2%
16.3%
16.5%
16.6%
16.7%
16.8%
16.9%
17.0%
17.2%
17.3%
17.4%
17.5%
17.6%
17.7%
17.8%
18.0%
18.1%
18.2%
18.3%
18.4%
18.5%
18.6%
18.8%
18.9%
19.0%
19.1%
19.2%
19.3%
19.5%
19.6%
19.7%
19.8%
19.9%
20.0%
20.1%
20.3%
20.4%
20.5%
20.6%
20.7%
20.8%
20.9%
21.1%
21.2%
21.3%
21.4%
21.5%
21.6%
21.8%
21.9%
22.0%
22.1%
22.2%
22.3%
22.4%
22.6%
22.7%
22.8%
22.9%
23.0%
23.1%
23.3%
23.4%
23.5%
23.6%
23.7%
23.8%
23.9%
24.1%
24.2%
24.3%
24.4%
24.5%
24.6%
24.7%
24.9%
25.0%
25.1%
25.2%
25.3%
25.4%
25.6%
25.7%
25.8%
25.9%
26.0%
26.1%
26.2%
26.4%
26.5%
26.6%
26.7%
26.8%
26.9%
27.0%
27.2%
27.3%
27.4%
27.5%
27.6%
27.7%
27.9%
28.0%
28.1%
28.2%
28.3%
28.4%
28.5%
28.7%
28.8%
28.9%
29.0%
29.1%
29.2%
29.4%
29.5%
29.6%
29.7%
29.8%
29.9%
30.0%
30.2%
30.3%
30.4%
30.5%
30.6%
30.7%
30.8%
31.0%
31.1%
31.2%
31.3%
31.4%
31.5%
31.7%
31.8%
31.9%
32.0%
32.1%
32.2%
32.3%
32.5%
32.6%
32.7%
32.8%
32.9%
33.0%
33.2%
33.3%
33.4%
33.5%
33.6%
33.7%
33.8%
34.0%
34.1%
34.2%
34.3%
34.4%
34.5%
34.6%
34.8%
34.9%
35.0%
35.1%
35.2%
35.3%
35.5%
35.6%
35.7%
35.8%
35.9%
36.0%
36.1%
36.3%
36.4%
36.5%
36.6%
36.7%
36.8%
36.9%
37.1%
37.2%
37.3%
37.4%
37.5%
37.6%
37.8%
37.9%
38.0%
38.1%
38.2%
38.3%
38.4%
38.6%
38.7%
38.8%
38.9%
39.0%
39.1%
39.3%
39.4%
39.5%
39.6%
39.7%
39.8%
39.9%
40.1%
40.2%
40.3%
40.4%
40.5%
40.6%
40.7%
40.9%
41.0%
41.1%
41.2%
41.3%
41.4%
41.6%
41.7%
41.8%
41.9%
42.0%
42.1%
42.2%
42.4%
42.5%
42.6%
42.7%
42.8%
42.9%
43.0%
43.2%
43.3%
43.4%
43.5%
43.6%
43.7%
43.9%
44.0%
44.1%
44.2%
44.3%
44.4%
44.5%
44.7%
44.8%
44.9%
45.0%
45.1%
45.2%
45.4%
45.5%
45.6%
45.7%
45.8%
45.9%
46.0%
46.2%
46.3%
46.4%
46.5%
46.6%
46.7%
46.8%
47.0%
47.1%
47.2%
47.3%
47.4%
47.5%
47.7%
47.8%
47.9%
48.0%
48.1%
48.2%
48.3%
48.5%
48.6%
48.7%
48.8%
48.9%
49.0%
49.2%
49.3%
49.4%
49.5%
49.6%
49.7%
49.8%
50.0%
50.1%
50.2%
50.3%
50.4%
50.5%
50.6%
50.8%
50.9%
51.0%
51.1%
51.2%
51.3%
51.5%
51.6%
51.7%
51.8%
51.9%
52.0%
52.1%
52.3%
52.4%
52.5%
52.6%
52.7%
52.8%
52.9%
53.1%
53.2%
53.3%
53.4%
53.5%
53.6%
53.8%
53.9%
54.0%
54.1%
54.2%
54.3%
54.4%
54.6%
54.7%
54.8%
54.9%
55.0%
55.1%
55.3%
55.4%
55.5%
55.6%
55.7%
55.8%
55.9%
56.1%
56.2%
56.3%
56.4%
56.5%
56.6%
56.7%
56.9%
57.0%
57.1%
57.2%
57.3%
57.4%
57.6%
57.7%
57.8%
57.9%
58.0%
58.1%
58.2%
58.4%
58.5%
58.6%
58.7%
58.8%
58.9%
59.0%
59.2%
59.3%
59.4%
59.5%
59.6%
59.7%
59.9%
60.0%
60.1%
60.2%
60.3%
60.4%
60.5%
60.7%
60.8%
60.9%
61.0%
61.1%
61.2%
61.4%
61.5%
61.6%
61.7%
61.8%
61.9%
62.0%
62.2%
62.3%
62.4%
62.5%
62.6%
62.7%
62.8%
63.0%
63.1%
63.2%
63.3%
63.4%
63.5%
63.7%
63.8%
63.9%
64.0%
64.1%
64.2%
64.3%
64.5%
64.6%
64.7%
64.8%
64.9%
65.0%
65.1%
65.3%
65.4%
65.5%
65.6%
65.7%
65.8%
66.0%
66.1%
66.2%
66.3%
66.4%
66.5%
66.6%
66.8%
66.9%
67.0%
67.1%
67.2%
67.3%
67.5%
67.6%
67.7%
67.8%
67.9%
68.0%
68.1%
68.3%
68.4%
68.5%
68.6%
68.7%
68.8%
68.9%
69.1%
69.2%
69.3%
69.4%
69.5%
69.6%
69.8%
69.9%
70.0%
70.1%
70.2%
70.3%
70.4%
70.6%
70.7%
70.8%
70.9%
71.0%
71.1%
71.3%
71.4%
71.5%
71.6%
71.7%
71.8%
71.9%
72.1%
72.2%
72.3%
72.4%
72.5%
72.6%
72.7%
72.9%
73.0%
73.1%
73.2%
73.3%
73.4%
73.6%
73.7%
73.8%
73.9%
74.0%
74.1%
74.2%
74.4%
74.5%
74.6%
74.7%
74.8%
74.9%
75.0%
75.2%
75.3%
75.4%
75.5%
75.6%
75.7%
75.9%
76.0%
76.1%
76.2%
76.3%
76.4%
76.5%
76.7%
76.8%
76.9%
77.0%
77.1%
77.2%
77.4%
77.5%
77.6%
77.7%
77.8%
77.9%
78.0%
78.2%
78.3%
78.4%
78.5%
78.6%
78.7%
78.8%
79.0%
79.1%
79.2%
79.3%
79.4%
79.5%
79.7%
79.8%
79.9%
80.0%
80.1%
80.2%
80.3%
80.5%
80.6%
80.7%
80.8%
80.9%
81.0%
81.1%
81.3%
81.4%
81.5%
81.6%
81.7%
81.8%
82.0%
82.1%
82.2%
82.3%
82.4%
82.5%
82.6%
82.8%
82.9%
83.0%
83.1%
83.2%
83.3%
83.5%
83.6%
83.7%
83.8%
83.9%
84.0%
84.1%
84.3%
84.4%
84.5%
84.6%
84.7%
84.8%
84.9%
85.1%
85.2%
85.3%
85.4%
85.5%
85.6%
85.8%
85.9%
86.0%
86.1%
86.2%
86.3%
86.4%
86.6%
86.7%
86.8%
86.9%
87.0%
87.1%
87.2%
87.4%
87.5%
87.6%
87.7%
87.8%
87.9%
88.1%
88.2%
88.3%
88.4%
88.5%
88.6%
88.7%
88.9%
89.0%
89.1%
89.2%
89.3%
89.4%
89.6%
89.7%
89.8%
89.9%
90.0%
90.1%
90.2%
90.4%
90.5%
90.6%
90.7%
90.8%
90.9%
91.0%
91.2%
91.3%
91.4%
91.5%
91.6%
91.7%
91.9%
92.0%
92.1%
92.2%
92.3%
92.4%
92.5%
92.7%
92.8%
92.9%
93.0%
93.1%
93.2%
93.4%
93.5%
93.6%
93.7%
93.8%
93.9%
94.0%
94.2%
94.3%
94.4%
94.5%
94.6%
94.7%
94.8%
95.0%
95.1%
95.2%
95.3%
95.4%
95.5%
95.7%
95.8%
95.9%
96.0%
96.1%
96.2%
96.3%
96.5%
96.6%
96.7%
96.8%
96.9%
97.0%
97.1%
97.3%
97.4%
97.5%
97.6%
97.7%
97.8%
98.0%
98.1%
98.2%
98.3%
98.4%
98.5%
98.6%
98.8%
98.9%
99.0%
99.1%
99.2%
99.3%
99.5%
99.6%
99.7%
99.8%
99.9%
100.0%
Downloading https://raw.githubusercontent.com/pytorch/vision/main/test/assets/videos/RATRACE_wave_f_nm_np1_fr_goo_37.avi to ./dataset/1/RATRACE_wave_f_nm_np1_fr_goo_37.avi

0.4%
0.8%
1.2%
1.6%
1.9%
2.3%
2.7%
3.1%
3.5%
3.9%
4.3%
4.7%
5.0%
5.4%
5.8%
6.2%
6.6%
7.0%
7.4%
7.8%
8.2%
8.5%
8.9%
9.3%
9.7%
10.1%
10.5%
10.9%
11.3%
11.7%
12.0%
12.4%
12.8%
13.2%
13.6%
14.0%
14.4%
14.8%
15.1%
15.5%
15.9%
16.3%
16.7%
17.1%
17.5%
17.9%
18.3%
18.6%
19.0%
19.4%
19.8%
20.2%
20.6%
21.0%
21.4%
21.7%
22.1%
22.5%
22.9%
23.3%
23.7%
24.1%
24.5%
24.9%
25.2%
25.6%
26.0%
26.4%
26.8%
27.2%
27.6%
28.0%
28.3%
28.7%
29.1%
29.5%
29.9%
30.3%
30.7%
31.1%
31.5%
31.8%
32.2%
32.6%
33.0%
33.4%
33.8%
34.2%
34.6%
35.0%
35.3%
35.7%
36.1%
36.5%
36.9%
37.3%
37.7%
38.1%
38.4%
38.8%
39.2%
39.6%
40.0%
40.4%
40.8%
41.2%
41.6%
41.9%
42.3%
42.7%
43.1%
43.5%
43.9%
44.3%
44.7%
45.0%
45.4%
45.8%
46.2%
46.6%
47.0%
47.4%
47.8%
48.2%
48.5%
48.9%
49.3%
49.7%
50.1%
50.5%
50.9%
51.3%
51.7%
52.0%
52.4%
52.8%
53.2%
53.6%
54.0%
54.4%
54.8%
55.1%
55.5%
55.9%
56.3%
56.7%
57.1%
57.5%
57.9%
58.3%
58.6%
59.0%
59.4%
59.8%
60.2%
60.6%
61.0%
61.4%
61.7%
62.1%
62.5%
62.9%
63.3%
63.7%
64.1%
64.5%
64.9%
65.2%
65.6%
66.0%
66.4%
66.8%
67.2%
67.6%
68.0%
68.3%
68.7%
69.1%
69.5%
69.9%
70.3%
70.7%
71.1%
71.5%
71.8%
72.2%
72.6%
73.0%
73.4%
73.8%
74.2%
74.6%
75.0%
75.3%
75.7%
76.1%
76.5%
76.9%
77.3%
77.7%
78.1%
78.4%
78.8%
79.2%
79.6%
80.0%
80.4%
80.8%
81.2%
81.6%
81.9%
82.3%
82.7%
83.1%
83.5%
83.9%
84.3%
84.7%
85.0%
85.4%
85.8%
86.2%
86.6%
87.0%
87.4%
87.8%
88.2%
88.5%
88.9%
89.3%
89.7%
90.1%
90.5%
90.9%
91.3%
91.7%
92.0%
92.4%
92.8%
93.2%
93.6%
94.0%
94.4%
94.8%
95.1%
95.5%
95.9%
96.3%
96.7%
97.1%
97.5%
97.9%
98.3%
98.6%
99.0%
99.4%
99.8%
100.2%
Downloading https://raw.githubusercontent.com/pytorch/vision/main/test/assets/videos/SOX5yA1l24A.mp4 to ./dataset/2/SOX5yA1l24A.mp4

0.2%
0.4%
0.5%
0.7%
0.9%
1.1%
1.3%
1.5%
1.6%
1.8%
2.0%
2.2%
2.4%
2.6%
2.7%
2.9%
3.1%
3.3%
3.5%
3.7%
3.8%
4.0%
4.2%
4.4%
4.6%
4.8%
4.9%
5.1%
5.3%
5.5%
5.7%
5.8%
6.0%
6.2%
6.4%
6.6%
6.8%
6.9%
7.1%
7.3%
7.5%
7.7%
7.9%
8.0%
8.2%
8.4%
8.6%
8.8%
9.0%
9.1%
9.3%
9.5%
9.7%
9.9%
10.1%
10.2%
10.4%
10.6%
10.8%
11.0%
11.1%
11.3%
11.5%
11.7%
11.9%
12.1%
12.2%
12.4%
12.6%
12.8%
13.0%
13.2%
13.3%
13.5%
13.7%
13.9%
14.1%
14.3%
14.4%
14.6%
14.8%
15.0%
15.2%
15.4%
15.5%
15.7%
15.9%
16.1%
16.3%
16.4%
16.6%
16.8%
17.0%
17.2%
17.4%
17.5%
17.7%
17.9%
18.1%
18.3%
18.5%
18.6%
18.8%
19.0%
19.2%
19.4%
19.6%
19.7%
19.9%
20.1%
20.3%
20.5%
20.7%
20.8%
21.0%
21.2%
21.4%
21.6%
21.7%
21.9%
22.1%
22.3%
22.5%
22.7%
22.8%
23.0%
23.2%
23.4%
23.6%
23.8%
23.9%
24.1%
24.3%
24.5%
24.7%
24.9%
25.0%
25.2%
25.4%
25.6%
25.8%
26.0%
26.1%
26.3%
26.5%
26.7%
26.9%
27.0%
27.2%
27.4%
27.6%
27.8%
28.0%
28.1%
28.3%
28.5%
28.7%
28.9%
29.1%
29.2%
29.4%
29.6%
29.8%
30.0%
30.2%
30.3%
30.5%
30.7%
30.9%
31.1%
31.3%
31.4%
31.6%
31.8%
32.0%
32.2%
32.3%
32.5%
32.7%
32.9%
33.1%
33.3%
33.4%
33.6%
33.8%
34.0%
34.2%
34.4%
34.5%
34.7%
34.9%
35.1%
35.3%
35.5%
35.6%
35.8%
36.0%
36.2%
36.4%
36.6%
36.7%
36.9%
37.1%
37.3%
37.5%
37.6%
37.8%
38.0%
38.2%
38.4%
38.6%
38.7%
38.9%
39.1%
39.3%
39.5%
39.7%
39.8%
40.0%
40.2%
40.4%
40.6%
40.8%
40.9%
41.1%
41.3%
41.5%
41.7%
41.9%
42.0%
42.2%
42.4%
42.6%
42.8%
42.9%
43.1%
43.3%
43.5%
43.7%
43.9%
44.0%
44.2%
44.4%
44.6%
44.8%
45.0%
45.1%
45.3%
45.5%
45.7%
45.9%
46.1%
46.2%
46.4%
46.6%
46.8%
47.0%
47.2%
47.3%
47.5%
47.7%
47.9%
48.1%
48.2%
48.4%
48.6%
48.8%
49.0%
49.2%
49.3%
49.5%
49.7%
49.9%
50.1%
50.3%
50.4%
50.6%
50.8%
51.0%
51.2%
51.4%
51.5%
51.7%
51.9%
52.1%
52.3%
52.5%
52.6%
52.8%
53.0%
53.2%
53.4%
53.5%
53.7%
53.9%
54.1%
54.3%
54.5%
54.6%
54.8%
55.0%
55.2%
55.4%
55.6%
55.7%
55.9%
56.1%
56.3%
56.5%
56.7%
56.8%
57.0%
57.2%
57.4%
57.6%
57.8%
57.9%
58.1%
58.3%
58.5%
58.7%
58.8%
59.0%
59.2%
59.4%
59.6%
59.8%
59.9%
60.1%
60.3%
60.5%
60.7%
60.9%
61.0%
61.2%
61.4%
61.6%
61.8%
62.0%
62.1%
62.3%
62.5%
62.7%
62.9%
63.1%
63.2%
63.4%
63.6%
63.8%
64.0%
64.1%
64.3%
64.5%
64.7%
64.9%
65.1%
65.2%
65.4%
65.6%
65.8%
66.0%
66.2%
66.3%
66.5%
66.7%
66.9%
67.1%
67.3%
67.4%
67.6%
67.8%
68.0%
68.2%
68.4%
68.5%
68.7%
68.9%
69.1%
69.3%
69.4%
69.6%
69.8%
70.0%
70.2%
70.4%
70.5%
70.7%
70.9%
71.1%
71.3%
71.5%
71.6%
71.8%
72.0%
72.2%
72.4%
72.6%
72.7%
72.9%
73.1%
73.3%
73.5%
73.7%
73.8%
74.0%
74.2%
74.4%
74.6%
74.7%
74.9%
75.1%
75.3%
75.5%
75.7%
75.8%
76.0%
76.2%
76.4%
76.6%
76.8%
76.9%
77.1%
77.3%
77.5%
77.7%
77.9%
78.0%
78.2%
78.4%
78.6%
78.8%
79.0%
79.1%
79.3%
79.5%
79.7%
79.9%
80.0%
80.2%
80.4%
80.6%
80.8%
81.0%
81.1%
81.3%
81.5%
81.7%
81.9%
82.1%
82.2%
82.4%
82.6%
82.8%
83.0%
83.2%
83.3%
83.5%
83.7%
83.9%
84.1%
84.3%
84.4%
84.6%
84.8%
85.0%
85.2%
85.3%
85.5%
85.7%
85.9%
86.1%
86.3%
86.4%
86.6%
86.8%
87.0%
87.2%
87.4%
87.5%
87.7%
87.9%
88.1%
88.3%
88.5%
88.6%
88.8%
89.0%
89.2%
89.4%
89.6%
89.7%
89.9%
90.1%
90.3%
90.5%
90.6%
90.8%
91.0%
91.2%
91.4%
91.6%
91.7%
91.9%
92.1%
92.3%
92.5%
92.7%
92.8%
93.0%
93.2%
93.4%
93.6%
93.8%
93.9%
94.1%
94.3%
94.5%
94.7%
94.9%
95.0%
95.2%
95.4%
95.6%
95.8%
95.9%
96.1%
96.3%
96.5%
96.7%
96.9%
97.0%
97.2%
97.4%
97.6%
97.8%
98.0%
98.1%
98.3%
98.5%
98.7%
98.9%
99.1%
99.2%
99.4%
99.6%
99.8%
100.0%
100.2%
Downloading https://raw.githubusercontent.com/pytorch/vision/main/test/assets/videos/v_SoccerJuggling_g23_c01.avi to ./dataset/2/v_SoccerJuggling_g23_c01.avi

0.2%
0.4%
0.6%
0.8%
1.0%
1.2%
1.4%
1.6%
1.8%
2.0%
2.2%
2.4%
2.6%
2.8%
3.0%
3.2%
3.4%
3.6%
3.8%
4.0%
4.2%
4.4%
4.6%
4.8%
5.0%
5.2%
5.4%
5.6%
5.8%
6.0%
6.2%
6.4%
6.6%
6.8%
7.0%
7.3%
7.5%
7.7%
7.9%
8.1%
8.3%
8.5%
8.7%
8.9%
9.1%
9.3%
9.5%
9.7%
9.9%
10.1%
10.3%
10.5%
10.7%
10.9%
11.1%
11.3%
11.5%
11.7%
11.9%
12.1%
12.3%
12.5%
12.7%
12.9%
13.1%
13.3%
13.5%
13.7%
13.9%
14.1%
14.3%
14.5%
14.7%
14.9%
15.1%
15.3%
15.5%
15.7%
15.9%
16.1%
16.3%
16.5%
16.7%
16.9%
17.1%
17.3%
17.5%
17.7%
17.9%
18.1%
18.3%
18.5%
18.7%
18.9%
19.1%
19.3%
19.5%
19.7%
19.9%
20.1%
20.3%
20.5%
20.7%
20.9%
21.1%
21.4%
21.6%
21.8%
22.0%
22.2%
22.4%
22.6%
22.8%
23.0%
23.2%
23.4%
23.6%
23.8%
24.0%
24.2%
24.4%
24.6%
24.8%
25.0%
25.2%
25.4%
25.6%
25.8%
26.0%
26.2%
26.4%
26.6%
26.8%
27.0%
27.2%
27.4%
27.6%
27.8%
28.0%
28.2%
28.4%
28.6%
28.8%
29.0%
29.2%
29.4%
29.6%
29.8%
30.0%
30.2%
30.4%
30.6%
30.8%
31.0%
31.2%
31.4%
31.6%
31.8%
32.0%
32.2%
32.4%
32.6%
32.8%
33.0%
33.2%
33.4%
33.6%
33.8%
34.0%
34.2%
34.4%
34.6%
34.8%
35.0%
35.2%
35.4%
35.7%
35.9%
36.1%
36.3%
36.5%
36.7%
36.9%
37.1%
37.3%
37.5%
37.7%
37.9%
38.1%
38.3%
38.5%
38.7%
38.9%
39.1%
39.3%
39.5%
39.7%
39.9%
40.1%
40.3%
40.5%
40.7%
40.9%
41.1%
41.3%
41.5%
41.7%
41.9%
42.1%
42.3%
42.5%
42.7%
42.9%
43.1%
43.3%
43.5%
43.7%
43.9%
44.1%
44.3%
44.5%
44.7%
44.9%
45.1%
45.3%
45.5%
45.7%
45.9%
46.1%
46.3%
46.5%
46.7%
46.9%
47.1%
47.3%
47.5%
47.7%
47.9%
48.1%
48.3%
48.5%
48.7%
48.9%
49.1%
49.3%
49.5%
49.8%
50.0%
50.2%
50.4%
50.6%
50.8%
51.0%
51.2%
51.4%
51.6%
51.8%
52.0%
52.2%
52.4%
52.6%
52.8%
53.0%
53.2%
53.4%
53.6%
53.8%
54.0%
54.2%
54.4%
54.6%
54.8%
55.0%
55.2%
55.4%
55.6%
55.8%
56.0%
56.2%
56.4%
56.6%
56.8%
57.0%
57.2%
57.4%
57.6%
57.8%
58.0%
58.2%
58.4%
58.6%
58.8%
59.0%
59.2%
59.4%
59.6%
59.8%
60.0%
60.2%
60.4%
60.6%
60.8%
61.0%
61.2%
61.4%
61.6%
61.8%
62.0%
62.2%
62.4%
62.6%
62.8%
63.0%
63.2%
63.4%
63.6%
63.8%
64.1%
64.3%
64.5%
64.7%
64.9%
65.1%
65.3%
65.5%
65.7%
65.9%
66.1%
66.3%
66.5%
66.7%
66.9%
67.1%
67.3%
67.5%
67.7%
67.9%
68.1%
68.3%
68.5%
68.7%
68.9%
69.1%
69.3%
69.5%
69.7%
69.9%
70.1%
70.3%
70.5%
70.7%
70.9%
71.1%
71.3%
71.5%
71.7%
71.9%
72.1%
72.3%
72.5%
72.7%
72.9%
73.1%
73.3%
73.5%
73.7%
73.9%
74.1%
74.3%
74.5%
74.7%
74.9%
75.1%
75.3%
75.5%
75.7%
75.9%
76.1%
76.3%
76.5%
76.7%
76.9%
77.1%
77.3%
77.5%
77.7%
77.9%
78.2%
78.4%
78.6%
78.8%
79.0%
79.2%
79.4%
79.6%
79.8%
80.0%
80.2%
80.4%
80.6%
80.8%
81.0%
81.2%
81.4%
81.6%
81.8%
82.0%
82.2%
82.4%
82.6%
82.8%
83.0%
83.2%
83.4%
83.6%
83.8%
84.0%
84.2%
84.4%
84.6%
84.8%
85.0%
85.2%
85.4%
85.6%
85.8%
86.0%
86.2%
86.4%
86.6%
86.8%
87.0%
87.2%
87.4%
87.6%
87.8%
88.0%
88.2%
88.4%
88.6%
88.8%
89.0%
89.2%
89.4%
89.6%
89.8%
90.0%
90.2%
90.4%
90.6%
90.8%
91.0%
91.2%
91.4%
91.6%
91.8%
92.0%
92.2%
92.5%
92.7%
92.9%
93.1%
93.3%
93.5%
93.7%
93.9%
94.1%
94.3%
94.5%
94.7%
94.9%
95.1%
95.3%
95.5%
95.7%
95.9%
96.1%
96.3%
96.5%
96.7%
96.9%
97.1%
97.3%
97.5%
97.7%
97.9%
98.1%
98.3%
98.5%
98.7%
98.9%
99.1%
99.3%
99.5%
99.7%
99.9%
100.1%
Downloading https://raw.githubusercontent.com/pytorch/vision/main/test/assets/videos/v_SoccerJuggling_g24_c01.avi to ./dataset/2/v_SoccerJuggling_g24_c01.avi

0.2%
0.3%
0.5%
0.7%
0.8%
1.0%
1.2%
1.3%
1.5%
1.6%
1.8%
2.0%
2.1%
2.3%
2.5%
2.6%
2.8%
3.0%
3.1%
3.3%
3.5%
3.6%
3.8%
3.9%
4.1%
4.3%
4.4%
4.6%
4.8%
4.9%
5.1%
5.3%
5.4%
5.6%
5.8%
5.9%
6.1%
6.2%
6.4%
6.6%
6.7%
6.9%
7.1%
7.2%
7.4%
7.6%
7.7%
7.9%
8.1%
8.2%
8.4%
8.5%
8.7%
8.9%
9.0%
9.2%
9.4%
9.5%
9.7%
9.9%
10.0%
10.2%
10.4%
10.5%
10.7%
10.8%
11.0%
11.2%
11.3%
11.5%
11.7%
11.8%
12.0%
12.2%
12.3%
12.5%
12.7%
12.8%
13.0%
13.2%
13.3%
13.5%
13.6%
13.8%
14.0%
14.1%
14.3%
14.5%
14.6%
14.8%
15.0%
15.1%
15.3%
15.5%
15.6%
15.8%
15.9%
16.1%
16.3%
16.4%
16.6%
16.8%
16.9%
17.1%
17.3%
17.4%
17.6%
17.8%
17.9%
18.1%
18.2%
18.4%
18.6%
18.7%
18.9%
19.1%
19.2%
19.4%
19.6%
19.7%
19.9%
20.1%
20.2%
20.4%
20.5%
20.7%
20.9%
21.0%
21.2%
21.4%
21.5%
21.7%
21.9%
22.0%
22.2%
22.4%
22.5%
22.7%
22.9%
23.0%
23.2%
23.3%
23.5%
23.7%
23.8%
24.0%
24.2%
24.3%
24.5%
24.7%
24.8%
25.0%
25.2%
25.3%
25.5%
25.6%
25.8%
26.0%
26.1%
26.3%
26.5%
26.6%
26.8%
27.0%
27.1%
27.3%
27.5%
27.6%
27.8%
27.9%
28.1%
28.3%
28.4%
28.6%
28.8%
28.9%
29.1%
29.3%
29.4%
29.6%
29.8%
29.9%
30.1%
30.2%
30.4%
30.6%
30.7%
30.9%
31.1%
31.2%
31.4%
31.6%
31.7%
31.9%
32.1%
32.2%
32.4%
32.5%
32.7%
32.9%
33.0%
33.2%
33.4%
33.5%
33.7%
33.9%
34.0%
34.2%
34.4%
34.5%
34.7%
34.9%
35.0%
35.2%
35.3%
35.5%
35.7%
35.8%
36.0%
36.2%
36.3%
36.5%
36.7%
36.8%
37.0%
37.2%
37.3%
37.5%
37.6%
37.8%
38.0%
38.1%
38.3%
38.5%
38.6%
38.8%
39.0%
39.1%
39.3%
39.5%
39.6%
39.8%
39.9%
40.1%
40.3%
40.4%
40.6%
40.8%
40.9%
41.1%
41.3%
41.4%
41.6%
41.8%
41.9%
42.1%
42.2%
42.4%
42.6%
42.7%
42.9%
43.1%
43.2%
43.4%
43.6%
43.7%
43.9%
44.1%
44.2%
44.4%
44.5%
44.7%
44.9%
45.0%
45.2%
45.4%
45.5%
45.7%
45.9%
46.0%
46.2%
46.4%
46.5%
46.7%
46.9%
47.0%
47.2%
47.3%
47.5%
47.7%
47.8%
48.0%
48.2%
48.3%
48.5%
48.7%
48.8%
49.0%
49.2%
49.3%
49.5%
49.6%
49.8%
50.0%
50.1%
50.3%
50.5%
50.6%
50.8%
51.0%
51.1%
51.3%
51.5%
51.6%
51.8%
51.9%
52.1%
52.3%
52.4%
52.6%
52.8%
52.9%
53.1%
53.3%
53.4%
53.6%
53.8%
53.9%
54.1%
54.2%
54.4%
54.6%
54.7%
54.9%
55.1%
55.2%
55.4%
55.6%
55.7%
55.9%
56.1%
56.2%
56.4%
56.6%
56.7%
56.9%
57.0%
57.2%
57.4%
57.5%
57.7%
57.9%
58.0%
58.2%
58.4%
58.5%
58.7%
58.9%
59.0%
59.2%
59.3%
59.5%
59.7%
59.8%
60.0%
60.2%
60.3%
60.5%
60.7%
60.8%
61.0%
61.2%
61.3%
61.5%
61.6%
61.8%
62.0%
62.1%
62.3%
62.5%
62.6%
62.8%
63.0%
63.1%
63.3%
63.5%
63.6%
63.8%
63.9%
64.1%
64.3%
64.4%
64.6%
64.8%
64.9%
65.1%
65.3%
65.4%
65.6%
65.8%
65.9%
66.1%
66.2%
66.4%
66.6%
66.7%
66.9%
67.1%
67.2%
67.4%
67.6%
67.7%
67.9%
68.1%
68.2%
68.4%
68.6%
68.7%
68.9%
69.0%
69.2%
69.4%
69.5%
69.7%
69.9%
70.0%
70.2%
70.4%
70.5%
70.7%
70.9%
71.0%
71.2%
71.3%
71.5%
71.7%
71.8%
72.0%
72.2%
72.3%
72.5%
72.7%
72.8%
73.0%
73.2%
73.3%
73.5%
73.6%
73.8%
74.0%
74.1%
74.3%
74.5%
74.6%
74.8%
75.0%
75.1%
75.3%
75.5%
75.6%
75.8%
75.9%
76.1%
76.3%
76.4%
76.6%
76.8%
76.9%
77.1%
77.3%
77.4%
77.6%
77.8%
77.9%
78.1%
78.3%
78.4%
78.6%
78.7%
78.9%
79.1%
79.2%
79.4%
79.6%
79.7%
79.9%
80.1%
80.2%
80.4%
80.6%
80.7%
80.9%
81.0%
81.2%
81.4%
81.5%
81.7%
81.9%
82.0%
82.2%
82.4%
82.5%
82.7%
82.9%
83.0%
83.2%
83.3%
83.5%
83.7%
83.8%
84.0%
84.2%
84.3%
84.5%
84.7%
84.8%
85.0%
85.2%
85.3%
85.5%
85.6%
85.8%
86.0%
86.1%
86.3%
86.5%
86.6%
86.8%
87.0%
87.1%
87.3%
87.5%
87.6%
87.8%
87.9%
88.1%
88.3%
88.4%
88.6%
88.8%
88.9%
89.1%
89.3%
89.4%
89.6%
89.8%
89.9%
90.1%
90.3%
90.4%
90.6%
90.7%
90.9%
91.1%
91.2%
91.4%
91.6%
91.7%
91.9%
92.1%
92.2%
92.4%
92.6%
92.7%
92.9%
93.0%
93.2%
93.4%
93.5%
93.7%
93.9%
94.0%
94.2%
94.4%
94.5%
94.7%
94.9%
95.0%
95.2%
95.3%
95.5%
95.7%
95.8%
96.0%
96.2%
96.3%
96.5%
96.7%
96.8%
97.0%
97.2%
97.3%
97.5%
97.6%
97.8%
98.0%
98.1%
98.3%
98.5%
98.6%
98.8%
99.0%
99.1%
99.3%
99.5%
99.6%
99.8%
99.9%
100.1%

Housekeeping and utilities

import os
import random

from torchvision.datasets.folder import make_dataset
from torchvision import transforms as t


def _find_classes(dir):
    classes = [d.name for d in os.scandir(dir) if d.is_dir()]
    classes.sort()
    class_to_idx = {cls_name: i for i, cls_name in enumerate(classes)}
    return classes, class_to_idx


def get_samples(root, extensions=(".mp4", ".avi")):
    _, class_to_idx = _find_classes(root)
    return make_dataset(root, class_to_idx, extensions=extensions)

We are going to define the dataset and some basic arguments. We assume the structure of the FolderDataset, and add the following parameters:

  • clip_len: length of a clip in frames

  • frame_transform: transform for every frame individually

  • video_transform: transform on a video sequence

Note

We actually add epoch size as using IterableDataset() class allows us to naturally oversample clips or images from each video if needed.

class RandomDataset(torch.utils.data.IterableDataset):
    def __init__(self, root, epoch_size=None, frame_transform=None, video_transform=None, clip_len=16):
        super(RandomDataset).__init__()

        self.samples = get_samples(root)

        # Allow for temporal jittering
        if epoch_size is None:
            epoch_size = len(self.samples)
        self.epoch_size = epoch_size

        self.clip_len = clip_len
        self.frame_transform = frame_transform
        self.video_transform = video_transform

    def __iter__(self):
        for i in range(self.epoch_size):
            # Get random sample
            path, target = random.choice(self.samples)
            # Get video object
            vid = torchvision.io.VideoReader(path, "video")
            metadata = vid.get_metadata()
            video_frames = []  # video frame buffer

            # Seek and return frames
            max_seek = metadata["video"]['duration'][0] - (self.clip_len / metadata["video"]['fps'][0])
            start = random.uniform(0., max_seek)
            for frame in itertools.islice(vid.seek(start), self.clip_len):
                video_frames.append(self.frame_transform(frame['data']))
                current_pts = frame['pts']
            # Stack it into a tensor
            video = torch.stack(video_frames, 0)
            if self.video_transform:
                video = self.video_transform(video)
            output = {
                'path': path,
                'video': video,
                'target': target,
                'start': start,
                'end': current_pts}
            yield output

Given a path of videos in a folder structure, i.e:

  • dataset
    • class 1
      • file 0

      • file 1

    • class 2
      • file 0

      • file 1

We can generate a dataloader and test the dataset.

transforms = [t.Resize((112, 112))]
frame_transform = t.Compose(transforms)

dataset = RandomDataset("./dataset", epoch_size=None, frame_transform=frame_transform)
from torch.utils.data import DataLoader
loader = DataLoader(dataset, batch_size=12)
data = {"video": [], 'start': [], 'end': [], 'tensorsize': []}
for batch in loader:
    for i in range(len(batch['path'])):
        data['video'].append(batch['path'][i])
        data['start'].append(batch['start'][i].item())
        data['end'].append(batch['end'][i].item())
        data['tensorsize'].append(batch['video'][i].size())
print(data)

Out:

{'video': ['./dataset/2/v_SoccerJuggling_g23_c01.avi', './dataset/2/SOX5yA1l24A.mp4', './dataset/1/WUzgd7C1pWA.mp4', './dataset/2/v_SoccerJuggling_g24_c01.avi', './dataset/2/v_SoccerJuggling_g24_c01.avi'], 'start': [4.871550503945114, 0.39844179310790934, 0.8933558079557632, 3.301046395731584, 5.393511986190442], 'end': [5.405399999999999, 0.9008999999999999, 1.4014, 3.8038, 5.9059], 'tensorsize': [torch.Size([16, 3, 112, 112]), torch.Size([16, 3, 112, 112]), torch.Size([16, 3, 112, 112]), torch.Size([16, 3, 112, 112]), torch.Size([16, 3, 112, 112])]}

4. Data Visualization

Example of visualized video

import matplotlib.pylab as plt

plt.figure(figsize=(12, 12))
for i in range(16):
    plt.subplot(4, 4, i + 1)
    plt.imshow(batch["video"][0, i, ...].permute(1, 2, 0))
    plt.axis("off")
plot video api

Cleanup the video and dataset:

import os
import shutil
os.remove("./WUzgd7C1pWA.mp4")
shutil.rmtree("./dataset")

Total running time of the script: ( 0 minutes 3.595 seconds)

Gallery generated by Sphinx-Gallery

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources