Automatically stop training of neural network if certain accuracy in training is reached
2 ビュー (過去 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 で Deep Learning Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!