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

Let v2.functional.gaussian_blur backprop through sigma parameter #8450

Open
NicolasHug opened this issue May 29, 2024 · 3 comments · May be fixed by #8486
Open

Let v2.functional.gaussian_blur backprop through sigma parameter #8450

NicolasHug opened this issue May 29, 2024 · 3 comments · May be fixed by #8486

Comments

@NicolasHug
Copy link
Member

the v1 version of gaussian_blur allows to backprop through sigma

(example taken from #8401)

import torch
from torchvision.transforms.functional import gaussian_blur

device = "cuda"
device = "cpu"
k = 15
s = torch.tensor(0.3 * ((5 - 1) * 0.5 - 1) + 0.8, requires_grad=True, device=device)

blurred = gaussian_blur(torch.randn(1, 3, 256, 256, device=device), k, [s])
blurred.mean().backward()
print(s.grad)

on CPU and on GPU (after #8426).

However, the v2 version fails with

RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn

The support in v1 is sort of undocumented and probably just works out of luck (sigma is typically expected to be a list of floats rather than a tensor). So while it works, it's not 100% clear to me whether this is a feature we absolutely want. I guess we can implement it if it doesn't make the code much more complex or slower.

@Bhavay-2001
Copy link

Hi @NicolasHug, can I work on this issue? Can you please guide me with a starting point on where can I start looking for?
Thanks

@NicolasHug
Copy link
Member Author

Hi Bhavay, I see you've commented on a bunch of issues/PRs on torchvision.

At this time, torchvision is a fairly mature project and unfortunately there are no low-hanging fruit PRs that are easy to address for beginners. If you're trying to hone your open source skills, I'd advise contributing into up-and-coming github repos rather than something like torchvision. (You can usethe github search for that)

That being said, I'd also encourage you to simply just try contributing and submit a PR instead of asking for guidance of all these posts. For example here in this issue, I feel like the issue is descriptive enough to get someone started (perhaps with some non-trivial initial effort, sure). If you find that it's too advanced for you at this time then that's completely fine, but that probably means you should consider contributing to more beginner friendly repos for now.

@Bhavay-2001
Copy link

Bhavay-2001 commented Jun 6, 2024

Hi @NicolasHug, thanks for your reply. Actually, I thought that maybe discussing the issue first and then opening a PR would be a good idea but I get your point of try working it our myself first and then opening a draft PR to discuss further.

I have some experience in open source and I think I can manage to contribute to torchvision library. In future, I will try to work on issues myself first and then maybe discuss with the team by opening a sample PR.

Thanks for the insight.

@andreasfloros andreasfloros linked a pull request Jun 8, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants