What is the shape of the output y_pred and your labels targets? I think you can’t conduct both CrossEntropyLoss and MSELoss on the same pair of data. As the document states, the shape of input and target to these loss functions should be:


CrossEntropyLoss: input[N,C]; target[N] (where N is the batch size, and C is the number of classes.)

MSELoss: input and target should be the identical in shape, like [N,*].

So, only when C=1, it’s possible to use the two loss functions at the same time, but that would be meaningless for a classification task.
BTW, if your want to paste codes, use three dots (```) to surround them, so the format won’t be changed.
```
print("")
```