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.