i​nputLaye​rでの適したイメージ​サイズ​の変更につい​て

조회 수: 2 (최근 30일)
Kohei 
Kohei  2021년 10월 5일
댓글: Kohei  2021년 10월 8일
深層学習を用いて画像分類を行いたいのですが、size(img)を用いて、画像サイズの高さと幅を取得しました。その後、i​nputLayerで取得した値を入れるとエラーが出て、学習をすることができません。また、直接画像サイズの数値を代入しても、同じエラーが出ました。どうすればよいのでしょうか?学習元のイメージサイズは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);

채택된 답변

Kenta
Kenta 2021년 10월 5일
[height, width,ch] = size(img)
に変更してはいかがでしょうか。imgがRGBでチャンネルのサイズもあるので、chという出力があると良いと思います
  댓글 수: 1
Kohei 
Kohei  2021년 10월 8일
chを追加すると、無事に学習を行うことができました。
ありがとうございます。

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 イメージを使用した深層学習에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!