-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheval_sem_seg.py
50 lines (40 loc) · 1.54 KB
/
eval_sem_seg.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
import numpy as np
import os
from chainercv.datasets import VOCSemanticSegmentationDataset
from chainercv.evaluations import calc_semantic_segmentation_confusion
import imageio
from misc import pyutils
import argparse
def run(config):
chainer_eval_set = config['chainer_eval_set']
voc12_root = config['voc12_root']
sem_seg_out_dir = config['sem_seg_out_dir']
dataset = VOCSemanticSegmentationDataset(
split=chainer_eval_set, data_dir=voc12_root)
labels = [dataset.get_example_by_keys(
i, (1,))[0] for i in range(len(dataset))]
preds = []
for id in dataset.ids:
cls_labels = imageio.imread(os.path.join(
sem_seg_out_dir, id + '.png')).astype(np.uint8)
cls_labels[cls_labels == 255] = 0
preds.append(cls_labels.copy())
confusion = calc_semantic_segmentation_confusion(preds, labels)[:21, :21]
gtj = confusion.sum(axis=1)
resj = confusion.sum(axis=0)
gtjresj = np.diag(confusion)
denominator = gtj + resj - gtjresj
fp = 1. - gtj / denominator
fn = 1. - resj / denominator
iou = gtjresj / denominator
print(fp[0], fn[0])
print(np.mean(fp[1:]), np.mean(fn[1:]))
print({'iou': iou, 'miou': np.nanmean(iou)})
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Front Door Semantic Segmentation')
parser.add_argument('--config', type=str,
help='YAML config file path', default='./cfg/ir_net.yml')
args = parser.parse_args()
config = pyutils.parse_config(args.config)
run(config)