예제 #1
0
def SPExtractFace(context):
    args = context.args

    PARSER = cli.FullHelpArgumentParser()
    EXTRACT = cli.ExtractArgs(PARSER, "extract",
                              "Extract the faces from pictures")

    ARGUMENTS = PARSER.parse_args([
        "--input-dir",
        args.inputData,
        "--output-dir",
        args.outputData1,
        "--alignments",
        os.path.join(args.outputData2, "alignments.json"),
        "--detector",
        args.detector,
        "--aligner",
        args.aligner,
        "--normalization",
        args.normalization,
        "--min-size",
        str(args.minSize),
        "--blur-threshold",
        str(args.blurThreshold),
    ])
    ARGUMENTS.func(ARGUMENTS)

    return args.outputData1, args.outputData2
예제 #2
0
def SPTrain(context):
    args = context.args

    PARSER = cli.FullHelpArgumentParser()
    TRAIN = cli.TrainArgs(
        PARSER, "train",
        "This command trains the model for the two faces A and B")

    argsTransfer = [
        "--input-A",
        args.inputData1,
        "--input-B",
        args.inputData2,
        "--model-dir",
        args.outputModel,
        "--batch-size",
        str(args.batchSize),
        "--trainer",
        args.trainer,
        "--iterations",
        str(args.iterations),
        "--gpus",
        str(args.__gpu),
    ]
    if args.alignments1:
        argsTransfer += [
            "--alignments-A",
            os.path.join(args.alignments1, "alignments.json"),
        ]

    if args.alignments2:
        argsTransfer += [
            "--alignments-A",
            os.path.join(args.alignments2, "alignments.json"),
        ]

    argsNoValue = [
        ("--allow-growth", args.allowGrowth),
        ("--warp-to-landmarks", args.warpToLandmarks),
        ("--no-flip", args.noFlip),
        ("--no-augment-color", args.noAugmentColor),
    ]
    for name, value in argsNoValue:
        if value:
            argsTransfer.append(name)

    ARGUMENTS = PARSER.parse_args(argsTransfer)
    ARGUMENTS.func(ARGUMENTS)

    return args.outputModel
예제 #3
0
파일: faceit.py 프로젝트: glitch003/faceit
 def _run_script(self, args_str):
     PARSER = cli.FullHelpArgumentParser()
     SUBPARSER = PARSER.add_subparsers()
     EXTRACT = cli.ExtractArgs(SUBPARSER, "extract",
                               "Extract the faces from pictures")
     TRAIN = cli.TrainArgs(
         SUBPARSER, "train",
         "This command trains the model for the two faces A and B")
     CONVERT = cli.ConvertArgs(
         SUBPARSER, "convert",
         "Convert a source image to a new one with the face swapped")
     GUI = cli.GuiArgs(SUBPARSER, "gui",
                       "Launch the Faceswap Graphical User Interface")
     PARSER.set_defaults(func=self.bad_args)
     ARGUMENTS = PARSER.parse_args(args_str.split(' '))
     ARGUMENTS.func(ARGUMENTS)
예제 #4
0
def SPConvert(context):
    args = context.args

    video = get_all_files(args.refVideo)[0] if args.refVideo else args.refVideo

    PARSER = cli.FullHelpArgumentParser()
    CONVERT = cli.ConvertArgs(
        PARSER, "convert",
        "Convert a source image to a new one with the face swapped")

    argsTransfer = [
        "--input-dir",
        args.inputData1,
        "--model-dir",
        args.inputModel,
        "--output-dir",
        args.outputData,
        "--color-adjustment",
        args.colorAdjustment,
        "--mask-type",
        args.maskType,
        "--scaling",
        args.scaling,
        "--gpus",
        str(args.__gpu),
    ]

    if args.inputData2:
        argsTransfer += [
            "--alignments",
            os.path.join(args.inputData2, "alignments.json"),
        ]

    ARGUMENTS = PARSER.parse_args(argsTransfer)
    ARGUMENTS.func(ARGUMENTS)

    return args.outputData
예제 #5
0
class MyFaceSwap():

    GPUS = 2

    # ---------------------------------------
    # DATA DIRS:
    # ---------------------------------------

    MODEL_DIR = '_data/video_prep_ffmpeg/model/'

    INPUT_DIR_EXTRACT = '_data/video_prep_ffmpeg/frames/'
    OUTPUT_DIR_EXTRACT = '_data/video_prep_ffmpeg/faces/'

    DIR_A_TRAIN = '_data/video_prep_ffmpeg/faces/emma_360_cut.mp4_faces/'
    DIR_B_TRAIN = '_data/video_prep_ffmpeg/faces/jade_360_cut.mp4_faces/'

    INPUT_DIR_CONVERT = INPUT_DIR_EXTRACT
    OUTPUT_DIR_CONVERT = '_data/video_prep_ffmpeg/frames_swapped/'

    # ---------------------------------------
    # INIT PARSER:
    # ---------------------------------------

    PARSER = cli.FullHelpArgumentParser()
    SUBPARSER = PARSER.add_subparsers()

    cli.ExtractArgs(SUBPARSER, "extract", "Extract the faces from pictures")
    cli.TrainArgs(SUBPARSER, "train",
                  "This command trains the model for the two faces A and B")
    cli.ConvertArgs(
        SUBPARSER, "convert",
        "Convert a source image to a new one with the face swapped")

    PARSER.set_defaults(func=bad_args)

    def __init__(self):
        pass

    def extract(self, input_dir=None, output_dir=None):

        if input_dir is None:
            input_dir = MyFaceSwap.INPUT_DIR_EXTRACT
        if output_dir is None:
            output_dir = MyFaceSwap.OUTPUT_DIR_EXTRACT

        ARGUMENTS = MyFaceSwap.PARSER.parse_args(["extract"])

        ARGUMENTS.input_dir = input_dir
        ARGUMENTS.output_dir = output_dir

        ARGUMENTS.func(ARGUMENTS)

    def train(self,
              input_A=None,
              input_B=None,
              model_dir=None,
              gpus=None,
              preview=True,
              stop_threshold=0,
              stop_iternum=float('inf')):

        if input_A is None:
            input_A = MyFaceSwap.DIR_A_TRAIN
        if input_B is None:
            input_B = MyFaceSwap.DIR_B_TRAIN
        if model_dir is None:
            model_dir = MyFaceSwap.MODEL_DIR
        if gpus is None:
            gpus = MyFaceSwap.GPUS

        ARGUMENTS = MyFaceSwap.PARSER.parse_args(["train"])

        ARGUMENTS.input_A = input_A
        ARGUMENTS.input_B = input_B
        ARGUMENTS.model_dir = model_dir
        ARGUMENTS.gpus = gpus
        ARGUMENTS.preview = preview

        ARGUMENTS.thresh = stop_threshold
        ARGUMENTS.iter_num = stop_iternum

        ARGUMENTS.func(ARGUMENTS)

        # removing backup-files to free space
        import os
        for item in os.listdir(model_dir):
            if item.endswith(".bk"):
                os.remove(os.path.join(model_dir, item))
        print('backup-files were removed')

    def convert(self,
                input_dir=INPUT_DIR_CONVERT,
                output_dir=OUTPUT_DIR_CONVERT,
                model_dir=MODEL_DIR,
                gpus=GPUS):

        ARGUMENTS = MyFaceSwap.PARSER.parse_args(["convert"])

        ARGUMENTS.input_dir = input_dir
        ARGUMENTS.output_dir = output_dir
        ARGUMENTS.model_dir = model_dir
        ARGUMENTS.gpus = gpus

        ARGUMENTS.func(ARGUMENTS)
예제 #6
0
파일: faceswap.py 프로젝트: Sjobom/deepfake
""" The master faceswap.py script """
import sys
import lib.cli as cli

if sys.version_info[0] < 3:
    raise Exception("This program requires at least python3.2")
if sys.version_info[0] == 3 and sys.version_info[1] < 2:
    raise Exception("This program requires at least python3.2")


def bad_args(args):
    """ Print help on bad arguments """
    PARSER.print_help()
    exit(0)


if __name__ == "__main__":
    PARSER = cli.FullHelpArgumentParser()
    SUBPARSER = PARSER.add_subparsers()
    EXTRACT = cli.ExtractArgs(SUBPARSER, "extract",
                              "Extract the faces from pictures")
    TRAIN = cli.TrainArgs(
        SUBPARSER, "train",
        "This command trains the model for the two faces A and B")
    CONVERT = cli.ConvertArgs(
        SUBPARSER, "convert",
        "Convert a source image to a new one with the face swapped")
    PARSER.set_defaults(func=bad_args)
    ARGUMENTS = PARSER.parse_args()
    ARGUMENTS.func(ARGUMENTS)
예제 #7
0
파일: faceit.py 프로젝트: ohnx/faceit
 def __init__(self):
     self._parser = cli.FullHelpArgumentParser()
     self._subparser = self._parser.add_subparsers()