Skip to content

Commit

Permalink
Update image translation demo (PaddlePaddle#68)
Browse files Browse the repository at this point in the history
* update demo
  • Loading branch information
LielinJiang authored Nov 2, 2020
1 parent e54169d commit 896939b
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 22 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ PaddleGAN 是一个基于飞桨的生成对抗网络开发工具包.

### 图片变换
<div align='center'>
<img src='./docs/imgs/A2B.png'>
</div>
<div align='center'>
<img src='./docs/imgs/B2A.png'>
<img src='./docs/imgs/horse2zebra.gif'>
</div>

### 妆容迁移
Expand Down
5 changes: 1 addition & 4 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ PaddleGAN is an development kit of Generative Adversarial Network based on Paddl

### Image Translation
<div align='center'>
<img src='./docs/imgs/A2B.png'>
</div>
<div align='center'>
<img src='./docs/imgs/B2A.png'>
<img src='./docs/imgs/horse2zebra.gif'>
</div>


Expand Down
17 changes: 12 additions & 5 deletions docs/en_US/tutorials/pix2pix_cyclegan.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@

## 1.3 Results

![](../imgs/horse2zebra.png)
![](../../imgs/horse2zebra.png)

[model download](TODO)
## 1.4 模型下载
| 模型 | 数据集 | 下载地址 |
|---|---|---|
| Pix2Pix_cityscapes | cityscapes | [Pix2Pix_cityscapes](https://paddlegan.bj.bcebos.com/models/Pix2Pix_cityscapes.pdparams)



Expand All @@ -49,7 +52,7 @@

CycleGAN uses unpaired pictures for image translation, input two different images with different styles, and automatically perform style transfer. CycleGAN consists of two generators and two discriminators, generator A is inputting images of style A and outputting images of style B, generator B is inputting images of style B and outputting images of style A. The biggest difference between CycleGAN and pix2pix is that CycleGAN can realize image translation without establishing a one-to-one mapping between the source domain and the target domain.

![](../imgs/cyclegan.png)
![](../../imgs/cyclegan.png)

## 2.2 How to use

Expand Down Expand Up @@ -87,9 +90,13 @@

## 2.3 Results

![](../imgs/A2B.png)
![](../../imgs/A2B.png)

[model download](TODO)
## 2.4 模型下载
| 模型 | 数据集 | 下载地址 |
|---|---|---|
| CycleGAN_cityscapes | cityscapes | [CycleGAN_cityscapes](https://paddlegan.bj.bcebos.com/models/CycleGAN_cityscapes.pdparams) |
| CycleGAN_horse2zebra | horse2zebra | [CycleGAN_horse2zebra](https://paddlegan.bj.bcebos.com/models/CycleGAN_horse2zebra.pdparams)


# References
Expand Down
4 changes: 2 additions & 2 deletions docs/en_US/tutorials/psgan.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This paper is to address the makeup transfer task, which aims to transfer the ma

## 2. How to use
### 2.1 Test
Pretrained model can be downloaded under following link: [psgan_weight](https://paddlegan.bj.bcebos.com/models/psgan_weight.pkl)
Pretrained model can be downloaded under following link: [psgan_weight](https://paddlegan.bj.bcebos.com/models/psgan_weight.pdparams)

Running the following command to complete the makeup transfer task. It will geneate the transfered image in the current path when the program running sucessfully.

Expand Down Expand Up @@ -79,7 +79,7 @@ Notation: In train phase, the `isTrain` value in makeup.yaml file is `True`, but

Model|Dataset|BatchSize|Inference speed|Download
---|:--:|:--:|:--:|:--:
PSGAN|MT-Dataset| 1 | 1.9s/image (GPU:P40) | [model](https://paddlegan.bj.bcebos.com/models/psgan_weight.pkl)
PSGAN|MT-Dataset| 1 | 1.9s/image (GPU:P40) | [model](https://paddlegan.bj.bcebos.com/models/psgan_weight.pdparams)

## 3. Result
![](../../imgs/makeup_shifter.png)
Expand Down
Binary file added docs/imgs/horse2zebra.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions docs/zh_CN/tutorials/pix2pix_cyclegan.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@

![](../../imgs/horse2zebra.png)

[模型下载](TODO)
## 1.4 模型下载
| 模型 | 数据集 | 下载地址 |
|---|---|---|
| Pix2Pix_cityscapes | cityscapes | [Pix2Pix_cityscapes](https://paddlegan.bj.bcebos.com/models/Pix2Pix_cityscapes.pdparams)


# 2 CycleGAN
Expand Down Expand Up @@ -88,7 +91,11 @@

![](../../imgs/A2B.png)

[模型下载](TODO)
## 2.4 模型下载
| 模型 | 数据集 | 下载地址 |
|---|---|---|
| CycleGAN_cityscapes | cityscapes | [CycleGAN_cityscapes](https://paddlegan.bj.bcebos.com/models/CycleGAN_cityscapes.pdparams) |
| CycleGAN_horse2zebra | horse2zebra | [CycleGAN_horse2zebra](https://paddlegan.bj.bcebos.com/models/CycleGAN_horse2zebra.pdparams)


# 参考:
Expand Down
4 changes: 2 additions & 2 deletions docs/zh_CN/tutorials/psgan.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

## 2. 使用方法
### 2.1 测试
预训练模型可以从如下地址下载: [psgan_weight](https://paddlegan.bj.bcebos.com/models/psgan_weight.pkl)
预训练模型可以从如下地址下载: [psgan_weight](https://paddlegan.bj.bcebos.com/models/psgan_weight.pdparams)

运行如下命令,就可以完成妆容迁移,程序运行成功后,会在当前文件夹生成妆容迁移后的图片文件。本项目中提供了原始图片和参考供展示使用,具体命令如下所示:

Expand Down Expand Up @@ -75,7 +75,7 @@ data
### 2.3 模型
Model|Dataset|BatchSize|Inference speed|Download
---|:--:|:--:|:--:|:--:
PSGAN|MT-Dataset| 1 | 1.9s(GPU:P40) | [model](https://paddlegan.bj.bcebos.com/models/psgan_weight.pkl)
PSGAN|MT-Dataset| 1 | 1.9s(GPU:P40) | [model](https://paddlegan.bj.bcebos.com/models/psgan_weight.pdparams)

## 3. 妆容迁移结果展示

Expand Down
2 changes: 1 addition & 1 deletion ppgan/apps/psgan_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def mask2image(mask: np.array, format="HWC"):
return canvas


PS_WEIGHT_URL = "https://paddlegan.bj.bcebos.com/models/psgan_weight.pkl"
PS_WEIGHT_URL = "https://paddlegan.bj.bcebos.com/models/psgan_weight.pdparams"


class PreProcess:
Expand Down
5 changes: 3 additions & 2 deletions ppgan/engine/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def save(self, epoch, name='checkpoint', keep=1):
assert name in ['checkpoint', 'weight']

state_dicts = {}
save_filename = 'epoch_%s_%s.pkl' % (epoch, name)
save_filename = 'epoch_%s_%s.pdparams' % (epoch, name)
save_path = os.path.join(self.output_dir, save_filename)
for net_name, net in self.model.nets.items():
state_dicts[net_name] = net.state_dict()
Expand All @@ -275,7 +275,8 @@ def save(self, epoch, name='checkpoint', keep=1):
if keep > 0:
try:
checkpoint_name_to_be_removed = os.path.join(
self.output_dir, 'epoch_%s_%s.pkl' % (epoch - keep, name))
self.output_dir,
'epoch_%s_%s.pdparams' % (epoch - keep, name))
if os.path.exists(checkpoint_name_to_be_removed):
os.remove(checkpoint_name_to_be_removed)

Expand Down

0 comments on commit 896939b

Please sign in to comment.