PyTorch NN : RuntimeError: mat1 dim 1 must match mat2 dim 0
I'm new to the Neural Network domain and I have stuck on a problem.
I'm trying to create a NN with dropout with 0.1 probability for the hidden fully connected layer.
When I code like below:
class ConvNet(torch.nn.Module): 
    def __init__(self):
        super().__init__()
        self.layers = torch.nn.Sequential(
            
            #layer1
            torch.nn.Conv2d(in_channels=3, out_channels=16, kernel_size=3, stride=1),
            torch.nn.MaxPool2d(kernel_size=2, stride=3),
            torch.nn.BatchNorm2d(num_features=16),
            torch.nn.ReLU(),
        
            #layer2
            torch.nn.Conv2d(in_channels=16, out_channels=32, kernel_size=3, stride=1),
            torch.nn.MaxPool2d(kernel_size=2, stride=3),
            torch.nn.BatchNorm2d(num_features=32),
            torch.nn.ReLU(),
        
            #layer3
            torch.nn.Conv2d(in_channels=32, out_channels=32, kernel_size=3, stride=1),
            torch.nn.MaxPool2d(kernel_size=2, stride=3),
            torch.nn.BatchNorm2d(num_features=32),
            torch.nn.Flatten(),
            torch.nn.Linear(32,16), 
            torch.nn.Dropout2d(p=0.1),
            torch.nn.Linear(16, 2)
        )


        
    def forward(self, x):
        return self.layers(x)
        

test_convnet = ConvNet().to('cuda')
test_input = torch.randn(16, 3, 100, 100, device='cuda')
test_output = test_convnet(test_input)
print(test_output.shape)

And then I got the error:
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
&lt;ipython-input-27-b5ce1c300266&gt; in &lt;module&gt;()
     48 test_convnet = ConvNet().to('cuda')
     49 test_input = torch.randn(16, 3, 100, 100, device='cuda')
---&gt; 50 test_output = test_convnet(test_input)
     51 print(test_output.shape)

6 frames
/usr/local/lib/python3.7/dist-packages/torch/nn/functional.py in linear(input, weight, bias)
   1751     if has_torch_function_variadic(input, weight):
   1752         return handle_torch_function(linear, (input, weight), input, weight, bias=bias)
-&gt; 1753     return torch._C._nn.linear(input, weight, bias)
   1754 
   1755 

RuntimeError: mat1 dim 1 must match mat2 dim 0
Thanks in advance for all of your help

In layer 3
 #layer3
            torch.nn.Conv2d(in_channels=32, out_channels=32, kernel_size=3, stride=1),
            torch.nn.MaxPool2d(kernel_size=2, stride=3),
            torch.nn.BatchNorm2d(num_features=32),
            torch.nn.Flatten(),
            torch.nn.Linear(288,16), 
            torch.nn.Dropout2d(p=0.1),
            torch.nn.Linear(16, 2)

Corrected Line = torch.nn.Linear(288,16)
This is the wrong shape: torch.nn.Linear(32,16)
Full code:
from argparse import ArgumentParser
import numpy as np
from torch.utils.data import random_split, DataLoader, TensorDataset
import torch
from torch.autograd import Variable
from torchvision import transforms
import torch
from torch import nn
from torch.nn import functional as F
from torch.optim import Adam
from torch.optim.optimizer import Optimizer

class ConvNet(torch.nn.Module): 
    def __init__(self):
        super().__init__()
        self.layers = torch.nn.Sequential(
            
            #layer1
            torch.nn.Conv2d(in_channels=3, out_channels=16, kernel_size=3, stride=1),
            torch.nn.MaxPool2d(kernel_size=2, stride=3),
            torch.nn.BatchNorm2d(num_features=16),
            torch.nn.ReLU(),
        
            #layer2
            torch.nn.Conv2d(in_channels=16, out_channels=32, kernel_size=3, stride=1),
            torch.nn.MaxPool2d(kernel_size=2, stride=3),
            torch.nn.BatchNorm2d(num_features=32),
            torch.nn.ReLU(),
        
            #layer3
            torch.nn.Conv2d(in_channels=32, out_channels=32, kernel_size=3, stride=1),
            torch.nn.MaxPool2d(kernel_size=2, stride=3),
            torch.nn.BatchNorm2d(num_features=32),
            torch.nn.Flatten(),
            torch.nn.Linear(288,16), 
            torch.nn.Dropout2d(p=0.1),
            torch.nn.Linear(16, 2)
        )


        
    def forward(self, x):
        return self.layers(x)
        

test_convnet = ConvNet()
test_input = torch.randn(16, 3, 100, 100)
test_output = test_convnet(test_input)
print(test_output.shape)

