Hi,
Variables are not needed anymore, you can remove them and use Tensors everywhere.
I think the input_img from your preprocess function does not require gradients. You should do input_img.requires_grad_(True) to make this Tensor require gradients.