提交 f5b1277d 编写于 作者: L LielinJiang

Merge branch 'master' of https://github.com/PaddlePaddle/PaddleGAN into refine-code-1020

English | [简体中文](./README.md)
English | [简体中文](./README_cn.md)
# PaddleGAN
still under development!!
PaddleGAN is an development kit of Generative Adversarial Network based on PaddlePaddle.
## Download Dataset
This script could download several dataset for paired images for image2image translation task.
### Image Translation
![](./docs/imgs/A2B.png)
![](./docs/imgs/B2A.png)
```
cd PaddleGAN/script/
bash pix2pix_download.sh [cityscapes|facades|edges2handbags|edges2shoes|maps]
```
## Train
```
python -u tools/main.py --config-file configs/cyclegan-cityscapes.yaml
```
### Makeup shifter
![](./docs/imgs/makeup_shifter.png)
### Old video restore
![](./docs/imgs/color_sr_peking.gif)
### Super resolution
![](./docs/imgs/sr_demo.png)
Features:
- Highly Flexible:
Components are designed to be modular. Model architectures, as well as data
preprocess pipelines, can be easily customized with simple configuration
changes.
- Rich applications:
PaddleGAN provides rich of applications, such as image generation, image restore, image colorization, video interpolate, makeup shifter.
## Install
### 1. install paddlepaddle
PaddleGAN work with:
* PaddlePaddle >= 2.0.0-rc
* Python >= 3.5+
continue train from last checkpoint
```
python -u tools/main.py --config-file configs/cyclegan-cityscapes.yaml --resume your_checkpoint_path
pip install -U paddlepaddle-gpu
```
multiple gpus train:
### 2. install ppgan
```
CUDA_VISIBLE_DEVICES=0,1 python -m paddle.distributed.launch tools/main.py --config-file configs/pix2pix-cityscapes.yaml
python -m pip install 'git+https://github.com/PaddlePaddle/PaddleGAN.git'
```
## Evaluate
Or install it from a local clone
```
python tools/main.py --config-file configs/cyclegan-cityscapes.yaml --evaluate-only --load your_weight_path
git clone https://github.com/PaddlePaddle/PaddleGAN
cd PaddleGAN
pip install -v -e . # or "python setup.py develop"
```
## Data Prepare
Please refer to [data prepare](./docs/data_prepare.md) for dataset preparation.
## Get Start
Please refer [get stated](./docs/get_started.md) for the basic usage of PaddleGAN.
## Model tutorial
* [Pixel2Pixel and CycleGAN](./docs/tutorials/pix2pix_cyclegan.md)
* [PSGAN](./docs/tutorials/psgan.md)
* [Video restore](./docs/tutorails/video_restore.md)
* [Motion driving](./docs/tutorials/motion_driving.md)
## License
PaddleGAN is released under the [Apache 2.0 license](LICENSE).
## Contributing
Contributions and suggestions are highly welcomed. Most contributions require you to agree to a [Contributor License Agreement (CLA)](https://cla-assistant.io/PaddlePaddle/PaddleGAN) declaring.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA. Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
For more, please reference [contribution guidelines](docs/CONTRIBUTE.md).
## External Projects
External gan projects in the community that base on PaddlePaddle:
+ [PaddleGAN](https://github.com/PaddlePaddle/PaddleGAN)
[English](./README.md) | 简体中文
# PaddleGAN
PaddleGAN 是一个基于飞桨的生成对抗网络开发工具包.
### 图片变换
![](./docs/imgs/A2B.png)
![](./docs/imgs/B2A.png)
### 妆容迁移
![](./docs/imgs/makeup_shifter.png)
### 老视频修复
![](./docs/imgs/color_sr_peking.gif)
### 超分辨率
![](./docs/imgs/sr_demo.png)
特性:
- 高度的灵活性:
模块化设计,解耦各个网络组件,开发者轻松搭建、试用各种检测模型及优化策略,快速得到高性能、定制化的算法。
- 丰富的应用:
PaddleGAN 提供了非常多的应用,比如说图像生成,图像修复,图像上色,视频补帧,人脸妆容迁移等.
## 安装
### 1. 安装 paddlepaddle
PaddleGAN 所需的版本:
* PaddlePaddle >= 2.0.0-rc
* Python >= 3.5+
```
pip install -U paddlepaddle-gpu
```
### 2. 安装ppgan
```
python -m pip install 'git+https://github.com/PaddlePaddle/PaddleGAN.git'
```
或者通过将项目克隆到本地
```
git clone https://github.com/PaddlePaddle/PaddleGAN
cd PaddleGAN
pip install -v -e . # or "python setup.py develop"
```
## 数据准备
请参考 [数据准备](./docs/data_prepare.md) 来准备对应的数据.
## 快速开始
训练,预测,推理等请参考 [快速开始](./docs/get_started.md).
## 模型教程
* [Pixel2Pixel and CycleGAN](./docs/tutorals/pix2pix_cyclegan.md)
* [PSGAN](./docs/tutorals/psgan.md)
* [视频修复](./docs/tutorails/video_restore.md)
* [动作驱动](./docs/tutorials/motion_driving.md)
## 许可证书
本项目的发布受[Apache 2.0 license](LICENSE)许可认证。
## 贡献代码
我们非常欢迎你可以为PaddleGAN提供任何贡献和建议。大多数贡献都需要你同意参与者许可协议(CLA)。当你提交拉取请求时,CLA机器人会自动检查你是否需要提供CLA。 只需要按照机器人提供的说明进行操作即可。CLA只需要同意一次,就能应用到所有的代码仓库上。关于更多的流程请参考[贡献指南](docs/CONTRIBUTE.md)
## 外部项目
外部基于飞桨的生成对抗网络模型
+ [PaddleGAN](https://github.com/PaddlePaddle/PaddleGAN)
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
import argparse
import paddle
from ppgan.apps import DAINPredictor
from ppgan.apps import DeepRemasterPredictor
from ppgan.apps import DeOldifyPredictor
from ppgan.apps import RealSRPredictor
from ppgan.apps import EDVRPredictor
parser = argparse.ArgumentParser(description='Fix video')
parser.add_argument('--input', type=str, default=None, help='Input video')
parser.add_argument('--output', type=str, default='output', help='output dir')
parser.add_argument('--DAIN_weight',
type=str,
default=None,
help='Path to model weight')
parser.add_argument('--DeepRemaster_weight',
type=str,
default=None,
help='Path to model weight')
parser.add_argument('--DeOldify_weight',
type=str,
default=None,
help='Path to model weight')
parser.add_argument('--RealSR_weight',
type=str,
default=None,
help='Path to model weight')
parser.add_argument('--EDVR_weight',
type=str,
default=None,
help='Path to model weight')
# DAIN args
parser.add_argument('--time_step',
type=float,
default=0.5,
help='choose the time steps')
# DeepRemaster args
parser.add_argument('--reference_dir',
type=str,
default=None,
help='Path to the reference image directory')
parser.add_argument('--colorization',
action='store_true',
default=False,
help='Remaster with colorization')
parser.add_argument('--mindim',
type=int,
default=360,
help='Length of minimum image edges')
# DeOldify args
parser.add_argument('--render_factor',
type=int,
default=32,
help='model inputsize=render_factor*16')
#process order support model name:[DAIN, DeepRemaster, DeOldify, RealSR, EDVR]
parser.add_argument('--proccess_order',
type=str,
default='none',
nargs='+',
help='Process order')
if __name__ == "__main__":
args = parser.parse_args()
orders = args.proccess_order
temp_video_path = None
for order in orders:
print('Model {} proccess start..'.format(order))
if temp_video_path is None:
temp_video_path = args.input
if order == 'DAIN':
paddle.enable_static()
predictor = DAINPredictor(args.output,
weight_path=args.DAIN_weight,
time_step=args.time_step)
frames_path, temp_video_path = predictor.run(temp_video_path)
paddle.disable_static()
elif order == 'DeepRemaster':
predictor = DeepRemasterPredictor(
args.output,
weight_path=args.DeepRemaster_weight,
colorization=args.colorization,
reference_dir=args.reference_dir,
mindim=args.mindim)
frames_path, temp_video_path = predictor.run(temp_video_path)
elif order == 'DeOldify':
predictor = DeOldifyPredictor(args.output,
weight_path=args.DeOldify_weight,
render_factor=args.render_factor)
frames_path, temp_video_path = predictor.run(temp_video_path)
elif order == 'RealSR':
predictor = RealSRPredictor(args.output,
weight_path=args.RealSR_weight)
frames_path, temp_video_path = predictor.run(temp_video_path)
elif order == 'EDVR':
paddle.enable_static()
predictor = EDVRPredictor(args.output, weight_path=args.EDVR_weight)
frames_path, temp_video_path = predictor.run(temp_video_path)
paddle.disable_static()
print('Model {} output frames path:'.format(order), frames_path)
print('Model {} output video path:'.format(order), temp_video_path)
print('Model {} proccess done!'.format(order))
# How to contribute
You are welcome to contribute to project PaddleGAN. Contributions can be:
- documentation
- source code and bug fixes
- new features or models
- solve existing issues
We sincerely appreciate your contribution. This document explains our workflow and work style.
The following guidiance tells you how to submit code.
## Workflow
1. [Fork](https://help.github.com/articles/fork-a-repo/)
Transfer to the home page of Github [PaddleGAN](https://github.com/PaddlePaddle/PaddleGAN), and then click button `Fork` to generate the git under your own file directory, such as <https://github.com/USERNAME/PaddleGAN>.
2. Clone
Clone remote git to local:
```bash
➜ git clone https://github.com/USERNAME/PaddleGAN
➜ cd PaddleGAN
```
3. Create local branch
At present [Git stream branch model](http://nvie.com/posts/a-successful-git-branching-model/) is applied to PaddleGAN to undergo task of development, test, release and maintenance.
All development tasks of feature and bug fix should be finished in a new branch which is extended from `master` branch.
Create and switch to a new branch with command `git checkout -b`.
```bash
➜ git checkout -b my-cool-stuff
```
It is worth noting that before the checkout, you need to keep the current branch directory clean, otherwise the untracked file will be brought to the new branch, which can be viewed by `git status` .
4. Use `pre-commit` hook
We use the [pre-commit](http://pre-commit.com/) tool to manage Git pre-commit hooks. It helps us format the source code (C++, Python) and automatically check some basic things before committing (such as having only one EOL per file, not adding large files in Git, etc.).
The `pre-commit` test is part of the unit test in Travis-CI. A PR that does not satisfy the hook cannot be submitted to Paddle. Install `pre-commit` first and then run it in current directory:
```bash
➜ pip install pre-commit
➜ pre-commit install
```
Once installed, `pre-commit` checks the style of code and documentation in every commit. We will see something like the following when you run `git commit`:
```
➜ git commit
CRLF end-lines remover...............................(no files to check)Skipped
yapf.................................................(no files to check)Skipped
Check for added large files..............................................Passed
Check for merge conflicts................................................Passed
Check for broken symlinks................................................Passed
Detect Private Key...................................(no files to check)Skipped
Fix End of Files.....................................(no files to check)Skipped
clang-formater.......................................(no files to check)Skipped
[my-cool-stuff c703c041] add test file
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 233
```
NOTE: The `yapf` installed by `pip install pre-commit` and `conda install -c conda-forge pre-commit` is slightly different. We use `pip install pre-commit`.
5. Start development
I delete a line of README.md and create a new file in the case.
View the current state via `git status`, which will prompt some changes to the current directory, and you can also view the file's specific changes via `git diff`.
```bash
➜ git status
On branch test
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: README.md
Untracked files:
(use "git add <file>..." to include in what will be committed)
test
no changes added to commit (use "git add" and/or "git commit -a")
```
6. Test
Add unit testing if needed.
7. Commit
Next we cancel the modification of README.md, and submit new added test file.
```bash
➜ git checkout -- README.md
➜ git status
On branch test
Untracked files:
(use "git add <file>..." to include in what will be committed)
test
nothing added to commit but untracked files present (use "git add" to track)
➜ git add test
```
It's required that the commit message is also given on every Git commit, through which other developers will be notified of what changes have been made. Type `git commit` to realize it.
```bash
➜ git commit
CRLF end-lines remover...............................(no files to check)Skipped
yapf.................................................(no files to check)Skipped
Check for added large files..............................................Passed
Check for merge conflicts................................................Passed
Check for broken symlinks................................................Passed
Detect Private Key...................................(no files to check)Skipped
Fix End of Files.....................................(no files to check)Skipped
clang-formater.......................................(no files to check)Skipped
[my-cool-stuff c703c041] add test file
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 233
```
8. Keep pulling
An experienced Git user pulls from the official repo often -- daily or even hourly, so they notice conflicts with others work early, and it's easier to resolve smaller conflicts.
Check the name of current remote repository with `git remote`.
```bash
➜ git remote
origin
➜ git remote -v
origin https://github.com/USERNAME/PaddleGAN (fetch)
origin https://github.com/USERNAME/PaddleGAN (push)
```
origin is the name of remote repository that we clone, we create a remote host of an original PaddleGAN and name it upstream.
```bash
➜ git remote add upstream https://github.com/PaddlePaddle/PaddleGAN
➜ git remote
origin
upstream
```
Get the latest code of upstream and update current branch.
```bash
➜ git fetch upstream
➜ git pull upstream develop
```
9. Push to remote repository
Push local modification to GitHub (https://github.com/USERNAME/PaddleGAN).
```bash
# submit it to remote git the branch my-cool-stuff of origin
➜ git push origin my-cool-stuff
```
The push allows you to create a pull request, requesting owners of this [official repo](https://github.com/PaddlePaddle/PaddleGAN) to pull your change into the official one.
To create a pull request, please follow [these steps](https://help.github.com/articles/creating-a-pull-request/).
If your change is for fixing an issue, please write ["Fixes <issue-URL>"](https://help.github.com/articles/closing-issues-using-keywords/) in the description section of your pull request. Github would close the issue when the owners merge your pull request.
Please remember to specify some reviewers for your pull request. If you don't know who are the right ones, please follow Github's recommendation.
10. Delete local and remote branches
To keep your local workspace and your fork clean, you might want to remove merged branches:
```bash
git push origin :my-cool-stuff
git checkout develop
git pull upstream develop
git branch -d my-cool-stuff
```
## Code Review
- Please feel free to ping your reviewers by sending them the URL of your pull request via IM or email. Please do this after your pull request passes the CI.
- Please answer reviewers' every comment. If you are to follow the comment, please write "Done"; please give a reason otherwise.
- If you don't want your reviewers to get overwhelmed by email notifications, you might reply their comments by [in a batch](https://help.github.com/articles/reviewing-proposed-changes-in-a-pull-request/).
- Reduce the unnecessary commits. Some developers commit often. It is recommended to append a sequence of small changes into one commit by running `git commit --amend` instead of `git commit`.
## Coding Standard
### Code Style
Our C/C++ code follows the [Google style guide](http://google.github.io/styleguide/cppguide.html).
Our Python code follows the [PEP8 style guide](https://www.python.org/dev/peps/pep-0008/).
Please install pre-commit, which automatically reformat the changes to C/C++ and Python code whenever we run `git commit`.
### Unit Tests
Please remember to add related unit tests.
- For C/C++ code, please follow [`google-test` Primer](https://github.com/google/googletest/blob/master/googletest/docs/primer.md) .
- For Python code, please use [Python's standard `unittest` package](http://pythontesting.net/framework/unittest/unittest-introduction/).
## data prepare
It is recommended to symlink the dataset root to `$PaddleGAN/data`.
```
PaddleGAN
|-- configs
|-- data
| |-- cityscapes
| | ├── test
| | ├── testA
| | ├── testB
| | ├── train
| | ├── trainA
| | └── trainB
| ├── horse2zebra
| | ├── testA
| | ├── testB
| | ├── trainA
| | └── trainB
| └── facades
| ├── test
| ├── train
| └── val
|-- docs
|-- ppgan
|-- tools
```
### cyclegan datasets
more dataset for cyclegan you can download from [here](https://people.eecs.berkeley.edu/~taesung_park/CycleGAN/datasets/)
### pix2pix datasets
more dataset for pix2pix you can download from [here](hhttps://people.eecs.berkeley.edu/~tinghuiz/projects/pix2pix/datasets/)
## Getting started with PaddleGAN
### Train
```
python -u tools/main.py --config-file configs/cyclegan_cityscapes.yaml
```
continue train from last checkpoint
```
python -u tools/main.py --config-file configs/cyclegan_cityscapes.yaml --resume your_checkpoint_path
```
multiple gpus train:
```
CUDA_VISIBLE_DEVICES=0,1 python -m paddle.distributed.launch tools/main.py --config-file configs/pix2pix_cityscapes.yaml
```
### Evaluate
```
python tools/main.py --config-file configs/cyclegan_cityscapes.yaml --evaluate-only --load your_weight_path
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册