MCPcopy Create free account
hub / github.com/Vegetebird/GraphMLP / p_mpjpe

Function p_mpjpe

common/eval_cal.py:163–195  ·  view source on GitHub ↗
(predicted, target)

Source from the content-addressed store, hash-verified

161
162
163def p_mpjpe(predicted, target):
164 assert predicted.shape == target.shape
165
166 muX = np.mean(target, axis=1, keepdims=True)
167 muY = np.mean(predicted, axis=1, keepdims=True)
168
169 X0 = target - muX
170 Y0 = predicted - muY
171
172 normX = np.sqrt(np.sum(X0 ** 2, axis=(1, 2), keepdims=True))
173 normY = np.sqrt(np.sum(Y0 ** 2, axis=(1, 2), keepdims=True))
174
175 X0 /= normX
176 Y0 /= normY
177
178 H = np.matmul(X0.transpose(0, 2, 1), Y0)
179 U, s, Vt = np.linalg.svd(H)
180 V = Vt.transpose(0, 2, 1)
181 R = np.matmul(V, U.transpose(0, 2, 1))
182
183 sign_detR = np.sign(np.expand_dims(np.linalg.det(R), axis=1))
184 V[:, :, -1] *= sign_detR
185 s[:, -1] *= sign_detR.flatten()
186 R = np.matmul(V, U.transpose(0, 2, 1))
187
188 tr = np.expand_dims(np.sum(s, axis=1, keepdims=True), axis=2)
189
190 a = tr * normX / normY
191 t = muX - a * np.matmul(muY, R)
192
193 predicted_aligned = a * np.matmul(predicted, R) + t
194
195 return np.mean(np.linalg.norm(predicted_aligned - target, axis=len(target.shape) - 1), axis=len(target.shape) - 2)
196
197
198

Callers 1

mpjpe_by_action_p2Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected