-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathmpiinf3dhp_dataset.py
185 lines (148 loc) · 7.75 KB
/
mpiinf3dhp_dataset.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
from lib.dataset import BaseDataset
import numpy as np
import os
from lib.utils.geometry_utils import *
class MPIINF3DHPDataset(BaseDataset):
def __init__(self, cfg, estimator='spin', return_type='3D', phase='test'):
BaseDataset.__init__(self, cfg)
self.dataset_name = "mpiinf3dhp"
if phase == 'test':
self.phase = phase
else:
raise NotImplementedError(
"Unknown phase type! Valid phase: [\'test\']. You can edit the code for additional implements"
)
if return_type in ['3D']: # no 2D
self.return_type = return_type # '3D' | '2D' | 'smpl'
else:
raise NotImplementedError(
"Unknown return type! Valid phase: [\'3D\','smpl']. You can edit the code for additional implement"
)
if estimator in ['spin', 'vibe', 'tcmr']:
self.estimator = estimator # 'spin' | 'vibe' | 'tcmr'
else:
raise NotImplementedError(
"Unknown estimator! Valid phase: [\'spin\',\'vibe\','tcmr']. You can edit the code for additional implement"
)
print('#############################################################')
print('You are loading the [' + self.phase + 'ing set] of dataset [' +
self.dataset_name + ']')
print('You are using pose esimator [' + self.estimator + ']')
print('The type of the data is [' + self.return_type + ']')
self.slide_window_size = cfg.MODEL.SLIDE_WINDOW_SIZE
self.evaluate_slide_window_step=cfg.EVALUATE.SLIDE_WINDOW_STEP_SIZE
self.base_data_path = cfg.DATASET.BASE_DIR
try:
ground_truth_data = np.load(os.path.join(
self.base_data_path,
self.dataset_name+"_"+self.estimator+"_"+self.return_type,
"groundtruth",
self.dataset_name + "_" + "gt"+"_"+self.return_type + "_" + self.phase + ".npz"),
allow_pickle=True)
except:
raise ImportError("Ground-truth data do not exist!")
try:
detected_data = np.load(os.path.join(
self.base_data_path,
self.dataset_name+"_"+self.estimator+"_"+self.return_type,
"detected",
self.dataset_name + "_" + self.estimator+"_"+self.return_type + "_" + self.phase + ".npz"),
allow_pickle=True)
except:
raise ImportError("Detected data do not exist!")
ground_truth_data_len = sum(
len(seq) for seq in ground_truth_data["imgname"])
detected_data_len = sum(len(seq) for seq in detected_data["imgname"])
if ground_truth_data_len != detected_data_len:
raise ImportError(
"Detected data is not the same size with ground_truth data!")
self.data_len = [len(seq)-self.slide_window_size if (len(seq)-self.slide_window_size)>0 else 0 for seq in ground_truth_data["imgname"]]
self.data_start_num = [
sum(self.data_len[0:i]) for i in range(len(self.data_len))
]
for i in range(len(self.data_start_num)-2,1):
if self.data_start_num[i]==self.data_start_num[i-1]:
self.data_start_num[i]=self.data_start_num[i+1]
self.frame_num = sum(self.data_len)
print('The frame number is [' + str(self.frame_num) + ']')
self.sequence_num = len(ground_truth_data["imgname"])
print('The sequence number is [' + str(self.sequence_num) + ']')
print('#############################################################')
if self.return_type == '3D':
self.ground_truth_data_imgname = ground_truth_data["imgname"]
self.ground_truth_data_joints_3d = ground_truth_data["joints_3d"]
self.detected_data_imgname = detected_data["imgname"]
self.detected_data_joints_3d = detected_data["joints_3d"]
self.input_dimension = ground_truth_data["joints_3d"][0].shape[1]
elif self.return_type == 'smpl':
self.ground_truth_data_imgname = ground_truth_data["imgname"]
self.ground_truth_data_pose = ground_truth_data["pose"]
self.ground_truth_data_shape = ground_truth_data["shape"]
self.detected_data_imgname = detected_data["imgname"]
self.detected_data_pose = detected_data["pose"]
self.detected_data_shape = detected_data["shape"]
if cfg.TRAIN.USE_6D_SMPL:
self.input_dimension = 6 * 24
for i in range(len(self.ground_truth_data_pose)):
self.ground_truth_data_pose[i] = numpy_axis_to_rot6D(
self.ground_truth_data_pose[i].reshape(-1, 3)).reshape(
-1, self.input_dimension)
for i in range(len(self.detected_data_pose)):
self.detected_data_pose[i] = numpy_axis_to_rot6D(
self.detected_data_pose[i].reshape(-1, 3)).reshape(
-1, self.input_dimension)
else:
self.input_dimension = 3 * 24
def __len__(self):
if self.phase == "test":
return self.sequence_num
def __getitem__(self, index):
if self.phase == "test":
return self.get_test_data(index)
def get_test_data(self, index):
ground_truth_data_len = len(self.ground_truth_data_imgname[index])
detected_data_len = len(self.detected_data_imgname[index])
if ground_truth_data_len != detected_data_len:
raise ImportError(
"Detected data is not the same size with ground_truth data!")
if self.return_type == '3D':
gt_data = self.ground_truth_data_joints_3d[index].reshape(
ground_truth_data_len, -1, 3)
pred_data = self.detected_data_joints_3d[index].reshape(
ground_truth_data_len, -1, 3)
gt_data = gt_data.reshape(ground_truth_data_len, -1)
pred_data = pred_data.reshape(ground_truth_data_len, -1)
elif self.return_type == 'smpl':
gt_data = self.ground_truth_data_pose[index].reshape(
ground_truth_data_len, -1)
pred_data = self.detected_data_pose[index].reshape(
ground_truth_data_len, -1)
gt_shape = self.ground_truth_data_shape[index].reshape(
ground_truth_data_len, -1)
pred_shape = self.detected_data_shape[index].reshape(
ground_truth_data_len, -1)
gt_data = np.concatenate((gt_data, gt_shape), axis=-1)
pred_data = np.concatenate((pred_data, pred_shape), axis=-1)
if self.slide_window_size <= ground_truth_data_len:
start_idx=np.arange(0,ground_truth_data_len-self.slide_window_size+1,self.evaluate_slide_window_step)
gt_data_=[]
pred_data_=[]
for idx in start_idx:
gt_data_.append(gt_data[idx:idx+self.slide_window_size,:])
pred_data_.append(pred_data[idx:idx+self.slide_window_size,:])
gt_data=np.array(gt_data_)
pred_data=np.array(pred_data_)
else:
gt_data = np.concatenate((
gt_data,
np.zeros(
tuple((self.slide_window_size - ground_truth_data_len, )) +
tuple(gt_data.shape[1:]))),
axis=0)[np.newaxis, :]
pred_data = np.concatenate((
pred_data,
np.zeros(
tuple((self.slide_window_size - ground_truth_data_len, )) +
tuple(pred_data.shape[1:]))),
axis=0)[np.newaxis, :]
return {"gt": gt_data, "pred": pred_data}