Thanks for your comments @ptrblck! What happens is that my network is not learning, as you can see in the following image:
But if the loss function is correct, I think the problem may be something else, like the network is not good enough for my problem or the dataset. I just wanted to make sure that I was not making any silly mistakes by implementing my loss function in pytorch.