How to get "image gradient" in PyTorch?

image_grad

A is RGB image and hat A is predicted RGB image from PyTorch CNN
Same with S.
How to get “triangle down (gradient) image”?

Hi,

You can set requires_grad=True on the input before feeding it to the network. That way after the backward pass you can check it’s .grad field to get the gradients.

1 Like