Size mismatch for DNN for the MNIST dataset in pytorch
I have to find a way to create a neural network model and train it on the MNIST dataset. I need there to be 5 layers, with 100 neurons each. However, when I try to set this up I get an error that there is a size mismatch. Can you please help? I am hoping that I can train on the model below:

class Mnist_DNN(nn.Module):
    def __init__(self):
        super().__init__()
        self.layer1 = nn.Linear(784, 100)
        self.layer2 = nn.Linear(100, 100)
        self.layer3 = nn.Linear(100, 100)
        self.layer4 = nn.Linear(100, 100)
        self.layer5 = nn.Linear(100, 10)

    def forward(self, xb):
        xb = xb.view(-1, 1, 28, 28)
        xb = F.relu(self.layer1(xb))
        xb = F.relu(self.layer2(xb))
        xb = F.relu(self.layer3(xb))
        xb = F.relu(self.layer4(xb))
        xb = F.relu(self.layer5(xb))
        return self.layer5(xb)



You setup your layer to get a batch of 1D vectors of dim 784 (=28*28). However, in your forward function you view the input as a batch of 2D matrices of size 28*28.
try viewing the input as a batch of 1D signals:

xb = xb.view(-1, 784)

