Write Custom Loss Function

I want to define a new loss function similar to the one defined in the action recognition using visual attention paper i.e. eq. 7.

I thought it would be useful to use the NLL Loss defined in PyTorch as a guide but I can’t seem to find the source code. What I found on github was this but I do not see its implementation [here] (https://github.com/pytorch/pytorch/blob/master/torch/nn/_functions/thnn/loss.py).

Would anyone be kind enough to post the link to the source code?

Most of the functions are implemented in C / CUDA. For reference, here is the C implementation of NLLLoss

2 Likes

But you don’t have to use that in your custom loss function; you should just implement an nn.Module with ordinary torch math ops in the forward method.

2 Likes

Sorry I am a bit late to the conversation, but will there be any performance issues if we just implement it fully in torch ops?