This folder contains a script to train 'Lightweight' GAN for unconditional image generation, leveraging the Hugging Face ecosystem for processing your data and pushing the model to the Hub.
The script leverages 馃 Datasets for loading and processing data, and 馃 Accelerate for instantly running on CPU, single, multi-GPUs or TPU, also supporting mixed precision.
Pizza's that don't exist. Courtesy of Phil Wang.
To train the model with the default parameters on huggan/CelebA-faces, first run:
accelerate configand answer the questions asked about your environment. Next, launch the script as follows:
accelerate launch cli.pyThis will instantly run on multi-GPUs (if you asked for that). To train on another dataset available on the hub, simply do (for instance):
accelerate launch cli.py --dataset_name huggan/pokemonIn case you'd like to tweak the script to your liking, first fork the "community-events" repo (see the button on the top right), then clone it locally:
git clone https://github.com/<your Github username>/community-events.gitand edit to your liking.
You can of course also train on your own images. For this, one can leverage Datasets' ImageFolder. Make sure to authenticate with the hub first, by running the huggingface-cli login command in a terminal, or the following in case you're working in a notebook:
from huggingface_hub import notebook_login
notebook_login()Next, run the following in a notebook/script:
from datasets import load_dataset
# first: load dataset
# option 1: from local folder
dataset = load_dataset("imagefolder", data_dir="path_to_folder")
# option 2: from remote URL (e.g. a zip file)
dataset = load_dataset("imagefolder", data_files="URL to .zip file")
# next: push to the hub (assuming git-LFS is installed)
dataset.push_to_hub("huggan/my-awesome-dataset")You can then simply pass the name of the dataset to the script:
accelerate launch cli.py --dataset huggan/my-awesome-datasetYou can easily add logging to Weights and Biases by passing the --wandb flag:
accelerate launch cli.py --wandbYou can then follow the progress of your GAN in a browser:
This repo is entirely based on lucidrains' Pytorch implementation, but with added HuggingFace goodies.

