CNN, resnet50 - plot accuracy
Show older comments
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')
countEachLabel(imds)
normal = find(imds.Labels == 'normal', 1)
slow = find(imds.Labels == 'slow', 1)
net = resnet50();
net.Layers(1);
net.Layers(end);
numel(net.Layers(end).ClassNames);
[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))
mean(diag(confMat))
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, ...
'Plots','training-progress');
netT = trainNetwork(imds,layers,options);
Accepted Answer
More Answers (0)
Categories
Find more on Classification Ensembles in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!