unrecognized method property or field Labels for class augmentdatastore?

조회 수: 12 (최근 30일)
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)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get 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