Convert StyleGAN2 TensorFlow weights to Pytorch

MLBoy
2 min readFeb 6, 2022

--

How to generate a realistic image with Pytorch’s StyleGAN

I want to play with StyleGAN

The official repository of StyleGAN2 is TensorFlow1.
I will convert it to Pytorch and use it.

stylegan2-pytorch

Clone the official repository and the pytorch version of the repository.

Convert the original checkpoint file pkl to pytorch format.
There are various pre-trained weights such as anime.

python convert_weight.py --repo ../stylegan2 {path_to_checkpoint.pkl}

The Pytorch weight pt file and the original and pytorch version image generation comparison png files are saved.

The original and converted versions have the same output.

Generate an image with the converted weight pt.

python generate.py --sample 1 --pics 1 --ckpt {converted_checkpoint_path.pt}

🐣

I’m a freelance engineer.
Work consultation
Please feel free to contact us with a brief development description.
rockyshikoku@gmail.com

I am making an app that uses Core ML and ARKit.
We send machine learning / AR related information.

GitHub

Twitter
Medium

--

--

MLBoy
MLBoy

No responses yet