Hello, i am getting the error when i am trying to train a CNN model using custom dataset.
here is my model:
class CNNMnist(nn.Module): def __init__(self, args): super(CNNMnist, self).__init__() self.conv1 = nn.Conv2d(args.num_channels, 10, kernel_size=5) self.conv2 = nn.Conv2d(10, 20, kernel_size=5) self.conv2_drop = nn.Dropout2d() self.fc1 = nn.Linear(720, 50) self.fc2 = nn.Linear(128, args.num_classes) def forward(self, x): x = F.relu(F.max_pool2d(self.conv1(x), 2)) x = F.relu(F.max_pool2d(self.conv2_drop(self.conv2(x)), 2)) x = x.view(-1, x.shape*x.shape*x.shape) print(x.shape) x = F.relu(self.fc1(x)) x = F.dropout(x, training=self.training) x = self.fc2(x) return F.log_softmax(x, dim=1)
i reshape my images while loading with
i initialize my model:
global_model = CNNMnist(args=args)
for my custom dataset, the number of class is 6 and the number of channel is 3.
The error is thrown at
x = F.relu(self.fc1(x)).
After spending hours trying to find out the problem, my guess is the values used in the following lines are not correct:
self.fc1 = nn.Linear(720, 50) self.fc2 = nn.Linear(128, args.num_classes)
Since i actually have no idea how these values are calculated, I would really appreciate some help on this.