CNN, resnet50 - plot accuracy

1 vue (au cours des 30 derniers jours)
HK le 19 Nov 2021
Modifié(e) : Prateek Rai le 24 Nov 2021
Can anyone help me with plotting the training progress (accuracy and loss)?
There seems to be a problem with the last line, but I'm not sure what the problem is. Help!
outputFolder = fullfile('Caltech')
rootFolder = fullfile(outputFolder, '101_ObjectCategories')
categories = {'normal_NB_resized', 'slow_OB_resized'}
imds = imageDatastore(fullfile(rootFolder,categories), 'LabelSource','foldernames')
tbl = countEachLabel(imds)
minSetCount = min(tbl{:,2})
imds = splitEachLabel(imds, minSetCount, 'randomize')
normal = find(imds.Labels == 'normal', 1)
slow = find(imds.Labels == 'slow', 1)
net = resnet50();
[trainingSet, testSet] = splitEachLabel(imds, 0.7, 'randomize');
imageSize = net.Layers(1).InputSize;
augmentedTrainingSet = augmentedImageDatastore(imageSize,...
trainingSet, 'ColorPreprocessing', 'gray2rgb');
augmentedTestSet = augmentedImageDatastore(imageSize,...
testSet, 'ColorPreprocessing', 'gray2rgb');
w1 = net.Layers(2).Weights;
w1 = mat2gray(w1);
featureLayer = 'fc1000';
trainingFeatures = activations(net,...
augmentedTrainingSet, featureLayer, 'MiniBatchSize', 64, 'OutputAs', 'columns');
trainingLables = trainingSet.Labels;
classifier = fitcecoc(trainingFeatures, trainingLables,...
'Learner', 'Linear', 'Coding', 'onevsall', 'ObservationsIn', 'columns');
testFeatures = activations(net,...
augmentedTestSet, featureLayer, 'MiniBatchSize', 64, 'OutputAs', 'columns');
predictLabels = predict(classifier, testFeatures, 'ObservationsIn', 'columns');
testLables = testSet.Labels
confMat = confusionmat(testLables, predictLabels)
confMat = bsxfun(@rdivide, confMat, sum(confMat,2))
newImage = imread(fullfile('test.jpg'));
ds = augmentedImageDatastore(imageSize,...
newImage, 'ColorPreprocessing', 'gray2rgb');
imageFeatures = activations(net,...
ds, featureLayer, 'MiniBatchSize', 64, 'OutputAs', 'columns');
label = predict(classifier, imageFeatures, 'ObservationsIn', 'columns');
sprintf('loaded image belongs to %s class', label)
options = trainingOptions('sgdm', ...
'InitialLearnRate',0.01, ...
'MaxEpochs',4, ...
'Shuffle','every-epoch', ...
'ValidationData',imds, ...
'ValidationFrequency',30, ...
'Verbose',false, ...
netT = trainNetwork(imds,layers,options);

Réponse acceptée

Prateek Rai
Prateek Rai le 22 Nov 2021
Modifié(e) : Prateek Rai le 24 Nov 2021
There are 2 facts about the code which is important to note:
(1) Since, your dataset is big that is why it is taking more time to perform dataset involving tasks and hence you are not able to reach the last line of the code i.e. training the network and plotting the training progress. Thus, it seems that the network training started already without showing the training progress but actually training has not started.
(2) Secondly, if your image datastore is somehow created and your last line started executing then also error will come stating: "Unrecognized function or variable 'layers'. It is because you have not declared variable 'layers' but used it in the last line of the code.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by