add typeerror in shape mismatch

This commit is contained in:
shahules786 2022-09-13 22:02:09 +05:30
parent 35da955c07
commit e4cd6ef10e
1 changed files with 8 additions and 0 deletions

View File

@ -11,6 +11,10 @@ class mean_squared_error(nn.Module):
self.loss_fun = nn.MSELoss(reduction=reduction)
def forward(self,prediction:torch.Tensor, target: torch.Tensor):
if prediction.size() != target.size() or target.ndim < 3:
raise TypeError(f"""Inputs must be of the same shape (batch_size,channels,samples)
got {prediction.size()} and {target.size()} instead""")
return self.loss_fun(prediction, target)
@ -23,6 +27,10 @@ class mean_absolute_error(nn.Module):
def forward(self, prediction:torch.Tensor, target: torch.Tensor):
if prediction.size() != target.size() or target.ndim < 3:
raise TypeError(f"""Inputs must be of the same shape (batch_size,channels,samples)
got {prediction.size()} and {target.size()} instead""")
return self.loss_fun(prediction, target)
class Avergeloss(nn.Module):