-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathensemble.py
More file actions
66 lines (54 loc) · 1.8 KB
/
Copy pathensemble.py
File metadata and controls
66 lines (54 loc) · 1.8 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
# Ensemble of Mask RCNN and Pointrend
# Predicted Masks of 10 images KITTI semantic stored in .npy files
import warnings as wr
import glob
import os
import cv2
import numpy as np
wr.filterwarnings("ignore")
# Save predicted masks (im_predmasks) in mrcnn/ptrend.npy files
# with open('ptrend_masks.npy', 'wb') as f:
# np.save(f,im_predmasks)
# with open('mrcnn_masks.npy', 'wb') as f:
# np.save(f,im_predmasks)
with open('mrcnn_masks.npy','rb') as f:
mrcnn_masks = np.load(f)
with open('ptrend_masks.npy','rb') as f:
ptrend_masks = np.load(f)
path = '/home/yln1kor/Downloads/kitti_official_semantic/training'
path_images = path + '/image_2'
path_instance = path + '/instance'
path_semantic = path + '/semantic_rgb'
gt_masks = []
c = 1
for imageName in sorted(glob.glob(os.path.join(path_semantic, '*.png'))):
im = cv2.imread(imageName)
mask = (im == [142,0,0]).all(-1)
gt_masks.append(mask)
c += 1
if c == 10:
break
im_predmasks = []
for i in range(len(gt_masks)):
pred_mask = np.full(gt_masks[0].shape,False, dtype =bool)
pred_mask = np.logical_or(pred_mask,ptrend_masks[i])
pred_mask = np.logical_and(pred_mask,mrcnn_masks[i])
im_predmasks.append(pred_mask)
cv2.imshow('ensemble_masks',pred_mask.astype(np.uint8)*255)
cv2.waitKey(0)
sum_IOU = 0
sum_DSC = 0
for i in range(len(gt_masks)):
gt = gt_masks[i]
pred = im_predmasks[i]
intersection = np.logical_and(gt,pred)
union = np.logical_or(gt,pred)
IOU = np.sum(intersection) / np.sum(union)
sum_IOU += IOU
Dice_coeff = 2 * np.sum(intersection) / (np.sum(gt) + np.sum(pred))
sum_DSC += Dice_coeff
#print('IOU:',IOU, 'Dice Coeff:',Dice_coeff) '''Individual Images'''
print('IOU',sum_IOU/len(gt_masks))
print('DSC',sum_DSC/len(gt_masks))
def ensemble():
pass