-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats.py
More file actions
75 lines (60 loc) · 2.12 KB
/
stats.py
File metadata and controls
75 lines (60 loc) · 2.12 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
import argparse
import json
import multiprocessing
import os
from functools import partial
from tqdm import tqdm
def process_files(files, root_folder, key="joints"):
face = 0
l_hand = 0
r_hand = 0
frames = 0
for idx, file in enumerate(tqdm(files)):
path = os.path.join(root_folder, file)
with open(path, "r") as f:
keypoints = json.load(f)[key]
frames += len(keypoints)
for fidx in keypoints:
if isinstance(fidx, str):
kp = keypoints[fidx]
else:
kp = fidx
if len(kp["face_landmarks"]) > 0:
face += 1
if len(kp["right_hand_landmarks"]) > 0:
r_hand += 1
if len(kp["left_hand_landmarks"]) > 0:
l_hand += 1
return face / 2 ** 16, l_hand / 2 ** 16, r_hand / 2 ** 16, frames / 2 ** 16
def split(data, n):
splits = [data[i * n:(i + 1) * n] for i in range((len(data) + n - 1) // n)]
return splits
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--root_folder', type=str)
parser.add_argument('--workers', type=int, default=8)
parser.add_argument('--key', type=str, default="joints")
args = parser.parse_args()
files = os.listdir(args.root_folder)
files = [f for f in files if ".json" in f]
split_size = (len(files) // args.workers) + 1
process_function = partial(process_files, root_folder=args.root_folder, key=args.key)
file_splits = split(files, split_size)
print(f"Num files: {len(files)}")
print(f"Split size: {split_size}")
print(f"Num split: {len(file_splits)}")
pool = multiprocessing.Pool(processes=args.workers)
results = pool.map(process_function, file_splits)
face = 0
l_hand = 0
r_hand = 0
frames = 0
for _face, _l_hand, _r_hand, _frames in results:
print(_face, _l_hand, _r_hand, _frames)
face += _face
l_hand += _l_hand
r_hand += _r_hand
frames += _frames
print("face mean:", face / frames)
print("left mean:", l_hand / frames)
print("right mean:", r_hand / frames)