Skip to content

Add the instruction of using configs and optimize the tutorials of fom, lapstyle and data preparation #407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
6536ebd
revise video restore docs
YixinKristy May 25, 2021
e5221c2
delete photos
YixinKristy May 25, 2021
36af615
Update README.md
YixinKristy May 25, 2021
6cdceb0
Update install.md
YixinKristy May 25, 2021
4a0ac40
update readme
YixinKristy May 25, 2021
7c0b73f
Update README.md
YixinKristy May 25, 2021
9a2f4bc
Update get_started.md
YixinKristy May 26, 2021
60ff5b4
Merge branch 'develop' into develop
YixinKristy May 31, 2021
64f5f17
Update get_started.md
YixinKristy May 31, 2021
e172961
Update readme en
YixinKristy Jun 22, 2021
5dbd446
Merge branch 'develop' into develop
YixinKristy Jun 22, 2021
8d31848
Update get_started.md
YixinKristy Jun 22, 2021
9d2af9a
Update photo_color_en.md
YixinKristy Jun 30, 2021
51f38a1
add wechaty demo
YixinKristy Jul 7, 2021
9adc554
Update README.md
YixinKristy Jul 7, 2021
3dfdc9d
Merge branch 'PaddlePaddle:develop' into develop
YixinKristy Jul 7, 2021
da7329a
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleGAN i…
YixinKristy Jul 12, 2021
c811c3e
Merge branch 'develop' of https://github.com/YixinKristy/PaddleGAN in…
YixinKristy Jul 12, 2021
e49c0cb
Update README_cn.md
YixinKristy Jul 19, 2021
8d780b3
Update README_cn.md
YixinKristy Jul 19, 2021
6cb5236
Update README_cn.md
YixinKristy Jul 19, 2021
e96f172
Update README_cn.md
YixinKristy Jul 19, 2021
8810ed0
Merge branch 'PaddlePaddle:develop' into develop
YixinKristy Jul 19, 2021
01f37c5
Merge branch 'PaddlePaddle:develop' into develop
YixinKristy Jul 29, 2021
d9d842a
Update README_cn.md
YixinKristy Jul 29, 2021
6734105
Update motion_driving.md
YixinKristy Jul 29, 2021
b2e92d7
Merge branch 'PaddlePaddle:develop' into develop
YixinKristy Aug 11, 2021
f02f231
Update README_cn.md
YixinKristy Aug 11, 2021
4a9be03
Merge branch 'PaddlePaddle:develop' into develop
YixinKristy Aug 12, 2021
352fa05
Update README_cn.md
YixinKristy Aug 12, 2021
c81298d
Merge branch 'PaddlePaddle:develop' into develop
YixinKristy Aug 16, 2021
8533f41
Update README.md
YixinKristy Aug 16, 2021
f89d61a
Merge branch 'develop' of https://github.com/YixinKristy/PaddleGAN in…
YixinKristy Aug 16, 2021
7fe506b
Update README.md
YixinKristy Aug 16, 2021
9318b9b
Merge branch 'PaddlePaddle:develop' into develop
YixinKristy Aug 18, 2021
b9cf66c
Add paint transfer from vis
YixinKristy Aug 18, 2021
a68d099
Update README.md
YixinKristy Aug 18, 2021
54def3b
Create README.md
YixinKristy Aug 18, 2021
76415b0
Merge branch 'PaddlePaddle:develop' into develop
YixinKristy Aug 23, 2021
6620f53
update readme
YixinKristy Aug 23, 2021
91cfb84
Update README_cn.md
YixinKristy Aug 23, 2021
2fe0ce8
Update lap_style.md
YixinKristy Aug 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ GAN--生成对抗网络,被“卷积网络之父”**Yann LeCun(杨立昆)
<img src='https://user-images.githubusercontent.com/48054808/129904830-8b87e310-ea51-4aff-b29b-88920ee82447.png' width='700'/>
</div>

##

## 文档教程

### 安装
Expand All @@ -88,6 +86,7 @@ GAN--生成对抗网络,被“卷积网络之父”**Yann LeCun(杨立昆)
- [快速开始](./docs/zh_CN/get_started.md)
- [数据准备](./docs/zh_CN/data_prepare.md)
- [API接口使用文档](./docs/zh_CN/apis/apps.md)
- [配置文件/Config使用说明](./docs/zh_CN/config_doc.md)

## 模型库

Expand Down
77 changes: 77 additions & 0 deletions docs/zh_CN/config_doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# 配置文件说明文档

## Config文件参数介绍

以`lapstyle_rev_first.yaml`为例。

### Global

| 字段 | 用途 | 默认值 |
| ------------------------- | -------------------------- | --------------- |
| total_iters | 设置总训练步数 | 30000 |
| min_max | tensor数值范围(存图像时使用) | (0., 1.) |
| output_dir | 设置输出结果所在的文件路径 | ./output_dir |
| snapshot_config: interval | 设置保存模型参数的间隔 | 5000 |

### Model

| 字段 | 用途 | 默认值 |
| :---------------------- | -------- | ------ |
| name | 模型名称 | LapStyleRevFirstModel |
| revnet_generator | 设置revnet生成器 | RevisionNet |
| revnet_discriminator | 设置revnet判别器 | LapStyleDiscriminator |
| draftnet_encode | 设置draftnet编码器 | Encoder |
| draftnet_decode | 设置draftnet解码器 | DecoderNet |
| calc_style_emd_loss | 设置style损失1 | CalcStyleEmdLoss |
| calc_content_relt_loss | 设置content损失1 | CalcContentReltLoss |
| calc_content_loss | 设置content损失2 | CalcContentLoss |
| calc_style_loss | 设置style损失2 | CalcStyleLoss |
| gan_criterion: name | 设置GAN损失 | GANLoss |
| gan_criterion: gan_mode | 设置GAN损失模态参数 | vanilla |
| content_layers | 设置计算content损失2的网络层 |['r11', 'r21', 'r31', 'r41', 'r51']|
| style_layers | 设置计算style损失2的网络层 | ['r11', 'r21', 'r31', 'r41', 'r51'] |
| content_weight | 设置content总损失权重 | 1.0 |
| style_weigh | 设置style总损失权重 | 3.0 |

### Dataset (train & test)

| 字段 | 用途 | 默认值 |
| :----------- | -------------------- | -------------------- |
| name | 数据集名称 | LapStyleDataset |
| content_root | 数据集所在路径 | data/coco/train2017/ |
| style_root | 目标风格图片所在路径 | data/starrynew.png |
| load_size | 输入图像resize后图像大小 | 280 |
| crop_size | 随机剪裁图像后图像大小 | 256 |
| num_workers | 设置工作进程个数 | 16 |
| batch_size | 设置一次训练所抓取的数据样本数量 | 5 |

### Lr_scheduler

| 字段 | 用途 | 默认值 |
| :------------ | ---------------- | -------------- |
| name | 学习策略名称 | NonLinearDecay |
| learning_rate | 设置初始学习率 | 1e-4 |
| lr_decay | 设置学习率衰减率 | 5e-5 |

### Optimizer

| 字段 | 用途 | 默认值 |
| :-------- | ---------- | ------- |
| name | 优化器类名 | Adam |
| net_names | 优化器作用的网络 | net_rev |
| beta1 | 设置优化器参数beta1 | 0.9 |
| beta2 | 设置优化器参数beta2 | 0.999 |

### Validate

| 字段 | 用途 | 默认值 |
| :------- | ---- | ------ |
| interval | 设置验证间隔 | 500 |
| save_img | 验证时是否保存图像 | false |

### Log_config

| 字段 | 用途 | 默认值 |
| :--------------- | ---- | ------ |
| interval | 设置打印log间隔 | 10 |
| visiual_interval | 设置训练过程中保存生成图像的间隔 | 500 |
68 changes: 45 additions & 23 deletions docs/zh_CN/data_prepare.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## 数据准备
# 数据准备

## 1. 数据集路径配置

现有的配置默认数据集的路径是在`$PaddleGAN/data`下,目录结构如下图所示。如果你已经下载好数据集了,建议将数据集软链接到 `$PaddleGAN/data`。

Expand Down Expand Up @@ -39,52 +41,72 @@ dataset:
num_workers: 4
```

### CycleGAN模型相关的数据集下载
## 2. 准备数据集

### 2.1 下载数据集

#### 2.1.1 CycleGAN模型相关的数据集下载

- #### 从网页下载

#### 从网页下载

cyclgan模型相关的数据集可以在[这里](https://people.eecs.berkeley.edu/~taesung_park/CycleGAN/datasets/)下载
CycleGAN模型相关的数据集可以在[这里](https://people.eecs.berkeley.edu/~taesung_park/CycleGAN/datasets/)下载,下载后记得软连接到 ```PaddleGAN/data/``` 下。

- #### 使用脚本下载

#### 使用脚本下载

我们在 ```PaddleGAN/data``` 文件夹下提供了一个脚本 ```download_cyclegan_data.py``` 方便下载CycleGAN相关的
数据集。执行如下命令可以下载相关的数据集,目前支持的数据集名称有:apple2orange, summer2winter_yosemite,horse2zebra, monet2photo, cezanne2photo, ukiyoe2photo, vangogh2photo, maps, cityscapes, facades, iphone2dslr_flower, ae_photos, cityscapes。
数据集。

目前支持下载的数据集名称有:apple2orange, summer2winter_yosemite,horse2zebra, monet2photo, cezanne2photo, ukiyoe2photo, vangogh2photo, maps, cityscapes, facades, iphone2dslr_flower, ae_photos, cityscapes

执行如下命令,可以下载对应的数据集到 ```~/.cache/ppgan``` 并软连接到 ```PaddleGAN/data/``` 下。

```
python data/download_cyclegan_data.py --name horse2zebra
```

#### 使用自己的数据集
如果你使用自己的数据集,需要构造成如下目录的格式。注意 ```xxxA```,```xxxB```文件数量,文件内容无需一一对应。
```
custom_datasets
├── testA
├── testB
├── trainA
└── trainB
```
#### 2.1.2 Pix2Pix相关的数据集下载

### Pix2Pix相关的数据集下载
- #### 从网页下载

#### 从网页下载

pixel2pixel模型相关的数据集可以在[这里](https://people.eecs.berkeley.edu/~tinghuiz/projects/pix2pix/datasets/)下载
pixel2pixel模型相关的数据集可以在[这里](https://people.eecs.berkeley.edu/~tinghuiz/projects/pix2pix/datasets/)下载,下载后记得软连接到 ```PaddleGAN/data/``` 下。

#### 使用脚本下载
- #### 使用脚本下载

我们在 ```PaddleGAN/data``` 文件夹下提供了一个脚本 ```download_pix2pix_data.py``` 方便下载pix2pix模型相关的数据集。执行如下命令可以下载相关的数据集,目前支持的数据集名称有:apple2orange, summer2winter_yosemite,horse2zebra, monet2photo, cezanne2photo, ukiyoe2photo, vangogh2photo, maps, cityscapes, facades, iphone2dslr_flower, ae_photos, cityscapes。

执行如下命令,可以下载对应的数据集到 ```~/.cache/ppgan``` 并软连接到 ```PaddleGAN/data/``` 下。
我们在 ```PaddleGAN/data``` 文件夹下提供了一个脚本 ```download_pix2pix_data.py``` 方便下载pix2pix模型相关的数据集。

目前支持下载的数据集名称有:apple2orange, summer2winter_yosemite,horse2zebra, monet2photo, cezanne2photo, ukiyoe2photo, vangogh2photo, maps, cityscapes, facades, iphone2dslr_flower, ae_photos, cityscapes。

同理,执行如下命令,可以下载对应的数据集到 ```~/.cache/ppgan``` 并软连接到 ```PaddleGAN/data/``` 下。

```
python data/download_pix2pix_data.py --name cityscapes
```

#### 使用自己的数据集
### 2.2 自制数据集

#### 2.2.1非成对数据集构建

针对不需成对数据训练的模型,如CycleGAN等,如需使用自己的数据集,需要构造成如下目录的格式。

注意 ```xxxA```,```xxxB```文件数量,文件内容无需一一对应。

```
custom_datasets
├── testA
├── testB
├── trainA
└── trainB
```

### 2.2.2 成对数据集构建

针对需要成对数据训练的模型,如Pixel2Pixel等,如需使用自己的数据集,需要构造成如下目录的格式。

如果你使用自己的数据集,需要构造成如下目录的格式。同时图片应该制作成下图的样式,即左边为一种风格,另一边为相应转换的风格。
注意图片应该制作成下图的样式,即左边为一种风格,另一边为相应转换的风格。

```
facades
Expand Down
44 changes: 32 additions & 12 deletions docs/zh_CN/tutorials/lap_style.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@

# LapStyle

这个repo提供CVPR2021论文"Drafting and Revision: Laplacian Pyramid Network for Fast High-Quality Artistic Style Transfer"的官方代码
**LapStyle--拉普拉斯金字塔风格化网络**,是一种能够生成高质量风格化图的快速前馈风格化网络,能渐进地生成复杂的纹理迁移效果,同时能够在**512分辨率**下达到**100fps**的速度。可实现多种不同艺术风格的快速迁移,在艺术图像生成、滤镜等领域有广泛的应用

## 1 论文介绍
本文档提供CVPR2021论文"Drafting and Revision: Laplacian Pyramid Network for Fast High-Quality Artistic Style Transfer"的官方代码。

## 1. 论文介绍

艺术风格迁移的目的是将一个实例图像的艺术风格迁移到一个内容图像。目前,基于优化的方法已经取得了很好的合成质量,但昂贵的时间成本限制了其实际应用。

同时,前馈方法仍然不能合成复杂风格,特别是存在全局和局部模式时。受绘制草图和修改细节这一常见绘画过程的启发,[论文](https://arxiv.org/pdf/2104.05376.pdf) 提出了一种新的前馈方法拉普拉斯金字塔网络(LapStyle)。

LapStyle首先通过绘图网络(Drafting Network)传输低分辨率的全局风格模式。然后通过修正网络(Revision Network)对局部细节进行高分辨率的修正,它根据拉普拉斯滤波提取的图像纹理和草图产生图像残差。通过叠加具有多个拉普拉斯金字塔级别的修订网络,可以很容易地生成更高分辨率的细节。最终的样式化图像是通过聚合所有金字塔级别的输出得到的。论文还引入了一个补丁鉴别器,以更好地对抗的学习局部风格。实验表明,该方法能实时合成高质量的风格化图像,并能正确生成整体风格模式。

![lapstyle_overview](https://user-images.githubusercontent.com/79366697/118654987-b24dc100-b81b-11eb-9430-d84630f80511.png)

## 2. 快速体验

PaddleGAN为大家提供了四种不同艺术风格的预训练模型,风格预览如下:

| 原图 | StarryNew | Stars | Ocean | Circuit |
| :----------------------------------------------------------: | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
| <img src='https://user-images.githubusercontent.com/48054808/130388598-1e2b27e7-be66-49df-84d5-57b4dc7730d6.png' width='300'/> | <img src='https://user-images.githubusercontent.com/48054808/130388606-78a3a682-2ae4-4753-a07c-671a46930de8.png' width='300'/> | <img src='https://user-images.githubusercontent.com/48054808/130388615-b04197b3-2fdf-4494-ad17-490afe0fd1cd.png' width='300'/> | <img src='https://user-images.githubusercontent.com/48054808/130388623-2eec0cca-fee1-47f0-8398-cae0171aa7a5.png' width='300'/> | <img src='https://user-images.githubusercontent.com/48054808/130388624-f27d0712-ba71-42b2-ada4-44bf60e36512.png' width='300'/> |

只需运行下面的代码即可迁移至指定风格:

## 2 快速体验
```
python applications/tools/lapstyle.py --content_img ${PATH_OF_CONTENT_IMG}
```
Expand All @@ -24,7 +36,9 @@ python applications/tools/lapstyle.py --content_img ${PATH_OF_CONTENT_IMG}
- `--style (str)`: 生成图像风格,当`weight_path`为`None`时,可以在`starrynew`, `circuit`, `ocean` 和 `stars`中选择,默认为`starrynew`。
- `--style_image_path (str)`: 输入的风格图像路径,当`weight_path`不为`None`时需要输入,默认为`None`。

## 3 如何使用
## 3. 模型训练

配置文件参数详情:[Config文件使用说明](../config_doc.md)

### 3.1 数据准备

Expand All @@ -34,32 +48,38 @@ python applications/tools/lapstyle.py --content_img ${PATH_OF_CONTENT_IMG}

示例以COCO数据为例。如果您想使用自己的数据集,可以在配置文件中修改数据集为您自己的数据集。

注意,LapStyle模型训练暂时不支持Windows系统。
<div align="center">
<img src="https://user-images.githubusercontent.com/48054808/130389113-981ef29c-12ac-4fcd-9a2c-c7fcbc7031be.png" width="300"/>
</div>



**注意,LapStyle模型训练暂时不支持Windows系统。**

(1) 首先在128*128像素下训练LapStyle的绘图网络(Drafting Network):
(1) 首先在128*128像素下训练LapStyle的绘图网络(**Drafting Network**):
```
python -u tools/main.py --config-file configs/lapstyle_draft.yaml
```

(2) 然后,在256*256像素下训练LapStyle的修正网络(Revision Network):
(2) 然后,在256*256像素下训练LapStyle的修正网络(**Revision Network**):
```
python -u tools/main.py --config-file configs/lapstyle_rev_first.yaml --load ${PATH_OF_LAST_STAGE_WEIGHT}
```

(3) 最后,在512*512像素下再次训练LapStyle的修正网络(Revision Network):
(3) 最后,在512*512像素下再次训练LapStyle的修正网络(**Revision Network**):
```
python -u tools/main.py --config-file configs/lapstyle_rev_second.yaml --load ${PATH_OF_LAST_STAGE_WEIGHT}
```

### 3.4 测试
### 3.3 测试

测试时需要将配置文件中的`validate/save_img`参数改成`True`以保存输出图像。
测试训练好的模型,您可以直接测试 "lapstyle_rev_second",因为它包含了之前步骤里的训练权重:
```
python tools/main.py --config-file configs/lapstyle_rev_second.yaml --evaluate-only --load ${PATH_OF_WEIGHT}
```

## 4 结果展示
## 4. 结果展示

| Style | Stylized Results |
| --- | --- |
Expand All @@ -69,9 +89,9 @@ python tools/main.py --config-file configs/lapstyle_rev_second.yaml --evaluate-o
| ![circuit](https://user-images.githubusercontent.com/79366697/118655399-196b7580-b81c-11eb-8bc5-d5ece80c18ba.jpg) | ![chicago_stylized_circuit](https://user-images.githubusercontent.com/79366697/118655660-56376c80-b81c-11eb-87f2-64ae5a82375c.png)|


## 5 模型下载
## 5. 模型下载

我们提供几个训练好的权重。
PaddleGAN中提供四个风格的预训练模型下载:

| 模型 | 风格 | 下载地址 |
|---|---|---|
Expand Down
16 changes: 8 additions & 8 deletions docs/zh_CN/tutorials/motion_driving.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ First Order Motion的任务是图像动画/Image Animation,即输入为一张
- 👨**父亲节特辑**:https://aistudio.baidu.com/aistudio/projectdetail/2068655

## 使用方法
### 1. 人脸检测与效果增强
### 1. 快速体验:人脸检测与效果增强
用户可上传一张单人/多人照片与驱动视频,并在如下命令中的`source_image`参数和`driving_video`参数分别换成自己的图片和视频路径,然后运行如下命令,即可完成单人/多人脸动作表情迁移,运行结果为命名为result.mp4的视频文件,保存在output文件夹中。

注意:使用多人脸时,尽量使用人脸间距较大的照片,效果更佳,也可通过手动调节ratio进行效果优化。
Expand Down Expand Up @@ -132,7 +132,7 @@ python -m paddle.distributed.launch \
</div>


### 2. 模型压缩
### 3. 模型压缩
数据处理同上述,模型分为kp_detector和generator,首先固定原始generator部分,训练压缩版的kp_detector部分,然后固定原始kp_detector部分,去训练generator部分,最后将两个压缩的模型一起训练,同时添加中间的蒸馏loss。

**预测:**
Expand All @@ -153,8 +153,8 @@ python -u tools/first-order-demo.py \
| 原始 | 229 | 0.012058867 |
| 压缩 | 6.1 | 0.015025159 |

### 3. 模型部署
#### 3.1 导出模型
### 4. 模型部署
#### 4.1 导出模型
使用`tools/fom_export.py`脚本导出模型已经部署时使用的配置文件,配置文件名字为`firstorder_vox_mobile_256.yml`。模型导出脚本如下:
```bash
# 导出FOM模型
Expand All @@ -171,12 +171,12 @@ python tools/export_model.py \
预测模型会导出到`output_inference/fom_dy2st/`目录下,分别为`model.pdiparams`, `model.pdiparams.info`, `model.pdmodel`。


#### 3.3 PaddleLite部署
- [使用PaddleLite部署FOM模型](./lite/README.md)
#### 4.2 PaddleLite部署
- [使用Paddle Lite部署FOM模型](./lite/README.md)
- [FOM-Lite-Demo](https://paddlegan.bj.bcebos.com/applications/first_order_model/paddle_lite/apk/face_detection_demo%202.zip)。更多内容,请参考[Paddle-Lite](https://github.com/PaddlePaddle/Paddle-Lite)
目前问题:
(a).paddlelite运行效果略差于inference,正在优化中
(b).单线程跑generator,帧数多了会跑到小核不跑大核
(a).Paddle Lite运行效果略差于Paddle Inference,正在优化中
(b).单线程跑Generator,帧数多了会跑到小核不跑大核

## 参考文献

Expand Down