Hey guys,
I’m kinda new to pytorch/ML in general and haven’t tried writing my own loss function before, I’m looking at Custom loss functions - #9 by ptrblck 4 and it doesn’t seem too difficult. My specific question is to do with implementing a cost matrix which is what I think How to make cost function out of confusion matrix? 1 is trying to do but it seems confusing.
Specifically I’m training a EfficientNet on the ISIC 2019 dataset and wanted to ask if there is any specific standard way for doing this in pytorch?
For those of you who don’t know a confusion matrix is something looks like this:

Using this matrix I would multiply the loss by a factor of 10 if my model predicted ‘not faulty’ when it was in fact ‘faulty’, and multiply the loss by only a factor of 1 if it predicted something that was ‘not faulty’ as ‘faulty’ (and multiply by 0 if it got it right). My cost matrix won’t look like this exactly, as mine is on skin lesions and ISIC has 8 different unbalanced classes of skin cancer, and some classifications are more dangerous than others, which is why it’s important that my model learns which incorrect predictions are more costly.
Any help would be appreciated