How can I add new images to a trained deep learning network to classify new images ?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Thushyanthan KANESALINGAM
el 12 de Jul. de 2021
Comentada: Thushyanthan KANESALINGAM
el 13 de Jul. de 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 comentarios
Respuestas (1)
Chetan Gupta
el 13 de Jul. de 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 comentario
Ver también
Categorías
Más información sobre Deep Learning Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!