pytorch RuntimeError: size mismatch, m1: [64 x 784], m2: [784 x 10] at


from torch import nn

class Mnist_Logistic(nn.Module):
    def __init__(self):
        super().__init__()
        self.lin=nn.Linear(748,10)
    
    def forward(self,xb):
        return self.lin(xb)
        
print(loss_func(model(xb),yb))

出现错误
size mismatch, m1: [64 x 784], m2: [748 x 10] at c:\a\w\1\s\windows\pytorch\aten\src\th\generic/THTensorMath.cpp:940
意思是说我输入的矩阵是64784
但是weights的矩阵是748
10
矩阵大小不匹配 不能相乘

修改

self.lin=nn.Linear(784,10)
    

你可能感兴趣的:(pytorch)