Skip to content

Commit

Permalink
add mpr predictor and doc (PaddlePaddle#530)
Browse files Browse the repository at this point in the history
* add mpr predictor and doc

* add doc

* fix result

* fix Results

* fix copyright
  • Loading branch information
wangna11BD authored Dec 21, 2021
1 parent 49ef722 commit 2b28df6
Show file tree
Hide file tree
Showing 15 changed files with 571 additions and 55 deletions.
15 changes: 15 additions & 0 deletions applications/tools/animeganv2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# Copyright (c) 2021 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 paddle
import os
import sys

sys.path.insert(0, os.getcwd())
from ppgan.apps import AnimeGANPredictor
import argparse
Expand Down
14 changes: 14 additions & 0 deletions applications/tools/face_parse.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright (c) 2021 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
Expand Down
43 changes: 28 additions & 15 deletions applications/tools/image_restoration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# Copyright (c) 2021 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 paddle
import os
import sys

sys.path.insert(0, os.getcwd())
from ppgan.apps import MPRPredictor
import argparse
Expand All @@ -22,18 +37,18 @@
default=None,
help="sample random seed for model's image generation")

parser.add_argument('--images_path',
default=None,
parser.add_argument('--images_path',
default=None,
required=True,
type=str,
type=str,
help='Single image or images directory.')

parser.add_argument('--task',
required=True,
type=str,
help='Task to run',
parser.add_argument('--task',
required=True,
type=str,
help='Task to run',
choices=['Deblurring', 'Denoising', 'Deraining'])

parser.add_argument("--cpu",
dest="cpu",
action="store_true",
Expand All @@ -44,11 +59,9 @@
if args.cpu:
paddle.set_device('cpu')

predictor = MPRPredictor(
images_path=args.images_path,
output_path=args.output_path,
weight_path=args.weight_path,
seed=args.seed,
task=args.task
)
predictor = MPRPredictor(images_path=args.images_path,
output_path=args.output_path,
weight_path=args.weight_path,
seed=args.seed,
task=args.task)
predictor.run()
14 changes: 14 additions & 0 deletions applications/tools/lapstyle.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright (c) 2021 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 paddle
import os
import sys
Expand Down
56 changes: 56 additions & 0 deletions applications/tools/mprnet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright (c) 2021 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 paddle
import os
import sys

sys.path.insert(0, os.getcwd())
from ppgan.apps import MPRPredictor
import argparse

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--input_image", type=str, help="path to image")

parser.add_argument("--output_path",
type=str,
default='output_dir',
help="path to output image dir")

parser.add_argument("--weight_path",
type=str,
default=None,
help="path to model weight path")

parser.add_argument(
"--task",
type=str,
default='Deblurring',
help="task can be chosen in 'Deblurring', 'Denoising', 'Deraining'")

parser.add_argument("--cpu",
dest="cpu",
action="store_true",
help="cpu mode.")

args = parser.parse_args()

if args.cpu:
paddle.set_device('cpu')

predictor = MPRPredictor(output_path=args.output_path,
task=args.task,
weight_path=args.weight_path)
predictor.run(args.input_image)
21 changes: 17 additions & 4 deletions applications/tools/photopen.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright (c) 2021 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 paddle
import os
import sys
Expand Down Expand Up @@ -39,10 +53,9 @@

if args.cpu:
paddle.set_device('cpu')

cfg = get_config(args.config_file)
predictor = PhotoPenPredictor(output_path=args.output_path,
weight_path=args.weight_path,
gen_cfg=cfg.predict)
weight_path=args.weight_path,
gen_cfg=cfg.predict)
predictor.run(semantic_label_path=args.semantic_label_path)

49 changes: 31 additions & 18 deletions applications/tools/wav2lip.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright (c) 2021 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
Expand Down Expand Up @@ -103,29 +117,28 @@
type=str,
default='sfd',
help="face detector to be used, can choose s3fd or blazeface")
parser.add_argument(
"--face_enhancement",
dest="face_enhancement",
action="store_true",
help="use face enhance for face")
parser.add_argument("--face_enhancement",
dest="face_enhancement",
action="store_true",
help="use face enhance for face")
parser.set_defaults(face_enhancement=False)

if __name__ == "__main__":
args = parser.parse_args()
if args.cpu:
paddle.set_device('cpu')

predictor = Wav2LipPredictor(checkpoint_path = args.checkpoint_path,
static = args.static,
fps = args.fps,
pads = args.pads,
face_det_batch_size = args.face_det_batch_size,
wav2lip_batch_size = args.wav2lip_batch_size,
resize_factor = args.resize_factor,
crop = args.crop,
box = args.box,
rotate = args.rotate,
nosmooth = args.nosmooth,
face_detector = args.face_detector,
face_enhancement = args.face_enhancement)
predictor = Wav2LipPredictor(checkpoint_path=args.checkpoint_path,
static=args.static,
fps=args.fps,
pads=args.pads,
face_det_batch_size=args.face_det_batch_size,
wav2lip_batch_size=args.wav2lip_batch_size,
resize_factor=args.resize_factor,
crop=args.crop,
box=args.box,
rotate=args.rotate,
nosmooth=args.nosmooth,
face_detector=args.face_detector,
face_enhancement=args.face_enhancement)
predictor.run(args.face, args.audio, args.outfile)
13 changes: 8 additions & 5 deletions configs/mprnet_deblurring.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ model:
name: MPRModel
generator:
name: MPRNet
n_feat: 96
scale_unetfeats: 48
scale_orsnetfeats: 32

char_criterion:
name: CharbonnierLoss
Expand All @@ -15,16 +18,16 @@ model:
dataset:
train:
name: MPRTrain
rgb_dir: 'data/GoPro/train'
rgb_dir: data/GoPro/train
num_workers: 4
batch_size: 2
batch_size: 2 # 8GPUs
img_options:
patch_size: 256
test:
name: MPRVal
rgb_dir: 'data/GoPro/test'
num_workers: 4
batch_size: 2
rgb_dir: data/GoPro/test
num_workers: 1
batch_size: 1
img_options:
patch_size: 256

Expand Down
69 changes: 69 additions & 0 deletions configs/mprnet_denoising.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
total_iters: 100000
output_dir: output_dir

model:
name: MPRModel
generator:
name: MPRNet
n_feat: 80
scale_unetfeats: 48
scale_orsnetfeats: 32

char_criterion:
name: CharbonnierLoss
edge_criterion:
name: EdgeLoss

dataset:
train:
name: MPRTrain
rgb_dir: data/SIDD/train
num_workers: 16
batch_size: 4 # 4GPUs
img_options:
patch_size: 256
test:
name: MPRTrain
rgb_dir: data/SIDD/val
num_workers: 1
batch_size: 1
img_options:
patch_size: 256

lr_scheduler:
name: CosineAnnealingRestartLR
learning_rate: !!float 2e-4
periods: [25000, 25000, 25000, 25000]
restart_weights: [1, 1, 1, 1]
eta_min: !!float 1e-6

validate:
interval: 5000
save_img: false

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

optimizer:
name: Adam
# add parameters of net_name to optim
# name should in self.nets
net_names:
- generator
beta1: 0.9
beta2: 0.999
epsilon: 1e-8

log_config:
interval: 10
visiual_interval: 5000

snapshot_config:
interval: 5000
Loading

0 comments on commit 2b28df6

Please sign in to comment.