How to save GAN Model after training?

8 views (last 30 days)
I am using the GAN example live script to train the generator and discrimnator for a synthetic data generator. However, after training the generator and discrimantor (netD, netG) i save the workspace for using the models for later use. Although after reloading the .mat file, i was not able to generate images as it started from begining. Is there any specific way of saving those GAN models in matlab for later use? Thanks.

Accepted Answer

Vignesh Murugavel
Vignesh Murugavel on 11 Nov 2022
Hi Suhail,
If you want to save your trained GAN network model , you need to use save('path_to_file', 'variable').
Example:
save('C:\Temp\trainedModel_netG.mat','netG');
In this case netG is the name of the network and this trained network will be saved under the given file name “trainedModel_netG.mat”
The next time you want to use the saved pre-trained network you just need to call load('path_to_file').
Example:
load('C:\Temp\trained_netG.mat');
Hope this helps!
  1 Comment
Jorge Muñoz
Jorge Muñoz on 24 Mar 2024
Hello, it seems that the issue mentioned by Suhail is not solely about saving the workspace and reloading it. I'm experiencing something similar to the problem described. When I train the flower image generation example, everything seems to go well as long as the GPU memory keeps the parameters loaded. If I save the complete training workspace using the "save" command (for example, GANWorkspacefile.mat, which also includes netG), then clear the GPU memory (reset), and subsequently reload the previous workspace, the images generated with "predict" end up blurry, like the ones generated at the beginning of training. The same happens if I transfer the saved workspace and load it on another machine with the same version of MATLAB. It seems that something is missing when loading the workspace variables that prevents generating the images in the same way as they are generated just at the end of training.

Sign in to comment.

More Answers (0)

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!