Importing Transparent Images Gives Runtimeerror: The Size Of Tensor A (4) Must Match The Size Of Tensor B (3) At Non-singleton Dimension 0
Solution 1:
Regarding the error message
RuntimeError: The size of tensor a
(4)must match the size of tensorb(3)at non-singleton dimension0
would lead to suggest that there's a problem with this call: sample = self.transform(sample)
Indeed, the issue is you are using a T.Normalize transform which only expects three channels (you specified a mean and std for three channels only, not four).
transform = transforms.Compose([
transforms.Resize((imageSize, imageSize)),
transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5,0.5))])
Instead, you should provide a four-element tuple for both arguments. For example (this is an example, this might run but won't necessarily make sense... see explanation below):
transforms.Normalize((0.5, 0.5, 0.5, 0.5), (0.5, 0.5,0.5, 0.5))])
Other than that, I should ask: do you know why you are using .5 for both parameters of mean and std? If not, chances are you are not using it properly. Please read about it on this answer and its applications.
Post a Comment for "Importing Transparent Images Gives Runtimeerror: The Size Of Tensor A (4) Must Match The Size Of Tensor B (3) At Non-singleton Dimension 0"