-
Notifications
You must be signed in to change notification settings - Fork 195
/
demoEvaluation.m
executable file
·87 lines (73 loc) · 2.83 KB
/
demoEvaluation.m
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
78
79
80
81
82
83
84
85
86
87
% This script demos evaluation on all the prediction maps in pathPred
% make sure you have corresponding ground truth label maps in pathLab
close all; clc; clear;
%% Options and paths
VERBOSE = 0; % to show individual image results, set it to 1
% path to image(.jpg), prediction(.png) and annotation(.png)
% *NOTE: change these paths while evaluating your own predictions
pathImg = fullfile('sampleData', 'images');
pathPred = fullfile('sampleData', 'predictions');
pathAnno = fullfile('sampleData', 'annotations');
addpath(genpath('evaluationCode/'));
addpath(genpath('visualizationCode'));
% number of object classes: 150
numClass = 150;
% load class names
load('objectName150.mat');
% load pre-defined colors
load('color150.mat');
%% Evaluation
% initialize statistics
cnt=0;
area_intersection = double.empty;
area_union = double.empty;
pixel_accuracy = double.empty;
pixel_correct = double.empty;
pixel_labeled = double.empty;
% main loop
filesPred = dir(fullfile(pathPred, '*.png'));
for i = 1: numel(filesPred)
% check file existence
filePred = fullfile(pathPred, filesPred(i).name);
fileLab = fullfile(pathAnno, filesPred(i).name);
if ~exist(fileLab, 'file')
fprintf('Label file [%s] does not exist!\n', fileLab); continue;
end
% read in prediction and label
imPred = imread(filePred);
imAnno = imread(fileLab);
% check image size
if size(imPred, 3) ~= 1
fprintf('Label image [%s] should be a gray-scale image!\n', fileLab); continue;
end
if size(imPred, 1)~=size(imAnno, 1) || size(imPred, 2)~=size(imAnno, 2)
fprintf('Label image [%s] should have the same size as label image! Resizing...\n', fileLab);
imPred = imresize(imPred, size(imAnno));
end
% compute IoU
cnt = cnt + 1;
fprintf('Evaluating %d/%d...\n', cnt, numel(filesPred));
[area_intersection(:,cnt), area_union(:,cnt)] = intersectionAndUnion(imPred, imAnno, numClass);
% compute pixel-wise accuracy
[pixel_accuracy(i), pixel_correct(i), pixel_labeled(i)] = pixelAccuracy(imPred, imAnno);
% Verbose: show indivudual image results
if (VERBOSE)
% read image
fileImg = fullfile(pathImg, strrep(filesPred(i).name, '.png', '.jpg'));
im = imread(fileImg);
% plot result
plotResult(im, imPred, imAnno, objectNames, colors, fileImg);
fprintf('[%s] Pixel-wise accuracy: %2.2f%%\n', fileImg, pixel_accuracy(i)*100.);
waitforbuttonpress;
end
end
%% Summary
IoU = sum(area_intersection,2)./sum(eps+area_union,2);
mean_IoU = mean(IoU);
accuracy = sum(pixel_correct)/sum(pixel_labeled);
fprintf('==== Summary IoU ====\n');
for i = 1:numClass
fprintf('%3d %16s: %.4f\n', i, objectNames{i}, IoU(i));
end
fprintf('Mean IoU over %d classes: %.4f\n', numClass, mean_IoU);
fprintf('Pixel-wise Accuracy: %2.2f%%\n', accuracy*100.);