Kerwind:

And I also noticed that the dimension of y_pre and batchY is different. Is this the reason why the model seems to be unefficient?


If you look at the nn.CrossEntropyLoss documentation, you can see that y_pre (shape B x C) and batchY (shape C) have the correct shape, so no problem here (B = batch_size and C = number_classes).



 Kerwind:

I also get confused that my CPU utilization is 100% but my GPU’s is 0, but I already transfered the whole process to cuda.


You might want to make sure that torch.cuda.is_available() returns True. I tried your code and it went on my GPU no problem, so you may not be using yours.