温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

pytorch dataloader 取batch_size时候出现bug的解决方式

发布时间:2020-10-09 12:34:52 来源:脚本之家 阅读:260 作者:U_C 栏目:开发技术

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

以上这篇pytorch dataloader 取batch_size时候出现bug的解决方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持亿速云。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI