Automatically stop training of neural network if certain accuracy in training is reached
9 次查看(过去 30 天)
显示 更早的评论
I would like to do a sensitivity analysis to get the best parameters of my simulated training data. To make it automatic i would like the training to stop automatically when the network reaches an accuracy of x% on the training dataset. Is there an option or parameter for this?
Currently my code looks like this:
layers = [...
imageInputLayer([100,100,1])
convolution2dLayer(3,4,'Stride',1,'Padding',1)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2,'Padding',0)
convolution2dLayer(3,8,'Stride',1,'Padding',1)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2,'Padding',0)
fullyConnectedLayer(32)
fullyConnectedLayer(32)
fullyConnectedLayer(2)
softmaxLayer
classificationLayer];
options = trainingOptions('sgdm','InitialLearnRate',0.001,'MaxEpochs',20,'Plots','none','MiniBatchSize',500);
net = trainNetwork(trainingHeatmapComplete4d,trainingOutputsComplete,layers,options);
0 个评论
采纳的回答
Milan Bansal
2023-9-14
Hi,
In my understanding, you want to interrupt the training of Neural Network automatically when a certain accuracy is reached.
It is possible to do so by defining a callback function and setting it as "OutputFcn" in "options" argument of the "trainNetwork" function. Add the following function at the bottom of the script.
function stop = accuracyCallback(info)
stop = false; % Initialize the stop flag as false
if info.TrainingAccuracy > 90 % Desired accuracy
stop = true; % Set the stop flag to true if desired accuracy is reached
end
end
This function will act as callback function to stop the training at 90% accuracy.
Set the 'OutputFcn' option to the callback function defined above in the "options" argument as shown below.
options = trainingOptions('sgdm','InitialLearnRate',0.001, ...
'MaxEpochs',20,'Plots','none','MiniBatchSize',500, ...
'OutputFcn', @accuracyCallback);
Refer to the documentation link to know more about "trainNetwork" function.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!