RuntimeError: shape '[-1, 1031]' is invalid for input of size 900
I am trying to build a CNN but I get this error:
shape '[-1, 1031]' is invalid for input of size 900

My code is below:
class CPillModel(nn.Module):
    def __init__(self, input_dim, hidden_dim, output_dim):
        super(CPillModel, self).__init__()
        self.fc1 = nn.Linear(input_dim, hidden_dim) 
        self.relu1 = nn.ReLU()
        
        self.fc2 = nn.Linear(hidden_dim, hidden_dim)
        self.relu2 = nn.ReLU()
        
        self.fc3 = nn.Linear(hidden_dim, hidden_dim)
        self.relu3 = nn.ReLU()
        
        self.fc4 = nn.Linear(hidden_dim, output_dim)  
        self.act4 = Sigmoid()
    
    def forward(self, x):
        
       ....
       ....
       return x

# instantiate ANN
input_dim = 1031
hidden_dim = 150 
output_dim = 10

# Create ANN
model = CPillModel(input_dim, hidden_dim, output_dim)

# Cross Entropy Loss 
error = nn.CrossEntropyLoss()


# SGD Optimizer
learning_rate = 0.02
optimizer = torch.optim.SGD(model.parameters(), lr=learning_rate)


# ANN model training
count = 0
loss_list = []
iteration_list = []
accuracy_list = []      
for epoch in range(num_epochs):
# enumerate mini batches
    for i, (data_a, data_b) in enumerate(train_loader):
        train = Variable(data_a.view(-1, 1031))
        labels = Variable(data_b)
        # clear the gradients
        optimizer.zero_grad()
        optimizer.zero_grad()
        # compute the model output
        outputs = model(data_a)
        # calculate loss
        loss = error(outputs, data_b)
        # credit assignment
        loss.backward()
        # update model weights
        optimizer.step()
        count += 1


I think the issue I have is with my train variable line: train = Variable(data_a.view(-1, 1031))
I have 1031 rows of features training data but they are not being converted.
Do I split these 1031 data points into a format such as: a x b to work?
Would data reshape work?
The print out of data_a is: data_a is torch.Size([100, 9]

First, the number of features is 9 not 1031, so you would have to change input_dim to 9.
I would also suggest you reduce the value of hidden_dim.
You would also change this line train = Variable(data_a.view(-1, 1031)) to train = Variable(data_a) as there is no need for data_a to be reshaped.
I don't know what's inside the forward method so I guess that's all you need to change.
