报错:
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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)