first-order-demo.py 3.6 KB
Newer Older
L
LielinJiang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#  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
L
lijianshe02 已提交
18
from ppgan.apps.first_order_predictor import FirstOrderPredictor
L
LielinJiang 已提交
19 20 21 22 23 24 25 26 27

parser = argparse.ArgumentParser()
parser.add_argument("--config", default=None, help="path to config")
parser.add_argument("--weight_path",
                    default=None,
                    help="path to checkpoint to restore")
parser.add_argument("--source_image", type=str, help="path to source image")
parser.add_argument("--driving_video", type=str, help="path to driving video")
parser.add_argument("--output", default='output', help="path to output")
L
lijianshe02 已提交
28 29 30
parser.add_argument("--filename",
                    default='result.mp4',
                    help="filename to output")
L
LielinJiang 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
parser.add_argument("--relative",
                    dest="relative",
                    action="store_true",
                    help="use relative or absolute keypoint coordinates")
parser.add_argument(
    "--adapt_scale",
    dest="adapt_scale",
    action="store_true",
    help="adapt movement scale based on convex hull of keypoints")

parser.add_argument(
    "--find_best_frame",
    dest="find_best_frame",
    action="store_true",
    help=
    "Generate from the frame that is the most alligned with source. (Only for faces, requires face_aligment lib)"
)

parser.add_argument("--best_frame",
                    dest="best_frame",
                    type=int,
                    default=None,
                    help="Set frame to start from.")
parser.add_argument("--cpu", dest="cpu", action="store_true", help="cpu mode.")
55 56 57
parser.add_argument("--ratio",
                    dest="ratio",
                    type=float,
L
lijianshe02 已提交
58
                    default=0.4,
59
                    help="margin ratio")
L
lijianshe02 已提交
60 61 62 63 64 65
parser.add_argument(
    "--face_detector",
    dest="face_detector",
    type=str,
    default='sfd',
    help="face detector to be used, can choose s3fd or blazeface")
F
FNRE 已提交
66 67 68 69 70
parser.add_argument("--multi_person",
                    dest="multi_person",
                    action="store_true",
                    default=False,
                    help="whether there is only one person in the image or not")
L
LielinJiang 已提交
71 72 73 74 75 76 77 78 79 80

parser.set_defaults(relative=False)
parser.set_defaults(adapt_scale=False)

if __name__ == "__main__":
    args = parser.parse_args()

    if args.cpu:
        paddle.set_device('cpu')
    predictor = FirstOrderPredictor(output=args.output,
81
                                    filename=args.filename,
L
LielinJiang 已提交
82 83 84 85 86
                                    weight_path=args.weight_path,
                                    config=args.config,
                                    relative=args.relative,
                                    adapt_scale=args.adapt_scale,
                                    find_best_frame=args.find_best_frame,
87
                                    best_frame=args.best_frame,
L
lijianshe02 已提交
88
                                    ratio=args.ratio,
F
FNRE 已提交
89 90
                                    face_detector=args.face_detector,
                                    multi_person=args.multi_person)
L
LielinJiang 已提交
91
    predictor.run(args.source_image, args.driving_video)