|
| 1 | +function res = voc_eval(path, comp_id, test_set, output_dir, rm_res) |
| 2 | + |
| 3 | +VOCopts = get_voc_opts(path); |
| 4 | +VOCopts.testset = test_set; |
| 5 | + |
| 6 | +for i = 1:length(VOCopts.classes) |
| 7 | + cls = VOCopts.classes{i}; |
| 8 | + res(i) = voc_eval_cls(cls, VOCopts, comp_id, output_dir, rm_res); |
| 9 | +end |
| 10 | + |
| 11 | +fprintf('\n~~~~~~~~~~~~~~~~~~~~\n'); |
| 12 | +fprintf('Results:\n'); |
| 13 | +aps = [res(:).ap]'; |
| 14 | +fprintf('%.1f\n', aps * 100); |
| 15 | +fprintf('%.1f\n', mean(aps) * 100); |
| 16 | +fprintf('~~~~~~~~~~~~~~~~~~~~\n'); |
| 17 | + |
| 18 | +function res = voc_eval_cls(cls, VOCopts, comp_id, output_dir, rm_res) |
| 19 | + |
| 20 | +test_set = VOCopts.testset; |
| 21 | +year = VOCopts.dataset(4:end); |
| 22 | + |
| 23 | +addpath(fullfile(VOCopts.datadir, 'VOCcode')); |
| 24 | + |
| 25 | +res_fn = sprintf(VOCopts.detrespath, comp_id, cls); |
| 26 | + |
| 27 | +recall = []; |
| 28 | +prec = []; |
| 29 | +ap = 0; |
| 30 | +ap_auc = 0; |
| 31 | + |
| 32 | +do_eval = (str2num(year) <= 2007) | ~strcmp(test_set, 'test'); |
| 33 | +if do_eval |
| 34 | + % Bug in VOCevaldet requires that tic has been called first |
| 35 | + tic; |
| 36 | + [recall, prec, ap] = VOCevaldet(VOCopts, comp_id, cls, true); |
| 37 | + ap_auc = xVOCap(recall, prec); |
| 38 | + |
| 39 | + % force plot limits |
| 40 | + ylim([0 1]); |
| 41 | + xlim([0 1]); |
| 42 | + |
| 43 | + print(gcf, '-djpeg', '-r0', ... |
| 44 | + [output_dir '/' cls '_pr.jpg']); |
| 45 | +end |
| 46 | +fprintf('!!! %s : %.4f %.4f\n', cls, ap, ap_auc); |
| 47 | + |
| 48 | +res.recall = recall; |
| 49 | +res.prec = prec; |
| 50 | +res.ap = ap; |
| 51 | +res.ap_auc = ap_auc; |
| 52 | + |
| 53 | +save([output_dir '/' cls '_pr.mat'], ... |
| 54 | + 'res', 'recall', 'prec', 'ap', 'ap_auc'); |
| 55 | + |
| 56 | +if rm_res |
| 57 | + delete(res_fn); |
| 58 | +end |
| 59 | + |
| 60 | +rmpath(fullfile(VOCopts.datadir, 'VOCcode')); |
0 commit comments