Error on shape in tensor multiplication

I am experimenting with Pytorch and I want to build a 3D CNN. My input is a tensor of size 25x25x25 and the output is a binary [0, 1]. I have defined the following architecture:

 # Architecture of CNN
 class Net(nn.Module):
     def __init__(self):
         super().__init__()
         self.conv1 = nn.Conv3d(in_channels=1, out_channels=3, kernel_size=5)
         self.pool = nn.MaxPool3d(kernel_size=3) # Stride equals `kernel_size`
         self.fc1 = nn.Linear(7*7*7*3, 20)
         self.fc2 = nn.Linear(20, 5)
         self.fc3 = nn.Linear(5, 2)
 
     def forward(self, x):
         x = self.pool(F.relu(self.conv1(x)))
         x = torch.flatten(x, 1)
         x = F.relu(self.fc1(x))
         x = F.relu(self.fc2(x))
         x = self.fc3(x)
         return x


I am getting the following error: RuntimeError: mat1 and mat2 shapes cannot be multiplied (3x343 and 1029x20). Note that 3*343 == 1029 and I am flatteting except the batch size dimension.

Your model works fine for me:

model = Net()

x = torch.randn(2, 1, 25, 25, 25)
out = model(x)
print(out.shape)
# torch.Size([2, 2])

x = torch.randn(64, 1, 25, 25, 25)
out = model(x)
print(out.shape)
# torch.Size([64, 2])

@ptrblck Thanks for the answer and your time. I tried your snippet and works fine. The error happened during training where I forgot to reshape my training inputs to include 1 channel.