Pytorch报错解决:The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimensio
报错内容
报错分析
在执行 F.normalize(tensor, self.mean, self.std, self.inplace) 时,出现了tensor维度不匹配的问题(在axis=0的轴上,需要3维,得到的tensor为4维),该函数由 img = self.transform(img) 调用,因此可以判断在执行 self.transform(img) 前得到的img维度就不对,即读取的img包含RGBA四个通道。
报错代码定位
验证及解决
使用的图像:
验证代码:
from PIL import Image
import numpy as npimg_path = r"E:\datasets\plants\ip102_v1_1_old\splited_images\Alfalfa\train\Pieris canidia\40563.jpg"with open(img_path, 'rb') as f:img = Image.open(f)img2 = img.convert("RGB")temp_img = np.array(img).transpose(2, 0, 1)
temp_img2 = np.array(img2).transpose(2, 0, 1)
if(temp_img.shape[0] == 4):print("abnormal img")
debug截图: 因此,使用PIL.Image读取图像后,要用 .convert("RGB") 转为RGB三个通道。
错误代码修改:
注意: .convert("RGB")是一个有返回值的函数,并不直接对原来的img进行修改。
Pytorch报错解决:The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimensio相关推荐
- Pytorch——报错解决:TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, found
报错信息 TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; ...
- Pytorch——报错解决:RuntimeError: Output 0 of SelectBackward is a view and is being modified inplace.
我在做Semi-Supervised过程中,需要分别计算labeled和unlabeled data的loss,但是在多卡分布式过程中,不允许出现同一个model前向两次的情况,会报错(Runtime ...
- pytorch报错: invalid argument 0: Sizes of tensors must match except in dimension 0.
这个问题是在dataloader遇到的,网上一般是数据的维度不同,但我这里其实是最后一份数据和之前的数据比数量不足,所以凑不够一个batch,所以我的做法是加入drop_last=True意思是如果数 ...
- 报错解决——RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton
问题描述 RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dim ...
- 安装pytorch报错及解决
环境,win10,64位,Anaconda4.10.3,Cuda 9.2.148,cudnn应该为v7.4.2.24 其中在Anaconda中好像安装tensorflow-gpu 1.9 ,pytho ...
- 报错解决:ResourceExhaustedError: OOM when allocating tensor with shape
报错解决:ResourceExhaustedError: OOM when allocating tensor with shape 早上在使用tensorflow时遇到如下报错: Traceback ...
- Pytorch | 报错The given NumPy array is not writeable,and PyTorch does not support non-writeable tensor
Pytorch | 报错 The given NumPy array is not writeable,and PyTorch does not support non-writeable tenso ...
- Oracle因修改pga和sga超过memory限制size报错解决
小记一例 (因修改pga和sga超过memory限制size) ORA-00838: Specified value of MEMORY_TARGET is too small, needs to b ...
- pycharm安装pytorch报错 提示系列问题 torch 包找不到因为pip版本低,结果升级了pip从19.3到20.2 4又提示高版不支持torch安装
pycharm安装pytorch报错 提示系列问题 torch 包找不到因为pip版本低,结果升级了pip从19.3到20.2 4又提示高版不支持torch安装 DEPRECATION: The - ...
- pytorch报错Unable to get repr for
pytorch报错Unable to get repr for 标签出现了-1,2或者其他值,loss计算之后, 报错:CUDA error: device-side assert triggered ...
最新文章
- viewpager 无网络的时候滑动异常
- 12864输出字符c语言,大家看看该怎么改才能让12864液晶显示屏显示21个字符啊?...
- MSBuild学习总结
- sap abap中动态指定查询条件
- php——验证身份证是否合法的函数
- 汉王云名片识别(SM)组件开发详解
- 1019 数字黑洞 (20分)
- python字符编码与转码
- 经典面试题(16):以下代码将输出的结果是什么?
- 机器学习实战7-sklearn集成学习和随机森林
- 以前的某个程序安装已在安装计算机上创建挂起的文件操作。运行安装程序之前必须重新启动计算机...
- EMNLP 2017 北京论文报告会笔记
- 获取对象属性名的方法 Object.keys() 与 Object.getOwnPropertyNames() 与 for循环
- 【笔试面试】75道逻辑推理题及答案
- wireshark图解ip报文分片
- 查找下载外文文献,这个网站比知网好用多了,经过对比后,五星推荐给大家!
- 内置单片机的433无线模块高速连传典型运用
- python 自动问答系统_问答系统介绍
- axurerp出现错误报告_Windows 应用程序无法安装 事件查看器报错
- 副业搞钱的几个野路子:两个年入10万的零成本赚钱项目
热门文章
- python写的串口助手_Python实现的简单的单片机串口助手程序
- 攻防世界-misc高手进阶篇-2017_Dating_in_Singapore
- iOS开发中使用代码控制横竖屏的切换
- 【网络营销】CPA、CPS、CPM、CPT、CPC 是什么
- fpu测试_「正点原子NANO STM32开发板资料连载」第三十一章 FPU 测试实验
- Python.习题六 字典与集合(下)
- mapbox/minemap 获取比例尺
- How far away ? HDU - 2586 trajan算法lca
- hdu 2586 How far away ? (LCA转RMQ)
- 开机引导界面grub找不到