forked from OpenGVLab/VideoMAEv2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kinetics_merge.py
38 lines (34 loc) · 1007 Bytes
/
kinetics_merge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pathlib
from tqdm import tqdm
from decord import VideoReader,cpu
corrupt = 0
skipped = 0
data_d = pathlib.Path('/data/kinetics-400')
videos = dict()
fs = list((data_d / 'replacement/replacement_for_corrupted_k400').iterdir())
for f in tqdm(fs):
if f.suffix == '.mp4':
try:
VideoReader(str(f),ctx=cpu(0))
except:
corrupt += 1
continue
videos[f.name] = str(f.relative_to('/data'))
fs = list((data_d / 'train').iterdir())
for f in tqdm(fs):
if f.suffix == '.mp4':
if f.name not in videos:
try:
VideoReader(str(f),ctx=cpu(0))
except:
corrupt += 1
continue
videos[f.name] = str(f.relative_to('/data'))
else:
skipped += 1
print(f'skipped = {skipped:,}')
print(f'corrupt = {corrupt:,}')
videos = [f'{v} 0 -1'
for v in sorted(videos.values())]
videos = '\n'.join(videos)
open('/data/videos.txt','w').write(videos)