Thanks for the code!
I’m not familiar with sklearn’s compute_clas_weight method, but from the docs it looks like the inverse class frequencies are returned, which should be alright.
It seems your classes 0 to 2 are the minority classes while you have a lot of samples of class3. Is that correct?
Skimming through your code I cannot find any obvious errors. Could you tell me your PyTorch version so that I could have a look later why it’s not working?