Created
May 9, 2018 02:40
-
-
Save jamesr2323/33c67ba5ac29880171b63d2c7f1acdc5 to your computer and use it in GitHub Desktop.
How to use RMSE loss function in PyTorch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Thanks https://discuss.pytorch.org/t/rmse-loss-function/16540 | |
class RMSELoss(torch.nn.Module): | |
def __init__(self): | |
super(RMSELoss,self).__init__() | |
def forward(self,x,y): | |
criterion = nn.MSELoss() | |
loss = torch.sqrt(criterion(x, y)) | |
return loss |
You need to add an epsilone in case of 0, as in backpropagation it will result in nans!
for example sth like this:eps = 1e-6 loss = torch.sqrt(criterion(x, y) + eps)
That was incredibly useful thanks !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to add an epsilone in case of 0, as in backpropagation it will result in nans!
for example sth like this: