added AP, MAP
This commit is contained in:
parent
cdb3b64ef5
commit
e5302730b7
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
dataset
|
dataset
|
||||||
|
descriptors
|
||||||
|
@ -22,6 +22,7 @@ OUT_FOLDER = 'descriptors';
|
|||||||
%% and within that folder, create another folder to hold these descriptors
|
%% and within that folder, create another folder to hold these descriptors
|
||||||
%% the idea is all your descriptors are in individual folders - within
|
%% the idea is all your descriptors are in individual folders - within
|
||||||
%% the folder specified as 'OUT_FOLDER'.
|
%% the folder specified as 'OUT_FOLDER'.
|
||||||
|
% OUT_SUBFOLDER='avgRGB';
|
||||||
OUT_SUBFOLDER='globalRGBhisto';
|
OUT_SUBFOLDER='globalRGBhisto';
|
||||||
|
|
||||||
allfiles=dir (fullfile([DATASET_FOLDER,'/Images/*.bmp']));
|
allfiles=dir (fullfile([DATASET_FOLDER,'/Images/*.bmp']));
|
||||||
@ -34,6 +35,7 @@ for filenum=1:length(allfiles)
|
|||||||
fout=[OUT_FOLDER,'/',OUT_SUBFOLDER,'/',fname(1:end-4),'.mat'];%replace .bmp with .mat
|
fout=[OUT_FOLDER,'/',OUT_SUBFOLDER,'/',fname(1:end-4),'.mat'];%replace .bmp with .mat
|
||||||
|
|
||||||
%% EXTRACT FUNCTION
|
%% EXTRACT FUNCTION
|
||||||
|
% F=extractAvgRGB(img);
|
||||||
F=extractGlobalColHist(img);
|
F=extractGlobalColHist(img);
|
||||||
save(fout,'F');
|
save(fout,'F');
|
||||||
toc
|
toc
|
||||||
|
@ -27,6 +27,7 @@ DATASET_FOLDER = 'dataset';
|
|||||||
DESCRIPTOR_FOLDER = 'descriptors';
|
DESCRIPTOR_FOLDER = 'descriptors';
|
||||||
%% and within that folder, another folder to hold the descriptors
|
%% and within that folder, another folder to hold the descriptors
|
||||||
%% we are interested in working with
|
%% we are interested in working with
|
||||||
|
% DESCRIPTOR_SUBFOLDER='avgRGB';
|
||||||
DESCRIPTOR_SUBFOLDER='globalRGBhisto';
|
DESCRIPTOR_SUBFOLDER='globalRGBhisto';
|
||||||
|
|
||||||
|
|
||||||
@ -58,65 +59,105 @@ end
|
|||||||
% get counts for each category for PR calculation
|
% get counts for each category for PR calculation
|
||||||
CAT_HIST = histogram(ALLCATs).Values;
|
CAT_HIST = histogram(ALLCATs).Values;
|
||||||
|
|
||||||
%% 2) Pick an image at random to be the query
|
run_total = 20;
|
||||||
NIMG=size(ALLFEAT,1); % number of images in collection
|
AP_values = zeros([1, run_total]);
|
||||||
queryimg=floor(rand()*NIMG); % index of a random image
|
for run=1:run_total
|
||||||
|
%% 2) Pick an image at random to be the query
|
||||||
|
NIMG=size(ALLFEAT,1); % number of images in collection
|
||||||
|
queryimg=floor(rand()*NIMG); % index of a random image
|
||||||
|
|
||||||
|
|
||||||
%% 3) Compute the distance of image to the query
|
%% 3) Compute the distance of image to the query
|
||||||
dst=[];
|
dst=[];
|
||||||
for i=1:NIMG
|
for i=1:NIMG
|
||||||
candidate=ALLFEAT(i,:);
|
candidate=ALLFEAT(i,:);
|
||||||
query=ALLFEAT(queryimg,:);
|
query=ALLFEAT(queryimg,:);
|
||||||
|
|
||||||
category=ALLCATs(i);
|
category=ALLCATs(i);
|
||||||
|
|
||||||
%% COMPARE FUNCTION
|
%% COMPARE FUNCTION
|
||||||
thedst=compareEuclidean(query,candidate);
|
thedst=compareEuclidean(query,candidate);
|
||||||
dst=[dst ; [thedst i category]];
|
dst=[dst ; [thedst i category]];
|
||||||
end
|
end
|
||||||
dst=sortrows(dst,1); % sort the results
|
dst=sortrows(dst,1); % sort the results
|
||||||
|
|
||||||
%% 3.5) Calculate PR
|
%% 3.5) Calculate PR
|
||||||
precision_values=[];
|
precision_values=zeros([1, NIMG]);
|
||||||
recall_values=[];
|
recall_values=zeros([1, NIMG]);
|
||||||
query_row = dst(1,:);
|
|
||||||
query_category = query_row(1,3);
|
|
||||||
for i=1:NIMG
|
|
||||||
|
|
||||||
rows = dst(1:i, :);
|
correct_at_n=zeros([1, NIMG]);
|
||||||
|
|
||||||
correct_results = 0;
|
query_row = dst(1,:);
|
||||||
incorrect_results = 0;
|
query_category = query_row(1,3);
|
||||||
|
for i=1:NIMG
|
||||||
|
|
||||||
for n=1:i
|
rows = dst(1:i, :);
|
||||||
row = rows(n, :);
|
|
||||||
|
correct_results = 0;
|
||||||
|
incorrect_results = 0;
|
||||||
|
|
||||||
|
if i > 1
|
||||||
|
for n=1:i - 1
|
||||||
|
row = rows(n, :);
|
||||||
|
category = row(3);
|
||||||
|
|
||||||
|
if category == query_category
|
||||||
|
correct_results = correct_results + 1;
|
||||||
|
else
|
||||||
|
incorrect_results = incorrect_results + 1;
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
% LAST ROW
|
||||||
|
row = rows(i, :);
|
||||||
category = row(3);
|
category = row(3);
|
||||||
|
|
||||||
if category == query_category
|
if category == query_category
|
||||||
correct_results = correct_results + 1;
|
correct_results = correct_results + 1;
|
||||||
|
correct_at_n(i) = 1;
|
||||||
else
|
else
|
||||||
incorrect_results = incorrect_results + 1;
|
incorrect_results = incorrect_results + 1;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
precision = correct_results / i;
|
||||||
|
recall = correct_results / CAT_HIST(1,query_category);
|
||||||
|
|
||||||
|
precision_values(i) = precision;
|
||||||
|
recall_values(i) = recall;
|
||||||
end
|
end
|
||||||
|
|
||||||
precision = correct_results / i;
|
|
||||||
recall = correct_results / CAT_HIST(1,query_category);
|
|
||||||
|
|
||||||
precision_values(i) = precision;
|
%% 3.6) calculate AP
|
||||||
recall_values(i) = recall;
|
P_rel_n = zeros([1, NIMG]);
|
||||||
|
for i = 1:NIMG
|
||||||
|
precision = precision_values(i);
|
||||||
|
i_result_relevant = correct_at_n(i);
|
||||||
|
|
||||||
|
P_rel_n(i) = precision * i_result_relevant;
|
||||||
|
end
|
||||||
|
|
||||||
|
sum_P_rel_n = sum(P_rel_n);
|
||||||
|
average_precision = sum_P_rel_n / CAT_HIST(1,query_category);
|
||||||
|
|
||||||
|
AP_values(run) = average_precision;
|
||||||
|
|
||||||
|
|
||||||
|
%% 3.8) plot PR curve
|
||||||
|
figure(1)
|
||||||
|
plot(recall_values, precision_values);
|
||||||
|
hold on;
|
||||||
|
title('PR Curve');
|
||||||
|
xlabel('Recall');
|
||||||
|
ylabel('Precision');
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
% plot PR curve
|
%% 3.9 Calculate MAP
|
||||||
plot(recall_values, precision_values);
|
AP_values
|
||||||
title('PR Curve');
|
MAP = mean(AP_values)
|
||||||
xlabel('Recall');
|
|
||||||
ylabel('Precision');
|
|
||||||
|
|
||||||
% for i=1:NIMG
|
|
||||||
% [i, " -> p: ", precision_values(i), "r: ", recall_values(i)]
|
|
||||||
% end
|
|
||||||
|
|
||||||
%% 4) Visualise the results
|
%% 4) Visualise the results
|
||||||
%% These may be a little hard to see using imgshow
|
%% These may be a little hard to see using imgshow
|
||||||
@ -131,5 +172,6 @@ for i=1:size(dst,1)
|
|||||||
img=img(1:81,:,:); % crop image to uniform size vertically (some MSVC images are different heights)
|
img=img(1:81,:,:); % crop image to uniform size vertically (some MSVC images are different heights)
|
||||||
outdisplay=[outdisplay img];
|
outdisplay=[outdisplay img];
|
||||||
end
|
end
|
||||||
% imgshow(outdisplay);
|
figure(2)
|
||||||
% axis off;
|
imgshow(outdisplay);
|
||||||
|
axis off;
|
||||||
|
@ -78,8 +78,11 @@ end
|
|||||||
dst=sortrows(dst,1); % sort the results
|
dst=sortrows(dst,1); % sort the results
|
||||||
|
|
||||||
%% 3.5) Calculate PR
|
%% 3.5) Calculate PR
|
||||||
precision_values=[];
|
precision_values=zeros([1, NIMG]);
|
||||||
recall_values=[];
|
recall_values=zeros([1, NIMG]);
|
||||||
|
|
||||||
|
correct_at_n=zeros([1, NIMG]);
|
||||||
|
|
||||||
query_row = dst(1,:);
|
query_row = dst(1,:);
|
||||||
query_category = query_row(1,3);
|
query_category = query_row(1,3);
|
||||||
for i=1:NIMG
|
for i=1:NIMG
|
||||||
@ -89,16 +92,29 @@ for i=1:NIMG
|
|||||||
correct_results = 0;
|
correct_results = 0;
|
||||||
incorrect_results = 0;
|
incorrect_results = 0;
|
||||||
|
|
||||||
for n=1:i
|
if i > 1
|
||||||
row = rows(i, :);
|
for n=1:i - 1
|
||||||
category = row(3);
|
row = rows(n, :);
|
||||||
|
category = row(3);
|
||||||
|
|
||||||
|
if category == query_category
|
||||||
|
correct_results = correct_results + 1;
|
||||||
|
else
|
||||||
|
incorrect_results = incorrect_results + 1;
|
||||||
|
end
|
||||||
|
|
||||||
if category == query_category
|
|
||||||
correct_results = correct_results + 1;
|
|
||||||
else
|
|
||||||
incorrect_results = incorrect_results + 1;
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
% LAST ROW
|
||||||
|
row = rows(i, :);
|
||||||
|
category = row(3);
|
||||||
|
|
||||||
|
if category == query_category
|
||||||
|
correct_results = correct_results + 1;
|
||||||
|
correct_at_n(i) = 1;
|
||||||
|
else
|
||||||
|
incorrect_results = incorrect_results + 1;
|
||||||
end
|
end
|
||||||
|
|
||||||
precision = correct_results / i;
|
precision = correct_results / i;
|
||||||
@ -108,9 +124,20 @@ for i=1:NIMG
|
|||||||
recall_values(i) = recall;
|
recall_values(i) = recall;
|
||||||
end
|
end
|
||||||
|
|
||||||
% for i=1:NIMG
|
|
||||||
% [i, " -> p: ", precision_values(i), "r: ", recall_values(i)]
|
%% 3.6) calculate AP
|
||||||
% end
|
for i = 1:NIMG
|
||||||
|
precision = precision_values(i);
|
||||||
|
i
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
%% 3.8) plot PR curve
|
||||||
|
% plot(recall_values, precision_values);
|
||||||
|
% title('PR Curve');
|
||||||
|
% xlabel('Recall');
|
||||||
|
% ylabel('Precision');
|
||||||
|
|
||||||
|
|
||||||
%% 4) Visualise the results
|
%% 4) Visualise the results
|
||||||
%% These may be a little hard to see using imgshow
|
%% These may be a little hard to see using imgshow
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user