class FaceSwapInterface: def __init__(self): self._parser = FullHelpArgumentParser() self._subparser = self._parser.add_subparsers() def extract(self, input_dir, output_dir, filter_path, processes): extract = ExtractTrainingData( self._subparser, "extract", "Extract the faces from a pictures.") args_str = "extract --input-dir {} --output-dir {} --processes {} --detector cnn --filter {}" args_str = args_str.format(input_dir, output_dir, processes, filter_path) self._run_script(args_str) def train(self, input_a_dir, input_b_dir, model_dir, gan = False): model_type = "Original" if gan: model_type = "GAN" train = TrainingProcessor( self._subparser, "train", "This command trains the model for the two faces A and B.") args_str = "train --input-A {} --input-B {} --model-dir {} --trainer {} --batch-size {} --write-image" args_str = args_str.format(input_a_dir, input_b_dir, model_dir, model_type, 512) self._run_script(args_str) def _run_script(self, args_str): args = self._parser.parse_args(args_str.split(' ')) args.func(args)
class FaceSwapInterface: def __init__(self): self._parser = FullHelpArgumentParser() self._subparser = self._parser.add_subparsers() def extract(self, input_dir, output_dir, filter_path): extract = ExtractTrainingData(self._subparser, "extract", "Extract the faces from a pictures.") args_str = "extract --input-dir {} --output-dir {} --processes 1 --detector cnn --filter {}" args_str = args_str.format(input_dir, output_dir, filter_path) self._run_script(args_str) def train(self, input_a_dir, input_b_dir, model_dir, gpus, gan=False, preview=True, stop_threshold=0, stop_iternum=float('inf')): # -------------------------- # ORIGINAL IMPLEMENTATION: # -------------------------- # model_type = "Original" # if gan: # model_type = "GAN" # train = TrainingProcessor( # self._subparser, "train", "This command trains the model for the two faces A and B.") # args_str = "train --input-A {} --input-B {} --model-dir {} --trainer {} --batch-size {} --gpus {} --write-image" # if preview: # args_str += " -p" # args_str = args_str.format(input_a_dir, input_b_dir, model_dir, model_type, 512, gpus) # self._run_script(args_str) myswap = MyFaceSwap() myswap.train(input_A=input_a_dir, input_B=input_b_dir, model_dir=model_dir, gpus=gpus, preview=preview, stop_threshold=stop_threshold, stop_iternum=stop_iternum) def _run_script(self, args_str): args = self._parser.parse_args(args_str.split(' ')) # print('\n\nARGS: {}\n\n'.format(args)) args.func(args)
def __init__(self): self._parser = FullHelpArgumentParser() self._subparser = self._parser.add_subparsers()
import sys 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") from lib.utils import FullHelpArgumentParser from scripts.extract import ExtractTrainingData from scripts.train import TrainingProcessor from scripts.convert import ConvertImage from tensorflow.compat.v1 import ConfigProto from tensorflow.compat.v1 import InteractiveSession config = ConfigProto() config.gpu_options.allow_growth = True session = InteractiveSession(config=config) if __name__ == "__main__": parser = FullHelpArgumentParser() subparser = parser.add_subparsers() extract = ExtractTrainingData( subparser, "extract", "Extract the faces from a pictures.") train = TrainingProcessor( subparser, "train", "This command trains the model for the two faces A and B.") convert = ConvertImage( subparser, "convert", "Convert a source image to a new one with the face swapped.") arguments = parser.parse_args() arguments.func(arguments)
raise Exception("This Program requires atleast Python3.2") def bad_args(args): parser.print_help() exit(0) from lib.utils import FullHelpArgumentParser from script.extract import ExtractTrainingData from script.train import TrainingProcessor from script.convert import ConvertImage if __name__ == '__main__': #parser parser = FullHelpArgumentParser() subparser = parser.add_subparsers() #to extract the face from the images extract = ExtractTrainingData(subparser, "extract", "Extract the faces from the picture") #to train the whole autoencoder network train = TrainingProcessor(subparser, "train", "To Train a model for two faces A and B") #convert src image to new one with face swapped convert = ConvertImage(subparser, "convert", "Convert a src image into Target Image") parser.set_defaults(func=bad_args) #parse the arguments arguments = parser.parse_args() arguments.func(arguments)
#!/usr/bin/env python3 import sys 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") from lib.utils import FullHelpArgumentParser from scripts.extract import ExtractTrainingData from scripts.train import TrainingProcessor from scripts.convert import ConvertImage def bad_args(args): parser.print_help() exit(0) if __name__ == "__main__": parser = FullHelpArgumentParser() subparser = parser.add_subparsers() extract = ExtractTrainingData( subparser, "extract", "Extract the faces from a pictures.") train = TrainingProcessor( subparser, "train", "This command trains the model for the two faces A and B.") convert = ConvertImage( 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)