Skip to content

Commit 11e160c

Browse files
committed
commit
1 parent 1f49a8b commit 11e160c

File tree

312 files changed

+805219
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

312 files changed

+805219
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
##Pascal Voc dataset
2+
Put your pascal voc dataset here.
3+
It should be:
4+
-VOC2007
5+
--Annotations
6+
--ImageSets
7+
--JPEGImages
8+
--SegmentationClass
9+
--SegmentationObject
10+
11+
The dataset download Path:
12+
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar
13+
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar
14+
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function object=PASemptyobject
2+
object.label='';
3+
object.orglabel='';
4+
object.bbox=[];
5+
object.polygon=[];
6+
object.mask='';
7+
object.class='';
8+
object.view='';
9+
object.truncated=false;
10+
object.difficult=false;
11+
return
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function record=PASemptyrecord
2+
record.imgname='';
3+
record.imgsize=[];
4+
record.database='';
5+
record.objects=PASemptyobject;
6+
return
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function PASerrmsg(PASerr,SYSerr)
2+
fprintf('Pascal Error Message: %s\n',PASerr);
3+
fprintf('System Error Message: %s\n',SYSerr);
4+
k=input('Enter K for keyboard, any other key to continue or ^C to quit ...','s');
5+
if (~isempty(k)), if (lower(k)=='k'), keyboard; end; end;
6+
fprintf('\n');
7+
return
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function rec = PASreadrecord(path)
2+
3+
if length(path)<4
4+
error('unable to determine format: %s',path);
5+
end
6+
7+
if strcmp(path(end-3:end),'.txt')
8+
rec=PASreadrectxt(path);
9+
else
10+
rec=VOCreadrecxml(path);
11+
end
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
function record=PASreadrectxt(filename)
2+
[fd,syserrmsg]=fopen(filename,'rt');
3+
if (fd==-1),
4+
PASmsg=sprintf('Could not open %s for reading',filename);
5+
PASerrmsg(PASmsg,syserrmsg);
6+
end;
7+
8+
matchstrs=initstrings;
9+
record=PASemptyrecord;
10+
notEOF=1;
11+
while (notEOF),
12+
line=fgetl(fd);
13+
notEOF=ischar(line);
14+
if (notEOF),
15+
matchnum=match(line,matchstrs);
16+
switch matchnum,
17+
case 1, [imgname]=strread(line,matchstrs(matchnum).str);
18+
record.imgname=char(imgname);
19+
case 2, [x,y,c]=strread(line,matchstrs(matchnum).str);
20+
record.imgsize=[x y c];
21+
case 3, [database]=strread(line,matchstrs(matchnum).str);
22+
record.database=char(database);
23+
case 4, [obj,lbl,xmin,ymin,xmax,ymax]=strread(line,matchstrs(matchnum).str);
24+
record.objects(obj).label=char(lbl);
25+
record.objects(obj).bbox=[min(xmin,xmax),min(ymin,ymax),max(xmin,xmax),max(ymin,ymax)];
26+
case 5, tmp=findstr(line,' : ');
27+
[obj,lbl]=strread(line(1:tmp),matchstrs(matchnum).str);
28+
record.objects(obj).label=char(lbl);
29+
record.objects(obj).polygon=sscanf(line(tmp+3:end),'(%d, %d) ')';
30+
case 6, [obj,lbl,mask]=strread(line,matchstrs(matchnum).str);
31+
record.objects(obj).label=char(lbl);
32+
record.objects(obj).mask=char(mask);
33+
case 7, [obj,lbl,orglbl]=strread(line,matchstrs(matchnum).str);
34+
lbl=char(lbl);
35+
record.objects(obj).label=lbl;
36+
record.objects(obj).orglabel=char(orglbl);
37+
if strcmp(lbl(max(end-8,1):end),'Difficult')
38+
record.objects(obj).difficult=true;
39+
lbl(end-8:end)=[];
40+
else
41+
record.objects(obj).difficult=false;
42+
end
43+
if strcmp(lbl(max(end-4,1):end),'Trunc')
44+
record.objects(obj).truncated=true;
45+
lbl(end-4:end)=[];
46+
else
47+
record.objects(obj).truncated=false;
48+
end
49+
t=find(lbl>='A'&lbl<='Z');
50+
t=t(t>=4);
51+
if ~isempty(t)
52+
record.objects(obj).view=lbl(t(1):end);
53+
lbl(t(1):end)=[];
54+
else
55+
record.objects(obj).view='';
56+
end
57+
record.objects(obj).class=lbl(4:end);
58+
59+
otherwise, %fprintf('Skipping: %s\n',line);
60+
end;
61+
end;
62+
end;
63+
fclose(fd);
64+
return
65+
66+
function matchnum=match(line,matchstrs)
67+
for i=1:length(matchstrs),
68+
matched(i)=strncmp(line,matchstrs(i).str,matchstrs(i).matchlen);
69+
end;
70+
matchnum=find(matched);
71+
if isempty(matchnum), matchnum=0; end;
72+
if (length(matchnum)~=1),
73+
PASerrmsg('Multiple matches while parsing','');
74+
end;
75+
return
76+
77+
function s=initstrings
78+
s(1).matchlen=14;
79+
s(1).str='Image filename : %q';
80+
81+
s(2).matchlen=10;
82+
s(2).str='Image size (X x Y x C) : %d x %d x %d';
83+
84+
s(3).matchlen=8;
85+
s(3).str='Database : %q';
86+
87+
s(4).matchlen=8;
88+
s(4).str='Bounding box for object %d %q (Xmin, Ymin) - (Xmax, Ymax) : (%d, %d) - (%d, %d)';
89+
90+
s(5).matchlen=7;
91+
s(5).str='Polygon for object %d %q (X, Y)';
92+
93+
s(6).matchlen=5;
94+
s(6).str='Pixel mask for object %d %q : %q';
95+
96+
s(7).matchlen=8;
97+
s(7).str='Original label for object %d %q : %q';
98+
99+
return
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
function [rec,prec,ap] = VOCevalcls(VOCopts,id,cls,draw)
2+
3+
% load test set
4+
[gtids,gt]=textread(sprintf(VOCopts.clsimgsetpath,cls,VOCopts.testset),'%s %d');
5+
6+
% load results
7+
[ids,confidence]=textread(sprintf(VOCopts.clsrespath,id,cls),'%s %f');
8+
9+
% map results to ground truth images
10+
out=ones(size(gt))*-inf;
11+
tic;
12+
for i=1:length(ids)
13+
% display progress
14+
if toc>1
15+
fprintf('%s: pr: %d/%d\n',cls,i,length(ids));
16+
drawnow;
17+
tic;
18+
end
19+
20+
% find ground truth image
21+
j=strmatch(ids{i},gtids,'exact');
22+
if isempty(j)
23+
error('unrecognized image "%s"',ids{i});
24+
elseif length(j)>1
25+
error('multiple image "%s"',ids{i});
26+
else
27+
out(j)=confidence(i);
28+
end
29+
end
30+
31+
% compute precision/recall
32+
33+
[so,si]=sort(-out);
34+
tp=gt(si)>0;
35+
fp=gt(si)<0;
36+
37+
fp=cumsum(fp);
38+
tp=cumsum(tp);
39+
rec=tp/sum(gt>0);
40+
prec=tp./(fp+tp);
41+
42+
% compute average precision
43+
44+
ap=0;
45+
for t=0:0.1:1
46+
p=max(prec(rec>=t));
47+
if isempty(p)
48+
p=0;
49+
end
50+
ap=ap+p/11;
51+
end
52+
53+
if draw
54+
% plot precision/recall
55+
plot(rec,prec,'-');
56+
grid;
57+
xlabel 'recall'
58+
ylabel 'precision'
59+
title(sprintf('class: %s, subset: %s, AP = %.3f',cls,VOCopts.testset,ap));
60+
end
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
function [rec,prec,ap] = VOCevaldet(VOCopts,id,cls,draw)
2+
3+
% load test set
4+
[gtids,t]=textread(sprintf(VOCopts.imgsetpath,VOCopts.testset),'%s %d');
5+
6+
% load ground truth objects
7+
tic;
8+
npos=0;
9+
gt(length(gtids))=struct('BB',[],'diff',[],'det',[]);
10+
for i=1:length(gtids)
11+
% display progress
12+
if toc>1
13+
fprintf('%s: pr: load: %d/%d\n',cls,i,length(gtids));
14+
drawnow;
15+
tic;
16+
end
17+
18+
% read annotation
19+
rec=PASreadrecord(sprintf(VOCopts.annopath,gtids{i}));
20+
21+
% extract objects of class
22+
clsinds=strmatch(cls,{rec.objects(:).class},'exact');
23+
gt(i).BB=cat(1,rec.objects(clsinds).bbox)';
24+
gt(i).diff=[rec.objects(clsinds).difficult];
25+
gt(i).det=false(length(clsinds),1);
26+
npos=npos+sum(~gt(i).diff);
27+
end
28+
29+
% load results
30+
[ids,confidence,b1,b2,b3,b4]=textread(sprintf(VOCopts.detrespath,id,cls),'%s %f %f %f %f %f');
31+
BB=[b1 b2 b3 b4]';
32+
33+
% sort detections by decreasing confidence
34+
[sc,si]=sort(-confidence);
35+
ids=ids(si);
36+
BB=BB(:,si);
37+
38+
% assign detections to ground truth objects
39+
nd=length(confidence);
40+
tp=zeros(nd,1);
41+
fp=zeros(nd,1);
42+
tic;
43+
for d=1:nd
44+
% display progress
45+
if toc>1
46+
fprintf('%s: pr: compute: %d/%d\n',cls,d,nd);
47+
drawnow;
48+
tic;
49+
end
50+
51+
% find ground truth image
52+
i=strmatch(ids{d},gtids,'exact');
53+
if isempty(i)
54+
error('unrecognized image "%s"',ids{d});
55+
elseif length(i)>1
56+
error('multiple image "%s"',ids{d});
57+
end
58+
59+
% assign detection to ground truth object if any
60+
bb=BB(:,d);
61+
ovmax=-inf;
62+
for j=1:size(gt(i).BB,2)
63+
bbgt=gt(i).BB(:,j);
64+
bi=[max(bb(1),bbgt(1)) ; max(bb(2),bbgt(2)) ; min(bb(3),bbgt(3)) ; min(bb(4),bbgt(4))];
65+
iw=bi(3)-bi(1)+1;
66+
ih=bi(4)-bi(2)+1;
67+
if iw>0 & ih>0
68+
% compute overlap as area of intersection / area of union
69+
ua=(bb(3)-bb(1)+1)*(bb(4)-bb(2)+1)+...
70+
(bbgt(3)-bbgt(1)+1)*(bbgt(4)-bbgt(2)+1)-...
71+
iw*ih;
72+
ov=iw*ih/ua;
73+
if ov>ovmax
74+
ovmax=ov;
75+
jmax=j;
76+
end
77+
end
78+
end
79+
% assign detection as true positive/don't care/false positive
80+
if ovmax>=VOCopts.minoverlap
81+
if ~gt(i).diff(jmax)
82+
if ~gt(i).det(jmax)
83+
tp(d)=1; % true positive
84+
gt(i).det(jmax)=true;
85+
else
86+
fp(d)=1; % false positive (multiple detection)
87+
end
88+
end
89+
else
90+
fp(d)=1; % false positive
91+
end
92+
end
93+
94+
% compute precision/recall
95+
fp=cumsum(fp);
96+
tp=cumsum(tp);
97+
rec=tp/npos;
98+
prec=tp./(fp+tp);
99+
100+
% compute average precision
101+
102+
ap=0;
103+
for t=0:0.1:1
104+
p=max(prec(rec>=t));
105+
if isempty(p)
106+
p=0;
107+
end
108+
ap=ap+p/11;
109+
end
110+
111+
if draw
112+
% plot precision/recall
113+
plot(rec,prec,'-');
114+
grid;
115+
xlabel 'recall'
116+
ylabel 'precision'
117+
title(sprintf('class: %s, subset: %s, AP = %.3f',cls,VOCopts.testset,ap));
118+
end

0 commit comments

Comments
 (0)