karfly / learnable-triangulation-pytorch

This repository is an official PyTorch implementation of the paper "Learnable Triangulation of Human Pose" (ICCV 2019, oral). Proposed method archives state-of-the-art results in multi-view 3D human pose estimation!
MIT License
1.09k stars 181 forks source link

Modified function 'apply_umeyama' in mvn/utils/tred.py #141

Closed RichardChen20 closed 3 years ago

RichardChen20 commented 3 years ago

I have modified the function 'apply_umeyama' so that it can directly process data from a batch much more efficiently. Here are the codes:

def apply_umeyama(batch_gt, batch_pred, rotation=True, scaling=True):

# pred and gt size (batch_size, num_joints, 3)
pred_centered = batch_pred - batch_pred.mean(axis=1, keepdim=True)
gt_centered = batch_gt - batch_gt.mean(axis=1, keepdim=True)

H = pred_centered.transpose(1, 2).matmul(gt_centered)
u, _, v = torch.svd(H)  # Kabsch algorithm
R = v.matmul(u.transpose(1, 2))

if scaling:
    c = (gt_centered.norm(p='fro', dim=2) / pred_centered.norm(p='fro', dim=2)).mean(axis=1, keepdim=True).unsqueeze(-1)
else:
    c = 1.0

if rotation:
    return batch_pred.matmul(R.transpose(1, 2)) * c
else:
    return batch_pred * c