-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathkitml.py
More file actions
82 lines (59 loc) · 2.52 KB
/
kitml.py
File metadata and controls
82 lines (59 loc) · 2.52 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import os
from tqdm import tqdm
from tools.jtools import load_json, save_dict_json
from tools.amass import load_amass_npz, compute_duration
from tools.kitml import load_mmm_csv, load_kit_mocap_annotation
from sanitize_text import sanitize
from tools.saving import store_keyid
def process_kitml(amass_path: str, kitml_path: str, kitml_process_folder: str, outputs: str = "outputs"):
amasspath2kitml_path = os.path.join(kitml_process_folder, "amass-path2kitml.json")
if not os.path.exists(amasspath2kitml_path):
raise FileNotFoundError("You should launch the cmd 'python kitml_text_preprocess.py' first")
os.makedirs(outputs, exist_ok=True)
save_json_index_path = os.path.join(outputs, "kitml.json")
original_dico = load_json(amasspath2kitml_path)
dico = {}
for keyid, path in tqdm(original_dico.items()):
csv_path = os.path.join(kitml_path, keyid + "_fke.csv")
mmm = load_mmm_csv(csv_path)
npz_path = os.path.join(amass_path, path)
smpl_data = load_amass_npz(npz_path)
len_seq = len(mmm)
len_amass_seq = len(smpl_data["trans"])
if len_seq != len_amass_seq:
print(f"Excluding {keyid}, as there is a mismatch between AMASS and MMM motions")
continue
start = 0.0
duration = compute_duration(smpl_data)
# whole sequence for KIT-ML
end = duration
texts = load_kit_mocap_annotation(kitml_path, keyid)
# drop the sequence
if not texts:
continue
annotations = []
for idx, text in enumerate(texts):
text = sanitize(text)
seg_id = f"{keyid}_{idx}"
element = {
# to save the correspondance
# with the original KIT-ML dataset
"seg_id": f"{keyid}_{idx}",
"text": text,
"start": start,
"end": end
}
if not text.isascii():
raise TypeError("The text should not have non-ascii characters")
annotations.append(element)
# at least one
if len(annotations) >= 1:
store_keyid(dico, keyid, path, duration, annotations)
# saving the annotations
save_dict_json(dico, save_json_index_path)
print(f"Saving the annotations to {save_json_index_path}")
if __name__ == "__main__":
amass_path = "datasets/AMASS/"
kitml_path = "datasets/kit-mocap/"
kitml_process_folder = "kitml_process"
process_kitml(amass_path, kitml_path, kitml_process_folder)