Thank you for the answer. That was exactly what I am trying to do.
Just one question, how do I pass the image only to the optimizer? Should I make it a parameter or can I just pass the image tensor with requires_grad = True to the optimizer?