non maximum suppression boxes display

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
clc
clearvars
clear
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])
reluLayer("Name","relu")
convolution2dLayer([5 5],32,"Name","conv_1","BiasLearnRateFactor",2,"Padding",[2 2 2 2],"WeightsInitializer","narrow-normal")
reluLayer("Name","relu_1")
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")
reluLayer("Name","relu_2")
averagePooling2dLayer([3 3],"Name","avgpool_1","Stride",[2 2])
fullyConnectedLayer(64,"Name","fc","BiasLearnRateFactor",2,"WeightsInitializer","narrow-normal")
reluLayer("Name","relu_3")
fullyConnectedLayer(2,"Name","fc_rcnn","BiasL2Factor",1,"BiasLearnRateFactor",5,"WeightLearnRateFactor",8,"WeightsInitializer","narrow-normal")
softmaxLayer("Name","softmax")
classificationLayer("Name","classoutput")]
load('Wgtruth.mat');
%% 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')
addpath(imDir)
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);
figure
imshow(detectedImg);

回答(1 个)

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.

7 个评论

I see! So what do i do with the labels?
How does this work I ran this test with and with out the label using your code and nothing happened!
Can you display where you modified that in my code so that i can have a greater understanding of your instructions which I am following?
for understanding i removed this
[bbox, score, label] = detect(rcnn, img, 'MiniBatchSize', 10)
[bboxes,scores] = detect(rcnn,img,'SelectStrongest',false);
%% Test the R-CNN detector on a test image.
img = imread('14.jpg');
[bbox, score, label] = detect(rcnn, img, 'SelectStrongest',false)
[score, idx] = max(score)
YUP!! I tried that! it did not work!!
Any other suggessions? the box is not drawing around the gun!!
for the output from the rcnn detector I am trying to get this in the image bellow!
and then display the image as seen above with the gun but with the box around it!!
Thank you Ajay Pattassery great job thus far but we aren't there yet!!
Could you verify that [bbox, score, label] is containing a single detected bounding box? From the following code segment, only the bounding box with the maximum score is displayed
[score, idx] = max(score)
bbox = bbox(idx, :)
Could you remove the above statement and try.
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!
error::::
Unrecognized function or variable 'idx'.
Error in test (line 113)
annotation = sprintf('%s: (Confidence = %f)', label(idx), score);
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!
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);

请先登录,再进行评论。

提问:

2020-2-16

评论:

2020-5-11

Community Treasure Hunt

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

Start Hunting!

Translated by