CNN Model Error

class Net(Module):
def init(self):
super(Net, self).init()

    self.cnn = Sequential(
        Conv2d(in_channels=1, out_channels=4, kernel_size=3, stride=1),
        ReLU(inplace=True),
        MaxPool2d(kernel_size=3, stride=1),
        Conv2d(in_channels=4, out_channels=4, kernel_size=3, stride=1),
        ReLU(inplace=True),
        MaxPool2d(kernel_size=3, stride=1),
        Linear(in_features=1000, out_features=500),
        ReLU(inplace=True),
        Linear(in_features=500, out_features=250),
        ReLU(inplace=True),
        Linear(in_features=250, out_features=4)
    )

def forward(self, x):
    x = self.cnn(x)
    x = x.view(x.size(0), -1)
    return x

Please tell me what is wrong, I don’t get it.
Error is: RuntimeError: Given groups=1, weight of size [4, 1, 3, 3], expected input[2190, 64, 64, 3] to have 1 channels, but got 64 channels instead

It seems you are passing the input tensor in a channels-last memory format, while PyTorch expects channels-first by default, so you would have to permute the dimensions into [batch_size, channels, height, width]. In case you are changing the memory format via tensor.to(memory_format=torch.channels_last) note that you should not change the dimensions manually, but let PyTorch do it internally.

Once you’ve permuted the input tensor you would run into the next error of a wrong number of in_channels in the first conv layer.
While it seems that your input tensor uses 3 channels, the first conv layer uses 1 input channel, so you would have to change this next.

Thanks a lot. I will try that.