inputLayerでの適したイメージサイズの変更について
조회 수: 3 (최근 30일)
이전 댓글 표시
深層学習を用いて画像分類を行いたいのですが、size(img)を用いて、画像サイズの高さと幅を取得しました。その後、inputLayerで取得した値を入れるとエラーが出て、学習をすることができません。また、直接画像サイズの数値を代入しても、同じエラーが出ました。どうすればよいのでしょうか?学習元のイメージサイズは768x1024x3です。
エラーメッセージは以下の通りです。
エラー:trainNetwork (行 183)
検証イメージのサイズは 768x1024x3 ですが、入力層にはサイズ 768x3072x3 のイメージが必要です。
コードは学習オプションを省略して記載させていただきます。
imds = imageDatastore(trainDatasetPath, ...
'IncludeSubfolders',true,'LabelSource','foldernames');
% 各クラスの画像数の確認(表示)
labelCount = countEachLabel(imds)
% クラス数の取得 ⇒ 出力層のサイズ
num_class = length(labelCount.Label)
% 最初の画像を1枚読み込み
img = readimage(imds,1);
% 画像サイズの取得 ⇒ 入力層のサイズ
[height, width] = size(img)
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7,'randomize')
%% ネットワークの定義
layers = [
imageInputLayer([height width 3])
convolution2dLayer(3,8,'Padding','same')
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,16,'Padding','same')
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,32,'Padding','same')
batchNormalizationLayer
reluLayer
fullyConnectedLayer(num_class)
softmaxLayer
classificationLayer];
net = trainNetwork(allTrain,layers,options);
댓글 수: 0
채택된 답변
Kenta
2021년 10월 5일
[height, width,ch] = size(img)
に変更してはいかがでしょうか。imgがRGBでチャンネルのサイズもあるので、chという出力があると良いと思います
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 イメージを使用した深層学習에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!