I’m trying to optimise an image based on a trained model Is there a way to set requires_grad = False for a portion of the image? This way allowing only a specific region of an image to optimise and update through training.
I’m trying this but get the following error:
xin = Variable(x, requires_grad = False)
xin[:,:,r_start:r_end,c_start:c_end].requires_grad = True



RuntimeError: you can only change requires_grad flags of leaf variables.