pytorch dataloader 取batch_size时候出现bug的解决方式
作者:U_C 时间:2023-08-12 01:27:45
1、
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 342 and 281 in dimension 3 at /pytorch/aten/src/TH/generic/THTensorMoreMath.cpp:1333
2、
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 3 and 1 in dimension 1
bug1 修改方法是将图片resize 成一个尺度:
解决1:
如果用transforms来resize ,关于尺寸的transform就是transforms.Resize(input_size, interpolation=3)了。
查看Resize的文档:
size (sequence or int) – Desired output size. If size is a sequence like (h, w), output size will be matched to this.
If size is an int, smaller edge of the image will be matched to this number. i.e, if height > width, then image will be rescaled to (size * height / width, size)
size这个参数既可以是一个数字,又可以是一个tuple,如果是数字,图片处理后的输出尺寸每次都会被重新计算为(input_size*height/width, size),这样如果输入图片尺寸不一致,输出图片尺寸会不一致, 将导致bug1 问题
解决2:
也可以直接用opencv resize
来源:https://www.cnblogs.com/llfctt/p/11912884.html
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
浅谈Python小波分析库Pywavelets的一点使用心得
![](https://img.aspxhome.com/file/2023/7/75207_0s.png)
详解DeBug Python神级工具PySnooper
jquery+ashx无刷新GridView数据显示插件(实现分页、排序、过滤功能)
![](https://img.aspxhome.com/file/2023/2/126372_0s.jpg)
如何过滤中国站长站(chianz)文章干扰码
![](https://img.aspxhome.com/file/UploadPic/up/2008010420592338.gif)
Javascript实现购物车功能的详细代码
![](https://img.aspxhome.com/file/2023/5/123445_0s.png)
python爬取免费代理并验证代理是否可用
学习Python3 Dlib19.7进行人脸面部识别
![](https://img.aspxhome.com/file/2023/5/76035_0s.png)
Django 如何使用日期时间选择器规范用户的时间输入示例代码详解
![](https://img.aspxhome.com/file/2023/1/64321_0s.gif)
SQL指令植入式攻击的危害及其防范措施
django中模板的html自动转意方法
Python如何加载模型并查看网络
![](https://img.aspxhome.com/file/2023/3/115123_0s.png)
图文详解mysql中with...as用法
![](https://img.aspxhome.com/file/2023/2/128032_0s.png)
python连接远程ftp服务器并列出目录下文件的方法
python中format函数与round函数的区别
python编写实现抽奖器
![](https://img.aspxhome.com/file/2023/0/71400_0s.jpg)
python多进程并发demo实例解析
python和php哪个更适合写爬虫
mssql查找备注(text,ntext)类型字段为空的方法
HTTP缓存之ETag使用经验及效果
教你使用pyinstaller打包Python教程
![](https://img.aspxhome.com/file/2023/4/128554_0s.png)