MATLAB Answers

0

Why I cannot get results when I detect multiple labels

Asked by Carla Shaw on 15 Sep 2019
Latest activity Commented on by Image Analyst
on 18 Sep 2019
after I train FasterRCNN object detector, and use the detector to detect multiple labels, the results did not shown
I cannot figure out why the results not shown in the table. so that I cannot calculate the average precision.
I showed my code
%%
trainingData = apple
numClasses = 3;
numClassesPlusBackground = numClasses + 1;
%%
inputLayer = imageInputLayer([32 32 3]);
filterSize = [3 3];
numFilters = 32;
middleLayers = [
convolution2dLayer(filterSize, numFilters, 'Padding', 1)
reluLayer()
convolution2dLayer(filterSize, numFilters, 'Padding', 1)
reluLayer()
maxPooling2dLayer(3, 'Stride',2)
];
finalLayers = [
fullyConnectedLayer(4)
reluLayer
fullyConnectedLayer(width(trainingData))
softmaxLayer
classificationLayer
];
layers = [
inputLayer
middleLayers
finalLayers
]
options = trainingOptions('sgdm', ...
'MiniBatchSize', 1, ...
'InitialLearnRate', 1e-3, ...
'MaxEpochs', 10, ...
'VerboseFrequency', 200, ...
'CheckpointPath', tempdir);
detector = trainFasterRCNNObjectDetector(trainingData, layers, ...
'NegativeOverlapRange',[0 0.3], ...
'PositiveOverlapRange',[0.6 1]);
%%
numImages = height(trainingData);
% Run detector on each image in the test set and collect results.
results = table('Size',[numImages 3],...
'VariableTypes',{'cell','cell','cell'},...
'VariableNames',{'Boxes','Scores','Labels'});
for i = 1:numImages
%ds = imageDatastore(trainingData.imageFilename{i});
% Read the image.
I = imread(trainingData.imageFilename{i});
% Run the detector.
[bboxes,scores,labels] = detect(detector, I);
I=insertObjectAnnotation(I, 'rectangle', bboxes, scores);
% Collect the results.
results.Boxes{i,1} = bboxes;
results.Scores{i,1} = scores;
results.Labels{i,1} = labels;
end
results=struct2table(resultsStruct);
expectedResults = trainingData(:, 2:4);
[ap, recall, precision] = evaluateDetectionPrecision(results,expectedResults);
figure
xlabel('unripeRecall')
ylabel('unripePrecision')
plot(recall, precision)
grid ON
title(sprintf('Average Precision = %.2f', ap));

  0 Comments

Sign in to comment.

2 Answers

Answer by Image Analyst
on 15 Sep 2019

What function did you call to show the regions? Did you use insertObjectAnnotation()?
post your script.

  0 Comments

Sign in to comment.


Answer by Image Analyst
on 16 Sep 2019

You ARE getting results. trainindData is not your results - that is the image datastore used to train your detector. Your results are bboxes.
What table are you talking about?

  4 Comments

Show 1 older comment
Since bboxes contains a different number of boxes, it will have to be in a cell. So let's say column 1 of results should contain the cell for that image. You'll need to say
results{i, 1} = {bboxes};
That way, that location of results, the first column in row "i", will be a cell because encasing bboxes in braces puts bboxes into a cell.
Please read the FAQ for a better explanation of what a cell is and how to use it.
I tried but still not work, I cannot fogure out why.
Can youi give the complete script, and tell me what kind of image datastore I need to have?

Sign in to comment.