Skip to main content

StyleGAN2 Pytorch - Typed, Commented, Installable :)

A simple, typed, commented Pytorch implementation of StyleGAN2.

action pypi codecov docs

This implementation is adapted from here. This implementation seems more stable and editable than the over-engineered official implementation.

The focus of this repository is simplicity and readability. If there are any bugs / issues, please kindly let me know or submit a pull request!

Refer to my blog post for an explanation on the custom CUDA kernels. The profiling code to optimize the custom operations is here.

Installation

pip install stylegan2-torch

Training Tips

  1. Use a multi-GPU setup. An RTX 3090 can handle batch size of up to 8 at 1024 resolution. Based on experience, batch size of 8 works but 16 or 32 should be safer.
  2. Use LMDB dataset + SSD storage + multiple dataloader workers (and a big enough prefetch factor to cache at least one batch ahead). You never know how much time you waste on dataloading until you optimize it. For me, that shorted the training time by 30% (more time-saving than the custom CUDA kernels).

Known Issues

Pytorch is known to cause random reboots when using non-deterministic algorithms. Set torch.use_deterministic_algorithms(True) if you encounter that.

To Dos / Won't Dos

  1. Tidy up conv2d_gradfix.py and fused_act.py. These were just copied over from the original repo so they are still ugly and untidy.
  2. Provide pretrained model conversion method (not that hard tbh, just go map the state_dict keys).
  3. Clean up util functions to aid training loop design.

Release files for stylegan2-torch 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stylegan2-torch 1.3.0
File Size Uploaded
stylegan2-torch-1.3.0.tar.gz 20.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stylegan2-torch 1.3.0
File Interpreter ABI Platform
stylegan2_torch-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 46.1 kB

Release files / stylegan2-torch-1.3.0.tar.gz

Download URL stylegan2-torch-1.3.0.tar.gz
Size 20.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2abcc04090380f03dfc861cb1bad8c85433df7d46e8bee9a6e3310886dc7d8e8
BLAKE2b-256 checksum
How to use checksums
d892e958e4998d8f253036b0677a978e97bad5036339a153ad6551a2797e7ec9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.8.12 Linux/5.11.0-1028-azure

Release files / stylegan2_torch-1.3.0-py3-none-any.whl

Download URL stylegan2_torch-1.3.0-py3-none-any.whl
Size 25.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab3de10e3f370a407f60f7bbd3dcb9dcd289b231f3c02564f9d5cb84f25a8ef3
BLAKE2b-256 checksum
How to use checksums
7079d0522ea9bf3693f9568c5e5c5549adcb090fe46b85a02275e2b8afa3cc68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.8.12 Linux/5.11.0-1028-azure

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.0

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page