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

Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead. #4

Closed
skylook opened this issue Sep 17, 2019 · 1 comment

Comments

@skylook
Copy link

skylook commented Sep 17, 2019

When I use liegroups in a loss function, it reports error as follows:
Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead.

Here is the code:

    print('rotation_ab_pred size = {} type = {}'.format(rotation_ab_pred.size(), rotation_ab_pred.type()))
    rvec_ab_pred = SO2.from_matrix(rotation_ab_pred)

And the result:

rotation_ab_pred size = torch.Size([32, 2, 2]) type = torch.cuda.FloatTensor

@leeclemnet
Copy link
Member

leeclemnet commented Nov 6, 2019

There are a couple places where we convert to numpy to use np.linalg functions (specifically the determinant and SVD) to validate and normalize rotation matrices. I added the missing detach() calls in c2b479e so it should work as expected now.

As an alternative, you can also use the less safe constructor, which doesn't do any validity checking:

rvec_ab_pred = SO2.from_matrix(rotation_ab_pred) # checks validity of matrix
rvec_ab_pred = SO2(rotation_ab_pred) # does not check validity of matrix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants