-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcriteria.py
38 lines (28 loc) · 923 Bytes
/
criteria.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Filename: criteria.py
# @Project: GuideNet
# @Author: jie
# @Time: 2021/3/14 7:51 PM
import torch
import torch.nn as nn
__all__ = [
'RMSE',
'MSE',
]
class RMSE(nn.Module):
def __init__(self):
super().__init__()
def forward(self, outputs, target, *args):
val_pixels = (target > 1e-3).float().cuda()
err = (target * val_pixels - outputs * val_pixels) ** 2
loss = torch.sum(err.view(err.size(0), 1, -1), -1, keepdim=True)
cnt = torch.sum(val_pixels.view(val_pixels.size(0), 1, -1), -1, keepdim=True)
return torch.sqrt(loss / cnt)
class MSE(nn.Module):
def __init__(self):
super().__init__()
def forward(self, outputs, target, *args):
val_pixels = (target > 1e-3).float().cuda()
loss = target * val_pixels - outputs * val_pixels
return loss ** 2