PyTorch错误 torch.addmm RuntimeError: mat1 dim 1 must match mat2 dim 0

PyTorch错误 torch.addmm RuntimeError: mat1 dim 1 must match mat2 dim 0

flyfish

详细提示

File "python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/media/ubuntu/data/pytorch1.7/soothsayer/model/net_regression.py", line 50, in forward
    x = self.predict(x)
  File "python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "python3.6/site-packages/torch/nn/modules/linear.py", line 93, in forward
    return F.linear(input, self.weight, self.bias)
  File "python3.6/site-packages/torch/nn/functional.py", line 1690, in linear
    ret = torch.addmm(bias, input, weight.t())
RuntimeError: mat1 dim 1 must match mat2 dim 0

代码

self.fc1 = nn.Linear(128, 120)
self.fc2 = nn.Linear(120, 84)

假设forward中要依次执行fc1和fc2
fc1的out_features 等于fc2的in_features就不会有错误,这里都是120不会有错误
反之

self.fc1 = nn.Linear(128, 121)
self.fc2 = nn.Linear(120, 84)

则出现让面的错误提示

上一篇:C++基础-单链表(ForwardList)


下一篇:docker容器的服务突然访问不了