StyleGAN3, StyleGAN-fun, dragGAN

Alias-Free Generative Adversarial Networks

StyleGAN install und usage instructions

Setup Remote Jupyterhub Notebook

1. Signing into Jupyterhub

Login to JupyterHub with your cluster credentials here 

Choose an XS or S slice

make sure to choose cuda 11.7 from the dropdown

cluster_01.gif

2. Installing Stylegan3
conda init bash
source ~/.bashrc
git clone https://github.com/NVlabs/stylegan3.git
cd stylegan3
conda env create -f environment.yml


conda activate stylegan3
conda install cudatoolkit
downloading models

make 'pretrained' directory

mkdir pretrained

ffhq flicker faces

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/j06LuPxYHRRtnQE/download -O pretrained/ffhq_faces.pkl

Wikiart

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/tbjJS7XBezbAC3B/download -O pretrained/wikiart.pkl

Metfaces

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/eFZAmR6dDLelSo7/download -O pretrained/metfaces.pkl


Setup Local Stylegan

1. Refer to the Github Page

For major installation process refer to the stylegan3 GitHub Page.

This is an in-depth YouTube tutorial on how to install stylegan3 locally

2. Installing Stylegan3
conda init bash
source ~/.bashrc
git clone https://github.com/NVlabs/stylegan3.git
cd stylegan3
conda env create -f environment.yml


conda activate stylegan3
conda install cudatoolkit
downloading models

make 'pretrained' directory

mkdir pretrained

ffhq flicker faces

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/j06LuPxYHRRtnQE/download -O pretrained/ffhq_faces.pkl

Wikiart

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/tbjJS7XBezbAC3B/download -O pretrained/wikiart.pkl

Metfaces

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/eFZAmR6dDLelSo7/download -O pretrained/metfaces.pkl


Inference

For generating single images and videos, you may follow these steps.

activating conda environment

this needs to be done before every session if you want to use stylegan

conda init bash
source ~/.bashrc
conda activate stylegan3

alternatively if you are not able to activate stylegan3 through the terminal on our workstations, you can use the anaconda Navigator and start the terminal with the environment activated:

image.png

inference images
python gen_images.py --outdir=out --trunc=1 --seeds=2 --network=https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan3/versions/1/files/stylegan3-r-afhqv2-512x512.pkl
inference video
python gen_video.py --output=out/wikiart.mp4 --trunc=1 --seeds=0-31 --network=pretrained/wikiart.pkl

Training

For training your own datasets, you can follow these steps.

For your own dataset make sure that your training data has the correct resolution. You may use either 1024x1024, 512x512 or 256x256 resolution. The chosen resolution has to match with the pre-existing dataset that you want to train on.
You may start a dataset from scratch, just be aware that generally training your collected images on a pre-existing dataset will usually give better results (and faster ones too).

activating conda environment

this needs to be done before every session if you want to use stylegan

 

conda init bash
source ~/.bashrc
conda activate stylegan3

alternatively if you are not able to activate stylegan3 through the terminal on our workstations, you can use the anaconda Navigator and start the terminal with the environment activated:

image.png


Dowload Training data

If not done before, set up a new directory for the training data

mkdir trainingdata

If you want to download your trainingdata from a sciebo folder, you may use this code. Instead of the given link you may use your own one.

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/7SzJ55ZroKPf5zY/download -O trainingdata/group01.zip
wget --no-check-certificate --content-disposition https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan3/versions/1/files/stylegan3-t-afhqv2-512x512.pkl -O datasets/stylegan3-t-afhqv2-512x512.pkl

https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan3/versions/1/files/stylegan3-t-afhqv2-512x512.pkl

Prepare training data

Before training, it is highly recommended to check your dataset through the given stylegan3 check-up. It can resize your images too, although it is usually better to do it before on your own. (Adobe Bridge is a great tool for batch processing.)

python dataset_tool.py --source=trainingdata/group01.zip --dest=trainingdata/group01.zip --resolution=512x512

--source= your directory with the given files
--destination= the output directory, dont forget to add .zip at the end
--resolution= resolution you want your images to be saved in. (1024x1024, 512x512 or 256x256 resolution)

start training
python train.py --outdir=~/training-runs --cfg=stylegan3-t --data=~/datasets/afhqv2-512x512.zip --gpus=8 --batch=32 --gamma=8.2 --mirror=1

--outdir= direction where you want to save the trained data
--data= your dataset you want to use
--gpus= depends on the gpus you have. usually 1 will be 
--batch= 

 

python train.py --outdir=~/training-runs --cfg=stylegan3-t --data=~/trainingdata/(...)  --gpus=1 --batch=8 --gamma=2 --snap=20 --resume=~/datasets/afhqv2-512x512.zip

 


Opening the Python Visualizer

Python Visualizer

The following script will open the python Visualizer

python visualizer.py

image.png

You can open one of the .pkl files that NVIDIA provided or paste a local URL to your own trainingdata to visualize and play around.

...

StyleGAN3 - Training


Dowload Training data

training data

Group 01

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/7SzJ55ZroKPf5zY/download

Group 03

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/YGR7BaeoIBSePNl/download

Group 05

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/b1I0rgEaPcyaP44/download



Handling errors specific to stylegan

Handling errors specific to stylegan

Setting up PyTorch plugin "bias_act_plugin"... Failed!

This error sometimes occurs if styleGAN is running inference and then interrupted.
Some cache files remain and they prevent the bias_act_plugin to be loaded, next time styleGAN is run.

From:

C:\Users*USER*\AppData\Local\torch_extensions\torch_extensions\Cache

there are a few folders called:
📁py37_cu117
📁py39_cu116

delete all of them.

bias_act_plugin_fails.png

StyleGAN workshop Dangerzones

Setup Remote Jupyterhub Notebook

1. Signing into Jupyterhub via keycloak

key in your keycloak credentials here 

Choose an XS slice

make sure to choose cuda 11.7 from the dropdown

cluster_01.gif

2. Installing Stylegan3
conda init bash
source ~/.bashrc
git clone https://github.com/NVlabs/stylegan3.git
cd stylegan3
conda env create -f environment.yml


conda activate stylegan3
conda install cudatoolkit
downloading models

make 'pretrained' directory

mkdir pretrained

ffhq flicker faces

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/j06LuPxYHRRtnQE/download -O pretrained/ffhq_faces.pkl

Wikiart

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/tbjJS7XBezbAC3B/download -O pretrained/wikiart.pkl

Metfaces

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/eFZAmR6dDLelSo7/download -O pretrained/metfaces.pkl


 

Setup Local Stylegan

1. Refer to the Github Page

For major installation process refer to the stylegan3 GitHub Page.

This is an in-depth YouTube tutorial on how to install stylegan3 locally

2. Installing Stylegan3
conda init bash
source ~/.bashrc
git clone https://github.com/NVlabs/stylegan3.git
cd stylegan3
conda env create -f environment.yml


conda activate stylegan3
conda install cudatoolkit
downloading models

make 'pretrained' directory

mkdir pretrained

ffhq flicker faces

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/j06LuPxYHRRtnQE/download -O pretrained/ffhq_faces.pkl

Wikiart

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/tbjJS7XBezbAC3B/download -O pretrained/wikiart.pkl

Metfaces

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/eFZAmR6dDLelSo7/download -O pretrained/metfaces.pkl



Inference

For generating single images and videos, you may follow these steps.

activating conda environment

this needs to be done before every session if you want to use stylegan

conda init bash
source ~/.bashrc
conda activate stylegan3


inference images
python gen_images.py --outdir=out --trunc=1 --seeds=2 --network=https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan3/versions/1/files/stylegan3-r-afhqv2-512x512.pkl
inference video
python gen_video.py --output=out/wikiart.mp4 --trunc=1 --seeds=0-31 --network=pretrained/wikiart.pkl

Training

For training your own datasets, you can follow these steps.

Dowload Training data
mkdir trainingdata

Group 01

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/7SzJ55ZroKPf5zY/download -O trainingdata/group01.zip

Group 02

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/7SzJ55ZroKPf5zY/download -O trainingdata/group02.zip

Group 03

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/YGR7BaeoIBSePNl/download -O trainingdata/group03.zip

Group 04

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/SsrPKyPcyswd8z2/download -O trainingdata/group04.zip

Group 05

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/b1I0rgEaPcyaP44/download -O trainingdata/group05

Group 06

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/Orv9FDqqKwtBMlB/download -O trainingdata/group06


Prepare training data
python dataset_tool.py --source=trainingdata/group01.zip --destination=trainingdata/group01 --resolution=512x512
start training
python train.py --help


Downloading the DangerzonesGANs

downloading dangerzones models

go into directory pretrained:

cd pretrained

 Download our trained models from the KISD Modelzoo:


image.png

Group 01 - androids gynoids

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/B7rOZIRzPN5rev1/download -O pretrained/group_01_220.pkl

Group 02 TBF - dataset error


image.png

Group 03 - grayscale faces

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/SRcjw6DPv9AIacn/download -O pretrained/group_03_500.pkl


image.png

Group 04 -future cities

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/CW8uQ2dsQbVOiXa/download -O pretrained/group_04_20.pkl

image.png

Group 05 - lamppost and sunflowers

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/fb0skqUV9ypIOEl/download -O pretrained/group_05.pkl

 Group 05 - encoded data


Workshop

Setup Remote Jupyterhub Notebook

1. Signing into Jupyterhub

Login to JupyterHub with your cluster credentials here 

Choose an XS or S slice

make sure to choose cuda 11.7 from the dropdown

cluster_01.gif

2. Installing Stylegan3
conda init bash
source ~/.bashrc
git clone https://github.com/NVlabs/stylegan3.git
cd stylegan3
conda env create -f environment.yml


conda activate stylegan3
conda install cudatoolkit

 

pip install torch torchvision
conda install psutil

 

 

Training

For training your own datasets, you can follow these steps.

For your own dataset make sure that your training data has the correct resolution. You may use either 1024x1024, 512x512 or 256x256 resolution. The chosen resolution has to match with the pre-existing dataset that you want to train on.
You may start a dataset from scratch, just be aware that generally training your collected images on a pre-existing dataset will usually give better results (and faster ones too).

activating conda environment

this needs to be done before every session if you want to use stylegan

 

conda init bash
source ~/.bashrc
conda activate stylegan3

alternatively if you are not able to activate stylegan3 through the terminal on our workstations, you can use the anaconda Navigator and start the terminal with the environment activated:

image.png


Dowload Training data

If not done before, set up a new directory for the training data

mkdir trainingdata

in the trainingdata folder: set up a new folder (for example called imgs) and upload your images

 

If you want to download your trainingdata from a sciebo folder, you may use this code. Instead of the given link you may use your own one.

wget --no-check-certificate --content-disposition https://th-koeln.sciebo.de/s/7SzJ55ZroKPf5zY/download -O trainingdata/group01.zip
wget --no-check-certificate --content-disposition https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan3/versions/1/files/stylegan3-t-afhqv2-512x512.pkl -O datasets/stylegan3-t-afhqv2-512x512.pkl

https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan3/versions/1/files/stylegan3-t-afhqv2-512x512.pkl

Prepare training data

Before training, it is highly recommended to check your dataset through the given stylegan3 check-up. It can resize your images too, although it is usually better to do it before on your own. (Adobe Bridge is a great tool for batch processing.)

python dataset_tool.py --source=trainingdata/imgs/ --dest=trainingdata/group01.zip --resolution=512x512

--source= your directory with the given files
--destination= the output directory, dont forget to add .zip at the end
--resolution= resolution you want your images to be saved in. (1024x1024, 512x512 or 256x256 resolution)

start training

 

python train.py --outdir=/home/jovyan/stylegan3/training-runs --cfg=stylegan3-t --data=/home/jovyan/stylegan3/trainingdata/group01.zip  --gpus=1 --batch=8 --gamma=2 --snap=20 --resume="https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan3/versions/1/files/stylegan3-t-afhqv2-512x512.pkl"

 

--outdir= direction where you want to save the trained data
--data= your dataset you want to use
--gpus= depends on the gpus you have. usually 1 will be 
--batch= 

 


Opening the Python Visualizer

Python Visualizer

The following script will open the python Visualizer

python visualizer.py

image.png

You can open one of the .pkl files that NVIDIA provided or paste a local URL to your own trainingdata to visualize and play around.

...