Closed joaolcguerreiro closed 1 year ago
Hi @joaolcguerreiro , to help debug, could you provide more details such as what is the input (tensor's shape) of self.vgg_transforms
?
Hi :)
The input of self.vgg_transforms
is a 3D image (CT Scan) with shape (1, 256, 256, 256)
, where the first dimension corresponds to the number of channels. This 3D image is the output of a neural network which I will use to compute a loss component. Essentially I'm passing these 3D image to a feature extractor, but before that I need to perform some transforms... maybe the problem is that I'm trying to change a tensor with gradients accumulated?
In the transform I start by transforming the grayscale image to RGB by repeating the channel dim and obtaining the shape (3, 256, 256, 256)
. Then I call the NormalizeIntensity with a subtrahend and a divisor for each RGB channel. The error only happens when I try to make an RGB normalization, i.e., channel_wise=True, subtrahend is a list and divisor is a list.
Also, I'm using MONAI 1.1.0, but I believe the source code for NormalizeIntensity is the same as in 1.2.0.
The problem can be overcome if I detach the gradients from my tensor. However this is not the optimal solution.
From:
img[slices] = (img[slices] - _sub) / _div
return img
To:
ret = img.detach().clone()
ret[slices] = (img[slices] - _sub) / _div
return ret
Is there any alternative?? I've tried almost anything at this point haha.
Hi @joaolcguerreiro, you can also try to use decollate_batch
with detach=True
or move detach before your transforms.
https://github.com/Project-MONAI/tutorials/blob/6436af79ccb8b495b4a2cb102fdf4a1085e101e4/3d_classification/torch/densenet_training_dict.py#L140
Hope it can help you, thanks! (convert this issue to discussion for now and if this is still an issue please feel free to create a bug report)
Hi, I'm trying to apply a z-score normalization in my RGB data. I am applying the following transforms:
However I'm getting the following error:
RuntimeError: Output 0 of AliasBackward0 is a view and its base or another view of its base has been modified inplace. This view is the output of a function that returns multiple views. Such functions do not allow the output views to be modified inplace. You should replace the inplace operation by an out-of-place one.
I believe the problem is in the line
img[slices] = (img[slices] - _sub) / _div
of_normalize
method inNormalizeIntensity
class.I believe I'm calling the transform correctly or am I doing something wrong?