Pytorch RuntimeError: Expected 4-dimensional input for 4-dimensional weight [512, 512, 3, 3], but go
发布时间
阅读量:
阅读量
RuntimeError: Expected 4-dimensional input for 4-dimensional weight [512, 512, 3, 3], but got 2-dimensional input of size [4, 512] instead
bash
conv2d卷积层的输入尺寸存在不匹配问题,系统期望接收的输入格式为[512, 512, 3, 3],但当前实际接收到的输入维度为[4, 512]。
临时应对措施为:将二维张量扩展为四维张量以满足输入要求。
someTensor = someTensor.unsqueeze(2).unsqueeze(3)
python
具体表现如下:
>>> 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])
bash
全部评论 (0)
还没有任何评论哟~
