Save finalized training progress plots using OutputFcn

79 views (last 30 days)
Teo on 16 May 2021
Commented: Teo on 28 May 2021
i currently using the OutputFcn to save the finalised training progress as a figure, however i noticed that the saved figure are not the finalised result of the training progress instead it is the figure before reaching the finalised training with the validation accauracy. The result that i obtained is as followed.
Obtained figure:
Desired Figure (with validation accuracy):
Attached is also the code that i'm using in the live editor.
options = trainingOptions('sgdm', ...
'MiniBatchSize',miniBatchSize, ...
'MaxEpochs',2, ...
'InitialLearnRate',1e-4, ...
'Shuffle','every-epoch', ...
'ValidationData',augimdsValidation, ...
'ValidationFrequency',valFrequency, ...
'Verbose',false, ...
'Plots','training-progress', ...
% ... Training code ...
% At the end of the script
function stop = SaveTrainingPlot(info)
stop = false;
if info.State == "done"
currentfig = findall(groot,'Type','Figure');
The problem seem to be related to info.State == "Done", but is there any workaround to save the desired output as figure/image?

Accepted Answer

Srivardhan Gadila
Srivardhan Gadila on 23 May 2021
I think that the final training plot is updated after exiting the function mentioned for the 'OutputFcn' argument. You can check it yourself by inserting pause(10) in the function and observe that the trianing progress plot updation will also pause for 10 seconds.
As you are interested in the final training progress plot, instead of placing the commands findall and savefig inside 'OutputFcn' function just place them after the trainNetwork function.
[net,info] = trainNetwork(___)
currentfig = findall(groot, 'Tag', 'NNET_CNN_TRAININGPLOT_UIFIGURE');
Teo on 28 May 2021
The code does work but there is an issue with the save figure where both of the line are same color compared to the orginal figure which have lighter color line for both training accuracy and loss (not smoothed). Below is the screen capture for your reference. Hope you are able to advice me on this.
Original Training plot
Saved Figure (Both line are same in color)
Thank You.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!