1
+ # 快速开始
1
2
2
- ## 快速开始使用PaddleGAN
3
+ PaddleGAN是飞桨生成对抗网络(GAN)开发套件,提供多种经典前沿网络的高性能复现,应用覆盖图像生成、风格迁移、动作驱动、影像超分及上色等多种领域。
3
4
4
- 注意:
5
- * 开始使用PaddleGAN前请确保已经阅读过[ 安装文档] ( ./install.md ) ,并根据[ 数据准备文档] ( ./data_prepare.md ) 准备好数据集。
6
- * 以下教程以CycleGAN模型在Cityscapes数据集上的训练预测作为示例。
5
+ 本章节将以CycleGAN模型在Cityscapes数据集上的训练预测作为示例,教大家如何快速上手使用PaddleGAN。
7
6
7
+ ** 注意,PaddleGAN中所有的模型配置文件均可在 [ ./PaddleGAN/configs] ( https://github.com/PaddlePaddle/PaddleGAN/tree/develop/configs ) 中找到。**
8
8
9
- ### 训练
9
+ ## 目录
10
+ - [ 安装] ( #安装 )
11
+ - [ 数据准备] ( #数据准备 )
12
+ - [ 训练] ( #训练 )
13
+ - [ 单卡训练] ( #1-单卡训练 )
14
+ - [ 参数] ( #参数 )
15
+ - [ 可视化训练] ( #可视化训练 )
16
+ - [ 恢复训练] ( #恢复训练 )
17
+ - [ 多卡训练] ( #2-多卡训练 )
18
+ - [ 预测] ( #预测 )
19
+
20
+ ## 安装
21
+
22
+ 关于安装配置运行环境,请参考[ 安装文档] ( ./install.md ) 完成Paddle及PaddleGAN的安装。
23
+
24
+ 在本演示案例中,假设用户将PaddleGAN的代码克隆并放置在 ’/home/paddle‘ 目录中。用户执行的命令操作均在 ’/home/paddle/PaddleGAN‘ 目录下完成。
25
+
26
+
27
+ ## 数据准备
28
+
29
+ 按照[ 数据准备文档] ( ./data_prepare.md ) 准备Cityscapes数据集。
30
+
31
+ - 使用脚本下载Cityscapes数据集到 ~ /.cache/ppgan 并软连接到 PaddleGAN/data/ 下:
32
+
33
+ ```
34
+ python data/download_cyclegan_data.py --name cityscapes
35
+ ```
36
+
37
+ ## 训练
38
+
39
+ ### 1. 单卡训练
10
40
11
- #### 单卡训练
12
41
```
13
42
python -u tools/main.py --config-file configs/cyclegan_cityscapes.yaml
14
43
```
44
+
15
45
#### 参数
46
+ - ` --config-file (str) ` : 配置文件的路径。此处用的是CycleGAN在Cityscapes数据集上训练的配置文件。
47
+ - 输出的日志,权重,可视化结果会默认保存在` ./output_dir ` 中,可以通过配置文件中的` output_dir ` 参数修改:
48
+
49
+ ```
50
+ output_dir: output_dir
51
+ ```
52
+ <div align =' center ' >
53
+ <img src =' https://user-images.githubusercontent.com/48054808/119620857-0b2ee200-be38-11eb-83c3-9c5c4c4cbedf.png ' width =60% >
54
+ </div >
16
55
17
- - ` --config-file (str) ` : 配置文件的路径。
18
56
19
- 输出的日志,权重,可视化结果会默认保存在``` ./output_dir ``` 中,可以通过配置文件中的``` output_dir ``` 参数修改:
20
- ```
21
- output_dir: output_dir
22
- ```
57
+ - 保存的文件夹会根据模型名字和时间戳自动生成一个新目录,目录示例如下:
23
58
24
- 保存的文件夹会根据模型名字和时间戳自动生成一个新目录,目录示例如下:
25
59
```
26
60
output_dir
27
61
└── CycleGANModel-2020-10-29-09-21
@@ -44,32 +78,55 @@ output_dir
44
78
├── epoch002_real_B.png
45
79
├── epoch002_rec_A.png
46
80
└── epoch002_rec_B.png
81
+
47
82
```
48
- 同时可以通过在配置文件中添加参数``` enable_visualdl: true ``` 使用[ 飞桨VisualDL] ( https://github.com/PaddlePaddle/VisualDL ) 对训练过程产生的指标或生成的图像进行记录,并运行相应命令对训练过程进行实时监控:
83
+
84
+ #### 可视化训练
85
+
86
+ [ 飞桨VisualDL] ( https://github.com/PaddlePaddle/VisualDL ) 是针对深度学习模型开发所打造的可视化分析工具,提供关键指标的实时趋势可视化、样本训练中间过程可视化、网络结构可视化等等,更能直观展示超参与模型效果间关系,辅助实现高效调参。
87
+
88
+ 以下操作请确保您已完成[ VisualDL] ( https://github.com/PaddlePaddle/VisualDL ) 的安装,安装指南请见[ VisualDL安装文档] ( https://github.com/PaddlePaddle/VisualDL/blob/develop/README_CN.md#%E5%AE%89%E8%A3%85%E6%96%B9%E5%BC%8F ) 。
89
+
90
+ ** 通过在配置文件 cyclegan_cityscapes.yaml 中添加参数` enable_visualdl: true ` 使用 [ 飞桨VisualDL] ( https://github.com/PaddlePaddle/VisualDL ) 对训练过程产生的指标或生成的图像进行记录,并运行相应命令对训练过程进行实时监控:**
91
+
92
+ <div align =' center ' >
93
+ <img src =' https://user-images.githubusercontent.com/48054808/119621184-68c32e80-be38-11eb-9830-95429db787cf.png ' width =60% >
94
+ </div >
95
+
96
+ 如果想要自定义[ 飞桨VisualDL] ( https://github.com/PaddlePaddle/VisualDL ) 可视化内容,可以到 [ ./PaddleGAN/ppgan/engine/trainer.py] ( https://github.com/PaddlePaddle/PaddleGAN/blob/develop/ppgan/engine/trainer.py ) 中进行修改。
97
+
98
+ 本地启动命令:
99
+
49
100
```
50
101
visualdl --logdir output_dir/CycleGANModel-2020-10-29-09-21/
51
102
```
103
+ 更多启动方式及可视化功能使用指南请见[ VisualDL使用指南] ( https://github.com/PaddlePaddle/VisualDL/blob/develop/docs/components/README_CN.md ) 。
52
104
53
105
#### 恢复训练
54
106
55
- 训练过程中默认会保存上一个epoch的checkpoint,方便恢复训练
107
+ 在训练过程中默认会** 保存上一个epoch的checkpoint在` output_dir ` 中,方便恢复训练。**
108
+
109
+ 本次示例中,cyclegan的训练默认** 每五个epoch会保存checkpoint** ,如需更改,可以到** config文件中的` interval ` ** 进行修改。
110
+
111
+ <div align =' center ' >
112
+ <img src =' https://user-images.githubusercontent.com/48054808/120147997-2758c780-c21a-11eb-9cf1-4288dbc01d22.png ' width =60% >
113
+ </div >
114
+
56
115
```
57
116
python -u tools/main.py --config-file configs/cyclegan_cityscapes.yaml --resume your_checkpoint_path
58
117
```
59
- #### 参数
118
+ - ` --resume (str) ` : 用来恢复训练的checkpoint路径(保存于上面配置文件中设置的output所在路径)。
60
119
61
- - ` --resume (str) ` : 用来恢复训练的checkpoint路径。
120
+ ### 2. 多卡训练
62
121
63
- #### 多卡训练:
64
122
```
65
123
CUDA_VISIBLE_DEVICES=0,1 python -m paddle.distributed.launch tools/main.py --config-file configs/cyclegan_cityscapes.yaml
66
124
```
67
125
68
- ### 预测
126
+ ## 预测
127
+
69
128
```
70
129
python tools/main.py --config-file configs/cyclegan_cityscapes.yaml --evaluate-only --load your_weight_path
71
130
```
72
-
73
- #### 参数
74
131
- ` --evaluate-only ` : 是否仅进行预测。
75
132
- ` --load (str) ` : 训练好的权重路径。
0 commit comments