I am practicing pytorch nowdays, actually shifting from keras.
But I can not understand why I am getting this error:
TypeError: NeuralNet02.init() takes 1 positional argument but 3 were given
Here’s my code:
‘’'class NeuralNet02(nn.Module):
def int(self, in_size, out_size, num_hidden_layer=10, hidden_layer_size=128):
super(NeuralNet02,self).int()
self.in_size = in_size
self.out_size = out_size
self.num_hidden_layer = num_hidden_layer
self.hidden_layer_size = hidden_layer_size
# In PyTorch, the terms "module" and "layer" are often used interchangeably to refer to a
# building block of a neural network that performs a specific computation on the input data.
self.layers = nn.Sequential() # initialization
for i in range(num_hidden_layer):
self.layers.add_module(f'fc{i}', nn.Linear(in_size, hidden_layer_size)) # adding layers/modules
self.layers.add_module('activation', nn.ReLU())
in_size = hidden_layer_size
self.layers.add_module('classifier', nn.Sigmoid(hidden_layer_size, out_size))
def forward(self,inputs):
out = self.layers(inputs)
return out
x = torch.randn(8,14)
model = NeuralNet02(14,4)
output = model(x)
print(output)‘’’