Save finalized training progress plots using OutputFcn
27 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Teo
il 16 Mag 2021
Commentato: Michael Alvarez
il 6 Ott 2022
Hi,
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/619363/image.png)
Desired Figure (with validation accuracy):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/619368/image.png)
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', ...
'OutputFcn',@(info)SaveTrainingPlot(info));
% ... Training code ...
% At the end of the script
function stop = SaveTrainingPlot(info)
stop = false;
if info.State == "done"
currentfig = findall(groot,'Type','Figure');
savefig(currentfig,'test.fig')
end
end
The problem seem to be related to info.State == "Done", but is there any workaround to save the desired output as figure/image?
0 Commenti
Risposta accettata
Srivardhan Gadila
il 23 Mag 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');
savefig(currentfig,'test.fig');
4 Commenti
Michael Alvarez
il 6 Ott 2022
I have the same problem with the "fig" image, but thinking of a solution, I decided to copy the screen and save it as a "png" image. Maybe this helps other people.
currentfig = findall(groot, 'Tag', 'NNET_CNN_TRAININGPLOT_UIFIGURE');
img = screencapture(0, 'Position', currentfig(1,1).Position);
imwrite(img,"TrainingProgress.png");
Michael Alvarez
il 6 Ott 2022
Screen capture function:
https://www.mathworks.com/matlabcentral/fileexchange/24323-screencapture-screenshot-of-component-figure-or-screen
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!