Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added two filtering options to pLoad to set the "ignore" flag when us… #22

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added VOC 2012 dev kit (VOCdevkit_18-May-2011.tar) as an external.
  • Loading branch information
zpezz committed Apr 13, 2018
commit 1691d57c7b95d8d528892e48b2e88580e5fec1fd
11 changes: 11 additions & 0 deletions external/VOCdevkit/VOCcode/PASemptyobject.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function object=PASemptyobject
object.label='';
object.orglabel='';
object.bbox=[];
object.polygon=[];
object.mask='';
object.class='';
object.view='';
object.truncated=false;
object.difficult=false;
return
6 changes: 6 additions & 0 deletions external/VOCdevkit/VOCcode/PASemptyrecord.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function record=PASemptyrecord
record.imgname='';
record.imgsize=[];
record.database='';
record.objects=PASemptyobject;
return
7 changes: 7 additions & 0 deletions external/VOCdevkit/VOCcode/PASerrmsg.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function PASerrmsg(PASerr,SYSerr)
fprintf('Pascal Error Message: %s\n',PASerr);
fprintf('System Error Message: %s\n',SYSerr);
k=input('Enter K for keyboard, any other key to continue or ^C to quit ...','s');
if (~isempty(k)), if (lower(k)=='k'), keyboard; end; end;
fprintf('\n');
return
11 changes: 11 additions & 0 deletions external/VOCdevkit/VOCcode/PASreadrecord.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function rec = PASreadrecord(path)

if length(path)<4
error('unable to determine format: %s',path);
end

if strcmp(path(end-3:end),'.txt')
rec=PASreadrectxt(path);
else
rec=VOCreadrecxml(path);
end
99 changes: 99 additions & 0 deletions external/VOCdevkit/VOCcode/PASreadrectxt.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
function record=PASreadrectxt(filename)
[fd,syserrmsg]=fopen(filename,'rt');
if (fd==-1),
PASmsg=sprintf('Could not open %s for reading',filename);
PASerrmsg(PASmsg,syserrmsg);
end;

matchstrs=initstrings;
record=PASemptyrecord;
notEOF=1;
while (notEOF),
line=fgetl(fd);
notEOF=ischar(line);
if (notEOF),
matchnum=match(line,matchstrs);
switch matchnum,
case 1, [imgname]=strread(line,matchstrs(matchnum).str);
record.imgname=char(imgname);
case 2, [x,y,c]=strread(line,matchstrs(matchnum).str);
record.imgsize=[x y c];
case 3, [database]=strread(line,matchstrs(matchnum).str);
record.database=char(database);
case 4, [obj,lbl,xmin,ymin,xmax,ymax]=strread(line,matchstrs(matchnum).str);
record.objects(obj).label=char(lbl);
record.objects(obj).bbox=[min(xmin,xmax),min(ymin,ymax),max(xmin,xmax),max(ymin,ymax)];
case 5, tmp=findstr(line,' : ');
[obj,lbl]=strread(line(1:tmp),matchstrs(matchnum).str);
record.objects(obj).label=char(lbl);
record.objects(obj).polygon=sscanf(line(tmp+3:end),'(%d, %d) ')';
case 6, [obj,lbl,mask]=strread(line,matchstrs(matchnum).str);
record.objects(obj).label=char(lbl);
record.objects(obj).mask=char(mask);
case 7, [obj,lbl,orglbl]=strread(line,matchstrs(matchnum).str);
lbl=char(lbl);
record.objects(obj).label=lbl;
record.objects(obj).orglabel=char(orglbl);
if strcmp(lbl(max(end-8,1):end),'Difficult')
record.objects(obj).difficult=true;
lbl(end-8:end)=[];
else
record.objects(obj).difficult=false;
end
if strcmp(lbl(max(end-4,1):end),'Trunc')
record.objects(obj).truncated=true;
lbl(end-4:end)=[];
else
record.objects(obj).truncated=false;
end
t=find(lbl>='A'&lbl<='Z');
t=t(t>=4);
if ~isempty(t)
record.objects(obj).view=lbl(t(1):end);
lbl(t(1):end)=[];
else
record.objects(obj).view='';
end
record.objects(obj).class=lbl(4:end);

otherwise, %fprintf('Skipping: %s\n',line);
end;
end;
end;
fclose(fd);
return

function matchnum=match(line,matchstrs)
for i=1:length(matchstrs),
matched(i)=strncmp(line,matchstrs(i).str,matchstrs(i).matchlen);
end;
matchnum=find(matched);
if isempty(matchnum), matchnum=0; end;
if (length(matchnum)~=1),
PASerrmsg('Multiple matches while parsing','');
end;
return

function s=initstrings
s(1).matchlen=14;
s(1).str='Image filename : %q';

s(2).matchlen=10;
s(2).str='Image size (X x Y x C) : %d x %d x %d';

s(3).matchlen=8;
s(3).str='Database : %q';

s(4).matchlen=8;
s(4).str='Bounding box for object %d %q (Xmin, Ymin) - (Xmax, Ymax) : (%d, %d) - (%d, %d)';

s(5).matchlen=7;
s(5).str='Polygon for object %d %q (X, Y)';

s(6).matchlen=5;
s(6).str='Pixel mask for object %d %q : %q';

s(7).matchlen=8;
s(7).str='Original label for object %d %q : %q';

return
10 changes: 10 additions & 0 deletions external/VOCdevkit/VOCcode/VOCap.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function ap = VOCap(rec,prec)

mrec=[0 ; rec ; 1];
mpre=[0 ; prec ; 0];
for i=numel(mpre)-1:-1:1
mpre(i)=max(mpre(i),mpre(i+1));
end
i=find(mrec(2:end)~=mrec(1:end-1))+1;
ap=sum((mrec(i)-mrec(i-1)).*mpre(i));

59 changes: 59 additions & 0 deletions external/VOCdevkit/VOCcode/VOCevalaction.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
function [rec,prec,ap] = VOCevalaction(VOCopts,id,cls,draw)

% load test set
[gtimg,gtobj,gt]=textread(sprintf(VOCopts.action.clsimgsetpath,cls,VOCopts.testset),'%s %d %d');

% hash image/object ids
gtid=cell(numel(gtimg),1);
for i=1:numel(gtimg);
gtid{i}=sprintf('%s/%d',gtimg{i},gtobj(i));
end
hash=VOChash_init(gtid);

% load results
[img,obj,confidence]=textread(sprintf(VOCopts.action.respath,id,cls),'%s %d %f');

% map results to ground truth objects
out=ones(size(gt))*-inf;
tic;
for i=1:length(img)
% display progress
if toc>1
fprintf('%s: pr: %d/%d\n',cls,i,length(img));
drawnow;
tic;
end

% find ground truth object
k=sprintf('%s/%d',img{i},obj(i));
j=VOChash_lookup(hash,k);
if isempty(j)
error('unrecognized object "%s"',k);
elseif length(j)>1
error('multiple image "%s"',k);
else
out(j)=confidence(i);
end
end

% compute precision/recall

[so,si]=sort(-out);
tp=gt(si)>0;
fp=gt(si)<0;

fp=cumsum(fp);
tp=cumsum(tp);
rec=tp/sum(gt>0);
prec=tp./(fp+tp);

ap=VOCap(rec,prec);

if draw
% plot precision/recall
plot(rec,prec,'-');
grid;
xlabel 'recall'
ylabel 'precision'
title(sprintf('class: %s, subset: %s, AP = %.3f',cls,VOCopts.testset,ap));
end
54 changes: 54 additions & 0 deletions external/VOCdevkit/VOCcode/VOCevalcls.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
function [rec,prec,ap] = VOCevalcls(VOCopts,id,cls,draw)

% load test set
[gtids,gt]=textread(sprintf(VOCopts.clsimgsetpath,cls,VOCopts.testset),'%s %d');

% hash image ids
hash=VOChash_init(gtids);

% load results
[ids,confidence]=textread(sprintf(VOCopts.clsrespath,id,cls),'%s %f');

% map results to ground truth images
out=ones(size(gt))*-inf;
tic;
for i=1:length(ids)
% display progress
if toc>1
fprintf('%s: pr: %d/%d\n',cls,i,length(ids));
drawnow;
tic;
end

% find ground truth image
j=VOChash_lookup(hash,ids{i});
if isempty(j)
error('unrecognized image "%s"',ids{i});
elseif length(j)>1
error('multiple image "%s"',ids{i});
else
out(j)=confidence(i);
end
end

% compute precision/recall

[so,si]=sort(-out);
tp=gt(si)>0;
fp=gt(si)<0;

fp=cumsum(fp);
tp=cumsum(tp);
rec=tp/sum(gt>0);
prec=tp./(fp+tp);

ap=VOCap(rec,prec);

if draw
% plot precision/recall
plot(rec,prec,'-');
grid;
xlabel 'recall'
ylabel 'precision'
title(sprintf('class: %s, subset: %s, AP = %.3f',cls,VOCopts.testset,ap));
end
123 changes: 123 additions & 0 deletions external/VOCdevkit/VOCcode/VOCevaldet.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
function [rec,prec,ap] = VOCevaldet(VOCopts,id,cls,draw)

% load test set

cp=sprintf(VOCopts.annocachepath,VOCopts.testset);
if exist(cp,'file')
fprintf('%s: pr: loading ground truth\n',cls);
load(cp,'gtids','recs');
else
[gtids,t]=textread(sprintf(VOCopts.imgsetpath,VOCopts.testset),'%s %d');
for i=1:length(gtids)
% display progress
if toc>1
fprintf('%s: pr: load: %d/%d\n',cls,i,length(gtids));
drawnow;
tic;
end

% read annotation
recs(i)=PASreadrecord(sprintf(VOCopts.annopath,gtids{i}));
end
save(cp,'gtids','recs');
end

fprintf('%s: pr: evaluating detections\n',cls);

% hash image ids
hash=VOChash_init(gtids);

% extract ground truth objects

npos=0;
gt(length(gtids))=struct('BB',[],'diff',[],'det',[]);
for i=1:length(gtids)
% extract objects of class
clsinds=strmatch(cls,{recs(i).objects(:).class},'exact');
gt(i).BB=cat(1,recs(i).objects(clsinds).bbox)';
gt(i).diff=[recs(i).objects(clsinds).difficult];
gt(i).det=false(length(clsinds),1);
npos=npos+sum(~gt(i).diff);
end

% load results
[ids,confidence,b1,b2,b3,b4]=textread(sprintf(VOCopts.detrespath,id,cls),'%s %f %f %f %f %f');
BB=[b1 b2 b3 b4]';

% sort detections by decreasing confidence
[sc,si]=sort(-confidence);
ids=ids(si);
BB=BB(:,si);

% assign detections to ground truth objects
nd=length(confidence);
tp=zeros(nd,1);
fp=zeros(nd,1);
tic;
for d=1:nd
% display progress
if toc>1
fprintf('%s: pr: compute: %d/%d\n',cls,d,nd);
drawnow;
tic;
end

% find ground truth image
i=VOChash_lookup(hash,ids{d});
if isempty(i)
error('unrecognized image "%s"',ids{d});
elseif length(i)>1
error('multiple image "%s"',ids{d});
end

% assign detection to ground truth object if any
bb=BB(:,d);
ovmax=-inf;
for j=1:size(gt(i).BB,2)
bbgt=gt(i).BB(:,j);
bi=[max(bb(1),bbgt(1)) ; max(bb(2),bbgt(2)) ; min(bb(3),bbgt(3)) ; min(bb(4),bbgt(4))];
iw=bi(3)-bi(1)+1;
ih=bi(4)-bi(2)+1;
if iw>0 & ih>0
% compute overlap as area of intersection / area of union
ua=(bb(3)-bb(1)+1)*(bb(4)-bb(2)+1)+...
(bbgt(3)-bbgt(1)+1)*(bbgt(4)-bbgt(2)+1)-...
iw*ih;
ov=iw*ih/ua;
if ov>ovmax
ovmax=ov;
jmax=j;
end
end
end
% assign detection as true positive/don't care/false positive
if ovmax>=VOCopts.minoverlap
if ~gt(i).diff(jmax)
if ~gt(i).det(jmax)
tp(d)=1; % true positive
gt(i).det(jmax)=true;
else
fp(d)=1; % false positive (multiple detection)
end
end
else
fp(d)=1; % false positive
end
end

% compute precision/recall
fp=cumsum(fp);
tp=cumsum(tp);
rec=tp/npos;
prec=tp./(fp+tp);

ap=VOCap(rec,prec);

if draw
% plot precision/recall
plot(rec,prec,'-');
grid;
xlabel 'recall'
ylabel 'precision'
title(sprintf('class: %s, subset: %s, AP = %.3f',cls,VOCopts.testset,ap));
end
Loading