Error "_init__() takes 1 positional argument but 2 were given" when trying to build a CNN model using PyTorch
I have recently started to learn coding with PyTorch. While I was trying to build a CNN model for the FashionMNIST dataset, I encountered the following problem :
TypeError                                 Traceback (most recent call last)
 in ()
----&gt; 1 model = CNN (K)
TypeError: init() takes 1 positional argument but 2 were given
I have read the answers to similar questions but still, I am not able to solve my problem. I would be deeply grateful if anyone could help me in this regard.
Here is the code:
train_dataset = torchvision.datasets.FashionMNIST (root = '.', train = True, transform = transforms.ToTensor (), download= True)
test_dataset = torchvision.datasets.FashionMNIST (root = '.', train= False, transform = transforms.ToTensor (), download = True)

K = len (set (train_dataset.targets.numpy ()))
class CNN (nn.Module):
  def __int__ (self, K):

    super (CNN, self).__int__ ()

    self.conv_layers = nn.Sequential (
    nn.Conv2d (in_channels= 1, out_channels= 32, kernel_size= 3, stride = 2),
    nn.ReLU (),
    nn.Conv2d (in_channels= 32, out_channels= 64, kernel_size= 3, stride = 2),
    nn.ReLU (),
    nn.Conv2d (in_channels= 64, out_channels= 128, kernel_size= 3, stride= 2),
    nn.ReLU ()
    )

    self.dense_layers = nn.Sequential (nn.Dropout (0.2),
                                   nn.Linear (128 * 2 * 2, 512),
                                   nn.ReLU (),
                                   nn.Dropout (0.2),
                                   nn.Linear (512, K)
                                   )
   def forward (self, x):
   out = self.conv_layers (x)
   out = out.view (out.size (0), -1)
   out = self.dense_layers (out)
   return out

                                   


There is a typo in your initializer method head: it should be def __init__, not def __int__.
