Skip to content

Commit

Permalink
Update usage markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
mingyuliutw committed Oct 4, 2017
1 parent ffac9d9 commit 2556375
Show file tree
Hide file tree
Showing 19 changed files with 109 additions and 94 deletions.
110 changes: 18 additions & 92 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,109 +9,35 @@ Licensed under the CC BY-NC-ND 4.0 license (https://creativecommons.org/licenses

[Ming-Yu Liu, Thomas Breuel, Jan Kautz, "Unsupervised Image-to-Image Translation Networks" NIPS 2017](https://arxiv.org/abs/1703.00848)

Please cite our paper if this software is used in your publications.

Left: Input foggy images. Right: Output sunny images. Learning was conducted using SYNTHIA dataset. For videos in the original resolution, check out https://www.youtube.com/watch?v=E6exDXjESHA
#### Result Videos

![](./docs/Fog2Summer_SEQS-02-Stereo_Left-Omni_B.gif)![](./docs/Fog2Summer_SEQS-02-Stereo_Left-Omni_F.gif)
- [Snowy2Summery-01](https://youtu.be/9VC0c3pndbI)
- [Snowy2Summery-02](https://youtu.be/eUBiiBS1mj0)
- [Day2Night-01](https://youtu.be/Z_Rxf0TfBJE)
- [Day2Night-02](https://youtu.be/mmj3iRIQw1k)
- [Translation Between 5 dog breeds](https://youtu.be/3a6Jc7PabB4)
- [Translation Between 6 cat species](https://youtu.be/Bwq7BmQ1Vbc)

![](./docs/Fog2Summer_SEQS-02-Stereo_Left-Omni_L.gif)![](./docs/Fog2Summer_SEQS-02-Stereo_Left-Omni_R.gif)
#### Street Scene Image Translation
From the first row to the fourth row, we show example results on day to night, sunny to rainy, summery to snowy, and real to synthetic image translation (two directions). For each image pair, left is the input image; right is the translated image.

### Note
![](./docs/street_scene.jpg)

As a researcher, I tried to keep all the hyperparameter values fixed. But for applying the code to your application, manually checking which training epoch generating the best results is recommended. Also, in this implementation, we do not use a single GAN trick (not even BatchNorm). But for improving image generation quality, I recommend you use them.
#### Dog Breed Image Translation

### Algorithm Overview
![](./docs/dog_trans.jpg)

Given a dataset of images from one domain and another dataset of images from other domain, CoVAE-GAN learns to translate an image from one domain to a corresponding image in the other domain without requiring corresponding images in the two domains. In some sense, it tries to learn a joint distribution of images from samples drawn from marginal distributions. In theory, this is not possible without additional assumption. The assumption CoVAE-GAN makes is the shared latent space assumption. It assumes pairs of corresponding images have the same latent code and implements weight-sharing constraints to enforce this assumption under the unsupervised setting. For more details, please refer to our paper https://arxiv.org/abs/1703.00848.
#### Cat Species Image Translation

### Dependency
pytorch, yaml, opencv, and tensorboard (from https://github.com/dmlc/tensorboard).
![](./docs/dog_trans.jpg)

If you use Anaconda2, then the following commands can be used to install all the dependencies.
#### Attribute-based Face Image Translation

```
conda install pytorch torchvision cuda80 -c soumith
conda install -c anaconda yaml=0.1.6
conda install -c menpo opencv=2.4.11
pip install tensorboard
```
![](./docs/faces.jpg)

### Usage
### Code usage

The scripts are based on our experiments on the [CelebA dataset](http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html).
Please go to the [user manual page](USAGE.md)

#### Training
```
python train.py --config ../exps/celeba_blond_hair.yaml --log ../logs;
```
#### Resume training
```
python train.py --config ../exps/celeba_blond_hair.yaml --log ../logs --resume 1;
```
#### Testing

We thank Ian Goodfellow for kindly providing his photo for our demo.

Download pretrained models from https://drive.google.com/drive/folders/0BwpOatrZwxK6STdZcXNNcXpFSHM?usp=sharing and save them in snapshots/ folder.

From no-blond-hair to blond-hair. (Turn blond hair attribute on)
```
./translate_one_image.py --config ../exps/celeba_blond_hair.yaml --image_name ../images/ian.jpg --output_image_name ../results/ian_to_blond_hair.jpg --weights ../snapshots/celeba_blond_hair_gen_00500000.pkl --a2b 0
```
![No-blond-hair to blond-hair](./results/ian_to_blond_hair.jpg)

From goatee to non-goatee. (Turn goatee attribute off)
```
./translate_one_image.py --config ../exps/celeba_blond_hair.yaml --image_name ../images/ian.jpg --output_image_name ../results/ian_to_no_goatee.jpg --weights ../snapshots/celeba_goatee_gen_00500000.pkl --a2b 1
```
![Goatee to non-goatee](./results/ian_to_no_goatee.jpg)

From no eyeglasses to eyeglasses. (Turn eyeglasses attribute on)
```
./translate_one_image.py --config ../exps/celeba_blond_hair.yaml --image_name ../images/ian.jpg --output_image_name ../results/ian_to_eyeglasses.jpg --weights ../snapshots/celeba_eyeglasses_gen_00500000.pkl --a2b 0
```
![No-eyeglasses to eyeglasses](./results/ian_to_eyeglasses.jpg)

From smiling to neutral. (Turn smiling attribute off)
```
./translate_one_image.py --config ../exps/celeba_blond_hair.yaml --image_name ../images/ian.jpg --output_image_name ../results/ian_to_no_smiling.jpg --weights ../snapshots/celeba_smiling_gen_00500000.pkl --a2b 1
```
![Smiling to neutral](./results/ian_to_no_smiling.jpg)

### Example Results

[1] thermal IR image to color image translation (Left, input and right, translation.)
![](./docs/ir2vis.jpg)
![](./docs/vis2ir.jpg)

[2] rainy day image to sunny day image translation (Left, input and right, translation.)
![](./docs/rain2sunny.jpg)
![](./docs/sunny2rain.jpg)

[3] night time image to day time image translation (Left, input and right, translation.)
![](./docs/night2day.jpg)
![](./docs/day2night.jpg)

![](./docs/face_visualization.jpg)


### One Example

Training for attribute-based face image translation.

- Step 1. Download the file img_aligned_celeba.zip based on the instructions in [CelebA dataset](http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html) and unzip it to datasets/celeba/img_align_celeba/ folder
- Step 2. Crop and resize CelebA images.
```
cd datasets/celeba/
./crop_and_resize.py
```
- Step 3. Write an experiment config file. Follow the example config file in exps/celeba_blond_hair.yaml
- Step 4. Training
```
python train.py --config ../exps/celeba_blond_hair.yaml --log ../logs;
```
- Step 5. Testing
```
python translate_one_image.py --config ../exps/celeba_blond_hair.yaml --image ../images/032162.jpg --weights ../outputs/celeba_blond_hair/celeba_blond_hair_gen_00500000.pkl --a2b 0 --output ../results/032162_with_blond_hair.jpg
```
93 changes: 91 additions & 2 deletions USAGE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


## PyTorch Implementation of the Coupled GAN algorithm for Unsupervised Image-to-Image Translation

### License
Expand All @@ -11,6 +13,93 @@ Licensed under the CC BY-NC-ND 4.0 license (https://creativecommons.org/licenses

Please cite our paper if this software is used in your publications.

### Code usage
### Dependency
pytorch, yaml, opencv, and tensorboard (from https://github.com/dmlc/tensorboard).

If you use Anaconda2, then the following commands can be used to install all the dependencies.

```
conda install pytorch torchvision cuda80 -c soumith
conda install -c anaconda yaml=0.1.6
conda install -c menpo opencv=2.4.11
pip install tensorboard
```

### Usage

The scripts are based on our experiments on the [CelebA dataset](http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html).

#### Training
```
python train.py --config ../exps/celeba_blond_hair.yaml --log ../logs;
```
#### Resume training
```
python train.py --config ../exps/celeba_blond_hair.yaml --log ../logs --resume 1;
```
#### Testing

We thank Ian Goodfellow for kindly providing his photo for our demo.

Download pretrained models from https://drive.google.com/drive/folders/0BwpOatrZwxK6STdZcXNNcXpFSHM?usp=sharing and save them in snapshots/ folder.

From no-blond-hair to blond-hair. (Turn blond hair attribute on)
```
./translate_one_image.py --config ../exps/celeba_blond_hair.yaml --image_name ../images/ian.jpg --output_image_name ../results/ian_to_blond_hair.jpg --weights ../snapshots/celeba_blond_hair_gen_00500000.pkl --a2b 0
```
![No-blond-hair to blond-hair](./results/ian_to_blond_hair.jpg)

From goatee to non-goatee. (Turn goatee attribute off)
```
./translate_one_image.py --config ../exps/celeba_blond_hair.yaml --image_name ../images/ian.jpg --output_image_name ../results/ian_to_no_goatee.jpg --weights ../snapshots/celeba_goatee_gen_00500000.pkl --a2b 1
```
![Goatee to non-goatee](./results/ian_to_no_goatee.jpg)

From no eyeglasses to eyeglasses. (Turn eyeglasses attribute on)
```
./translate_one_image.py --config ../exps/celeba_blond_hair.yaml --image_name ../images/ian.jpg --output_image_name ../results/ian_to_eyeglasses.jpg --weights ../snapshots/celeba_eyeglasses_gen_00500000.pkl --a2b 0
```
![No-eyeglasses to eyeglasses](./results/ian_to_eyeglasses.jpg)

From smiling to neutral. (Turn smiling attribute off)
```
./translate_one_image.py --config ../exps/celeba_blond_hair.yaml --image_name ../images/ian.jpg --output_image_name ../results/ian_to_no_smiling.jpg --weights ../snapshots/celeba_smiling_gen_00500000.pkl --a2b 1
```
![Smiling to neutral](./results/ian_to_no_smiling.jpg)

### Example Results

[1] thermal IR image to color image translation (Left, input and right, translation.)
![](./docs/ir2vis.jpg)
![](./docs/vis2ir.jpg)

[2] rainy day image to sunny day image translation (Left, input and right, translation.)
![](./docs/rain2sunny.jpg)
![](./docs/sunny2rain.jpg)

[3] night time image to day time image translation (Left, input and right, translation.)
![](./docs/night2day.jpg)
![](./docs/day2night.jpg)

![](./docs/face_visualization.jpg)


### One Example

Training for attribute-based face image translation.

Please go to the [user manual page](README.md)
- Step 1. Download the file img_aligned_celeba.zip based on the instructions in [CelebA dataset](http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html) and unzip it to datasets/celeba/img_align_celeba/ folder
- Step 2. Crop and resize CelebA images.
```
cd datasets/celeba/
./crop_and_resize.py
```
- Step 3. Write an experiment config file. Follow the example config file in exps/celeba_blond_hair.yaml
- Step 4. Training
```
python train.py --config ../exps/celeba_blond_hair.yaml --log ../logs;
```
- Step 5. Testing
```
python translate_one_image.py --config ../exps/celeba_blond_hair.yaml --image ../images/032162.jpg --weights ../outputs/celeba_blond_hair/celeba_blond_hair_gen_00500000.pkl --a2b 0 --output ../results/032162_with_blond_hair.jpg
```
Binary file removed docs/Fog2Summer_SEQS-02-Stereo_Left-Omni_B.gif
Binary file not shown.
Binary file removed docs/Fog2Summer_SEQS-02-Stereo_Left-Omni_F.gif
Binary file not shown.
Binary file removed docs/Fog2Summer_SEQS-02-Stereo_Left-Omni_L.gif
Binary file not shown.
Binary file removed docs/Fog2Summer_SEQS-02-Stereo_Left-Omni_R.gif
Binary file not shown.
Binary file added docs/cat_trans.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/colored_edges_visualization.jpg
Binary file not shown.
Binary file removed docs/day2night.jpg
Binary file not shown.
Binary file added docs/dog_trans.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/face_visualization.jpg
Binary file not shown.
Binary file added docs/faces.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/ir2vis.jpg
Binary file not shown.
Binary file removed docs/night2day.jpg
Binary file not shown.
Binary file removed docs/rain2sunny.jpg
Binary file not shown.
Binary file removed docs/set01_v002.png
Binary file not shown.
Binary file added docs/street_scene.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/sunny2rain.jpg
Binary file not shown.
Binary file removed docs/vis2ir.jpg
Binary file not shown.

0 comments on commit 2556375

Please sign in to comment.