unrecognized method property or field Labels for class augmentdatastore?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
john karli
le 14 Déc 2021
Commenté : john karli
le 15 Déc 2021
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
0 commentaires
Réponse acceptée
Walter Roberson
le 14 Déc 2021
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 commentaires
Walter Roberson
le 15 Déc 2021
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)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Get Started with Deep Learning Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!