Using PyTorch in python, I'm feeding-back one of my CNN's layers into input-space by using an inverse network that I'm training.
However, I'm interested in the representation of only one channel. I get this by setting all values to 0 except from those of the channel that I'm interested in.
image_representation is a [torch.FloatTensor of size 1x64x56x56]
image_representation[0, 1:, :, :] = 0
Inserting image_representation into the inverse net yields an image. I'm feeding this image into the original CNN results into another representation that I can compare with the representation resulting from the original image. This comparison makes my loss function
However, when I run it I get the error
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation
I understand that the gradient cannot be fully computed because of the zeros, but how can i design my code in such a way that it will omit this error, and do the computations only for one of the 64 channels?