Pytorch RuntimeError: Expected 4-dimensional input for 4-dimensional weight [512, 512, 3, 3], but go

Pytorch RuntimeError: Expected 4-dimensional input for 4-dimensional weight [512, 512, 3, 3], but go,第1张

报错:

RuntimeError: Expected 4-dimensional input for 4-dimensional weight [512, 512, 3, 3], but got 2-dimensional input of size [4, 512] instead

conv2d卷积层输入大小不匹配
要求输入 [512, 512, 3, 3]
实际输入 [4, 512]

临时解法:把2d tensor expand成4d

someTensor = someTensor.unsqueeze(2).unsqueeze(3)

效果如下:

>>> a.shape
torch.Size([2, 2])
>>> a.unsqueeze(2).shape
torch.Size([2, 2, 1])
>>> a.unsqueeze(2).unsqueeze(3).shape
torch.Size([2, 2, 1, 1])

https://stackoverflow.com/questions/57237381/runtimeerror-expected-4-dimensional-input-for-4-dimensional-weight-32-3-3-but

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/995309.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存