|
20 | 20 | % recThrs - [0:.01:1] R=101 recall thresholds for evaluation
|
21 | 21 | % areaRng - [...] A=4 object area ranges for evaluation
|
22 | 22 | % maxDets - [1 10 100] M=3 thresholds on max detections per image
|
23 |
| - % iouType - ['segm'] set iouType to 'segm' or 'bbox' |
| 23 | + % iouType - ['segm'] set iouType to 'segm', 'bbox' or 'keypoints' |
24 | 24 | % useCats - [1] if true use category labels for evaluation
|
25 | 25 | % Note: iouType replaced the now DEPRECATED useSegm parameter.
|
26 | 26 | % Note: if useCats=0 category labels are ignored as in proposal scoring.
|
|
83 | 83 | end
|
84 | 84 |
|
85 | 85 | methods
|
86 |
| - function ev = CocoEval( cocoGt, cocoDt ) |
| 86 | + function ev = CocoEval( cocoGt, cocoDt, iouType ) |
87 | 87 | % Initialize CocoEval using coco APIs for gt and dt.
|
88 | 88 | if(nargin>0), ev.cocoGt = cocoGt; end
|
89 | 89 | if(nargin>1), ev.cocoDt = cocoDt; end
|
90 | 90 | if(nargin>0), ev.params.imgIds = sort(ev.cocoGt.getImgIds()); end
|
91 | 91 | if(nargin>0), ev.params.catIds = sort(ev.cocoGt.getCatIds()); end
|
| 92 | + if(nargin<3), iouType='segm'; end |
92 | 93 | ev.params.iouThrs = .5:.05:.95;
|
93 | 94 | ev.params.recThrs = 0:.01:1;
|
94 |
| - ev.params.areaRng = [0 1e5; 0 32; 32 96; 96 1e5].^2; |
95 |
| - ev.params.maxDets = [1 10 100]; |
96 |
| - ev.params.iouType = 'segm'; |
| 95 | + if( any(strcmp(iouType,{'bbox','segm'})) ) |
| 96 | + ev.params.areaRng = [0 1e5; 0 32; 32 96; 96 1e5].^2; |
| 97 | + ev.params.maxDets = [1 10 100]; |
| 98 | + elseif( strcmp(iouType,'keypoints') ) |
| 99 | + ev.params.areaRng = [0 1e5; 32 96; 96 1e5].^2; |
| 100 | + ev.params.maxDets = 20; |
| 101 | + else |
| 102 | + error('unknown iouType: %s',iouType); |
| 103 | + end |
| 104 | + ev.params.iouType = iouType; |
97 | 105 | ev.params.useCats = 1;
|
98 | 106 | end
|
99 | 107 |
|
@@ -122,6 +130,9 @@ function evaluate( ev )
|
122 | 130 | f='bbox'; if(isempty(dt)), [dt(:).(f)]=deal(); end
|
123 | 131 | if(~isfield(dt,f)), s=MaskApi.toBbox([dt.segmentation]);
|
124 | 132 | for d=1:nDt(i), dt(d).(f)=s(d,:); end; end
|
| 133 | + elseif( strcmp(p.iouType,'keypoints') ) |
| 134 | + gtIg=[gt.ignore]|[gt.num_keypoints]==0; |
| 135 | + for g=1:nGt(i), gt(g).ignore=gtIg(g); end |
125 | 136 | else
|
126 | 137 | error('unknown iouType: %s',p.iouType);
|
127 | 138 | end
|
@@ -186,10 +197,17 @@ function accumulate( ev )
|
186 | 197 | function summarize( ev )
|
187 | 198 | % Compute and display summary metrics for evaluation results.
|
188 | 199 | if(isempty(ev.eval)), error('Please run accumulate() first'); end
|
189 |
| - k=100; M={{1,':','all',k},{1,.50,'all',k}, {1,.75,'all',k},... |
190 |
| - {1,':','small',k}, {1,':','medium',k}, {1,':','large',k},... |
191 |
| - {0,':','all',1}, {0,':','all',10}, {0,':','all',k},... |
192 |
| - {0,':','small',k}, {0,':','medium',k}, {0,':','large',k}}; |
| 200 | + if( any(strcmp(ev.params.iouType,{'bbox','segm'})) ) |
| 201 | + k=100; M={{1,':','all',k},{1,.50,'all',k}, {1,.75,'all',k},... |
| 202 | + {1,':','small',k}, {1,':','medium',k}, {1,':','large',k},... |
| 203 | + {0,':','all',1}, {0,':','all',10}, {0,':','all',k},... |
| 204 | + {0,':','small',k}, {0,':','medium',k}, {0,':','large',k}}; |
| 205 | + elseif( strcmp(ev.params.iouType,'keypoints') ) |
| 206 | + k=20; M={{1,':','all',k},{1,.50,'all',k}, {1,.75,'all',k},... |
| 207 | + {1,':','medium',k}, {1,':','large',k},... |
| 208 | + {0,':','all',k},{0,.50,'all',k}, {0,.75,'all',k},... |
| 209 | + {0,':','medium',k}, {0,':','large',k}}; |
| 210 | + end |
193 | 211 | k=length(M); ev.stats=zeros(1,k);
|
194 | 212 | for s=1:k, ev.stats(s)=summarize1(M{s}{:}); end
|
195 | 213 |
|
@@ -349,10 +367,11 @@ function makeplot( rs, ps, outDir, nm )
|
349 | 367 | if(D>p.maxDets), D=p.maxDets; dt=dt(1:D); end
|
350 | 368 | % compute iou between each dt and gt region
|
351 | 369 | iscrowd = uint8([gt.iscrowd]);
|
352 |
| - t=find(strcmp(p.iouType,{'segm','bbox'})); |
| 370 | + t=find(strcmp(p.iouType,{'segm','bbox','keypoints'})); |
353 | 371 | if(t==1), g=[gt.segmentation]; elseif(t==2), g=cat(1,gt.bbox); end
|
354 | 372 | if(t==1), d=[dt.segmentation]; elseif(t==2), d=cat(1,dt.bbox); end
|
355 |
| - ious=MaskApi.iou(d,g,iscrowd); |
| 373 | + if(t<=2), ious=MaskApi.iou(d,g,iscrowd); else |
| 374 | + ious=CocoEval.oks(gt,dt); end |
356 | 375 | % attempt to match each (sorted) dt to each (sorted) gt
|
357 | 376 | gtm=zeros(T,G); gtIds=[gt.id]; gtIg=[gt.ignore];
|
358 | 377 | dtm=zeros(T,D); dtIds=[dt.id]; dtIg=zeros(T,D);
|
@@ -380,5 +399,40 @@ function makeplot( rs, ps, outDir, nm )
|
380 | 399 | dtImgIds=ones(1,D)*p.imgIds; gtImgIds=ones(1,G)*p.imgIds;
|
381 | 400 | e = {dtIds,gtIds,dtImgIds,gtImgIds,dtm,gtm,[dt.score],dtIg,gtIg};
|
382 | 401 | end
|
| 402 | + |
| 403 | + function o = oks( gt, dt ) |
| 404 | + % Compute Object Keypoint Similarity (OKS) between objects. |
| 405 | + G=length(gt); D=length(dt); o=zeros(D,G); if(~D||~G), return; end |
| 406 | + % sigmas hard-coded for person class, will need params eventually |
| 407 | + sigmas=[.26 .25 .25 .35 .35 .79 .79 .72 .72 .62 ... |
| 408 | + .62 1.07 1.07 .87 .87 .89 .89]/10; |
| 409 | + vars=(sigmas*2).^2; k=length(sigmas); m=k*3; bb=cat(1,gt.bbox); |
| 410 | + % create bounds for ignore regions (double the gt bbox) |
| 411 | + x0=bb(:,1)-bb(:,3); x1=bb(:,1)+bb(:,3)*2; |
| 412 | + y0=bb(:,2)-bb(:,4); y1=bb(:,2)+bb(:,4)*2; |
| 413 | + % extract keypoint locations and visibility flags |
| 414 | + gKp=cat(1,gt.keypoints); assert(size(gKp,2)==m); |
| 415 | + dKp=cat(1,dt.keypoints); assert(size(dKp,2)==m); |
| 416 | + xg=gKp(:,1:3:m); yg=gKp(:,2:3:m); vg=gKp(:,3:3:m); |
| 417 | + xd=dKp(:,1:3:m); yd=dKp(:,2:3:m); |
| 418 | + % compute oks between each detection and ground truth object |
| 419 | + for d=1:D |
| 420 | + for g=1:G |
| 421 | + v=vg(g,:); x=xd(d,:); y=yd(d,:); k1=nnz(v); |
| 422 | + if( k1>0 ) |
| 423 | + % measure the per-keypoint distance if keypoints visible |
| 424 | + dx=x-xg(g,:); dy=y-yg(g,:); |
| 425 | + else |
| 426 | + % measure minimum distance to keypoints in (x0,y0) & (x1,y1) |
| 427 | + dx=max(0,x0(g,:)-x)+max(0,x-x1(g,:)); |
| 428 | + dy=max(0,y0(g,:)-y)+max(0,y-y1(g,:)); |
| 429 | + end |
| 430 | + % use the distances to compute the oks |
| 431 | + e=(dx.^2+dy.^2)./vars/gt(g).area/2; |
| 432 | + if(k1>0), e=e(v>0); else k1=k; end |
| 433 | + o(d,g)=sum(exp(-e))/k1; |
| 434 | + end |
| 435 | + end |
| 436 | + end |
383 | 437 | end
|
384 | 438 | end
|
0 commit comments