RCNNによる多クラス検出について
7 views (last 30 days)
Show older comments
現在以下のコードにてRCNNによる検出を行っています。テストイメージには検出したい物体が複数写っておりdetectコマンドで複数の物体を同時に検出したいと考えているのですができません。どのように改良を加えれば良いでしょうか
%%Load a pre-trained, deep, convolutional network
net = alexnet;
layersfirst = net.Layers
%%Delete Full Connected Layer
layersTransfer = layersfirst(1:end-3)
objectClasses = {'mouse','keyboard','mug','efan'};
numClassesPlusBackground = numel(objectClasses) + 1;
%%layers
layers = [layersTransfer
fullyConnectedLayer(numClassesPlusBackground,'WeightLearnRateFactor',20,'BiasLearnRateFactor',20)
softmaxLayer
classificationLayer]
%%RCNN
load ('TESTCHANGE.mat')
opts = trainingOptions('sgdm', 'InitialLearnRate', 0.001, 'MaxEpochs', 5, 'MiniBatchSize', 32);
rcnn = trainRCNNObjectDetector(TESTCHANGE,layers,opts,'NegativeOverlapRange',[0 0.3])
%%TEST
imDir = fullfile(matlabroot,'ImageData','TESTCHANGE');
addpath(imDir);
img = imread('TEST.jpg');
[bbox,score,label]=detect(rcnn,img,'MiniBatchSize',32);
[score,idx]=max(score);
bbox = bbox(idx,:);
annotation = sprintf('%s:(Confidence = %f)',label(idx),score)
detectedImg = insertObjectAnnotation(img,'rectangle',bbox,annotation);
figure
imshow(detectedImg)
rmpath(imDir);
どうかよろしくお願いします。
0 Comments
Accepted Answer
Tohru Kikawada
on 13 Nov 2017
下記の [score,idx]=max(score) でスコアが最大のもの選択しているようです。
[bbox,score,label]=detect(rcnn,img,'MiniBatchSize',32);
[score,idx]=max(score);
bbox = bbox(idx,:);
annotation = sprintf('%s:(Confidence = %f)',label(idx),score)
detectedImg = insertObjectAnnotation(img,'rectangle',bbox,annotation);
上記を下記のように書き換えると複数表示されると思いますよ。
[bboxes,score,label] = detect(rcnn,img,'MiniBatchSize',32);
detectedImg = insertObjectAnnotation(I, 'Rectangle', bboxes, cellstr(label));
ただし、 score である程度、絞らないと誤検出が増えると思います。
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!