Skip to content

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

@NicolasHug

Description

@NicolasHug

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions