STYLEGAN Procedure

Example 33.2 Generating Human Face Images — Continue Training

Note: This example assumes that the SAS 9 engine libref mydirlib and the SASVIYA engine libref mylib have already been created. For more information, see the section Using SAS Viya Workbench and Chapter 1, Shared Concepts (SAS Viya Workbench: Computer Vision Procedures).

This example is a follow-up to Example 33.1 and shows how to continue training a Style GAN model by using the CHECKPOINTIN= and CHECKPOINTOUT= options in the TRAIN statement. It uses the same data set as Example 33.1.

First, as in Example 33.1, you use PROC LOADIMAGES (see Chapter 10, LOADIMAGES Procedure (SAS Viya Workbench: Computer Vision Procedures)) as follows to load the images into the table mylib.images in your SAS library. This assumes that your SAS libref is named mylib, as in the section Using SAS Viya Workbench, but you can substitute any appropriately defined SAS libref. The specified path must be relative to the path that is associated with the mydirlib libref:

 proc loadimages libref=mydirlib path='path-to-images-folder/';
     output out=mylib.images;
 run;

Then, you use PROC STYLEGAN as follows to train a Style GAN model, save training checkpoints in a table, and save the trained generator network in an analytic store:

 proc stylegan        data=mylib.images imagesize=128
                      numsamples=4 useGPU seed=123 scoreseed=321;
      optimization    numiters=2
                      miniBatchSize=8 learningrate=0.002;
      train           useSmallNetwork truncation=0.95
                      regDFreq=2 regGFreq=1 regPathWeight=3.3 regR1Weight=11.57
                      printFreq=1 checkpointFreq=1 checkpointOut=mylib.checkpointout;
      savestate       rstore=mylib.astore;
      output          out=mylib.outtable;
 run;

In addition to the statements and options that are used in Example 33.1, the current example uses the following options. The SCORESEED= option specifies the random seed to use for scoring. The REGDFREQ= option specifies the regularization frequency of the discriminator model to be every two steps; The REGGFREQ= option regularizes the generator model at every step. The REGPATHWEIGHT= option specifies the weight for regularizing the path length loss. The REGR1WEIGHT= option specifies the truncation ratio for image generation. The PRINTFREQ= option prints loss values at every step. The CHECKPOINTFREQ= option saves checkpoints at every step of the training. The CHECKPOINTOUT= saves the training checkpoints to the mylib.checkpointout data table.

The following statements use PROC STYLEGAN to continue training a Style GAN model by using the last checkpoint that is saved in the mylib.checkpointout data table:

 proc stylegan        data=mylib.images imagesize=128
                      numsamples=6 useGPU seed=42 scoreseed=50;
      optimization    numiters=4
                      miniBatchSize=4 learningrate=0.001;
      train           useSmallNetwork truncation=0.95
                      regDFreq=2 regGFreq=2 regPathWeight=2.5 regR1Weight=10.2
                      checkpointIn=mylib.checkpointout printFreq=2
                      checkpointFreq=2 checkpointOut=mylib.checkpointout2;
      savestate       rstore=mylib.astore2;
      output          out=mylib.outtable2;
 run;

The CHECKPOINTIN= option tells PROC STYLEGAN to continue training from the last saved checkpoint available in the mylib.checkpointout data table. Note that the values of options such as SEED=, NUMITERS=, LEARNINGRATE=, and many others can differ from their values in the previous PROC STYLEGAN run that generated the mylib.checkpointout data table. The CHECKPOINTOUT= option saves the checkpoints from the recent training in the mylib.checkpointout2 data table. You can continue training the Style GAN model by using the checkpoints that are saved in the mylib.checkpointout2 data table in a similar fashion. PROC STYLEGAN generates results and ODS tables that are omitted here for brevity. See Example 33.1 for information about results and ODS tables.

Last updated: September 23, 2026