trainNetworkを使用し「入力イメージは4チャネル未満でなければなりません。」と出た時の対処法
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
imds=imageDatastore('Oguma_TestImages_Copy','IncludeSubfolder',true,'LabelSource','foldernames');
[imdsTrain,imdsValidation]=splitEachLabel(imds,0.7);
numTrainImages = numel(imdsTrain.Labels);
net=squeezenet;
inputSize = net.Layers(1).InputSize
lgraph = layerGraph(net);
[learnableLayer,classLayer] = findLayersToReplace(lgraph);
[learnableLayer,classLayer]
numClasses = numel(categories(imdsTrain.Labels))
newConvLayer = convolution2dLayer([1, 1],numClasses,'WeightLearnRateFactor',10,'BiasLearnRateFactor',10,"Name",'new_conv');
lgraph = replaceLayer(lgraph,'conv10',newConvLayer);
newClassificatonLayer = classificationLayer('Name','new_classoutput');
lgraph = replaceLayer(lgraph,'ClassificationLayer_predictions',newClassificatonLayer);
pixelRange = [-30 30];
imageAugmenter = imageDataAugmenter( ...
'RandXReflection',true, ...
'RandXTranslation',pixelRange, ...
'RandYTranslation',pixelRange);
augimdsTrain = augmentedImageDatastore([227 227 3],imdsTrain,'ColorPreprocessing','gray2rgb', ...
'DataAugmentation',imageAugmenter);
augimdsValidation = augmentedImageDatastore([227 227 3],imdsValidation,'ColorPreprocessing','gray2rgb');
options = trainingOptions('sgdm', ...
'MiniBatchSize',11, ...
'MaxEpochs',7, ...
'InitialLearnRate',2e-4, ...
'Shuffle','every-epoch', ...
'ValidationData',augimdsValidation, ...
'ValidationFrequency',3, ...
'Verbose',false, ...
'Plots','training-progress');
netTransfer = trainNetwork(augimdsTrain,lgraph,options);
[YPred,scores] = classify(netTransfer,augimdsValidation);
idx = randperm(numel(imdsValidation.Files),4);
figure
for i = 1:4
subplot(2,2,i)
I = readimage(imdsValidation,idx(i));
imshow(I)
label = YPred(idx(i));
title(string(label));
end
YValidation = imdsValidation.Labels;
accuracy = mean(YPred == YValidation)
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
SqueezNetによる画像の転移学習をしようと思ったのですが、
エラー: trainNetwork (line 170)
入力イメージは数値で、4 チャネル未満でなければなりません。
エラー: Oguma_SqueezeNet_Code_03 (line 38)
netTransfer = trainNetwork(augimdsTrain,lgraph,options);
原因:
エラー: imageDataAugmenter/augment (line 596)
入力イメージは数値で、4 チャネル未満でなければなりません。
と出て、うまくいきません。
24、26行目でイメージデータストアは[227 227 3]として3チャネルになるように指定しているにも関わらず、なぜtrainNetwork内では4チャネルと認識されているのでしょうか?
対処法をご存知の方がいれば教えていただきたいです。
製品は MATLAB R2020a です。
よろしくお願いいたします。
17 Kommentare
Kenta
am 20 Jul. 2021
なるほど!小熊さんありがとうございます。データストアにGIFも格納されてしまうのですね、、、私もGIFはよく使うので参考になります。原因がわかったようでよかったです。
「タグ」のところにimageDataAugmenterなど、今回のご質問で関連していそうな単語をいれておくと、今後似た問題が検索されたときに引っかかる確率があがりそうです。
Antworten (0)
Siehe auch
Kategorien
Mehr zu Deep Learning Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
