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

标签:pytorch,dataloader,batch,size
0
投稿

猜你喜欢

  • 浅谈Python小波分析库Pywavelets的一点使用心得

    2023-03-11 22:55:23
  • 详解DeBug Python神级工具PySnooper

    2022-12-14 15:44:31
  • jquery+ashx无刷新GridView数据显示插件(实现分页、排序、过滤功能)

    2024-05-11 09:17:35
  • 如何过滤中国站长站(chianz)文章干扰码

    2008-01-04 20:14:00
  • Javascript实现购物车功能的详细代码

    2024-05-22 10:32:27
  • python爬取免费代理并验证代理是否可用

    2021-12-24 20:02:48
  • 学习Python3 Dlib19.7进行人脸面部识别

    2022-03-18 00:01:30
  • Django 如何使用日期时间选择器规范用户的时间输入示例代码详解

    2023-06-18 23:56:20
  • SQL指令植入式攻击的危害及其防范措施

    2008-12-19 14:07:00
  • django中模板的html自动转意方法

    2023-06-28 15:33:49
  • Python如何加载模型并查看网络

    2021-11-01 15:53:22
  • 图文详解mysql中with...as用法

    2024-01-27 20:52:43
  • python连接远程ftp服务器并列出目录下文件的方法

    2023-10-20 10:35:04
  • python中format函数与round函数的区别

    2021-03-31 03:33:29
  • python编写实现抽奖器

    2023-02-25 00:44:45
  • python多进程并发demo实例解析

    2022-04-05 22:02:22
  • python和php哪个更适合写爬虫

    2023-10-28 00:51:14
  • mssql查找备注(text,ntext)类型字段为空的方法

    2024-01-28 04:13:18
  • HTTP缓存之ETag使用经验及效果

    2023-10-08 22:36:04
  • 教你使用pyinstaller打包Python教程

    2021-01-20 01:07:28
  • asp之家 网络编程 m.aspxhome.com