MATLAB Answers

non maximum suppression boxes display

23 views (last 30 days)
Matpar on 16 Feb 2020
Commented: Matpar on 11 May 2020
Hi all and thank you for responding in advance!
I am trying to display the region proposals and the bounding boxes on the Test Image!
Can someone guide me on coding the maximum suppression to display the boxes on the test output image?
Here is my code and thank you inadvance, attach is the files as well as the image that is being classified.
I want to display all the boxes on that image to see if the reagions are being distorted.
Thank you once more!
%% Classifing Features With SVM
%% Improving The Bounding Box
close all
Newlayers = [
imageInputLayer([32 32 3],"Name","imageinput")
convolution2dLayer([5 5],32,"Name","conv","BiasLearnRateFactor",2,"Padding",[2 2 2 2],"WeightsInitializer","narrow-normal")
maxPooling2dLayer([3 3],"Name","maxpool","Stride",[2 2])
convolution2dLayer([5 5],32,"Name","conv_1","BiasLearnRateFactor",2,"Padding",[2 2 2 2],"WeightsInitializer","narrow-normal")
averagePooling2dLayer([3 3],"Name","avgpool","Stride",[2 2])
convolution2dLayer([5 5],64,"Name","conv_2","BiasLearnRateFactor",2,"Padding",[2 2 2 2],"WeightsInitializer","narrow-normal")
averagePooling2dLayer([3 3],"Name","avgpool_1","Stride",[2 2])
%% Save Empty .Mat File/ Save Variables To File Then Load All
save gun.mat Wgtruth Newlayers
load('gun.mat', 'Wgtruth', 'Newlayers')
%% Add the image directory to the MATLAB path.
imDir = fullfile(matlabroot, 'Wgtruth')
options = trainingOptions('sgdm','MiniBatchSize', 10,'InitialLearnRate', 1e-4,'MaxEpochs', 67)
rcnn = trainRCNNObjectDetector(Wgtruth, Newlayers, options, 'NegativeOverlapRange', [0 0.3])
%% Test the R-CNN detector on a test image.
img = imread('14.jpg');
[bbox, score, label] = detect(rcnn, img, 'MiniBatchSize', 10)
[score, idx] = max(score)
bbox = bbox(idx, :)
annotation = sprintf('%s: (Confidence = %f)', label(idx), score);
detectedImg = insertObjectAnnotation(img, 'rectangle', bbox, annotation);


Sign in to comment.

Answers (1)

Ajay Pattassery
Ajay Pattassery on 19 Feb 2020
Edited: Ajay Pattassery on 19 Feb 2020
I assume you would like to see all the bounding boxes from the output of the R-CNN Object detector.
For this, you could give the argument SelectStrongest as false in the detect function.
[bboxes,scores] = detect(rcnn,img,'SelectStrongest',false);
Refer detect for more information.


Show 4 older comments
Matpar on 19 Feb 2020
No that didn't work either nice try! i think I tried that as well! just ran that test anyways to see if I may have missed something!
I got this error anyways!
it seems that it is asking for the details that was omitted!
Unrecognized function or variable 'idx'.
Error in test (line 113)
annotation = sprintf('%s: (Confidence = %f)', label(idx), score);
Matpar on 19 Feb 2020
Ajay Pattassery I revisited the code and it is not displaying the box, can you assist me to find it please?
Been googling but my knowledge of the terminology of the commads and the functions is limited!
Please assist!
Matpar on 11 May 2020
This actually work after some tries; best of luck
% img = imread('/Users/mmgp/Documents/MATLAB/Simulations/SimulationsTest3/ActivityData/Beating/Beating26.jpg');
% [bboxesObject,scoresObject] = detect(rcnn,img,'SelectStrongest',false);
% [bboxesBeat,scoresBeat] = detect(rcnn,img,'SelectStrongest',false);
% labs = cellstr(label);
% strcmp(labs(:,1),'Beat')
% Beat = find(strcmp(labs, 'Beat'))
% [bbox, score, label] = detect(rcnn, img, 'SelectStrongest',false);
% [selectbbox, selectscore, selectlabel]= selectStrongestBboxMulticlass(bbox, score, label,...
% 'RatioType', 'Min', 'OverlapThreshold', 0.60);
% [score, idx] = max(score);
% bbox = bbox(idx, :);
% annotation = sprintf('%s: (Confidence = %f)', label(idx), score);
% annotation1 = sprintf('%s: (Confidence = %f)', label(idx), selectscore);
% detectedImg1 = insertObjectAnnotation(img, 'rectangle', bbox,annotation,'Color','g');
% detectedImg2 = insertObjectAnnotation(img, 'rectangle', selectbbox,annotation1,'Color','r');
% figure
% imshow(detectedImg1);
% figure
% imshow(detectedImg2);

Sign in to comment.

Translated by