i was getting an error as unrecognised method,property or field 'Labels' for class 'augmentedImageDatastore' for image classification can anybody help me with this error
2 ビュー (過去 30 日間)
古いコメントを表示
clear all;
imds = imageDatastore('TRAINING',...
'IncludeSubfolders',true, ...
'LabelSource','foldernames');
imdsTest = imageDatastore('TESTING',...
'IncludeSubfolders',true, ...
'LabelSource','foldernames');
clear labels;
labelCount = countEachLabel(imds)
img = readimage(imds,1);
size(img)
[imdsTrain,imdsTesting] = splitEachLabel(imds,600,'randomize');
inputSize = [256 256 1];
imdsTrain = augmentedImageDatastore(inputSize, imdsTrain,'ColorPreprocessing','rgb2gray');
imdsTesting = augmentedImageDatastore(inputSize, imdsTesting,'ColorPreprocessing','rgb2gray');
numClasses = 2;
layers = [
imageInputLayer(inputSize)
convolution2dLayer(5,20)
batchNormalizationLayer
reluLayer
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
options = trainingOptions('sgdm', ...
'InitialLearnRate',0.05,...
'MaxEpochs',15, ...
'ValidationData',imdsTesting, ...
'ValidationFrequency',30, ...
'Verbose',false, ...
'Plots','training-progress');
net = trainNetwork(imdsTrain,layers,options);
YPred = classify(net,imdsTesting);
YTested = imdsTesting.Labels;
accuracy = mean(YPred == YTested);
0 件のコメント
回答 (1 件)
T.Nikhil kumar
2022 年 7 月 9 日
Hey Hanisha!
I understand that you’re facing an error while finding the accuracy of the network you trained.
In this line,
accuracy = mean(YPred == YTested);
You have compared the labels of the ground truth test data and predicted data.
Here, I would like to point that the augmentedImageDatastore() does not record the labels of the input data store.
You currently have
imdsTesting = augmentedImageDatastore(inputSize, imdsTesting,'ColorPreprocessing','rgb2gray');
which takes imdsTesting(an image data store that has labels) as input, and you assign the augmented data store to the same variable.You need to know but augmentedImageDatastore does not carry the labels.So, you cannot access any lables when you write ,
imdsTesting.Labels
If you store the augmented datastore in a different variable like
imdsTestingAug = augmentedImageDatastore(inputSize, imdsTesting,'ColorPreprocessing','rgb2gray');
then when you run
accuracy = mean(YPred == imdsValidation.Labels)
you will refer to the unaugmented data store that still contains the labels.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Image Data Workflows についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!