Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test camfer failed #2

Closed
tornadomeet opened this issue Oct 28, 2019 · 2 comments
Closed

test camfer failed #2

tornadomeet opened this issue Oct 28, 2019 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@tornadomeet
Copy link

tornadomeet commented Oct 28, 2019

pc1.npy.zip
pc2.npy.zip

the test will be failed if using the above of two point cloud, which the shape is [1, 8192, 3]. i found the min index is different between ext.chamferDist() and chamfer_python.distChamfer.

test will be ok if using https://github.com/ThibaultGROUEIX/chamfer_pytorch/blob/master/test_chamfer.py

pytorch version : 1.2

test code:

import torch
import dist_chamfer_idx as ext
import chamfer_python
distChamfer = ext.chamferDist()
from torch.autograd import Variable
import time
import numpy as np


def test_chamfer():
    distChamfer = ext.chamferDist()
    p1 = torch.from_numpy(np.load("pc1.npy")).cuda()
    p2 = torch.from_numpy(np.load("pc2.npy")).cuda()
    points1 = Variable(p1, requires_grad=True)
    points2 = Variable(p2)
    dist1, dist2, idx1, idx2= distChamfer(points1, points2)

    loss = torch.sum(dist1)
    print(loss)
    loss.backward()
    print(points1.grad, points2.grad)

    mydist1, mydist2, myidx1, myidx2 = chamfer_python.distChamfer(points1, points2)
    d1 = (dist1 - mydist1) ** 2
    d2 = (dist2 - mydist2) ** 2
    xd1 = idx1 - myidx1
    xd2 = idx2 - myidx2
    print("d1 = \n", d1)
    print("d2 = \n", d2)
    print("diff sum = \n", torch.sum(d1) + torch.sum(d2))
    print("xd1 = \n", xd1)
    print("xd2 = \n", xd2)
    print("xdiff norm sum = \n", torch.norm(xd1.float()) + torch.norm(xd2.float()))

    assert (
        torch.sum(d1) + torch.sum(d2) < 0.00000001
    ), "distance : chamfer cuda and chamfer normal are not giving the same results"
    assert (
            torch.norm(xd1.float()) + torch.norm(xd2.float()) == 0
    ), "index : chamfer cuda and chamfer normal are not giving the same results"

test_chamfer()

@ThibaultGROUEIX

@ThibaultGROUEIX
Copy link
Owner

Hi @tornadomeet

This is the conjunction of two factors:
-- 1 : i sum the errors on the points. You use more points than my test case, and the points size is two orders of magnitude larger than my test. This introduces a difference of about 1000 between the test case and your test.
--2 : chamfer_python has some numerical instability because of the type of the tensors (float). There are no longer any differences in the idx after changing them to double.

In summary, you can just git pull and your test should pass.

Best regards,
Thibault

@tornadomeet
Copy link
Author

thanks @ThibaultGROUEIX Now the test has passed!

@ThibaultGROUEIX ThibaultGROUEIX added the bug Something isn't working label Nov 13, 2019
@ThibaultGROUEIX ThibaultGROUEIX self-assigned this Nov 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants