comparison sceneClassificationMetrics_eval.m @ 1:96b1b8697b60

challenge version
author Gerard Roma <gerard.roma@upf.edu>
date Mon, 04 Nov 2013 10:43:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 1:96b1b8697b60
1 % from https://soundsoftware.ac.uk/projects/aasp-d-case-metrics
2
3 function [confusionMat, AccFolds, Acc, Std] = sceneClassificationMetrics_eval(numfolds, foldsGTlist, foldstestlist)
4
5 % Function takes as input a number of folds (numfolds), a text file
6 % containing a list of filenames with the ground truth per fold (foldsGTlist),
7 % and a text file containing a list of filenames with the classification
8 % output (foldstestlist)
9 %
10 % e.g. [confusionMat, AccFolds, Acc, Std] = sceneClassificationMetrics_eval(5, 'foldGTlist.txt', 'foldtestlist.txt');
11
12
13 % Initialize
14 classList = {'bus','busystreet','office','openairmarket','park','quietstreet','restaurant','supermarket','tube','tubestation'};
15 confusionMat = zeros(10,10);
16 AccFolds = zeros(1,numfolds);
17
18
19 % For each fold
20 fid1 = fopen(foldsGTlist,'r+');
21 fid2 = fopen(foldstestlist,'r+');
22 for i=1:numfolds
23
24 % Load classification output and ground truth
25 tline1 = fgetl(fid1);
26 [fileIDGT,classIDGT] = loadClassificationOutput(tline1);
27 tline2 = fgetl(fid2);
28 [fileID,classID] = loadClassificationOutput(tline2);
29
30 % Compute confusion matrix per fold
31 confusionMatTemp = zeros(10,10);
32 for j=1:length(classIDGT)
33 pos = strmatch(fileIDGT{j}, fileID, 'exact');
34 posClassGT = strmatch(classIDGT{j}, classList, 'exact');
35 posClass = strmatch(classID{pos}, classList, 'exact');
36 confusionMatTemp(posClassGT,posClass) = confusionMatTemp(posClassGT,posClass) + 1;
37 end
38
39 % Compute accuracy per fold
40 AccFolds(i) = sum(diag(confusionMatTemp))/sum(sum(confusionMatTemp));
41 confusionMat = confusionMat + confusionMatTemp;
42
43 end
44 fclose(fid1);
45 fclose(fid2);
46
47
48 % Compute global accuracy and std
49 Acc = mean(AccFolds);
50 Std = std(AccFolds);