Home

Awesome

stylegan2-ada-lightning

Simplified pytorch-lightning port of StyleGAN2-ADA.

Configuration provided with hydra config file config/stylegan2.yaml. Once configured, train with:

python trainer/train_stylegan.py wandb_main=True

Configuration can be overriden with command line flags.

Configuration

KeyDescriptionDefault
dataset_pathDirectory with training imagesdata/ffhq
img_listPath to the .txt with a list of images, useful when you have many files (optional; if provided, used instead of dataset_path)null
experimentExperiment name used for logsfast_dev
wandb_mainIf false, results logged to "<project>-dev" wandb project (for dev logs)False
num_mapping_layersNumber of layers in the mapping network2
lr_gGenerator learning rate0.002
lr_dDiscriminator learning rate0.00235
lambda_gpGradient penalty weight0.0256
lambda_plpPath length penalty weight2
lazy_gradient_penalty_intervalGradient penalty regularizer interval16
lazy_path_penalty_afterIteration after which path lenght penalty is active0
lazy_path_penalty_intervalPath length penalty regularizer interval4
latent_dimLatent dim of starting noise and mapping network output512
image_sizeSize of generated images64
num_eval_imagesNumber of images on which FID is computed8096
num_vis_imagesNumber of image visualized1024
batch_sizeMini batch size16
num_workersNumber of dataloader workers8
seedRNG seednull
save_epochEpoch interval for checkpoint saves1
sanity_stepsValidation sanity runs before training start1
max_epochMaximum training epochs250
val_check_intervalEpoch interval for evaluating metrics and saving generated samples1
resumeResume checkpointnull

The code has been tested with PyTorch 2.0.0+cu118, PyTorch Lightning 2.0.6, CUDA 11.8, Python 3.8.5.

References

Official stylegan2-ada code and paper.

@article{Karras2019stylegan2,
    title   = {Analyzing and Improving the Image Quality of {StyleGAN}},
    author  = {Tero Karras and Samuli Laine and Miika Aittala and Janne Hellsten and Jaakko Lehtinen and Timo Aila},
    journal = {CoRR},
    volume  = {abs/1912.04958},
    year    = {2019},
}

License

Copyright © 2021 nihalsid

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.