forked from seymayucer/ActionDatasetLoader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMSRAction3D.py
executable file
·51 lines (46 loc) · 1.77 KB
/
MSRAction3D.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
from os import listdir
from os.path import join
import numpy as np
import helpers
from helpers import logger
max_frame_num = 196
frame_size = 60
num_classes = 20
body_part_ids = [[19, 2, 3, 6, 0],
[0, 7, 4, 9],
[1, 8, 5, 10],
[11, 13, 15, 17],
[12, 14, 16, 18]]
logger = helpers.logging.getLogger(__name__)
def read(data_dir,split,subject_id):
print('Loading MSR 3D Data, data directory %s' % data_dir)
data, labels, lens, subjects = [], [], [], []
filenames = []
documents = [join(data_dir, d)
for d in sorted(listdir(data_dir))]
filenames.extend(documents)
filenames = np.array(filenames)
for file in filenames:
action = np.loadtxt(file)[:, :3].flatten()
labels.append(helpers.full_fname2_str(data_dir, file, 'a'))
frame_size = len(action) / 60 # 20 iskeleton num x,y,z 3D points
lens.append(frame_size)
action = np.asarray(action).reshape(frame_size, 60)
new_act = []
for frame in action:
new_frame = helpers.frame_normalizer(frame=frame, frame_size=60)
new_act.append(new_frame)
data.append(new_act)
subjects.append(helpers.full_fname2_str(data_dir, file, 's'))
# print(action.shape,frame_size)
data = np.asarray(data)
labels = np.asarray(labels) -1
lens = np.asarray(lens)
data=helpers.dataset_normalizer(data)
subjects = np.asarray(subjects)
# data, labels, lens, subjects = get_half(data, labels, lens, subjects)
print('initial shapes [data label len]: %s %s %s' % (data.shape, labels.shape, lens.shape))
if split:
return helpers.test_train_splitter(subject_id, data, labels, lens, subjects)
else:
return data,labels,lens