pytorch计算模型参数量时报错:RuntimeError: mat1 dim 1 must match mat2 dim 0

错误:

File “C:\Users\83543\PycharmProjects\graduate\CIFAR-10\VGG-Small\vgg.py”, line 220, in forward
x = self.fc(x)
File “D:\120\Python\Python37\lib\site-packages\torch\nn\modules\module.py”, line 727, in _call_impl
result = self.forward(*input, **kwargs)
File “D:\120\Python\Python37\lib\site-packages\torch\nn\modules\linear.py”, line 93, in forward
return F.linear(input, self.weight, self.bias)
File “D:\120\Python\Python37\lib\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

错误原因及解决方案:

flops, params = get_model_complexity_info(model, (3, 320, 320), as_strings=True, print_per_layer_stat=True)

输入跟模型的原输入不一样,改成:

flops, params = get_model_complexity_info(model, (3, 32, 32), as_strings=True, print_per_layer_stat=True)

你可能感兴趣的:(torch)