• Stars
    star
    662
  • Rank 67,654 (Top 2 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 3 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An official implementation of MobileStyleGAN in PyTorch

MobileStyleGAN: A Lightweight Convolutional Neural Network for High-Fidelity Image Synthesis

Official PyTorch Implementation

The accompanying videos can be found on YouTube. For more details, please refer to the paper.

Requirements

  • Python 3.8+
  • 1–8 high-end NVIDIA GPUs with at least 12 GB of memory. We have done all testing and development using DL Workstation with 4x2080Ti

Training

pip install -r requirements.txt
python train.py --cfg configs/mobile_stylegan_ffhq.json --gpus <n_gpus>

Convert checkpoint from rosinality/stylegan2-pytorch

Our framework supports StyleGAN2 checkpoints format from rosinality/stylegan2-pytorch. To convert ckpt your own checkpoint of StyleGAN2 to our framework:

python convert_rosinality_ckpt.py --ckpt <path_to_rosinality_stylegan2_ckpt> --ckpt-mnet <path_to_output_mapping_network_ckpt> --ckpt-snet <path_to_output_synthesis_network_ckpt> --cfg-path <path_to_output_config_json>

Check converted checkpoint

To check that your checkpoint is converted correctly, just run demo visualization:

python demo.py --cfg <path_to_output_config_json> --ckpt "" --generator teacher

Generate images using MobileStyleGAN

python generate.py --cfg configs/mobile_stylegan_ffhq.json --device cuda --ckpt <path_to_ckpt> --output-path <path_to_store_imgs> --batch-size <batch_size> --n-batches <n_batches>

Evaluate FID score

To evaluate the FID score we use a modified version of pytorch-fid library:

python evaluate_fid.py <path_to_ref_dataset> <path_to_generated_imgs>

Demo

Run demo visualization using MobileStyleGAN:

python demo.py --cfg configs/mobile_stylegan_ffhq.json --ckpt <path_to_ckpt>

Run visual comparison using StyleGAN2 vs. MobileStyleGAN:

python compare.py --cfg configs/mobile_stylegan_ffhq.json --ckpt <path_to_ckpt>

Convert to ONNX

python train.py --cfg configs/mobile_stylegan_ffhq.json --ckpt <path_to_ckpt> --export-model onnx --export-dir <output_dir>

Convert to CoreML

python train.py --cfg configs/mobile_stylegan_ffhq.json --ckpt <path_to_ckpt> --export-model coreml --export-dir <output_dir>

Deployment using OpenVINO

We provide external library random_face as an example of deploying our model at the edge devices using the OpenVINO framework.

Pretrained models

Name FID
mobilestylegan_ffhq.ckpt 7.75

(*) Our framework supports automatic download pretrained models, just use --ckpt <pretrined_model_name>.

Legacy license

Code Source License
Custom CUDA kernels https://github.com/NVlabs/stylegan2 Nvidia License
StyleGAN2 blocks https://github.com/rosinality/stylegan2-pytorch MIT

Acknowledgements

We want to thank the people whose works contributed to our project::

  • Tero Karras, Samuli Laine, Miika Aittala, Janne Hellsten, Jaakko Lehtinen, Timo Aila for research related to style based generative models.
  • Kim Seonghyeon for implementation of StyleGAN2 in PyTorch.
  • Fergal Cotter for implementation of Discrete Wavelet Transforms and Inverse Discrete Wavelet Transforms in PyTorch.
  • Cyril Diagne for the excellent demo of how to run MobileStyleGAN directly into the web-browser.

Citation

If you are using the results and code of this work, please cite it as:

@misc{belousov2021mobilestylegan,
      title={MobileStyleGAN: A Lightweight Convolutional Neural Network for High-Fidelity Image Synthesis},
      author={Sergei Belousov},
      year={2021},
      eprint={2104.04767},
      archivePrefix={arXiv},
      primaryClass={cs.CV}
}

@article{BELOUSOV2021100115,
      title = {MobileStyleGAN.pytorch: PyTorch-based toolkit to compress StyleGAN2 model},
      journal = {Software Impacts},
      year = {2021},
      issn = {2665-9638},
      doi = {https://doi.org/10.1016/j.simpa.2021.100115},
      url = {https://www.sciencedirect.com/science/article/pii/S2665963821000452},
      author = {Sergei Belousov},
}

More Repositories

1

stable_diffusion.openvino

Python
1,533
star
2

crnn-pytorch

Pytorch implementation of OCR system using CRNN + CTCLoss
Python
216
star
3

mean_average_precision

Mean Average Precision for Object Detection
Python
192
star
4

random_face

A simple python library for fast image generation of people who do not exist.
Python
177
star
5

mpl.pytorch

Pytorch implementation of MaxPoolingLoss.
Python
175
star
6

thinkpad_x1_carbon_6th_linux

Linux configuration guide for Thinkpad x1 Carbon 6th Gen (2018)
Shell
143
star
7

pytorch_clip_guided_loss

A simple library that implements CLIP guided loss in PyTorch.
Python
77
star
8

VIBE

VIBE Background Subtractior
C++
67
star
9

pytorch_clip_bbox

Pytorch based library to rank predicted bounding boxes using text/image user's prompts.
Python
51
star
10

ESOINN

An enhanced self-organizing incremental neural network for online unsupervised learning
C++
28
star
11

vqvae_dwt_distiller.pytorch

Python
26
star
12

HandDetector

Hand and Fingertip Detecot with OpenCV
C++
25
star
13

SOINN

Self-Organizing and Incremental Neural Networks
C++
20
star
14

haar_pytorch

Pytorch implementation of forward and inverse Haar Wavelets 2D
Python
18
star
15

libGNG

Growing Neural Gas
C++
12
star
16

story-diffusion-runpod-serverless-worker

StoryDiffusion serverless worker
Python
9
star
17

stable_diffusion_quantizer.pytorch

Custom pipelines for stable diffusion model
Python
6
star
18

pytorch_clip_interrogator

Image-to-prompt reconstruction.
Python
4
star
19

smart_pdf

Summarize PDF by LLM
Python
4
star
20

SandboxCV

SandboxCV: sandbox for some computer vision algorithms
C++
2
star
21

pytorch_clip

Pytorch API to work with CLIP models.
Python
2
star
22

random_prompt

Random Prompt generator for ArtWork creation
Python
2
star
23

CloudsStitcher

Framework for stitching point clouds
C++
2
star
24

tts-runpod-serverless-worker

Serverless implementation of Text-To-Speech
Python
2
star
25

PTAM

Implementation of the PTAM as crossplatform library
C++
1
star
26

pybind11_template

Template of python wrapper for C++ class using pybind11+CMake
Python
1
star
27

image_to_sticker

Convert image to sticker
Python
1
star
28

text_to_speech_lab

Some experiments with TTS pipelines
Python
1
star