<commit_before># About

This is a script to generate new images of human faces using the technique of generative adversarial networks (GAN), as described in the paper by [<NAME>](http://arxiv.org/abs/1406.2661).
GANs train two networks at the same time: A Generator (G) that draws/creates new images and a Discriminator (D) that distinguishes between real and fake images. G learns to trick D into thinking that his images are real (i.e. learns to produce good looking images). D learns to prevent getting tricked (i.e. learns what real images look like).
Ideally you end up with a G that produces beautiful images that look like real ones. On human faces that works reasonably well, probably because they contain a lot of structure (autoencoders work well on them too).

The code of this repository is a modified version of facebook's [eyescream project](https://github.com/facebook/eyescream). It does not use the upscaling feature (laplacian pyramid).

Note: This project is not fully finished yet, but mostly funtional.

# Example images

![Example faces](images/faces.png?raw=true "Example faces")

Example faces after 1.5 hours of training. 

# Requirements

To run this script optimally you need
* [Torch](http://torch.ch/) with the following libraries (most of them are probably already installed by default):
  * `nn` (`luarocks install nn`)
  * `paths` (`luarocks install paths`)
  * `image` (`luarocks install image`)
  * `optim` (`luarocks install optim`)
  * `cutorch` (`luarocks install cutorch`) (only for GPU training)
  * `cunn` (`luarocks install cunn`) (only for GPU training)
* [display](https://github.com/szym/display)
* [Labeled Faces in the Wild, cropped version](http://conradsanderson.id.au/lfwcrop/) (colored)

# Execution

To train a new model, follow these steps:
* Download the [lfw cropped dataset](http://conradsanderson.id.au/lfwcrop/). You should chose the colored dataset as you can activate `--grayscale` mode via the command line parameters.
* Clone the repository.
* Change in `train.lua` the line `DATASET.setDirs({"/path/to/lfw_cropped"})` to match your dataset's directory.
* Start the training with the command `th train.lua --gpu=0 --plot --grayscale`, which will train on grayscale images on the GPU and plot via `display` during the training. You can see the plots by opening `http://localhost:8000`.

# Architecture

G is a very small network which starts (by default) with a 100 dimensional noise vector, followed by one hidden layer of size 2048 (using PReLU activation) and the output layer, which consists of all image pixels (Sigmoid). No dropout is used.

D contains three subnetworks:
* A fully connected network that works directly on the images (without convolutions). It contains two layers of size 1024.<commit_msg>WIP notice<commit_after>Work in Progress.

# About

This is a script to generate new images of human faces using the technique of generative adversarial networks (GAN), as described in the paper by [<NAME>](http://arxiv.org/abs/1406.2661).
GANs train two networks at the same time: A Generator (G) that draws/creates new images and a Discriminator (D) that distinguishes between real and fake images. G learns to trick D into thinking that his images are real (i.e. learns to produce good looking images). D learns to prevent getting tricked (i.e. learns what real images look like).
Ideally you end up with a G that produces beautiful images that look like real ones. On human faces that works reasonably well, probably because they contain a lot of structure (autoencoders work well on them too).

The code of this repository is a modified version of facebook's [eyescream project](https://github.com/facebook/eyescream). It does not use the upscaling feature (laplacian pyramid).

# Example images

![Example faces](images/faces.png?raw=true "Example faces")

Example faces after 1.5 hours of training.

TODO add better image

# Requirements

To run this script optimally you need
* [Torch](http://torch.ch/) with the following libraries (most of them are probably already installed by default):
  * `nn` (`luarocks install nn`)
  * `paths` (`luarocks install paths`)
  * `image` (`luarocks install image`)
  * `optim` (`luarocks install optim`)
  * `cutorch` (`luarocks install cutorch`) (only for GPU training)
  * `cunn` (`luarocks install cunn`) (only for GPU training)
* [display](https://github.com/szym/display)
* [Labeled Faces in the Wild, cropped version](http://conradsanderson.id.au/lfwcrop/) (colored)

# Execution

To train a new model, follow these steps:
* Download the [lfw cropped dataset](http://conradsanderson.id.au/lfwcrop/). You should chose the colored dataset as you can activate `--grayscale` mode via the command line parameters.
* Clone the repository.
* Change in `train.lua` the line `DATASET.setDirs({"/path/to/lfw_cropped"})` to match your dataset's directory.
* Start the training with the command `th train.lua --gpu=0 --plot --grayscale`, which will train on grayscale images on the GPU and plot via `display` during the training. You can see the plots by opening `http://localhost:8000`.

# Architecture

G is a very small network which starts (by default) with a 100 dimensional noise vector, followed by one hidden layer of size 2048 (using PReLU activation) and the output layer, which consists of all image pixels (Sigmoid). No dropout is used.

D contains three subnetworks:
* A fully connected network that works directly on the images (without convolutions). It contains two layers of size 1024.
{'fraction_non_alphanumeric': 0.0870669327045166, 'fraction_numerical': 0.009432251042989299, 'mean_word_length': 4.558467741935484, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '36515', 'n_tokens_mistral': 1600, 'n_tokens_neox': 1490, 'n_words': 751}