How to implement the loss function of fully convolutional segmentation network?

In an implementation, it use the F.nll_loss as its loss function. And in the source code, it points to the NLLLoss. However, it is difficult for me to find the specific implementation because of its lots of inheritance. Could anyone tell me how to implementation the loss function in the fully convolutional network? I want to weight the loss according to the spatial position of every pixel.

Maybe you can refer to https://github.com/wkentaro/pytorch-fcn/blob/master/torchfcn/trainer.py#L19 .

Thanks! It will be helpful.