pytorch dataloader 取batch_size时候出现bug的解决方式
1、
RuntimeError:invalidargument0:Sizesoftensorsmustmatchexceptindimension0.Got342and281indimension3at/pytorch/aten/src/TH/generic/THTensorMoreMath.cpp:1333
2、
RuntimeError:invalidargument0:Sizesoftensorsmustmatchexceptindimension0.Got3and1indimension1
bug1修改方法是将图片resize成一个尺度:
解决1:
如果用transforms来resize,关于尺寸的transform就是transforms.Resize(input_size,interpolation=3)了。
查看Resize的文档:
size(sequenceorint)–Desiredoutputsize.Ifsizeisasequencelike(h,w),outputsizewillbematchedtothis.
Ifsizeisanint,smalleredgeoftheimagewillbematchedtothisnumber.i.e,ifheight>width,thenimagewillberescaledto(size*height/width,size)
size这个参数既可以是一个数字,又可以是一个tuple,如果是数字,图片处理后的输出尺寸每次都会被重新计算为(input_size*height/width,size),这样如果输入图片尺寸不一致,输出图片尺寸会不一致,将导致bug1问题
解决2:
也可以直接用opencvresize
以上这篇pytorchdataloader取batch_size时候出现bug的解决方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。