The error message would be raised, if input_image is not a leaf variable, i.e. if it was created by another operation. If that’s the case, it might already require gradients and you should be able to access them via imput_image.grad.
Since the current self.gradients shape is different than the input_image.shape, it seems you are registering the hook on a different parameter or layer.