pulling results, fixed deflation

This commit is contained in:
aj 2019-12-01 23:27:29 +00:00
parent ca4bd6562d
commit 5155601d59
18 changed files with 4229 additions and 440 deletions

View File

@ -23,10 +23,10 @@ OUT_FOLDER = '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='avgRGB';
OUT_SUBFOLDER='globalRGBhisto'; % OUT_SUBFOLDER='globalRGBhisto';
% OUT_SUBFOLDER='spatialColour'; % OUT_SUBFOLDER='spatialColour';
% DESCRIPTOR_SUBFOLDER='spatialTexture'; % OUT_SUBFOLDER='spatialTexture';
% OUT_SUBFOLDER='spatialColourTexture'; OUT_SUBFOLDER='spatialColourTexture';
allfiles=dir (fullfile([DATASET_FOLDER,'/Images/*.bmp'])); allfiles=dir (fullfile([DATASET_FOLDER,'/Images/*.bmp']));
for filenum=1:length(allfiles) for filenum=1:length(allfiles)
@ -39,10 +39,10 @@ for filenum=1:length(allfiles)
%% EXTRACT FUNCTION %% EXTRACT FUNCTION
% F=extractAvgRGB(img); % F=extractAvgRGB(img);
F=extractGlobalColHist(img, 2, 1, 8, 0.05); % F=extractGlobalColHist(img, 2, 1, 8, 0.05);
% F=extractSpatialColour(img, 2, 1); % F=extractSpatialColour(img, 14, 4);
% F=extractSpatialTexture(img, 2, 1, 8, 0.05); % F=extractSpatialTexture(img, 4, 4, 7, 0.09);
% F=extractSpatialColourTexture(img); F=extractSpatialColourTexture(img, 4, 4, 7, 0.09);
save(fout,'F'); save(fout,'F');
toc toc
end end

View File

@ -28,10 +28,10 @@ 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='avgRGB';
DESCRIPTOR_SUBFOLDER='globalRGBhisto'; % DESCRIPTOR_SUBFOLDER='globalRGBhisto';
% DESCRIPTOR_SUBFOLDER='spatialColour'; % DESCRIPTOR_SUBFOLDER='spatialColour';
% DESCRIPTOR_SUBFOLDER='spatialTexture'; % DESCRIPTOR_SUBFOLDER='spatialTexture';
% DESCRIPTOR_SUBFOLDER='spatialColourTexture'; DESCRIPTOR_SUBFOLDER='spatialColourTexture';
CATEGORIES = ["Farm Animal" CATEGORIES = ["Farm Animal"
"Tree" "Tree"
@ -92,6 +92,14 @@ CAT_TOTAL = length(CAT_HIST);
NIMG=size(ALLFEAT,1); % number of images in collection NIMG=size(ALLFEAT,1); % number of images in collection
map=[];
deflate_energy = [0:0.001:0.3];
for var_iter=1:size(deflate_energy, 2)
descriptor_list = ALLFEAT;
confusion_matrix = zeros(CAT_TOTAL); confusion_matrix = zeros(CAT_TOTAL);
all_precision = []; all_precision = [];
@ -104,18 +112,18 @@ for iteration=1:CAT_TOTAL
queryimg=QUERY_INDEXES(iteration); % index of a random image queryimg=QUERY_INDEXES(iteration); % index of a random image
%% 3) Compute EigenModel %% 3) Compute EigenModel
E = getEigenModel(ALLFEAT); E = getEigenModel(descriptor_list);
E = deflateEigen(E, 3); E = deflateEigen(E, 1-deflate_energy(var_iter));
%% 4) Project data to lower dimensionality %% 4) Project data to lower dimensionality
ALLFEAT=ALLFEAT-repmat(E.org,size(ALLFEAT,1),1); descriptor_list=descriptor_list-repmat(E.org,size(descriptor_list,1),1);
ALLFEAT=((E.vct')*(ALLFEAT'))'; descriptor_list=((E.vct')*(descriptor_list'))';
%% 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=descriptor_list(i,:);
query=ALLFEAT(queryimg,:); query=descriptor_list(queryimg,:);
category=ALLCATs(i); category=ALLCATs(i);
@ -133,9 +141,9 @@ for iteration=1:CAT_TOTAL
query_row = dst(1,:); query_row = dst(1,:);
query_category = query_row(1,3); query_category = query_row(1,3);
if query_category ~= iteration % if query_category ~= iteration
dst % dst
end % end
fprintf('category was %s\n', CATEGORIES(query_category)) fprintf('category was %s\n', CATEGORIES(query_category))
dst = dst(2:NIMG, :); dst = dst(2:NIMG, :);
@ -192,32 +200,32 @@ for iteration=1:CAT_TOTAL
%% 6) plot PR curve %% 6) plot PR curve
figure(1) % figure(1)
plot(recall_values, precision_values,'LineWidth',1.5); % plot(recall_values, precision_values,'LineWidth',1.5);
hold on; % hold on;
title('PR Curve'); % title('PR Curve');
xlabel('Recall'); % xlabel('Recall');
ylabel('Precision'); % ylabel('Precision');
xlim([0 1]); % xlim([0 1]);
ylim([0 1]); % ylim([0 1]);
%% 7) Visualise the results %% 7) Visualise the results
%% These may be a little hard to see using imgshow %% These may be a little hard to see using imgshow
%% If you have access, try using imshow(outdisplay) or imagesc(outdisplay) %% If you have access, try using imshow(outdisplay) or imagesc(outdisplay)
SHOW=25; % Show top 25 results % SHOW=25; % Show top 25 results
dst=dst(1:SHOW,:); % dst=dst(1:SHOW,:);
outdisplay=[]; % outdisplay=[];
for i=1:size(dst,1) % for i=1:size(dst,1)
img=imread(ALLFILES{dst(i,2)}); % img=imread(ALLFILES{dst(i,2)});
img=img(1:2:end,1:2:end,:); % make image a quarter size % img=img(1:2:end,1:2:end,:); % make image a quarter size
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];
%
%populate confusion matrix % %populate confusion matrix
confusion_matrix(query_category, dst(i,3)) = confusion_matrix(query_category, dst(i,3)) + 1; % confusion_matrix(query_category, dst(i,3)) = confusion_matrix(query_category, dst(i,3)) + 1;
end % end
% figure(3) % figure(3)
% imgshow(outdisplay); % imgshow(outdisplay);
% axis off; % axis off;
@ -225,18 +233,18 @@ for iteration=1:CAT_TOTAL
end end
%% Plot average PR curve %% Plot average PR curve
figure(4) % figure(4)
mean_precision = mean(all_precision); % mean_precision = mean(all_precision);
mean_recall = mean(all_recall); % mean_recall = mean(all_recall);
plot(mean_recall, mean_precision,'LineWidth',5); % plot(mean_recall, mean_precision,'LineWidth',5);
title('PR Curve'); % title('PR Curve');
xlabel('Average Recall'); % xlabel('Average Recall');
ylabel('Average Precision'); % ylabel('Average Precision');
xlim([0 1]); % xlim([0 1]);
ylim([0 1]); % ylim([0 1]);
% normalise confusion matrix % normalise confusion matrix
norm_confusion_matrix = confusion_matrix ./ sum(confusion_matrix, 'all'); % norm_confusion_matrix = confusion_matrix ./ sum(confusion_matrix, 'all');
%% 8 Calculate MAP %% 8 Calculate MAP
% figure(4) % figure(4)
@ -247,10 +255,14 @@ norm_confusion_matrix = confusion_matrix ./ sum(confusion_matrix, 'all');
% xlim([0, 1]); % xlim([0, 1]);
MAP = mean(AP_values) MAP = mean(AP_values)
AP_sd = std(AP_values) % AP_sd = std(AP_values);
% figure(2) % figure(2)
% plot(1:CAT_TOTAL, AP_values); % plot(1:CAT_TOTAL, AP_values);
% title('Average Precision Per Run'); % title('Average Precision Per Run');
% xlabel('Run'); % xlabel('Run');
% ylabel('Average Precision'); % ylabel('Average Precision');
map(var_iter) = MAP;
end

View File

@ -28,10 +28,10 @@ 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='avgRGB';
DESCRIPTOR_SUBFOLDER='globalRGBhisto'; % DESCRIPTOR_SUBFOLDER='globalRGBhisto';
% DESCRIPTOR_SUBFOLDER='spatialColour'; % DESCRIPTOR_SUBFOLDER='spatialColour';
% DESCRIPTOR_SUBFOLDER='spatialTexture'; % DESCRIPTOR_SUBFOLDER='spatialTexture';
% DESCRIPTOR_SUBFOLDER='spatialColourTexture'; DESCRIPTOR_SUBFOLDER='spatialColourTexture';
CATEGORIES = ["Farm Animal" CATEGORIES = ["Farm Animal"
"Tree" "Tree"
@ -221,7 +221,7 @@ figure(4)
mean_precision = mean(all_precision); mean_precision = mean(all_precision);
mean_recall = mean(all_recall); mean_recall = mean(all_recall);
plot(mean_recall, mean_precision,'LineWidth',5); plot(mean_recall, mean_precision,'LineWidth',5);
title('Global Colour Histogram Average PR (n=5)'); title('Spatial Texture Average PR (4x4, bin=7, thresh.=0.09)');
xlabel('Average Recall'); xlabel('Average Recall');
ylabel('Average Precision'); ylabel('Average Precision');
xlim([0 1]); xlim([0 1]);

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

View File

@ -25,12 +25,6 @@ DATASET_FOLDER = 'dataset';
%% Folder that holds the results... %% Folder that holds the results...
DESCRIPTOR_FOLDER = 'descriptors'; DESCRIPTOR_FOLDER = 'descriptors';
%% and within that folder, another folder to hold the descriptors
%% we are interested in working with
% DESCRIPTOR_SUBFOLDER='avgRGB';
% DESCRIPTOR_SUBFOLDER='globalRGBhisto';
DESCRIPTOR_SUBFOLDER='spatialColour';
% DESCRIPTOR_SUBFOLDER='spatialColourTexture';
CATEGORIES = ["Farm Animal" CATEGORIES = ["Farm Animal"
"Tree" "Tree"
@ -61,10 +55,8 @@ QUERY_INDEXES=[301 358 384 436 447 476 509 537 572 5 61 80 97 127 179 181 217 26
map = []; map = [];
thresholded = [0.01:0.01:0.15]; for r=9:9
for c=1:8
for b=1:15
% for c=1:10
%% 1) Load all the descriptors into "ALLFEAT" %% 1) Load all the descriptors into "ALLFEAT"
%% each row of ALLFEAT is a descriptor (is an image) %% each row of ALLFEAT is a descriptor (is an image)
@ -72,7 +64,6 @@ for b=1:15
ALLFEAT=[]; ALLFEAT=[];
ALLFILES=cell(1,0); ALLFILES=cell(1,0);
ALLCATs=[]; ALLCATs=[];
ctr=1;
allfiles=dir (fullfile([DATASET_FOLDER,'/Images/*.bmp'])); allfiles=dir (fullfile([DATASET_FOLDER,'/Images/*.bmp']));
for filenum=1:length(allfiles) for filenum=1:length(allfiles)
@ -89,9 +80,9 @@ for filenum=1:length(allfiles)
%% EXTRACT FUNCTION %% EXTRACT FUNCTION
% F=extractAvgRGB(img); % F=extractAvgRGB(img);
% F=extractGlobalColHist(img); % F=extractGlobalColHist(img);
% F = extractSpatialColour(img, b, c); % F=extractSpatialColour(img, r, c);
F=extractSpatialTexture(img, 4, 4, 7, thresholded(1,b)); F=extractSpatialTexture(img, r, c, 7, 0.09);
% F=extractSpatialColourTexture(img, b, c, 8, 0.08); % F=extractSpatialColourTexture(img, r, c, 7, 0.09);
% toc % toc
ALLFEAT=[ALLFEAT ; F]; ALLFEAT=[ALLFEAT ; F];
@ -139,7 +130,7 @@ for iteration=1:CAT_TOTAL
% if query_category ~= iteration % if query_category ~= iteration
% dst % dst
% end % end
fprintf('category was %s\n', CATEGORIES(query_category)) % fprintf('category was %s\n', CATEGORIES(query_category))
dst = dst(2:NIMG, :); dst = dst(2:NIMG, :);
@ -209,18 +200,18 @@ for iteration=1:CAT_TOTAL
%% These may be a little hard to see using imgshow %% These may be a little hard to see using imgshow
%% If you have access, try using imshow(outdisplay) or imagesc(outdisplay) %% If you have access, try using imshow(outdisplay) or imagesc(outdisplay)
SHOW=25; % Show top 25 results % SHOW=25; % Show top 25 results
dst=dst(1:SHOW,:); % dst=dst(1:SHOW,:);
outdisplay=[]; % outdisplay=[];
for i=1:size(dst,1) % for i=1:size(dst,1)
% img=imread(ALLFILES{dst(i,2)}); % % img=imread(ALLFILES{dst(i,2)});
% img=img(1:2:end,1:2:end,:); % make image a quarter size % % img=img(1:2:end,1:2:end,:); % make image a quarter size
% 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];
%
%populate confusion matrix % %populate confusion matrix
confusion_matrix(query_category, dst(i,3)) = confusion_matrix(query_category, dst(i,3)) + 1; % confusion_matrix(query_category, dst(i,3)) = confusion_matrix(query_category, dst(i,3)) + 1;
end % end
% figure(3) % figure(3)
% imgshow(outdisplay); % imgshow(outdisplay);
% axis off; % axis off;
@ -239,7 +230,7 @@ end
% ylim([0 1]); % ylim([0 1]);
% normalise confusion matrix % normalise confusion matrix
norm_confusion_matrix = confusion_matrix ./ sum(confusion_matrix, 'all'); % norm_confusion_matrix = confusion_matrix ./ sum(confusion_matrix, 'all');
%% 8 Calculate MAP %% 8 Calculate MAP
% figure(4) % figure(4)
@ -249,8 +240,8 @@ norm_confusion_matrix = confusion_matrix ./ sum(confusion_matrix, 'all');
% xlabel('Average Precision'); % xlabel('Average Precision');
% xlim([0, 1]); % xlim([0, 1]);
MAP = mean(AP_values) MAP = mean(AP_values);
AP_sd = std(AP_values) % AP_sd = std(AP_values)
% figure(2) % figure(2)
% plot(1:CAT_TOTAL, AP_values); % plot(1:CAT_TOTAL, AP_values);
@ -258,11 +249,11 @@ AP_sd = std(AP_values)
% xlabel('Run'); % xlabel('Run');
% ylabel('Average Precision'); % ylabel('Average Precision');
% fprintf('%i,%i %i', b, c, MAP); fprintf('%i,%i %i\n', r, c, MAP);
fprintf('%i,%i', b, MAP); % fprintf('%i,%i\n', r, MAP);
% map(b, c) = MAP; map(r, c) = MAP;
map(b) = MAP; % map(b) = MAP;
% end end
end end

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,15 @@
function E=deflateEigen(E, param) function E=deflateEigen(E, param)
E.val=E.val(1:param); totalenergy=sum(abs(E.val));
E.vct=E.vct(:,1:param); currentenergy=0;
rank=0;
for i=1:size(E.vct,2)
if currentenergy>(totalenergy*param)
break;
end
rank=rank+1;
currentenergy=currentenergy+E.val(i);
end
E.val=E.val(1:rank);
E.vct=E.vct(:,1:rank);