I’m (mostly) someone-else’s code in combination with PWC-Net with (their) existing inputs. I’m getting an error in one of the cases (not every case). Here is all the code that I think is relevant:
print("Shape of mask is:", mask.shape)
s = (mask > 0.999).shape
print("Shape of (mask > 0.999) is:", s)
mask[mask > 0.999] = 1.0 # <-- Error occurs here!
Here, mask is a PyTorch tensor. The output is:
Shape of mask is: torch.Size([1, 1, 28, 40])
Shape of (mask > 0.999) is: torch.Size([1, 1, 28, 40])
Traceback (most recent call last):
The only clue I found online is the C++ header file that raises this error in PyTorch.
Any clues as to what might be happening here?
Aside: I’m using PyTorch 1.7.1 compiled from source, i.e. version ‘1.7.0a0+57bffc3’ [also tested with the official 1.8.1 CUDA 11.1 release for pip]
Another aside: mask is of type torch.cuda.FloatTensor and is located on the cuda:0 device.
Here is the mask tensor serialized via torch.save(…) . When I load it in a separate python shell and try to perform the operation on it, the error does not occur.
Big thanks to Ahmed Taha, who (in another thread / forum) suggested to replace the mask[mask > 0.999] = 1.0
with mask = torch.where(mask > 0.999, torch.ones_like(mask), mask)
This solution didn’t produce any errors so far, so I think it is valid. Why the original code produced an error for some cases remains a mystery to me.
mask2, in both cases, is just a copy of the mask tensor I provide & talk about above loaded from disk. moduleFiv and moduleSix are Decoder objects based on torch.nn.Module, which vary only by in_channels counts to their convolutional layers.
@Algomorph I too encountered this issue when loading a tensor from the disk and trying to filter it with a mask.
Your solution helped me as well, but it is indeed confusing why…
I met this error as well… I used the padding mask tensor to filter out non-padding result: tensor[padding_mask], after I changed the padding_mask device to cuda as well, the error disappeared, but the final result seems wrong.