Is trainNetwork early stopping behavior wrong?

21 Ansichten (letzte 30 Tage)
Adriano Moutinho
Adriano Moutinho am 8 Aug. 2021
I decided to use validation and early stop to avoid overfitting. This is a classic feature in neural network training. So, everything is set like this:
options = trainingOptions('adam', ...
... other options...
'ValidationFrequency', 1, ...
'ValidationData', {XVAL, YVAL}, ...
'ValidationPatience', 25, ...
);
XVAL and YVAL are part of my database used specifically for validation. I train the network with data from XTRAIN and YTRAIN:
trainNetwork (XTrain, YTrain, layers, options);
But the problem is that although the early stop works well, stopping when validation has no gain for more than 25 epochs, as I configured in "ValidationPatience" trainingOptions, instead of going back to the epoch with the best LOSS obtained during training, the output network returned by trainNetwork is the one from last epoch!
So I ended up with a network trained with 25 epochs after the best result!
Is this is wrong? How can I fix this? I used verbose "on" to be sure about the results. I'm definitely getting the last epoch network, 25 epochs after the best validation result is found...

Antworten (1)

Lorenzo Cremonini
Lorenzo Cremonini am 28 Nov. 2021
Hi,
For what you want to obtain, you need to add another option in trainingOptions, that is “OutputNetwork”, “best-validation-loss”
Hoping it helps.
LC

Produkte


Version

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by