ディープラーニングに使用する画像のサイズについて

19 views (last 30 days)
大空
大空 on 25 Jun 2022
Edited: Kojiro Saito on 26 Jun 2022
ネットから拾ってきた画像を学習さえたいのですが
%% 画像読み込み
imds = imageDatastore('catdog','IncludeSubfolders',true,'LabelSource','foldernames');
labelCount = countEachLabel(imds)
%% データで振り分ける
rateTrainFiles = 0.6;
[imdsTrain,imdsValidation] = splitEachLabel(imds,rateTrainFiles,'randomize');
%%画像サイズ
layers = [256,256,3];
aug_imdsTrain = augmentedImageDatastore(layers,imdsTrain);
aug_imdsValidation = augmentedImageDatastore(layers,imdsValidation);
options = trainingOptions('sgdm', ...
'InitialLearnRate',0.01,...
'MaxEpochs',4,...
'Shuffle','every-epoch',...
'ValidationData',imdsValidation,...
'VerboseFrequency',30,...
'Verbose',false, ...
'Plots','training-progress');
net=trainNetwork(imdsTrain,layers,options);
これでエラーが学習イメージサイズが違いますってでてしまいました
どこを直せばよろしいでしょうか?

Accepted Answer

Atsushi Ueno
Atsushi Ueno on 25 Jun 2022
aug_imdsTrain = augmentedImageDatastore([256,256,3],imdsTrain);
は良いのですが、
net=trainNetwork(imdsTrain,[256,256,3],options);
は求められているネットワーク層の情報が与えられていません。2番目の引数layersは、学習させるニューラルネットワークのネットワーク層を指定する為の引数で、画像サイズではありません。
>どこを直せばよろしいでしょうか?
例えば以下の様にすればエラーは解消すると思います。
layers_for_trainNetwork = [imageInputLayer([28 28 1]) convolution2dLayer(5,20) reluLayer maxPooling2dLayer(2,'Stride',2) fullyConnectedLayer(10) softmaxLayer classificationLayer];
options = ...% optionsは修正不要
net=trainNetwork(imdsTrain,layers_for_trainNetwork,options);
  2 Comments
大空
大空 on 25 Jun 2022
layers_for_trainNetwork = [imageInputLayer([28 28 1]) convolution2dLayer(5,20) reluLayer maxPooling2dLayer(2,'Stride',2) fullyConnectedLayer(10) softmaxLayer classificationLayer];
options = trainingOptions('sgdm', ...
'InitialLearnRate',0.01,...
'MaxEpochs',4,...
'Shuffle','every-epoch',...
'ValidationData',imdsValidation,...
'VerboseFrequency',30,...
'Verbose',false, ...
'Plots','training-progress');
net=trainNetwork(imdsTrain,layers_for_trainNetwork,options);
こちらの文書に直しても使い方によるエラーtrainNetwork学習イメージのサイズ800×1200×3ですが入力層にはサイズ28×28×1のイメージが必要ですと出てしまいます
Atsushi Ueno
Atsushi Ueno on 25 Jun 2022
すいません。それでしたら下記の様にすれば良いです。
layers_for_trainNetwork = [imageInputLayer([800 1200 3]) convolution2dLayer(5,20) reluLayer maxPooling2dLayer(2,'Stride',2) fullyConnectedLayer(10) softmaxLayer classificationLayer];

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!