-
Notifications
You must be signed in to change notification settings - Fork 1
/
eval.py
56 lines (50 loc) · 1.31 KB
/
eval.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
from skimage.io import imread, imshow, imsave
from skimage import data, color
from skimage.transform import rescale, resize, downscale_local_mean
import numpy as np
import os, sys, glob
from collections import namedtuple
import fnmatch
classes = ['road' ,
'sidewalk',
'building' ,
'wall' ,
'fence' ,
'pole' ,
'traffic light',
'traffic sign' ,
'vegetation' ,
'terrain' ,
'sky' ,
'person' ,
'rider' ,
'car' ,
'truck' ,
'bus' ,
'train' ,
'motorcycle' ,
'bicycle' ]
def eval_preds(preds, groundTruth):
eps = 1e-8
class_ious = np.zeros(20)
iou_score = 0
for i in range(preds.shape[0]):
sys.stdout.write('\r')
sys.stdout.write("processed %d images" % i)
sys.stdout.flush()
pred = preds[i]
gt = groundTruth[i]
for j in range(20):
pred1 = (pred == j)
gt1 = (gt == j)
intersect = np.logical_and(pred1, gt1).sum()
union = np.logical_or(pred1, gt1).sum()
if union != 0:
class_ious[j]+=(intersect)/(union)
else:
class_ious[j]+=1
class_ious/=preds.shape[0]
print()
for i in range(len(classes)):
print(classes[i],':',class_ious[i])
return np.mean(class_ious)