i was getting an error as unrecognised method,property or field 'Labels' for class 'augmented​ImageDatas​tore' for image classification can anybody help me with this error

2 Ansichten (letzte 30 Tage)
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);

Antworten (1)

T.Nikhil kumar
T.Nikhil kumar am 9 Jul. 2022
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.

Kategorien

Mehr zu Image Data Workflows finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by