S-aiueo32 / contextual_loss_pytorch

Contextual Loss (CX) and Contextual Bilateral Loss (CoBi).
MIT License
171 stars 45 forks source link

Have anyone experience NaN loss with this loss function? #11

Closed xiankgx closed 2 years ago

xiankgx commented 2 years ago

I'm trying to reproduce the work "Deng, Q., Cao, J., Liu, Y., Chai, Z., Li, Q., & Sun, Z. (2020). Reference guided face component editing. IJCAI International Joint Conference on Artificial Intelligence, 2021-Janua, 502–508. https://doi.org/10.24963/ijcai.2020/70" which uses the contextual loss.

According to the paper, the input to the contextual loss are masked images, see Eqn. 7. I was able to use this loss on non-masked images without issues. However, using masked images results in NaN loss.

Have anyone experienced this before?

xiankgx commented 2 years ago

I was able to circumvent this problem by using Pytorch's softmax function instead of the following lines in the code:

https://github.com/S-aiueo32/contextual_loss_pytorch/blob/master/contextual_loss/functional.py#L119-L120