-
Notifications
You must be signed in to change notification settings - Fork 0
/
r2-b.py
77 lines (61 loc) · 1.76 KB
/
r2-b.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
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
import numpy as np
import scipy.spatial as sp
import cv2
import glob
import matplotlib.pyplot as plt
import time
# return arrays of images ORI, GT
def loadImages(I, color=cv2.COLOR_BGR2RGB):
Iout = []
imageFolder = './sfa/ORI/'
truthFolder = './sfa/GT/'
training = range(1, 783)
testing = range(951, 1119)
if (I == "trainImages"):
for j in training:
filename = "{}img ({}).jpg".format(imageFolder, j)
Iout.append(cv2.cvtColor(cv2.imread(filename), color))
elif (I == "trainGTs"):
for j in training:
filename = "{}img ({}).jpg".format(truthFolder, j)
Iout.append(cv2.cvtColor(cv2.imread(filename), color))
elif (I == "testImages"):
for j in testing:
filename = "{}img ({}).jpg".format(imageFolder, j)
Iout.append(cv2.cvtColor(cv2.imread(filename), color))
elif (I == "testGTs"):
for j in testing:
filename = "{}img ({}).jpg".format(truthFolder, j)
Iout.append(cv2.cvtColor(cv2.imread(filename), color))
else:
print("Not valid dataset")
return Iout
# Prediction and Truth are 0 or 1
def calcAccuracy():
T=loadImages(I = "testGTs")
T = np.asarray(T)
T = T[:,:,:,0]
misses = len(np.where(T > 0)[0])
P = T
P[:,:,:]=0
total = T.size #size of P, T or match
loss = misses/total
acc = 1 - loss
print("Loss {:.2f}%".format(loss*100))
print ("Accuracy: {:.2f}%".format(acc*100))
I = P
U = misses
I = 0
U = np.sum(U)
jacc = I/U
print("Jaccard: {:.2f}%".format(jacc*100))
return loss, acc, jacc
# import datasets
testImages = glob.glob('./dataset/test/ORI/*.jpg')
testGTs = glob.glob('./dataset/test/GT/*.jpg')
print ('\nNull Algorithm')
print ('='*20)
calcAccuracy()
# print('{:.3f} s'.format(duration))
#fazer com um canal (azul>x como sendo fundo)
#fazer chute de que