Wasserstein GAN (WGAN) Implementation
repository·master·Indexed 25 days ago
https://github.com/martinarjovsky/wassersteinganOfficial implementation of the Wasserstein GAN (WGAN) paper using PyTorch. This repository provides a command-line interface via main.py to train models on datasets such as cifar10, lsun, imagenet, and lfw, supporting both DCGAN and MLP architectures with Adam or RMSprop optimizers.
What's inside wassersteingan
- The first time you run the code on the LSUN dataset, creating the dataloader can take up to an hour. A small cache file containing a list of indices in the LSUN LMDB database will be created. Subsequent runs will use this cache and complete in seconds.
Prerequisites for Wasserstein GAN
masterTo run this project, ensure your environment meets the following requirements:
- Operating System: Linux or OSX.
- Framework: PyTorch.
- Hardware: An NVIDIA GPU is strongly recommended for training speed. While CPU support is available, training will be significantly slower.
Troubleshoot sudden drops in learning curves
masterIf your learning curve experiences a sudden, large drop, it indicates the critic is failing to stay close to optimum, causing its error to stop being a reliable Wasserstein estimate.
Common causes and solutions:
- High learning rates: Try reducing the learning rate.
- High momentum: Try reducing momentum.
- General fix: Implement any adjustments that help the critic return to an optimal state.
Apply median filter to discriminator loss for paper reproduction
masterTo reproduce the loss curves shown in the original paper, apply a median filter to the negative discriminator loss (-Loss_D) usingscipy.signal.medfilt.Run experiments with MLP architecture
masterTo run experiments using an MLP generator, use the
--mlp_Gflag. You can also specify the number of generator filters using--ngf.python main.py --mlp_G --ngf 512Run LSUN experiments with DCGAN
masterTo reproduce the LSUN experiments using a DCGAN architecture, use the following command. Replace
[lsun-train-folder]with the actual path to your LSUN dataset folder.python main.py --dataset lsun --dataroot [lsun-train-folder] --cudaReference: Training Hyperparameters and CLI Flags
masterThe following command-line arguments are available for configuring the Wasserstein GAN training process inmain.py.Train Wasserstein GAN via CLI
masterThe
main.pyscript provides a command-line interface to train a Wasserstein GAN. It supports multiple datasets includingcifar10,lsun,imagenet,folder, andlfw. You can configure model architectures (DCGAN or MLP), optimization algorithms (Adam or RMSprop), and various hyperparameters for both the Generator and Critic (Discriminator).Supported Datasets
cifar10: Usestorchvision.datasets.CIFAR10.lsun: Usestorchvision.datasets.LSUN(specificallybedroom_train).imagenet,folder,lfw: Usestorchvision.datasets.ImageFolder.
Key Configuration Options
--dataset: Required. The dataset type.--dataroot: Required. Path to the dataset directory.--experiment: Directory where samples and model checkpoints (.pth) will be stored. Defaults tosamples.--cuda: Enables CUDA training.--adam: Use Adam optimizer instead of the default RMSprop.--mlp_G/--mlp_D: Use MLP architectures for the Generator or Discriminator respectively.--noBN: Disable Batch Normalization (only applicable for DCGAN).--Diters: Number of Discriminator iterations per Generator iteration (default: 5).