ディープラーニングでの評価

7 views (last 30 days)
大空
大空 on 28 Jun 2022
Commented: 大空 on 29 Jun 2022
エラーの意味が分からなくまたなぜエラーが出ているのかわかりりません
クラス 'augmentedImageDatastore' のメソッド、プロパティまたはフィール
ド 'Labels' が認識されません。
このようなエラーがでました。
%% 画像読み込み
imds = imageDatastore('catdog','IncludeSubfolders',true,'LabelSource','foldernames');
labelCount = countEachLabel(imds)
%% データで振り分ける
rateTrainFiles = 0.6;
[imdsTrain,imdsValidation] = splitEachLabel(imds,rateTrainFiles,'randomize');
s_image = [256,256,3];
imdsTrain = augmentedImageDatastore(s_image,imdsTrain);
imdsValidation = augmentedImageDatastore(s_image,imdsValidation);
%%DNN
layers = [
imageInputLayer(s_image)
%% 特徴抽出
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(2)%クラスの数
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,options);
YPred = classify(net,imdsValidation);
クラス 'augmentedImageDatastore' のメソッド、プロパティまたはフィール
ド 'Labels' が認識されません。
YValidation = imdsValidation.Labels;
accuracy = sum(YPred == YValidation)/numel(YValidation)

Accepted Answer

Shunichi Kusano
Shunichi Kusano on 28 Jun 2022
9行目で imdsValidationaugmentedImageDatastore に上書きされていますが、augmentedImageDatastore にはimageDatastore とは違って Labels というフィールドがありません。なのでエラーとなっています。されたいことは上書き前のimdsValidation.Labels の中身を見たいということだと思いますので、9行目の
imdsValidation = augmentedImageDatastore(s_image,imdsValidation);
audsValidation = augmentedImageDatastore(s_image,imdsValidation);
等としてimdsValidationは残しておき、最後の3行を
YPred = classify(net,audsValidation);
YValidation = imdsValidation.Labels;
accuracy = sum(YPred == YValidation)/numel(YValidation)
でおそらく期待通りに動くかと思います。
  2 Comments
大空
大空 on 29 Jun 2022
実行してみたのですがそれですと net = trainNetwork(imdsTrain,layers,options); でイメージエラーを起こしてしまいました
大空
大空 on 29 Jun 2022
出来ましたありがとうございます

Sign in to comment.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!