EricGuo5513/HumanML3D

Zero divide error during qnormalize function

HoBeom opened this issue · 0 comments

HoBeom commented

An error occurs when calculating the root rotation of the skeleton data.

Accordingly, I confirmed that the nan value is generated in 007975.npy.

I think we missed the problem because I didn't get a runtime error warning while I was generating a value by changing to torch.

Therefore, we should add the _FLOAT_EPS value to the denominator during normalization.

def qnormalize(q):
assert q.shape[-1] == 4, 'q must be a tensor of shape (*, 4)'
return q / torch.norm(q, dim=-1, keepdim=True)

to

def qnormalize(q):
    assert q.shape[-1] == 4, 'q must be a tensor of shape (*, 4)'
    return q / (torch.norm(q, dim=-1, keepdim=True) + _FLOAT_EPS)

Alternatively, we can replace all processes with a Numpy function so that we can view runtime errors and correct the problem.

def qnormalize_np(q):
    assert q.shape[-1] == 4, 'q must be a tensor of shape (*, 4)'
    return q / (np.sqrt((q ** 2).sum(axis=-1, keepdims=True)) + _FLOAT_EPS)

def qbetween_np_alternative(v0, v1):
    """
    find the quaternion used to rotate v0 to v1
    using only numpy
    """
    assert v0.shape[-1] == 3, 'v0 must be of the shape (*, 3)'
    assert v1.shape[-1] == 3, 'v1 must be of the shape (*, 3)'

    v = np.cross(v0, v1)
    w = np.sqrt((v0 ** 2).sum(axis=-1, keepdims=True) * (v1 ** 2).sum(axis=-1, keepdims=True)) + (v0 * v1).sum(axis=-1,
                                                                                                              keepdims=True)
    return qnormalize_np(np.concatenate([w, v], axis=-1))

Add an eps value to the code and then run motion_representation.ipynb,
My error values that occurred while running are as follows.

abs(reference1 - reference1_1).sum()

0.0047665355

abs(reference2 - reference2_1).sum()

0.0182359

In processing cal_mean_variance.ipynb, the nan value did not appear in 007975.npy
And error in mean, std are as follows.

abs(mean-reference1).sum()

0.010780404

abs(std-reference2).sum()

0.000663111

This issue was created to help others acquire a complete dataset. If need the same version, I will try to pull requests my code.