Skip to content
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

Add PReNet to PaddleGan #617

Merged
merged 16 commits into from
May 9, 2022
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ GAN-Generative Adversarial Network, was praised by "the Father of Convolutional
<div align='center'>
<img src='https://user-images.githubusercontent.com/48054808/144848981-00c6ad21-0702-4381-9544-becb227ed9f0.gif' width='300'/>
</div>

- 😍 **Boy or Girl?:[StyleGAN V2 Face Editing](./docs/en_US/tutorials/styleganv2editing.md)-Changing genders!** 😍
- **[Online Toturials](https://aistudio.baidu.com/aistudio/projectdetail/2565277?contributionType=1)**
<div align='center'>
Expand Down Expand Up @@ -118,6 +118,7 @@ GAN-Generative Adversarial Network, was praised by "the Father of Convolutional
* [StarGANv2](docs/en_US/tutorials/starganv2.md)
* [MPR Net](./docs/en_US/tutorials/mpr_net.md)
* [FaceEnhancement](./docs/en_US/tutorials/face_enhancement.md)
* [PReNet](./docs/en_US/tutorials/prenet.md)


## Composite Application
Expand Down
3 changes: 2 additions & 1 deletion README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ GAN--生成对抗网络,被“卷积网络之父”**Yann LeCun(杨立昆)

## 近期活动🔥🔥🔥


- 🔥**2021.12.08**🔥
**💙 AI快车道👩‍🏫:视频超分算法及行业应用 💙**
- **课程回放链接🔗:https://aistudio.baidu.com/aistudio/education/group/info/25179**
Expand Down Expand Up @@ -140,6 +140,7 @@ GAN--生成对抗网络,被“卷积网络之父”**Yann LeCun(杨立昆)
* 图像视频修复
* 图像去模糊去噪去雨:[MPR Net](./docs/zh_CN/tutorials/mpr_net.md)
* 视频去模糊:[EDVR](./docs/zh_CN/tutorials/video_super_resolution.md)
* 图像去雨:[PReNet](./docs/zh_CN/tutorials/prenet.md)

## 产业级应用

Expand Down
98 changes: 98 additions & 0 deletions configs/prenet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
total_iters: 300000
output_dir: output_dir
find_unused_parameters: True
checkpoints_dir: checkpoints
use_dataset: True
# tensor range for function tensor2img
min_max:
(0., 1.)

model:
name: PReNetModel
generator:
name: PReNet
pixel_criterion:
name: SSIM

dataset:
train:
name: SRDataset
gt_folder: data/RainTrainH/norain
lq_folder: data/RainTrainH/rain
num_workers: 4
batch_size: 16
scale: 1
preprocess:
- name: LoadImageFromFile
key: lq
- name: LoadImageFromFile
key: gt
- name: Transforms
input_keys: [lq, gt]
pipeline:
- name: PairedRandomHorizontalFlip
keys: [image, image]
- name: PairedRandomVerticalFlip
keys: [image, image]
- name: PairedRandomTransposeHW
keys: [image, image]
- name: PairedRandomCrop
size: [100, 100]
keys: [image, image]
- name: PairedToTensor
keys: [image, image]
test:
name: SRDataset
gt_folder: data/Rain100H/norain
lq_folder: data/Rain100H/rain
scale: 1
preprocess:
- name: LoadImageFromFile
key: lq
- name: LoadImageFromFile
key: gt
- name: Transforms
input_keys: [lq, gt]
pipeline:
- name: PairedToTensor
keys: [image, image]


lr_scheduler:
name: MultiStepDecay
learning_rate: 0.0013
milestones: [36000,60000,96000]
gamma: 0.2

optimizer:
name: Adam
# add parameters of net_name to optim
# name should in self.nets
net_names:
- generator
beta1: 0.9
beta2: 0.99

validate:
interval: 5000
save_img: false

metrics:
psnr: # metric name, can be arbitrary
name: PSNR
crop_border: 0
test_y_channel: True
ssim:
name: SSIM
crop_border: 0
test_y_channel: True

log_config:
interval: 100
visiual_interval: 500

snapshot_config:
interval: 5000

export_model:
- {name: 'generator', inputs_num: 1}
92 changes: 92 additions & 0 deletions docs/en_US/tutorials/prenet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# PReNet

## 1 Introduction
"Progressive Image Deraining Networks: A Better and Simpler Baseline" provides a better and simpler baseline deraining network by considering network architecture, input and output, and loss functions.

<div align="center">
<img src="https://github.com/simonsLiang/PReNet_paddle/blob/main/data/net.jpg" width=800">
</div>

## 2 How to use

### 2.1 Prepare dataset

The dataset(RainH.zip) used by PReNet can be downloaded from [here](https://pan.baidu.com/s/1_vxCatOV3sOA6Vkx1l23eA?pwd=vitu),uncompress it and get two folders(RainTrainH、Rain100H).

The structure of dataset is as following:

```
├── data
├── RainTrainH
├── rain
├── 1.png
└── 2.png
.
.
└── norain
├── 1.png
└── 2.png
.
.
└── Rain100H
├── rain
├── 001.png
└── 002.png
.
.
└── norain
├── 001.png
└── 002.png
.
.
```


### 2.2 Train/Test


train model:
```
python -u tools/main.py --config-file configs/prenet.yaml
```

test model:
```
python tools/main.py --config-file configs/prenet.yaml --evaluate-only --load ${PATH_OF_WEIGHT}
```

## 3 Results

Input:

<div align="center">
<img src="https://github.com/simonsLiang/PReNet_paddle/blob/main/data/rain-001.png" width=300">
</div>

Output:

<div align="center">
<img src="https://github.com/simonsLiang/PReNet_paddle/blob/main/data/derain-rain-001.png" width=300">
</div>

## 4 Model Download
| model | dataset |
|---|---|
| [PReNet](https://paddlegan.bj.bcebos.com/models/PReNet.pdparams) | [RainH.zip](https://pan.baidu.com/s/1_vxCatOV3sOA6Vkx1l23eA?pwd=vitu) |




# References

- 1. [Progressive Image Deraining Networks: A Better and Simpler Baseline](https://arxiv.org/pdf/1901.09221v3.pdf)


```
@inproceedings{ren2019progressive,
title={Progressive Image Deraining Networks: A Better and Simpler Baseline},
author={Ren, Dongwei and Zuo, Wangmeng and Hu, Qinghua and Zhu, Pengfei and Meng, Deyu},
booktitle={IEEE Conference on Computer Vision and Pattern Recognition},
year={2019},
}
```
90 changes: 90 additions & 0 deletions docs/zh_CN/tutorials/prenet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# PReNet

## 1 简介
Progressive Image Deraining Networks: A Better and Simpler Baseline提出一种多阶段渐进的残差网络,每一个阶段都是resnet,每一res块的输入为上一res块输出和原始雨图,另外采用使用SSIM损失进行训练,进一步提升了网络的性能,网络总体简洁高效,在各种数据集上表现良好,为图像去雨提供了一个很好的基准。
<div align="center">
<img src="https://github.com/simonsLiang/PReNet_paddle/blob/main/data/net.jpg" width=800">
</div>

## 2 如何使用

### 2.1 数据准备

数据集(RainH.zip) 可以在[此处](https://pan.baidu.com/s/1_vxCatOV3sOA6Vkx1l23eA?pwd=vitu)下载,将其解压到./data路径下。

数据集文件结构如下:

```
├── data
├── RainTrainH
├── rain
├── 1.png
└── 2.png
.
.
└── norain
├── 1.png
└── 2.png
.
.
└── Rain100H
├── rain
├── 001.png
└── 002.png
.
.
└── norain
├── 001.png
└── 002.png
.
.
```

### 2.2 训练和测试


训练模型:
```
python -u tools/main.py --config-file configs/prenet.yaml
```

测试模型:
```
python tools/main.py --config-file configs/prenet.yaml --evaluate-only --load ${PATH_OF_WEIGHT}
```

## 3 预测结果

输入:

<div align="center">
<img src="https://github.com/simonsLiang/PReNet_paddle/blob/main/data/rain-001.png" width=300">
</div>

输出:

<div align="center">
<img src="https://github.com/simonsLiang/PReNet_paddle/blob/main/data/derain-rain-001.png" width=300">
</div>

## 4 模型参数下载
| 模型 | 数据集 |
|---|---|
| [PReNet](https://paddlegan.bj.bcebos.com/models/PReNet.pdparams) | [RainH.zip](https://pan.baidu.com/s/1_vxCatOV3sOA6Vkx1l23eA?pwd=vitu) |




## 参考

- 1. [Progressive Image Deraining Networks: A Better and Simpler Baseline](https://arxiv.org/pdf/1901.09221v3.pdf)


```
@inproceedings{ren2019progressive,
title={Progressive Image Deraining Networks: A Better and Simpler Baseline},
author={Ren, Dongwei and Zuo, Wangmeng and Hu, Qinghua and Zhu, Pengfei and Meng, Deyu},
booktitle={IEEE Conference on Computer Vision and Pattern Recognition},
year={2019},
}
```
2 changes: 1 addition & 1 deletion ppgan/datasets/preprocess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
PairedRandomVerticalFlip, PairedRandomTransposeHW,
SRPairedRandomCrop, SplitPairedImage, SRNoise,
NormalizeSequence, MirrorVideoSequence,
TransposeSequence)
TransposeSequence, PairedToTensor)

from .builder import build_preprocess
Loading