Skip to content

Image Generation

Thanos Masouris edited this page Aug 28, 2022 · 1 revision

To generate synthetic images using the pre-trained DiStyleGAN model, follow the steps below:

  1. Clone the GitHub repository.
  2. Install the python packages in the requirements file. (Python 3.10)
  3. Download the checkpoint for our pre-trained model and extract the zip file in the root directory of our repository.
  4. Generate synthetic samples using one of the following options:
  • Example in Python
from distylegan import DiStyleGAN
model = DiStyleGAN()
images= model.generate(
    checkpoint_path="../checkpoint", 
    nsamples=100,
    label=[0, 3, 7] # or label=x (int in range [0,9]), label=None
    save="synthetic-samples",
    batch_size=32
)
  • Using the command line options for the corresponding python script
$ python distylegan.py generate -h
usage: distylegan.py generate [-h] --checkpoint_path CHECKPOINT_PATH --nsamples NSAMPLES --save SAVE 
[--label [{0,1,2,3,4,5,6,7,8,9} ...]] [--batch_size BATCH_SIZE]

options:
  -h, --help            show this help message and exit

Required arguments for the generation procedure:
  --checkpoint_path CHECKPOINT_PATH
                        Path to previous checkpoint (the directory 
                        must contain the generator.pt and 
                        config.json files)
  --nsamples NSAMPLES   Number of samples to generate per label
  --save SAVE           Path to save the generated images to

Optional arguments about the generation procedure:
  --label [{0,1,2,3,4,5,6,7,8,9} ...]
                        Class label(s) for the samples (Default: 
                        None, random labels) --> e.g. --label 0 3 7
  --batch_size BATCH_SIZE
                        Number of samples per batch (Default: 32)
  • Using the flask webapp by running the command flask run inside the webapp/ directory of our repository. Then following the link displayed in the command line (e.g. http://127.0.0.1:5000/), you will be presented with the following interface where you can generate images.

webapp

The interface of our webapp for image generation.