RuntimeError: stack expects each tensor to be equal size, but got at entry



参考链接:​​​​​​解决Pytorch dataloader时报错每个tensor维度不一样的问题_python_脚本之家

记录一下自己遇到的bug:

问题描述: 

问题分析:

torch.stack(batch, 0, out=out)出错,原因可能是:同一个batch的数据图片的维度(H, W, C)要相同(可以见官方文档:其shape必须一致)

问题解决:

如果图像尺寸不固定一致的话,那batch_size设置为1,问题即可解决

猜你喜欢

转载自blog.csdn.net/m0_55780358/article/details/129907221