How can I add new images to a trained deep learning network to classify new images ?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Thushyanthan KANESALINGAM
am 12 Jul. 2021
Kommentiert: Thushyanthan KANESALINGAM
am 13 Jul. 2021
Hi,
I used the following code to train a network for image classification. I want to know how can I keep training the new network with the already added images ?
imds = imageDatastore('Images','IncludeSubfolders',true,'LabelSource','foldernames');
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7,'randomized');
net = resnet18;
numClasses = numel(categories(imdsTrain.Labels));
lgraph = layerGraph(net);
newFCLayer = fullyConnectedLayer(numClasses,'Name','new_fc','WeightLearnRateFactor',10,'BiasLearnRateFactor',10);
lgraph = replaceLayer(lgraph,'fc1000',newFCLayer);
newClassLayer = classificationLayer('Name','new_classoutput');
lgraph = replaceLayer(lgraph,'ClassificationLayer_predictions',newClassLayer);
inputSize = net.Layers(1).InputSize;
augimdsTrain = augmentedImageDatastore(inputSize(1:2),imdsTrain);
augimdsValidation = augmentedImageDatastore(inputSize(1:2),imdsValidation);
options = trainingOptions('sgdm', ...
'MiniBatchSize',10, ...
'MaxEpochs',8, ...
'InitialLearnRate',0.0001, ...
'Shuffle','every-epoch', ...
'ValidationData',augimdsValidation, ...
'ValidationFrequency',8, ...
'Verbose',false, ...
'Plots','training-progress');
trainedNet = trainNetwork(augimdsTrain,lgraph,options);
YPred = classify(trainedNet,augimdsValidation);
accuracy = mean(YPred == imdsValidation.Labels)
0 Kommentare
Antworten (1)
Chetan Gupta
am 13 Jul. 2021
Hi Thushyanthan,
I understand that you intend to train the neural network with imdsTrain for a larger number of iterations. You can do that by increasing the ‘MaxEpochs’ value in trainingOptions to some value larger than 8.
You can refer to Options for training deep learning neural network - MATLAB trainingOptions (mathworks.com) for more information about Epochs and other training options.
1 Kommentar
Siehe auch
Kategorien
Mehr zu Deep Learning Toolbox 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!