一见如故的我
2022-06-30 17:23
采纳率: 0%
浏览 23

残差网络x和out维度不匹配

Traceback (most recent call last):
File "C:/Users/一见如故/Desktop/torch/Resnet trian.py", line 243, in
test1 = net(test1.to(device)) # 将向量打入神经网络进行测试
File "D:\anaconda1\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1110, in _call_impl
return forward_call(*input, **kwargs)
File "C:/Users/一见如故/Desktop/torch/Resnet trian.py", line 183, in forward
x = self.layer2(x)
File "D:\anaconda1\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1110, in _call_impl
return forward_call(*input, **kwargs)
File "D:\anaconda1\envs\pytorch\lib\site-packages\torch\nn\modules\container.py", line 141, in forward
input = module(input)
File "D:\anaconda1\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1110, in _call_impl
return forward_call(*input, **kwargs)
File "C:/Users/一见如故/Desktop/torch/Resnet trian.py", line 66, in forward
out += identity
RuntimeError: The size of tensor a (14) must match the size of tensor b (28) at non-singleton dimension 3
在使用Resnet做分类器时,残差网络中
def forward(self, x):
identity = x

    out = self.conv1(x)
    out = self.bn1(out)
    out = self.relu(out)

    out = self.conv2(out)
    out = self.bn2(out)
    print(out.shape)
    print(identity.shape)

    if self.downsample is not None:
        identity = self.downsample(x)

    out += identity
    out = self.relu(out)

出现维度问题,该如何解决

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题