Utilities for monocular 3D human pose estimation.
The MPJPE helpers live in pose3dkit.metrics.
-
compute_mpjpe(predicted, target, *, reduce_axes="all", keepdims=False, joint_mask=None, joint_weights=None)- Accepts numpy arrays or torch tensors with shape
(B, T, J, 3)or(T, J, 3). - Returns values in the same backend/dtype/device as the inputs.
- Choose the output layout by selecting axes to average over: e.g.
reduce_axes="none"keeps(B, T, J),("joint",)yields(B, T),("joint", "time")yields(B,),("batch", "joint")yields(T,), and"global"collapses to a scalar. - Optional
joint_mask(boolean) andjoint_weights(non-negative) broadcast over(B, T, J)to skip or re-weight joints. Masked entries return zero whenreduce_axes="none"and are ignored in reductions otherwise. - Inputs must be floating point and finite; NaNs/Infs raise
ValueError.
- Accepts numpy arrays or torch tensors with shape
-
compute_p_mpjpe(predicted, target, *, reduce_axes="all", keepdims=False)- Procrustes-aligns (scale-rotation-translation) before measuring error and supports
(B, T, J, 3)or(T, J, 3)inputs across numpy/torch backends. - The aligned prediction adopts the target’s coordinate scale, delivering a unit-consistent error regardless of the original magnitude of
predicted. - Shares the same reduction semantics as
compute_mpjpe; raisesValueErrorwhen the alignment is ill-defined (e.g., zero-variance sequences).
- Procrustes-aligns (scale-rotation-translation) before measuring error and supports
-
mpjpe_loss(predicted, target, *, reduction="mean", joint_mask=None, joint_weights=None)- Torch-only functional loss helper that reuses
compute_mpjpe. - Supports
reduction="mean"(scalar) or"none"(per-sample(B,), requires batch dimension).
- Torch-only functional loss helper that reuses
-
p_mpjpe_loss(predicted, target, *, reduction="mean")- Torch-only PA-MPJPE loss matching the original
sample.pybehaviour, supporting batch inputs andreduction="mean"/"none". - Internally rescales
predictedto the target’s unit system during the rigid alignment step.
- Torch-only PA-MPJPE loss matching the original
-
n_mpjpe_loss(predicted, target, *, reduction="mean")- Torch-only normalized MPJPE (scale-only) matching the historical
sample.pyimplementation. - Supports
reduction="mean"(scalar) or"none"(per-sample(B,), requires batch dimension).
- Torch-only normalized MPJPE (scale-only) matching the historical
-
velocity_loss(predicted, target, *, reduction="mean")- Torch-only mean per-joint velocity error mirroring the historical
sample.pyhelper. - Supports
reduction="mean"(scalar) or"none"(per-sample(B,), requires batch dimension).
- Torch-only mean per-joint velocity error mirroring the historical
-
MPJPELoss(reduction="mean", joint_mask=None, joint_weights=None)- Thin
torch.nn.Modulewrapper aroundmpjpe_loss.
- Thin
-
PMPJPELoss(reduction="mean")torch.nn.Modulewrapper aroundp_mpjpe_loss.
-
NMPJPELoss(reduction="mean")torch.nn.Modulewrapper aroundn_mpjpe_loss.
-
VelocityLoss(reduction="mean")torch.nn.Modulewrapper aroundvelocity_loss.
-
pose3dkit.MPJPE()- TorchMetrics-compatible metric returning a scalar global MPJPE from
(B, T, J, 3)tensors. - Works with DataParallel and DDP thanks to
dist_reduce_fx="sum", and preserves mixed-precision dtypes in the final result.
- TorchMetrics-compatible metric returning a scalar global MPJPE from
-
pose3dkit.PMPJPE()- TorchMetrics-compatible PA-MPJPE counterpart with the same DDP-friendly accumulation strategy.
Units are not enforced—ensure callers use consistent coordinate scales (e.g. millimetres vs metres).