RuntimeError: Expected 4-dimensional input for 4-dimensional weight 32 1 7 7, but got 3-dimensional input of size [462, 2, 14] instead

class CNN(nn.Module):

def __init__(self):
    super(CNN, self).__init__()

    self.cnn1 = nn.Conv2d(in_channels=1, out_channels=32, kernel_size=7, stride=4, padding=3)
    self.relu1 = nn.ReLU()Preformatted text
    self.maxpool1 = nn.MaxPool2d(kernel_size=2)
    self.cnn2 = nn.Conv2d(in_channels=16, out_channels=64, kernel_size=5, stride=1, padding=2)
    self.relu2 = nn.ReLU()
    self.maxpool2 = nn.MaxPool2d(kernel_size=2)
    self.fc1 = nn.Linear(3136, 10)
    self.fcrelu = nn.ReLU()

def forward(self, x):
    out = self.cnn1(x)
    out = self.relu1(out)
    out = self.maxpool1(out)

    out = self.cnn2(out)
    out = self.relu2(out)
    out = self.maxpool2(out)

    out = out.view(out.size(0), -1)

    out = self.fc1(out)
    out = self.fcrelu(out)

    return out

A 2D layer, e.g. nn.Conv2d, expects the input to have the shape [batch_size, channels, height, width].
The in_channels of the first conv layer correspond to the channels in your input.

Based on the definition of self.cnn1 it seems you want to pass an input with a single channel, so you might want to call x = x.unsqueeze(1) to create the channel dimension.
This would only work, if your current input is defined as [batch_size, height, width].