Pytorch | I don't know why it is throwing an error? (Beginner)
import torch.nn as nn
import torch.nn.functional as F

## TODO: Define the NN architecture
class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        # linear layer (784 -&gt; 1 hidden node)
        self.fc1 = nn.Linear(28 * 28, 512)
        self.fc2 = nn.Linear(512 * 512)
        self.fc3 = nn.Linear(512 * 10)

    def forward(self, x):
        # flatten image input
        x = x.view(-1, 28 * 28)
        # add hidden layer, with relu activation function
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = F.relu(self.fc3(x))
        return x

# initialize the NN
model = Net()
print(model)


When I run this, it throws this error. Why?

TypeError: __ init __() missing 1 required positional argument: 'out_features'

This error is because you have not provided the output size of the fully connected layer in your fc2 and fc3.
Below is the modified code. I added the output size, I am not sure if this is the output size architecture you want. But for the demonstration, I put the output size. Please edit the code and add the output size as per your requirement.

Remember that the output size of the previous fully connected layer should be the input size of the next FC layer. Else it will throw size mismatch error.

import torch.nn as nn
import torch.nn.functional as F

## TODO: Define the NN architecture
class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        # linear layer (784 -&gt; 1 hidden node)
        self.fc1 = nn.Linear(28 * 28, 512)
        self.fc2 = nn.Linear(512 ,512*10)
        self.fc3 = nn.Linear(512 * 10,10)

    def forward(self, x):
        # flatten image input
        x = x.view(-1, 28 * 28)
        # add hidden layer, with relu activation function
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = F.relu(self.fc3(x))
        return x

# initialize the NN
model = Net()
print(model)

