-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointrend.py
More file actions
73 lines (62 loc) · 2.27 KB
/
Copy pathpointrend.py
File metadata and controls
73 lines (62 loc) · 2.27 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
# Pointrend masks and eval with ground truth
# 10 images KITTI semantic
import pixellib
from pixellib.torchbackend.instance import instanceSegmentation
import numpy as np
import warnings as wr
import cv2
import glob
import os
wr.filterwarnings("ignore")
ins = instanceSegmentation()
ins.load_model("pointrend_resnet50.pkl")
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
import numpy as np
import os, cv2
c =1
it = 0
im_predmasks = []
for imageName in sorted(glob.glob(os.path.join(path_images, '*.png'))):
results, output = ins.segmentImage(imageName, show_bboxes=True)
masks = results["masks"] # Getting Masks for all classes
masks = masks.transpose((2, 0, 1)) # Converting AxBxC into CxAxB to get each mask in masks into required shape of img, AxB
c += 1
pred_mask = np.full(masks[0].shape,False, dtype =bool)
for j in range(len(masks)):
if results["class_names"][j] == 'car': # Taking index of masks only true at class 'car'
pred_mask = np.logical_or(pred_mask,masks[j])
im_predmasks.append(pred_mask)
cv2.imshow('pred_mask', pred_mask.astype(np.uint8)*255)
cv2.imshow('gt',gt_masks[it].astype(np.uint8)*255)
cv2.waitKey(0)
it += 1
if c == 10:
break
sum_IOU = 0
sum_DSC = 0 # DSC = Dice_Coeff = f1_score
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))
with open('ptrend_masks.npy', 'wb') as f:
np.save(f,im_predmasks)