class LinearRegressionModel(nn.Module): #继承nn模块
def _init_(self,input_dim,output_dim):
super(LinearRegressionModel,self)._init_()
self.linear=nn.Linear(input_dim,output_dim)
def forward(self,x):
out=self.linear(x)
return out
input_dim=1
output_dim=1
model=LinearRegressionModel(input_dim,output_dim)
报错原因:__init__左右是两条短划线
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-60-46c0752f3cd8> in <module>
1 input_dim=1
2 output_dim=1
----> 3 model=LinearRegressionModel(input_dim,output_dim)
TypeError: __init__() takes 1 positional argument but 3 were given