mae/mse loss

This commit is contained in:
shahules786 2022-09-09 09:45:36 +05:30
parent 4cb417cdbe
commit 4dbefd51b3
1 changed files with 28 additions and 0 deletions

28
enhancer/utils/loss.py Normal file
View File

@ -0,0 +1,28 @@
import torch
import torch.nn as nn
class mean_squared_error(nn.Module):
def __init__(self,reduction="mean"):
super().__init__()
self.loss_fun = nn.MSELoss(reduction=reduction)
def forward(self,prediction:torch.Tensor, target: torch.Tensor):
return self.loss_fun(prediction, target)
class mean_absolute_error(nn.Module):
def __init__(self,reduction="mean"):
self.loss_fun = nn.L1Loss(reduction=reduction)
def forward(self, prediction:torch.Tensor, target: torch.Tensor):
return self.loss_fun(prediction, target)
LOSS_MAP = {"mea":mean_absolute_error, "mse": mean_squared_error}