Here’s my example for how to create a custom loss function (along with several other important things in PyTorch). See if going through it is of any help!

  
      
      GitHub
  
  
    

Spandan-Madan/A-Collection-of-important-tasks-in-pytorch 3.2k

A-Collection-of-important-tasks-in-pytorch - Everyday things people use in Pytorch. No need to spend hours reading Pytorch forums trying to find them!