MCPcopy Create free account
hub / github.com/AdaptiveMotorControlLab/FMPose3D / p_mpjpe

Function p_mpjpe

fmpose3d/common/utils.py:101–136  ·  view source on GitHub ↗
(predicted, target)

Source from the content-addressed store, hash-verified

99
100
101def p_mpjpe(predicted, target): # p2, Procrustes analysis MPJPE
102 assert predicted.shape == target.shape
103
104 muX = np.mean(target, axis=1, keepdims=True) # B,1,3
105 muY = np.mean(predicted, axis=1, keepdims=True) # B,1,3
106
107 X0 = target - muX
108 Y0 = predicted - muY
109
110 normX = np.sqrt(np.sum(X0**2, axis=(1, 2), keepdims=True)) # B,1,1
111 normY = np.sqrt(np.sum(Y0**2, axis=(1, 2), keepdims=True))
112
113 X0 /= normX
114 Y0 /= normY
115
116 H = np.matmul(X0.transpose(0, 2, 1), Y0)
117 U, s, Vt = np.linalg.svd(H)
118 V = Vt.transpose(0, 2, 1)
119 R = np.matmul(V, U.transpose(0, 2, 1))
120
121 sign_detR = np.sign(np.expand_dims(np.linalg.det(R), axis=1))
122 V[:, :, -1] *= sign_detR
123 s[:, -1] *= sign_detR.flatten()
124 R = np.matmul(V, U.transpose(0, 2, 1))
125
126 tr = np.expand_dims(np.sum(s, axis=1, keepdims=True), axis=2)
127
128 a = tr * normX / normY
129 t = muX - a * np.matmul(muY, R)
130
131 predicted_aligned = a * np.matmul(predicted, R) + t
132
133 return np.mean(
134 np.linalg.norm(predicted_aligned - target, axis=len(target.shape) - 1),
135 axis=len(target.shape) - 2,
136 )
137
138
139def mpjpe_by_action_p2(predicted, target, action, action_error_sum):

Callers 2

mpjpe_by_action_p2Function · 0.70
stepFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected