labelling retrived images, precision, recall, average precision, Mean average precision for image retrival

4 views (last 30 days)
I want to labell the retrieved images as their folder names , find precision & recall for image retrieved. I need to find some way to find the average precision & Mean average precisioon for tthe images retrieved and plot raph for precision recall. Is there some simple way ? I saw some methods for classification but I don't think if I can use them.
[file, path] = uigetfile('*.jpg');
full_file = fullfile(path, file);
output_Folder = fullfile('Train');
root_Folder = fullfile(output_Folder);
images_query = imageDatastore(root_Folder, 'IncludeSubfolders',true, 'LabelSource','foldernames');
Read_file = imread(full_file); % Read image
Input_Layer_Size_q = net.Layers(1).InputSize(1:2);
Resized_Test_image_q = augmentedImageDatastore(Input_Layer_Size_q, Read_file, 'ColorPreprocessing','gray2rgb');
%Extract feature
t_feature = activations(net, Resized_Training_image, 'conv3', 'OutputAs', 'Rows');
q_feature = activations(net, Resized_Test_image_q, 'conv3', 'OutputAs', 'Rows');
Training_Labels = Training_image.Labels; % label training
[Query_Label] = classify(net, Resized_Test_image_q);
label = Query_Label;
%%% No. retrievels
num = 20;
[Idx,Cb] = knnsearch(t_feature,q_feature,'K',num, 'Distance','cityblock');
files = cell(1, num);
for h =1:num
files{h} = Training_image.Files{Idx(h)};
end
%query image
figure;
imshow(Read_file);
title( "query: " + string(label));
% retrived image
figure;
montage(files);
title( "retrieved: " );

Answers (1)

T.Nikhil kumar
T.Nikhil kumar on 1 Dec 2023
Hello,
As per my understanding, you want to label the retrieved images as their folder names, find average precision/mean average precision and plot precision-recall graph for your image search results.
For labelling images as their folder names follow the below mentioned steps:
  1. Create a struct called ‘retrievedImages’ with two fields namely ‘Files’ and ‘Labels’. This ‘Files’ field would contain the filename of the retrieved image and ‘Labels’ would contain its corresponding label.
  2. Refer the below written code snippet for better understanding:
files = cell(1, num);
labels = cell(1, num);
for h =1:num
files{h} = Training_image.Files{Idx(h)};
labels{h} = Training_image.Labels{Idx(h)};
end
retrievedImages.Files=files;
retrievedImages.Labels=labels;
For finding performance metrics like average Precision and mean average precision, you can use the ‘evaluateImageRetrieval’ function.
  • The code snippet mentioned below will return the average precision metric for measuring the accuracy of image search results for theResized_Test_image_q’.
  • The expectedIDs input contains the indices of images that are known to be similar to the query image. This would be the ground truth and you will have to pass the correct set of IDs here.
  • imageIndex’ should contain the search index for the training images here. You can use the ‘indexImages’ function to create this object.
averagePrecision= evaluateImageRetrieval(Resized_Test_image_q, imageIndex,expectedIDs);
Please refer to the following MathWorks documentation to learn more about the ‘evaluateimageRetrieval’ and ‘indexImages’ functions:
Refer to the following documentation to understand more about the method to calculate precision and recall metrics:
Hope this solves your query!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!