CNN in result CNN

Hi ,

output_train = model(x_train.float(),x_train1.float())
    output_val = model(x_val.float(),x_val1.float())
    loss_train = criterion(output_train, ((y_train.long())))
    loss_val = criterion(output_val, (y_val.long()))
    train_losses.append(loss_train)
    val_losses.append(loss_val)

error:

help me plzz @ptrblck

Your target tensor contains class indices, which are out of bounds as indicated in the error message.
nn.CrossEntropyLoss expects a model output in the shape [batch_size, nb_classes] and a target in the shape [batch_size] containing values in the range [0, nb_classes-1] for a multi-class classification use case.
E.g. if you are dealing with 10 classes, the model output would have the shape [batch_size, 10] and the target the shape [batch_size] and contain values between 0 and 9.

The error message indicates that a class index of 149 is out of bounds, so the model output contains logits for less classes.

@ptrblck I didn’t understand what I’m changing in this code

You have to make sure the model output shape’s channel dimension size is as large as the number of classes you are dealing with.

@ptrblck

out = self.cnn6(out)
        out = self.batchnorm6(out)
        out = self.relu(out)
        out = self.cnn7(out)
        out = self.batchnorm7(out)
        out = self.cnn8(out)
        out = self.batchnorm8(out)
out1 = self.cnn6(out1)
        out1 = self.batchnorm6(out1)
        out1 = self.relu(out1)
        out1 = self.cnn7(out1)
        out1 = self.batchnorm7(out1)
        out1 = self.cnn8(out1)
        out1 = self.batchnorm8(out1)
        out2= out- out1

label with colum 12