get_started.md 5.9 KB
Newer Older
L
LielinJiang 已提交
1

2
# Quick Start
L
LielinJiang 已提交
3

4
PaddleGAN is a PaddlePaddle Generative Adversarial Network (GAN) development kit that provides a high-performance replication of a variety of classical networks with applications covering a wide range of areas such as image generation, style migration, ainimation driving, image/video super resolution and colorization.
L
LielinJiang 已提交
5

6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
This section will teach you how to quickly get started with PaddleGAN, using the  train and evaluate of the CycleGAN model on the Cityscapes dataset as an example.

Note that all model configuration files in PaddleGAN are available at [. /PaddleGAN/configs](https://github.com/PaddlePaddle/PaddleGAN/tree/develop/configs).

## Contents

* [Installation](#Installation)
* [Data preparation](#Data-preparation)
* [Training](#Trianing)
  * [Single Card Training](#Single-Card-Training)
    * [Parameters](#Parameters)
    * [Visualize Training](#Visualize-Training)
    * [Resume Training](#Resume-Training)
  * [Multi-Card Training](#Multi-Card-Training)
* [Evaluation](#Evaluation)

## Installation

For installation and configuration of the runtime environment, please refer to the [installation documentation](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/en_US/install.md) to complete the installation of PaddlePaddle and PaddleGAN.

In this demo, it is assumed that the user cloned and placed the code of PaddleGAN in the '/home/paddle' directory. The user executes the command operations in the '/home/paddle/PaddleGAN' directory.

## Data preparation

Prepare the Cityscapes dataset according to the [data preparation](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/en_US/data_prepare.md).

Download the Cityscapes dataset to ~/.cache/ppgan and softlink to PaddleGAN/data/ using the following script.
L
LielinJiang 已提交
33

L
LielinJiang 已提交
34
```
35
python data/download_cyclegan_data.py --name cityscapes
L
LielinJiang 已提交
36
```
37
## Trianing
L
LielinJiang 已提交
38

39
### 1. Single Card Training
L
LielinJiang 已提交
40 41

 ```
42
 python -u tools/main.py --config-file configs/cyclegan_cityscapes.yaml
L
LielinJiang 已提交
43 44
 ```

45 46 47 48 49
#### Parameters

* `--config-file (str)`: path to the config file. This is the configuration file used here for CycleGAN training on the Cityscapes dataset.

* The output logs, weights, and visualization results are saved by default in `. /output_dir`, which can be modified by the `output_dir` parameter in the configuration file:
L
LielinJiang 已提交
50

51 52 53 54 55 56 57 58 59
  ```
  output_dir: output_dir
  ```

  <div align='center'>
    <img src='https://user-images.githubusercontent.com/48054808/122734130-65448b00-d2b0-11eb-9fc4-302f3e851115.png' width=60%>
  </div>

* The saved folder will automatically generate a new directory based on the model name and timestamp, with the following directory example.
L
LielinJiang 已提交
60

L
LielinJiang 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
```
output_dir
└── CycleGANModel-2020-10-29-09-21
    ├── epoch_1_checkpoint.pkl
    ├── log.txt
    └── visual_train
        ├── epoch001_fake_A.png
        ├── epoch001_fake_B.png
        ├── epoch001_idt_A.png
        ├── epoch001_idt_B.png
        ├── epoch001_real_A.png
        ├── epoch001_real_B.png
        ├── epoch001_rec_A.png
        ├── epoch001_rec_B.png
        ├── epoch002_fake_A.png
        ├── epoch002_fake_B.png
        ├── epoch002_idt_A.png
        ├── epoch002_idt_B.png
        ├── epoch002_real_A.png
        ├── epoch002_real_B.png
        ├── epoch002_rec_A.png
        └── epoch002_rec_B.png
```
郑启航 已提交
84

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
#### Visualize Training

[VisualDL](https://github.com/PaddlePaddle/VisualDL) is a visual analysis tool developed for deep learning model development, providing real-time trend visualization of key metrics, sample training intermediate process visualization, network structure visualization, etc. It can visually show the relationship between the effects of super participant models and assist in efficient tuning.

Please make sure that you have installed [VisualDL](https://github.com/PaddlePaddle/VisualDL). Refer to the [VisualDL installation guide](https://github.com/PaddlePaddle/VisualDL/blob/develop/README.md#Installation).

Use the [VisualDL](https://github.com/PaddlePaddle/VisualDL) to record the metrics or images generated by the training process by adding the command `enable_visualdl: True` to the configuration file cyclegan_cityscapes.yaml, and run the corresponding command to monitor the training process in real time.

<div align='center'>
  <img src='https://user-images.githubusercontent.com/48054808/122736527-b786ab80-d2b2-11eb-96f8-235f6bbfba5a.png' width=60%>
</div>



If you want to customize the content of the [VisualDL](https://github.com/PaddlePaddle/VisualDL) visualization, you can go to . /PaddleGAN/ppgan/engine/trainer.py.

Launch  [VisualDL](https://github.com/PaddlePaddle/VisualDL) locally by:

郑启航 已提交
103 104 105 106
```
visualdl --logdir output_dir/CycleGANModel-2020-10-29-09-21/
```

107 108 109 110 111 112 113 114 115 116 117
Please refer to the [VisualDL User's Guide](https://github.com/PaddlePaddle/VisualDL/blob/develop/docs/components/README.md) for more guidance on how to start and use those visualization functions.

#### Resume Training

The checkpoint of the previous epoch is saved in `output_dir` by default during the training process to facilitate resuming the training.

In this demo, cyclegan's training will save checkpoint every five epochs by default, and if you want to change the number of epochs, you can go to the **config file to adjust the `interval` paramter**.

<div align='center'>
  <img src='https://user-images.githubusercontent.com/48054808/122886954-fda34400-d372-11eb-91a0-cd0e8328335f.png' width=60%>
</div>
L
LielinJiang 已提交
118

L
LielinJiang 已提交
119 120 121
```
python -u tools/main.py --config-file configs/cyclegan_cityscapes.yaml --resume your_checkpoint_path
```
L
LielinJiang 已提交
122 123
- `--resume (str)`: path of checkpoint。

124 125
### 2. Multi-Card Training

L
LielinJiang 已提交
126
```
L
LielinJiang 已提交
127
CUDA_VISIBLE_DEVICES=0,1 python -m paddle.distributed.launch tools/main.py --config-file configs/cyclegan_cityscapes.yaml
L
LielinJiang 已提交
128 129
```

130
## Evaluation
L
LielinJiang 已提交
131 132 133
```
python tools/main.py --config-file configs/cyclegan_cityscapes.yaml --evaluate-only --load your_weight_path
```
L
LielinJiang 已提交
134 135

#### Args
136 137 138
- `--evaluate-only`: If or not to make predictions only
- `--load (str)`: path of the weight