Skip to content

Commit

Permalink
Refine codes and docs (PaddlePaddle#93)
Browse files Browse the repository at this point in the history
* refine codes docs

* fix pix2pix to_tensor

* fix apps
  • Loading branch information
LielinJiang authored Nov 17, 2020
1 parent d3f8726 commit 4953961
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 12 deletions.
4 changes: 2 additions & 2 deletions applications/tools/video-enhance.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
default=32,
help='model inputsize=render_factor*16')
#process order support model name:[DAIN, DeepRemaster, DeOldify, RealSR, EDVR]
parser.add_argument('--proccess_order',
parser.add_argument('--process_order',
type=str,
default='none',
nargs='+',
Expand All @@ -85,7 +85,7 @@
if __name__ == "__main__":
args = parser.parse_args()

orders = args.proccess_order
orders = args.process_order
temp_video_path = None

for order in orders:
Expand Down
1 change: 1 addition & 0 deletions configs/cyclegan_cityscapes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dataset:
name: UnpairedDataset
dataroot: data/cityscapes
num_workers: 0
batch_size: 1
phase: train
max_dataset_size: inf
direction: AtoB
Expand Down
2 changes: 2 additions & 0 deletions configs/cyclegan_horse2zebra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ dataset:
train:
name: UnpairedDataset
dataroot: data/horse2zebra
num_workers: 0
batch_size: 1
phase: train
max_dataset_size: inf
direction: AtoB
Expand Down
1 change: 1 addition & 0 deletions configs/pix2pix_cityscapes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dataset:
name: PairedDataset
dataroot: data/cityscapes
num_workers: 4
batch_size: 1
phase: train
max_dataset_size: inf
direction: BtoA
Expand Down
2 changes: 2 additions & 0 deletions configs/pix2pix_cityscapes_2gpus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ dataset:
train:
name: PairedDataset
dataroot: data/cityscapes
num_workers: 0
batch_size: 1
phase: train
max_dataset_size: inf
direction: BtoA
Expand Down
2 changes: 2 additions & 0 deletions configs/pix2pix_facades.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ dataset:
train:
name: PairedDataset
dataroot: data/facades/
num_workers: 0
batch_size: 1
phase: train
max_dataset_size: inf
direction: BtoA
Expand Down
10 changes: 10 additions & 0 deletions docs/en_US/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,13 @@ git clone https://github.com/PaddlePaddle/PaddleGAN
cd PaddleGAN
pip install -v -e . # or "python setup.py develop"
```

### 4. Installation of other tools that may be used

#### 4.1 ffmpeg

If you need to use ppgan to handle video-related tasks, you need to install ffmpeg. It is recommended that you use [conda](https://docs.conda.io/en/latest/miniconda.html) to install:

```
conda install x264=='1!152.20180717' ffmpeg=4.0.2 -c conda-forge
```
2 changes: 1 addition & 1 deletion docs/zh_CN/data_prepare.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ custom_datasets

#### 从网页下载

pixel2pixel模型相关的数据集可以在[这里](hhttps://people.eecs.berkeley.edu/~tinghuiz/projects/pix2pix/datasets/)下载
pixel2pixel模型相关的数据集可以在[这里](https://people.eecs.berkeley.edu/~tinghuiz/projects/pix2pix/datasets/)下载

#### 使用脚本下载

Expand Down
11 changes: 11 additions & 0 deletions docs/zh_CN/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,14 @@ pip install -v -e . # or "python setup.py develop"
```

按照上述方法安装成功后,本地的修改也会自动同步到ppgan中


### 4. 其他可能用到的工具安装

#### 4.1 ffmpeg

如果需要使用ppgan处理视频相关的任务,则需要安装ffmpeg。这里推荐您使用[conda](https://docs.conda.io/en/latest/miniconda.html)安装:

```
conda install x264=='1!152.20180717' ffmpeg=4.0.2 -c conda-forge
```
4 changes: 2 additions & 2 deletions docs/zh_CN/tutorials/video_restore.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
### 使用applications中的video-enhance.py工具进行快速开始视频修复
```
cd applications
python tools/video-enhance.py --input you_video_path.mp4 --proccess_order DAIN DeOldify EDVR --output output_dir
python tools/video-enhance.py --input you_video_path.mp4 --process_order DAIN DeOldify EDVR --output output_dir
```
#### 参数

- `--input (str)`: 输入的视频路径。
- `--output (str)`: 输出的视频路径。
- `--proccess_order`: 调用的模型名字和顺序,比如输入为 `DAIN DeOldify EDVR`,则会顺序调用 `DAINPredictor` `DeOldifyPredictor` `EDVRPredictor`
- `--process_order`: 调用的模型名字和顺序,比如输入为 `DAIN DeOldify EDVR`,则会顺序调用 `DAINPredictor` `DeOldifyPredictor` `EDVRPredictor`

#### 效果展示
![](../../imgs/color_sr_peking.gif)
Expand Down
3 changes: 3 additions & 0 deletions ppgan/apps/deoldify_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from ppgan.utils.download import get_path_from_url
from ppgan.utils.video import frames2video, video2frames
from ppgan.models.generators.deoldify import build_model
from ppgan.utils.logger import get_logger

from .base_predictor import BasePredictor

Expand Down Expand Up @@ -150,5 +151,7 @@ def run(self, input):
base_name = 'result'
out_path = os.path.join(self.output, base_name + '.png')
pred_img.save(out_path)
logger = get_logger()
logger.info('Image saved to {}'.format(out_path))

return pred_img, out_path
4 changes: 4 additions & 0 deletions ppgan/apps/realsr_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from ppgan.models.generators import RRDBNet
from ppgan.utils.video import frames2video, video2frames
from ppgan.utils.download import get_path_from_url
from ppgan.utils.logger import get_logger

from .base_predictor import BasePredictor

REALSR_WEIGHT_URL = 'https://paddlegan.bj.bcebos.com/applications/DF2K_JPEG.pdparams'
Expand Down Expand Up @@ -113,5 +115,7 @@ def run(self, input):
base_name = 'result'
out_path = os.path.join(self.output, base_name + '.png')
pred_img.save(out_path)
logger = get_logger()
logger.info('Image saved to {}'.format(out_path))

return pred_img, out_path
5 changes: 3 additions & 2 deletions ppgan/engine/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ def train(self):

step_start_time = time.time()

self.logger.info('train one epoch time: {}'.format(time.time() -
start_time))
self.logger.info(
'train one epoch use time: {:.3f} seconds.'.format(time.time() -
start_time))
if self.validate_interval > -1 and epoch % self.validate_interval:
self.validate()
self.model.lr_scheduler.step()
Expand Down
6 changes: 4 additions & 2 deletions ppgan/models/pix2pix_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ def set_input(self, input):

AtoB = self.cfg.dataset.train.direction == 'AtoB'

self.real_A = paddle.to_tensor(input['A' if AtoB else 'B'])
self.real_B = paddle.to_tensor(input['B' if AtoB else 'A'])
self.real_A = paddle.fluid.dygraph.to_variable(
input['A' if AtoB else 'B'])
self.real_B = paddle.fluid.dygraph.to_variable(
input['B' if AtoB else 'A'])

self.image_paths = input['A_paths' if AtoB else 'B_paths']

Expand Down
8 changes: 5 additions & 3 deletions ppgan/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

def setup_logger(output=None, name="ppgan"):
"""
Initialize the detectron2 logger and set its verbosity level to "INFO".
Initialize the ppgan logger and set its verbosity level to "INFO".
Args:
output (str): a file name or a directory to save log. If None, will not save log file.
Expand All @@ -35,6 +35,8 @@ def setup_logger(output=None, name="ppgan"):
logging.Logger: a logger
"""
logger = logging.getLogger(name)
if name in logger_initialized:
return logger
logger.setLevel(logging.INFO)
logger.propagate = False

Expand Down Expand Up @@ -71,9 +73,9 @@ def setup_logger(output=None, name="ppgan"):
return logger


def get_logger(name, output=None):
def get_logger(name='ppgan'):
logger = logging.getLogger(name)
if name in logger_initialized:
return logger

return setup_logger(name=name, output=name)
return setup_logger(name=name)

0 comments on commit 4953961

Please sign in to comment.