Hello everyone!
I’m studying CNN model, and i want to build a CNN with the following structure
CNN
Conv2D(in_channels=1, out_channels=32, kernel_size = 3, stride=1)
ReLU
MaxPool2D(kernel=2, stride=2)
Conv2D(in_channels=32, out_channels=64, kernel_size = 3, stride=1)
ReLU
MaxPool2D(kernel=2, stride=2)
Conv2D(in_channels=64, out_channels=128, kernel_size = 3, stride=1)
ReLU
MaxPool2D(kernel=2, stride=2)
Linear(in_features=2048, out_features=625)
ReLU
Dropout
Linear(in_features=625, out_features=10)
And then, the script i wrote is:
class CNN(nn.Module):
def init(self):
super(CNN, self).init()
self.conv1 = nn.Conv2d(in_channels=1, out_channels=32, kernel_size=3, stride=1)
self.conv2 = nn.Conv2d(in_channels=32, out_channels=64, kernel_size=3, stride=1)
self.conv3 = nn.Conv2d(in_channels=64, out_channels=128, kernel_size=3, stride=1)
self.dropout1 = nn.Dropout(0.25)
self.dropout2 = nn.Dropout(0.5)
self.fc1 = nn.Linear(in_features=2048, out_features=625)
self.fc2 = nn.Linear(in_features=625, out_features=10)
def forward(self, x):
x = self.conv1(x)
x = F.relu(x)
x = F.max_pool2d(x, 2)
x = self.conv2(x)
x = F.relu(x)
x = F.max_pool2d(x, 2)
x = self.conv3(x)
x = F.relu(x)
x = F.max_pool2d(x, 2)
x = self.fc1(x)
x = F.relu(x)
x = self.dropout1(x)
x = self.fc2(x)
output = F.log_softmax(x, dim=1)
return output
but i get RuntimeError!
RuntimeError: mat1 and mat2 shapes cannot be multiplied (8192x1 and 2048x625)
I would really appreciate it if you could let me know what’s wrong with my example.