The size of tensor a must match the size of tensor b at non-singleton dimension 0
Posted AI浩
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了The size of tensor a must match the size of tensor b at non-singleton dimension 0相关的知识,希望对你有一定的参考价值。
File "D:\\cv\\captcha.Pytorch-master\\train.py", line 352, in <module>
train_original(net)
File "D:\\cv\\captcha.Pytorch-master\\train.py", line 234, in train_original
for circle, input in enumerate(trainDataLoader, 0):
File "D:\\ProgramData\\Anaconda3\\lib\\site-packages\\torch\\utils\\data\\dataloader.py", line 521, in __next__
data = self._next_data()
File "D:\\ProgramData\\Anaconda3\\lib\\site-packages\\torch\\utils\\data\\dataloader.py", line 561, in _next_data
data = self._dataset_fetcher.fetch(index) # may raise StopIteration
File "D:\\ProgramData\\Anaconda3\\lib\\site-packages\\torch\\utils\\data\\_utils\\fetch.py", line 49, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "D:\\ProgramData\\Anaconda3\\lib\\site-packages\\torch\\utils\\data\\_utils\\fetch.py", line 49, in <listcomp>
data = [self.dataset[idx] for idx in possibly_batched_index]
File "D:\\cv\\captcha.Pytorch-master\\lib\\dataset.py", line 93, in __getitem__
data = self.transform(data)
File "D:\\ProgramData\\Anaconda3\\lib\\site-packages\\torchvision\\transforms\\transforms.py", line 61, in __call__
img = t(img)
File "D:\\ProgramData\\Anaconda3\\lib\\site-packages\\torch\\nn\\modules\\module.py", line 1102, in _call_impl
return forward_call(*input, **kwargs)
File "D:\\ProgramData\\Anaconda3\\lib\\site-packages\\torchvision\\transforms\\transforms.py", line 226, in forward
return F.normalize(tensor, self.mean, self.std, self.inplace)
File "D:\\ProgramData\\Anaconda3\\lib\\site-packages\\torchvision\\transforms\\functional.py", line 351, in normalize
tensor.sub_(mean).div_(std)
RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 0
Process finished with exit code 1
解决方法:将图像转为RGB
data = Image.open(imgPath).convert('RGB')
以上是关于The size of tensor a must match the size of tensor b at non-singleton dimension 0的主要内容,如果未能解决你的问题,请参考以下文章
解决ret = umr_sum(arr, axis, dtype, out, keepdims)RuntimeError: The size of tensor a (400) must match
解决ret = umr_sum(arr, axis, dtype, out, keepdims)RuntimeError: The size of tensor a (400) must match(
typeError:The value of a feed cannot be a tf.Tensor object.Acceptable feed values include Python sca
tf.keras遇见的坑:Output tensors to a Model must be the output of a TensorFlow `Layer`
Sizes of tensors must match except in dimension 1. Expected size 24 but got size 25 for tensor numbe
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1 #805