This is my class for implementing logistic regression and a code to instantiate this class.
class LogisticRegression(torch.nn.Module):
def __init__(self, input_dim):
super(LogisticRegression, self).__init__()
self.linear = torch.nn.Linear(input_dim, 1)
#self.linear = torch.nn.Linear(2*input_dim, output_dim)
#raise NotImplementedError()
def forward(self, x):
outputs = self.linear(x)
outputs = nn.Sigmoid(outputs)
return outputs
model = LogisticRegression(input_dim)
criterion = torch.nn.CrossEntropyLoss()
optimizer = torch.optim.SGD(model.parameters(), lr=lr_rate)
output=model(data_X)
I am getting the following error, … I have passed only one argument to model, yet it is saying there is mismatch.
TypeError Traceback (most recent call last)
in ()
11 #print(data_X.shape, data_X.type())
12
—> 13 outputs = model(data_X)
14 labels = labels.squeeze_()
15 loss = criterion(outputs, labels)
1 frames
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
539 result = self._slow_forward(*input, **kwargs)
540 else:
–> 541 result = self.forward(*input, **kwargs)
542 for hook in self._forward_hooks.values():
543 hook_result = hook(self, input, result)
in forward(self, x)
17 def forward(self, x):
18 outputs = self.linear(x)
—> 19 outputs = nn.Sigmoid(outputs)
20 return outputs
TypeError: init() takes 1 positional argument but 2 were given
Any help is much appreciated.