転移学習におけるR-CNNのエラーについて
Show older comments
以下のプログラムを用いて alexnetを転移学習させた後、それのレイヤーを用いてRCNNを利用しようとしています。
転移学習のための学習データとして、マグカップ、マウス、キーボード、扇風機の画像を用意しています。 またRCNNのためにTraining Image Labelerを用いてそれぞれ四種類がラベル付けされたmatファイルも作成済みです。
%%Load a pre-trained, deep, convolutional network
net = alexnet;
layersfirst = net.Layers
%%Delete Full Connected Layer
layersTransfer = layersfirst(1:end-3)
%%Set up our training data
digitDataPath = fullfile(matlabroot,'ImageData','myImages');
allImages = imageDatastore(digitDataPath, 'IncludeSubfolders', true, 'LabelSource', 'foldernames');
trainingImages= allImages;
numClasses = numel(categories(trainingImages.Labels));
%%layers
layers = [layersTransfer
fullyConnectedLayer(numClasses,'WeightLearnRateFactor',20,'BiasLearnRateFactor',20)
softmaxLayer
classificationLayer]
%%Pre-train the Network
opts = trainingOptions('sgdm', 'InitialLearnRate', 0.001, 'MaxEpochs', 5, 'MiniBatchSize', 32);
myNet = trainNetwork(trainingImages, layers, opts);
%%RCNN
load ('TESTCHANGE1.mat')
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(rcnnfinal,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);
しかし、いざプログラムを実行すようとすると
エラー: vision.internal.cnn.validation.checkNetworkClassificationLayer (line 6) ネットワーク分類層の数値オブジェクト クラスは、"Background" クラス用として入力 trainingData で定義されたクラスの数に 1 を加えた数と等しくなければなりません。
エラー: vision.internal.rcnn.parseInputs (line 35) vision.internal.cnn.validation.checkNetworkClassificationLayer(network, trainingData);
エラー: trainRCNNObjectDetector (line 185) params = vision.internal.rcnn.parseInputs(trainingData, network, options, mfilename, varargin{:});
エラー: RCNNCHANGE (line 33) rcnn = trainRCNNObjectDetector(TESTCHANGE,layers,opts,'NegativeOverlapRange',[0 0.3])
というエラーが吐き出されていまい実行できません。どのようにプログラム及び学習データの改善を行えばよいのでしょうか。
どうかよろしくお願いします。
Accepted Answer
More Answers (0)
Categories
Find more on モデル化 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!