forked from CMU-Perceptual-Computing-Lab/openpose_train
-
Notifications
You must be signed in to change notification settings - Fork 2
/
f_getFalsePosNeg.m
154 lines (145 loc) · 7.27 KB
/
f_getFalsePosNeg.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
%% Demo demonstrating the algorithm result formats for COCO
close all; clear variables; clc
%% Load parameters
loadConfigParameters
addpath('../matlab_utilities/');
addpath('../matlab_utilities/openpose/');
addpath([sDatasetFolder, '/cocoapi/MatlabAPI/']);
groundTruthDir='../dataset/COCO/cocoapi';
imagesDir='/home/gines/devel/images/val2017/';
jsonsDir='/home/gines/Dropbox/Perceptual_Computing_Lab/openpose/evaluation/coco_val_jsons/';
% prefix='instances';
dataType='val2017';
%% Select results type for demo (either bbox or segm)
type = {'segm','bbox','keypoints'}; type = type{3}; % specify type here
fprintf('Running demo for *%s* results.\n\n',type);
%% Initialize COCO ground truth api
if(strcmp(type,'keypoints')), prefix='person_keypoints'; end
groundTruthJson=sprintf('%s/annotations/%s_%s.json', groundTruthDir, prefix, dataType);
cocoGroundTruth = CocoApi(groundTruthJson);
%% Initialize COCO detections api
estimatedJson = [jsonsDir, 'OpenPose_1_2_0_4.json'];
cocoEstimated = cocoGroundTruth.loadRes(estimatedJson);
% Image ids to process
imageIds = sort(cocoGroundTruth.getImgIds());
% imageIds = imageIds(1:100);
for imageIdIndex=1:numel(imageIds)
%% Read image
imageId = imageIds(imageIdIndex);
imageStruct = cocoGroundTruth.loadImgs(imageId);
imageFilePath = sprintf('%s/images/%s/%s', groundTruthDir, dataType, imageStruct.file_name);
fprintf(imageFilePath);
fprintf('\n');
image = imread(imageFilePath);
%% Loading annotations
annotationIds = cocoGroundTruth.getAnnIds('imgIds',imageId);
annotationsGroundTruth = cocoGroundTruth.loadAnns(annotationIds);
annotationIds = cocoEstimated.getAnnIds('imgIds',imageId);
annotationsEstimated = cocoEstimated.loadAnns(annotationIds);
colorReal = [0,1,0];
colorEstimated = [1,0,0];
%% False negatives
for annotationId = 1:numel(annotationsGroundTruth)
% Get max IoU
realPerson = annotationsGroundTruth(annotationId);
realRectangle = getKeypointsRectangle(realPerson.keypoints);
% If keypoints annotated in ground truth
if numel(realRectangle) > 0 && getNumberKeypoints(realPerson.keypoints) > 2
IoUs = zeros(numel(annotationsEstimated), 1);
for annotationEstimatedId = 1:numel(annotationsEstimated)
estimatedPerson = annotationsEstimated(annotationEstimatedId);
estimatedRectangle = getKeypointsRectangle(estimatedPerson.keypoints);
IoUs(annotationEstimatedId) = getIoU(realRectangle, estimatedRectangle);
end
[IoU, index] = max(IoUs);
% Visualizing bad IoUs
if numel(IoU) == 0 || IoU < 0.1
%% Visualizing all
% Ground truth
figure(1);
plotSize = 4;
plotSize = 2^ceil(log2(plotSize)); % plotSize must be 2^n
subplot(plotSize,plotSize,1:plotSize/2); imagesc(image); axis('image'); axis off;
title('Ground truth')
cocoGroundTruth.showAnns(annotationsGroundTruth);
% Estimated
subplot(plotSize,plotSize,plotSize/2+1:plotSize); imagesc(image); axis('image'); axis off;
title('Results')
cocoEstimated.showAnns(annotationsEstimated);
subplot(plotSize,plotSize,plotSize+1:plotSize*plotSize)
%% Visualizing errors
% Figure
imagesc(image); axis('image'); axis off; % Slower: imshow(image)
title({['FALSE NEGATIVES (red = estimated) - ', num2str(imageStruct.file_name), ' - IoU: ', num2str(IoU)]}, 'Interpreter', 'none')
% Ground truth
cocoGroundTruth.showAnns(cocoGroundTruth.loadAnns(realPerson.id), 0.5*colorReal);
rectangle('Position', realRectangle, 'LineWidth', 3, 'EdgeColor', colorReal);
% Estimated
if numel(index) > 0
estimatedPerson = annotationsEstimated(index);
estimatedRectangle = getKeypointsRectangle(estimatedPerson.keypoints);
cocoEstimated.showAnns(cocoEstimated.loadAnns(estimatedPerson.id), 0.5*colorEstimated);
rectangle('Position', estimatedRectangle, 'LineWidth', 3, 'EdgeColor', colorEstimated)
end
% Pause to visualize
pause;
end
end
end
%% False positives
for annotationEstimatedId = 1:numel(annotationsEstimated)
% Get max IoU
estimatedPerson = annotationsEstimated(annotationEstimatedId);
estimatedRectangle = getKeypointsRectangle(estimatedPerson.keypoints);
% If keypoints annotated
if numel(estimatedRectangle) > 0 && getNumberKeypoints(estimatedPerson.keypoints) > 2
IoUs = zeros(numel(annotationsGroundTruth), 1);
for annotationId = 1:numel(annotationsGroundTruth)
realPerson = annotationsGroundTruth(annotationId);
realRectangle = getKeypointsRectangle(realPerson.keypoints);
% No keypoints annotated -> use bbox
if numel(realRectangle) == 0
realRectangle = realPerson.bbox;
end
IoUs(annotationId) = getIoU(realRectangle, estimatedRectangle);
end
[IoU, index] = max(IoUs);
% Visualizing bad IoUs
if numel(IoU) == 0 || IoU < 0.1
%% Visualizing all
% Ground truth
figure(1);
plotSize = 4;
plotSize = 2^ceil(log2(plotSize)); % plotSize must be 2^n
subplot(plotSize,plotSize,1:plotSize/2); imagesc(image); axis('image'); axis off;
title('Ground truth')
cocoGroundTruth.showAnns(annotationsGroundTruth);
% Estimated
subplot(plotSize,plotSize,plotSize/2+1:plotSize); imagesc(image); axis('image'); axis off;
title('Results')
cocoEstimated.showAnns(annotationsEstimated);
subplot(plotSize,plotSize,plotSize+1:plotSize*plotSize)
%% Visualizing errors
% Figure
imagesc(image); axis('image'); axis off; % Slower: imshow(image)
title({['FALSE POSITIVES (red = estimated) - ', num2str(imageStruct.file_name), ' - IoU: ', num2str(IoU)]}, 'Interpreter', 'none')
% Ground truth
if numel(index) > 0
realPerson = annotationsGroundTruth(index);
realRectangle = getKeypointsRectangle(realPerson.keypoints);
% No keypoints annotated -> use bbox
if numel(realRectangle) == 0
realRectangle = realPerson.bbox;
end
cocoGroundTruth.showAnns(cocoGroundTruth.loadAnns(realPerson.id), 0.5*colorReal);
rectangle('Position', realRectangle, 'LineWidth', 3, 'EdgeColor', colorReal);
end
% Estimated
cocoEstimated.showAnns(cocoEstimated.loadAnns(estimatedPerson.id), 0.5*colorEstimated);
rectangle('Position', estimatedRectangle, 'LineWidth', 3, 'EdgeColor', colorEstimated)
% Pause to visualize
pause;
end
end
end
end