Well, I rewrote the code and find the mistake. You were right about the number of classes, I fixed it. The code works properly with the torch.backends.cudnn.enabled = False setting. I trained 3 epoch with no mistake. Then I stopped, because my graphical card started to make a noise such as dj spinner and whilst I am not familiar with the hardware, I don’t know If something is going wrong, do you think that the noise can be harmful or just happened because of a training process? Also, the first error is still the same when cudnn is enabled.