forked from yysijie/st-gcn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kinetics_gendata.py
87 lines (69 loc) · 2.5 KB
/
kinetics_gendata.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
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
83
84
85
86
87
import os
import sys
import pickle
import argparse
import numpy as np
from numpy.lib.format import open_memmap
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from feeder.feeder_kinetics import Feeder_kinetics
toolbar_width = 30
def print_toolbar(rate, annotation=''):
# setup toolbar
sys.stdout.write("{}[".format(annotation))
for i in range(toolbar_width):
if i * 1.0 / toolbar_width > rate:
sys.stdout.write(' ')
else:
sys.stdout.write('-')
sys.stdout.flush()
sys.stdout.write(']\r')
def end_toolbar():
sys.stdout.write("\n")
def gendata(
data_path,
label_path,
data_out_path,
label_out_path,
num_person_in=5, #observe the first 5 persons
num_person_out=2, #then choose 2 persons with the highest score
max_frame=300):
feeder = Feeder_kinetics(
data_path=data_path,
label_path=label_path,
num_person_in=num_person_in,
num_person_out=num_person_out,
window_size=max_frame)
sample_name = feeder.sample_name
sample_label = []
fp = open_memmap(
data_out_path,
dtype='float32',
mode='w+',
shape=(len(sample_name), 3, max_frame, 18, num_person_out))
for i, s in enumerate(sample_name):
data, label = feeder[i]
print_toolbar(i * 1.0 / len(sample_name),
'({:>5}/{:<5}) Processing data: '.format(
i + 1, len(sample_name)))
fp[i, :, 0:data.shape[1], :, :] = data
sample_label.append(label)
with open(label_out_path, 'wb') as f:
pickle.dump((sample_name, list(sample_label)), f)
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Kinetics-skeleton Data Converter.')
parser.add_argument(
'--data_path', default='data/Kinetics/kinetics-skeleton')
parser.add_argument(
'--out_folder', default='data/Kinetics/kinetics-skeleton')
arg = parser.parse_args()
part = ['train', 'val']
for p in part:
data_path = '{}/kinetics_{}'.format(arg.data_path, p)
label_path = '{}/kinetics_{}_label.json'.format(arg.data_path, p)
data_out_path = '{}/{}_data.npy'.format(arg.out_folder, p)
label_out_path = '{}/{}_label.pkl'.format(arg.out_folder, p)
if not os.path.exists(arg.out_folder):
os.makedirs(arg.out_folder)
gendata(data_path, label_path, data_out_path, label_out_path)