-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.py
More file actions
80 lines (59 loc) · 1.78 KB
/
function.py
File metadata and controls
80 lines (59 loc) · 1.78 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import numpy as np
import torch
import matplotlib.pyplot as plt
from sklearn.metrics import roc_curve, auc, roc_auc_score
def get_mean(x):
x_mean = []
for i in range(x.shape[0]):
mean = np.mean(x[i])
x_mean.append(mean)
return x_mean
def get_median(x):
x_median = []
for i in range(x.shape[0]):
median = np.median(x[i])
x_median.append(median)
return x_median
def get_std(x):
x_std = []
for i in range(x.shape[0]):
std = np.std(x[i])
x_std.append(std)
return x_std
def get_var(x):
x_var = []
for i in range(x.shape[0]):
var = np.var(x[i])
x_var.append(var)
return x_var
def calculateMSE(y_pred, y, m):
num = y_pred - y
num = num * num * m
mseloss = torch.sum(num) / (33 * 49)
# print(mseloss.shape)
return mseloss
def calculateMAE(y_pred, y, m):
num = torch.abs(y_pred - y) * m
maeloss = torch.sum(num)/torch.sum(m)
return maeloss
def fan2(y_pred, y, m):
num = (y_pred - y) * m
fan = np.linalg.norm(num.detach().numpy(), ord=2)
return torch.tensor(fan, requires_grad=True)
def MSE(y_pred, y):
H, W = y_pred.shape[0], y_pred.shape[1]
num = y_pred - y
num = num * num
mseloss = torch.sum(num) / (H * W)
return mseloss
def plot_roc_and_auc_score(outputs, labels, title):
false_positive_rate, true_positive_rate, threshold = roc_curve(labels, outputs)
auc_score = roc_auc_score(labels, outputs)
plt.plot(false_positive_rate, true_positive_rate, label = 'ROC curve, AREA = {:.4f}'.format(auc_score))
plt.plot([0,1], [0,1], 'red')
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.axis([0, 1, 0, 1])
plt.title(title)
plt.legend(loc = 'lower right')
plt.savefig('roc.png')