Solved by ptrblck in post #2 
              
              
                The in_features of self.fc1 = nn.Linear(784, 16) do not match the number of features in the flattened activation in: 
        x = torch.flatten(x)
        x = self.fc1(x)

so you would need to set in_features of fc1 to 20588 or adapt the input shape to the model.