https://github.com/markdtw/least-squares-gan
GAN that adopts the least squares loss function for the discriminator in tensorflow
https://github.com/markdtw/least-squares-gan
generative-adversarial-network tensorflow
Last synced: 3 months ago
JSON representation
GAN that adopts the least squares loss function for the discriminator in tensorflow
- Host: GitHub
- URL: https://github.com/markdtw/least-squares-gan
- Owner: markdtw
- Created: 2017-06-29T13:49:50.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-09T14:57:22.000Z (almost 9 years ago)
- Last Synced: 2025-10-24T01:57:05.065Z (8 months ago)
- Topics: generative-adversarial-network, tensorflow
- Language: Python
- Size: 966 KB
- Stars: 10
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Least Squares Generative Adversarial Networks
Tensorflow implementation of [Least Squares Generative Adversarial Networks by Mao et al](https://arxiv.org/abs/1611.04076) (LSGAN).
## Prerequisites
- Python 2.7+
- [NumPy](http://www.numpy.org/)
- [SciPy](https://www.scipy.org/)
- [tqdm](https://pypi.python.org/pypi/tqdm)
- [Tensorflow r1.0+](https://www.tensorflow.org/install/)
- [lmdb](https://lmdb.readthedocs.io/en/release/) (for processing LSUN dataset only)
## Data
- [LSUN Scene Classification](http://lsun.cs.princeton.edu/)
- [CelebA](http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html)
## Preparation
1. Clone this repo, create `ckpt/` folder:
```bash
git clone https://github.com/markdtw/least-squares-gan.git
cd least-squares-gan
mkdir ckpt
```
2. To train on LSUN, use the [provided tools](https://github.com/fyu/lsun) to download and extract. For example:
```bash
python download.py -c conference_room
unzip conference_room_train_lmdb.zip
python data.py export conference_room_train_lmdb --out_dir conference_room_train_images --flat
```
I replaced _.webp_ from [this line](https://github.com/fyu/lsun/blob/master/data.py#L49) to _.jpg_
3. To train on CelebA, I use [this file](https://github.com/carpedm20/DCGAN-tensorflow/blob/master/download.py) to download. Shout out to carpedm20.
4. Now you are good to go, first time training on LSUN will center-crop all the images to 224x224 and store them in a new folder.
## Train
Train on LSUN conference room with default settings:
```bash
python main.py --train
```
Train on CelebA with default settings:
```bash
python main.py --train --dataset=CelebA
```
Train from a previous checkpoint at epoch X:
```bash
python main.py --train --modelpath=ckpt/lsgan-LSUN-X
```
Check out tunable hyper-parameters:
```bash
python main.py
```
## Some results
Epoch 10:

Epoch 25:

Epoch 45:

Results from epoch 45 is already nice and crispy.
Generator loss:

Discriminator loss:

## Notes
- The model will save 40 generated pictures in `log/` folder every epoch.
- Initialization is important! Default initialization with `tf.xavier_initializer` will lead to either D or G's gradient vanishing problem, instead I use `tf.truncated_normal_initializer` which is identical to DCGAN original implementation to solve the problem.
- Issues are more than welcome!
## Resources
- [The paper](https://arxiv.org/abs/1611.04076)
- Highly based on [This repo](https://github.com/cameronfabbri/LSGANs-Tensorflow)