RCNNによる多クラス検出について

11 ビュー (過去 30 日間)
- Tei
- Tei 2017 年 11 月 13 日
コメント済み: - Tei 2017 年 11 月 29 日
現在以下のコードにて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);
どうかよろしくお願いします。

採用された回答

Tohru Kikawada
Tohru Kikawada 2017 年 11 月 13 日
下記の [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 である程度、絞らないと誤検出が増えると思います。
  1 件のコメント
- Tei
- Tei 2017 年 11 月 29 日
コメントありがとうございます。 とりあえずは複数同時検出を行うことが出来ました。また、返答のコメントではスコア値の絞ることによって誤検出を減らすと回答されていますが、スコア値を絞る関数もしくは関数の引数というのは存在するでしょうか? よろしくお願いします。

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!