import torch


def mpjpe(predicted, target):
    """
    Mean per-joint position error (i.e. mean Euclidean distance),
    often referred to as "Protocol #1" in many papers.
    """
    assert predicted.shape == target.shape
    #l2_error = torch.mean(torch.norm((predicted - target), dim=len(target.shape) - 1), -1).squeeze()
    #print('each joint error:', torch.norm((predicted - target), dim=len(target.shape) - 1))
    #index = np.where(l2_error.cpu().detach().numpy() > 0.3)  # mean body l2 distance larger than 300mm
    #value = l2_error[l2_error > 0.3]
    #print('Index of mean body l2 distance larger than 300mm', index, value)
    return torch.mean(torch.norm((predicted - target), dim=len(target.shape) - 1))