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

Gradient Problems #84

Open
Squeemos opened this issue Oct 18, 2022 · 0 comments
Open

Gradient Problems #84

Squeemos opened this issue Oct 18, 2022 · 0 comments

Comments

@Squeemos
Copy link

Squeemos commented Oct 18, 2022

I'm trying to call:

gradient_saliency = saliency.GradientSaliency()
vanilla_mask_3d = gradient_saliency.GetMask(im, call_model_function, call_model_args)

but I'm stuck in a loop where I can't solve the problem.

If I setup my input like this:
im = img.unsqueeze(dim=0).to("cuda").requires_grad_(True)
Then I get
RuntimeError: Can't call numpy() on Tensor that requires grad. Use tensor.detach().numpy() instead.

But if I change it to
im = img.unsqueeze(dim = 0).to(device)
I get
RuntimeError: One of the differentiated Tensors does not require grad

It makes sense that it requires the gradient given its task, but why does it try to call .numpy() without doing a .detach()? Maybe I'm setting up something else wrong, but it seems to be isolated to this specific section.

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

1 participant