Hi everyone,
I got ValueError: expected 4D input (got 2D input) when I trained the following network:
class Net(nn.Module):
def init(self):
super(Net, self).init()
self.conv1=nn.Conv2d(3,32,3, padding = 1)
self.conv2=nn.Conv2d(32,64,3, padding = 1)
self.conv2_bn = nn.BatchNorm2d(64)
self.conv3=nn.Conv2d(64,128,3, padding = 1)
self.conv3_bn = nn.BatchNorm2d(128)
self.pool=nn.MaxPool2d(2,2)
self.fc1=nn.Linear(1282828,500)
self.dense1_bn = nn.BatchNorm2d(500)
self.fc2=nn.Linear(500,133)
self.dropout=nn.Dropout(0.20)
def forward(self, x):
   # add sequence of convolutional and max pooling layers
        x=self.pool(F.relu(self.conv1(x)))
        # print(x.shape)
        x=self.pool(F.relu(self.conv2_bn(self.conv2(x))))
        # print(x.shape)
        x=self.pool(F.relu(self.conv3_bn(self.conv3(x))))
        # print(x.shape)
        # flatten image input
        x=x.view(-1,128*28*28)
        x=self.dropout(x)
        x = F.relu(self.dense1_bn(self.fc1(x)))
        # add dropout layer
        x = self.dropout(x)
        x=self.fc2(x)
        return x

Can you please help me to know why this error happened?