StyleGAN3: Train your own dataset

Software tutorials of interest.
Post Reply
Message
Author
jstenner
Site Admin
Posts: 87
Joined: Wed Jan 27, 2010 7:33 pm

StyleGAN3: Train your own dataset

#1 Post by jstenner »

We've been playing with StyleGAN3 + CLIP. Now you want to tailor your project to access something other than Flicker Faces (FFHQ) or Met Faces, AFHQ, etc. That means you need to create a dataset and then train it.

Context
Here are some articles talking about what we've been doing that provide some context and info on what is happening behind the scenes:
Alien Dreams: An Emerging Art Scene
VICE: AI Generated Art Scene Explodes as Hackers Create Groundbreaking New Tools
VQGAN + CLIP How Does it Work?
Generating AI “Art” with VQGAN+CLIP

Tech
First, all of your images have to be RGB. They can't be Indexed Color, etc. So, I set up a Photoshop Action that converts any image to RGB color. Then, open File->Automate->Batch... and select your action. Tell it to override open and save dialogs and it will convert whatever folder of images you give it to RGB. IF you know your images are already RGB, then you don't have to preprocess them like this.

Next, you need to prepare the images into a "dataset" using the dataset_tool.py
This app will resize your images to powers of 2, so, 256x256, 512x512, 1024x1024, etc.
You can give it a single directory or nested directories (so, "insects" or "butterfly, etc.)

Code: Select all

python dataset_tool.py --source=insects/Butterfly/ --dest=datasets/butterflys-256x256.zip --resolution=256x256
Login to HiPerGator

Code: Select all

hgator

cd to your working directory

Code: Select all

cd blue_art4612/share/students/<whatever>

and load the Anaconda module

Code: Select all

module load conda
If this is your first time (i.e. you haven't already created a conda environment for this project), create a conda environment

Code: Select all

conda env create -f environment.yml
NOTE: I edited environment.yml to specify Python 3.8 only since by default it will install the latest version. Some people reported issues compiling with a more recent version.

Activate your conda environment

Code: Select all

conda activate stylegan3

Code: Select all

conda install psutil (this should be added to environment.yml)

Load a Cuda and GCC (compiler)

Code: Select all

module load cuda/11.1.0
module load gcc

Let's save our current list of modules so we can simply recall them all the next time we log in:

Code: Select all

module save sgan3
The next time we log in we can restore to this config with:

Code: Select all

module restore sgan3

If you log in and can't recall the name of the module list you created:

Code: Select all

module savelist

See here for more detail:
https://www.chpc.utah.edu/documentation ... vanced.php

Now we need to grab a GPU or two:

Code: Select all

srun -p gpu --gpus=a100:2 --mem=160gb --pty -u -A art4612 -q art4612 bash -i

And, now we need to initiate our training. Here I set "worker" to 2 since by default it's 3 and will work but give errors:

Code: Select all

python train.py --outdir=training-runs --cfg=stylegan3-t --data=datasets/butterflys-256x256.zip --gpus=2 --batch=24 --workers=2 --gamma=8.2 --mirror=1

YEAH, WE'RE TRAINING
StyleGAN3-Training.png
The master of disaster!

jstenner
Site Admin
Posts: 87
Joined: Wed Jan 27, 2010 7:33 pm

Re: StyleGAN3: Train your own dataset

#2 Post by jstenner »

Here's a nice tutorial on training your own dataset. His version on github has some nice features to resume at exactly where you stopped which is helpful for multi-day runs like we'll likely perform.



https://github.com/nerdyrodent/stylegan3
The master of disaster!

Post Reply