This repository has been archived by the owner on Jul 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
epic_symlinks.py
57 lines (44 loc) · 1.92 KB
/
epic_symlinks.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from pathlib import Path
import argparse
from parse import parse
import os
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("data_dir", type=Path, help="Directory of epic dataset")
parser.add_argument(
"symlinks_dir", type=Path, help="Directory to save symlinks for EPIC"
)
args = parser.parse_args()
if not args.symlinks_dir.exists():
args.symlinks_dir.mkdir(parents=True)
for modality in ["rgb", "flow"]:
if modality == "rgb":
pattern = "P[0-3][0-9]/P[0-3][0-9]_[0-9][0-9]/"
else:
pattern = "P[0-3][0-9]/P[0-3][0-9]_[0-9][0-9]/*/"
for split in ["train", "test"]:
modality_split_dir = args.data_dir / modality / split
for source_file in modality_split_dir.glob(pattern):
if modality == "rgb":
person, video = str(source_file).split("/")[-2:]
else:
person, video, _ = str(source_file).split("/")[-3:]
link_path = args.symlinks_dir / video
if not link_path.exists():
link_path.mkdir(parents=True)
all_files = sorted(
filter(lambda x: x.endswith("jpg"), os.listdir(source_file),),
key=lambda x: parse("frame_{:010d}.jpg", x)[0],
)
for i, f in enumerate(all_files):
source = source_file / f
if modality == "rgb":
link = link_path / "img_{:010d}.jpg".format(i)
else:
if source_file.name == "u":
link = link_path / "x_{:010d}.jpg".format(i)
else:
link = link_path / "y_{:010d}.jpg".format(i)
if link.exists():
link.unlink()
link.symlink_to(source)