unrecognized method property or field Labels for class augmentdatastore?

12 ビュー (過去 30 日間)
john karli
john karli 2021 年 12 月 14 日
コメント済み: john karli 2021 年 12 月 15 日
I am tring to train the model on .mat dataset. i have train the model sucessfully but when i tried to find the accuracy i got the error.
imds = imageDatastore('D:\yellow\img-data\iqmat\', 'FileExtensions', '.mat', 'IncludeSubfolders',true, ...
'LabelSource','foldernames',...
'ReadFcn',@matReader);
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7, 'randomized');
inputSize = lgraph_1.Layers(1).InputSize;
[learnableLayer,classLayer] = findLayersToReplace(lgraph_1);
numClasses = numel(categories(imdsTrain.Labels));
if isa(learnableLayer,'nnet.cnn.layer.FullyConnectedLayer')
newLearnableLayer = fullyConnectedLayer(numClasses, ...
'Name','new_fc', ...
'WeightLearnRateFactor',10, ...
'BiasLearnRateFactor',10);
elseif isa(learnableLayer,'nnet.cnn.layer.Convolution2DLayer')
newLearnableLayer = convolution2dLayer(1,numClasses, ...
'Name','new_conv', ...
'WeightLearnRateFactor',10, ...
'BiasLearnRateFactor',10);
end
lgraph_1 = replaceLayer(lgraph_1,learnableLayer.Name,newLearnableLayer);
newClassLayer = classificationLayer('Name','new_classoutput');
lgraph_1 = replaceLayer(lgraph_1,classLayer.Name,newClassLayer);
imdsTrain = augmentedImageDatastore([224,224],imdsTrain);
imdsValidation = augmentedImageDatastore([224,224],imdsValidation);
miniBatchSize =8;
valFrequency = floor(numel(imdsTrain.Files)/miniBatchSize);
checkpointPath = pwd;
options = trainingOptions('sgdm', ...
'MiniBatchSize',miniBatchSize, ...
'MaxEpochs',100, ...
'InitialLearnRate',1e-4, ...
'Shuffle','every-epoch', ...
'ValidationData',imdsValidation, ...
'ValidationFrequency',valFrequency, ...
'Verbose',false, ...
'Plots','training-progress', ...
'CheckpointPath',checkpointPath,...
'ExecutionEnvironment','gpu');
net = trainNetwork(imdsTrain,lgraph_1,options);
[YPred,probs] = classify(net,imdsValidation);
accuracy = mean(YPred == imdsValidation.Labels)
error:
unrecognized method property or field Labels for class augmentdatastore

採用された回答

Walter Roberson
Walter Roberson 2021 年 12 月 14 日
augmentedImageDatastore() does not record the labels of the input data store.
You currently have
imdsValidation = augmentedImageDatastore([224,224],imdsValidation);
which takes imdsValidation (an image data store that has labels) as input, and you write to the same variable... but augmentedImageDatastore does not carry the labels.
If you wrote to a different variable, then when you got to
accuracy = mean(YPred == imdsValidation.Labels)
you could be referring to the unaugmented data store that still has the labels.
  6 件のコメント
Walter Roberson
Walter Roberson 2021 年 12 月 15 日
imds = imageDatastore('D:\yellow\img-data\iqmat\', 'FileExtensions', '.mat', 'IncludeSubfolders',true, ...
'LabelSource','foldernames',...
'ReadFcn',@matReader);
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7, 'randomized');
inputSize = lgraph_1.Layers(1).InputSize;
[learnableLayer,classLayer] = findLayersToReplace(lgraph_1);
numClasses = numel(categories(imdsTrain.Labels));
if isa(learnableLayer,'nnet.cnn.layer.FullyConnectedLayer')
newLearnableLayer = fullyConnectedLayer(numClasses, ...
'Name','new_fc', ...
'WeightLearnRateFactor',10, ...
'BiasLearnRateFactor',10);
elseif isa(learnableLayer,'nnet.cnn.layer.Convolution2DLayer')
newLearnableLayer = convolution2dLayer(1,numClasses, ...
'Name','new_conv', ...
'WeightLearnRateFactor',10, ...
'BiasLearnRateFactor',10);
end
lgraph_1 = replaceLayer(lgraph_1,learnableLayer.Name,newLearnableLayer);
newClassLayer = classificationLayer('Name','new_classoutput');
lgraph_1 = replaceLayer(lgraph_1,classLayer.Name,newClassLayer);
imdsTrain = augmentedImageDatastore([224,224],imdsTrain);
imdsValidation_aug = augmentedImageDatastore([224,224],imdsValidation); %HERE
miniBatchSize =8;
valFrequency = floor(numel(imdsTrain.Files)/miniBatchSize);
checkpointPath = pwd;
options = trainingOptions('sgdm', ...
'MiniBatchSize',miniBatchSize, ...
'MaxEpochs',100, ...
'InitialLearnRate',1e-4, ...
'Shuffle','every-epoch', ...
'ValidationData',imdsValidation_aug, ... %HERE
'ValidationFrequency',valFrequency, ...
'Verbose',false, ...
'Plots','training-progress', ...
'CheckpointPath',checkpointPath,...
'ExecutionEnvironment','gpu');
net = trainNetwork(imdsTrain,lgraph_1,options);
[YPred,probs] = classify(net,imdsValidation_aug);
accuracy = mean(YPred == imdsValidation.Labels)
john karli
john karli 2021 年 12 月 15 日
thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Deep Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by