def process(self): # Original & LowMem models go with Adjust or Masked converter # GAN converter & model must go together # Note: GAN prediction outputs a mask + an image, while other predicts only an image model_name = self.arguments.trainer conv_name = self.arguments.converter if conv_name.startswith("GAN"): assert model_name.startswith( "GAN" ) is True, "GAN converter can only be used with GAN model!" else: assert model_name.startswith( "GAN" ) is False, "GAN model can only be used with GAN converter!" model = PluginLoader.get_model(model_name)(get_folder( self.arguments.model_dir)) if not model.load(self.arguments.swap_model): print( 'Model Not Found! A valid model must be provided to continue!') exit(1) converter = PluginLoader.get_converter(conv_name)( model.converter(False), blur_size=self.arguments.blur_size, seamless_clone=self.arguments.seamless_clone, mask_type=self.arguments.mask_type, erosion_kernel_size=self.arguments.erosion_kernel_size, smooth_mask=self.arguments.smooth_mask, avg_color_adjust=self.arguments.avg_color_adjust) batch = BackgroundGenerator(self.prepare_images(), 1) # frame ranges stuff... self.frame_ranges = None # split out the frame ranges and parse out "min" and "max" values minmax = { "min": 0, # never any frames less than 0 "max": float("inf") } if self.arguments.frame_ranges: self.frame_ranges = [ tuple( map(lambda q: minmax[q] if q in minmax.keys() else int(q), v.split("-"))) for v in self.arguments.frame_ranges ] # last number regex. I know regex is hacky, but its reliablyhacky(tm). self.imageidxre = re.compile(r'(\d+)(?!.*\d)') for item in batch.iterator(): self.convert(converter, item)
def process(self): self.convert_cache = self.input_A_path + '_convert' try: os.mkdir(self.convert_cache) except: import shutil shutil.rmtree(self.convert_cache) os.mkdir(self.convert_cache) # model_name = 'Original' # conv_name = 'Masked' #'Masked' # model = PluginLoader.get_model(model_name)(self.model_path) model = Model_Original.Model(self.model_path) if not model.load(swapped = True): exit(1) converter = Convert_Masked.Convert(model.converter(False), blur_size=2, seamless_clone=True, mask_type="facehullandrect", erosion_kernel_size=None, smooth_mask=True, avg_color_adjust=True ) batch = BackgroundGenerator(self.prepare_images(), 1) self.frame_ranges = None minmax = { "min": 0, # never any frames less than 0 "max": float("inf") } if self.frame_ranges: self.frame_ranges = [tuple(map(lambda q: minmax[q] if q in minmax.keys() else int(q), v.split("-"))) for v in self.arguments.frame_ranges] self.imageidxre = re.compile(r'(\d+)(?!.*\d)') try: for item in batch.iterator(): if not self.state.empty(): if self.state.get() == 'stop_con': print('取消合成,正在清理缓存文件') break else: self.convert(converter, item) else: self.convert(converter, item) finally: keras.backend.clear_session()
def process(self): # Original model goes with Adjust or Masked converter # does the LowMem one work with only one? # seems to work with both in testing - although Adjust with LowMem # looks a real mess - you can see that it is "working" model_name = self.arguments.trainer conv_name = self.arguments.converter model = PluginLoader.get_model(model_name)(self.arguments.model_dir) if not model.load(self.arguments.swap_model): print( 'Model Not Found! A valid model must be provided to continue!') exit(1) converter = PluginLoader.get_converter(conv_name)( model.converter(False), blur_size=self.arguments.blur_size, seamless_clone=self.arguments.seamless_clone, mask_type=self.arguments.mask_type, erosion_kernel_size=self.arguments.erosion_kernel_size, smooth_mask=self.arguments.smooth_mask, avg_color_adjust=self.arguments.avg_color_adjust) batch = BackgroundGenerator(self.prepare_images(), 1) # frame ranges stuff... self.frame_ranges = None # split out the frame ranges and parse out "min" and "max" values minmax = { "min": 0, # never any frames less than 0 "max": float("inf") } if self.arguments.frame_ranges: self.frame_ranges = [ tuple( map(lambda q: minmax[q] if q in minmax.keys() else int(q), v.split("-"))) for v in self.arguments.frame_ranges ] # last number regex. I know regex is hacky, but its reliablyhacky(tm). self.imageidxre = re.compile(r'(\d+)(?!.*\d)') for item in batch.iterator(): self.convert(converter, item)
def process(self): # Original model goes with Adjust or Masked converter model_name = "Original" # TODO Pass as argument conv_name = "Masked" # TODO Pass as argument model = PluginLoader.get_model(model_name)(self.arguments.model_dir) if not model.load(self.arguments.swap_model): print( 'Model Not Found! A valid model must be provided to continue!') exit(1) converter = PluginLoader.get_converter(conv_name)( model.converter(False)) batch = BackgroundGenerator(self.prepare_images(), 1) for item in batch.iterator(): self.convert(converter, item)
def process(self): model_name = self.arguments.trainer conv_name = self.arguments.converter if conv_name.startswith("GAN"): assert model_name.startswith("GAN") is True, "GAN converter can only be used with GAN model" else: assert model_name.startswith("GAN") is False, "GAN model can only be used with GAN Converter" model = PluginLoader.get_model(model_name)(get_folder(self.arguments.model_dir)) if not model.load(self.arguments.swap_model): print("Model Not Found! A valid model must be provided to continue!") exit(1) converter = PluginLoader.get_converter(conv_name)(model.converter(False), blur_size = self.arguments.blur_size, seamless_clone=self.arguments.seamless_clone, mask_type=self.arguments.mask_type, erosion_kernel_size=self.arguments.erosion_kernel_size, smooth_mask=self.arguments.smooth_mask, avg_color_adjust=self.arguments.avg_color_adjust) batch = BackgroundGenerator(self.prepare_images(),1) #frame ranges stuffs self.frame_ranges = None minmax = { "min":0, "max":float("inf") } if self.arguments.frame_ranges: self.frame_ranges = [tuple(map(lamda q: minmax[q] if q in minmax.keys() else int(q),v.split("-"))) for v in self.arguments.frame_ranges] self.imageidxre - re.compile(r'(\d+)(?!.*\d)') for item in batch.iterator(): self.convert(converter,item)
def process(self): """ Original & LowMem models go with Adjust or Masked converter Note: GAN prediction outputs a mask + an image, while other predicts only an image """ Utils.set_verbosity(self.args.verbose) if not self.alignments.have_alignments_file: self.generate_alignments() self.faces.faces_detected = self.alignments.read_alignments() model = self.load_model() converter = self.load_converter(model) batch = BackgroundGenerator(self.prepare_images(), 1) for item in batch.iterator(): self.convert(converter, item) Utils.finalize(self.images.images_found, self.faces.num_faces_detected, self.faces.verify_output)
def process(self): """ Original & LowMem models go with Adjust or Masked converter Note: GAN prediction outputs a mask + an image, while other predicts only an image. """ Utils.set_verbosity(self.args.verbose) if not self.alignments.have_alignments_file: self.generate_alignments() self.faces.faces_detected = self.alignments.read_alignments() model = self.load_model() converter = self.load_converter(model) batch = BackgroundGenerator(self.prepare_images(), 1) for item in batch.iterator(): self.convert(converter, item) Utils.finalize(self.images.images_found, self.faces.num_faces_detected, self.faces.verify_output)
def process(self): # Original model goes with Adjust or Masked converter # does the LowMem one work with only one? model_name = "Original" # TODO Pass as argument conv_name = self.arguments.converter model = PluginLoader.get_model(model_name)(self.arguments.model_dir) if not model.load(self.arguments.swap_model): print('Model Not Found! A valid model must be provided to continue!') exit(1) converter = PluginLoader.get_converter(conv_name)(model.converter(False), blur_size=self.arguments.blur_size, seamless_clone=self.arguments.seamless_clone, mask_type=self.arguments.mask_type, erosion_kernel_size=self.arguments.erosion_kernel_size, smooth_mask=self.arguments.smooth_mask, avg_color_adjust=self.arguments.avg_color_adjust ) batch = BackgroundGenerator(self.prepare_images(), 1) # frame ranges stuff... self.frame_ranges = None # split out the frame ranges and parse out "min" and "max" values minmax = { "min": 0, # never any frames less than 0 "max": float("inf") } if self.arguments.frame_ranges: self.frame_ranges = [tuple(map(lambda q: minmax[q] if q in minmax.keys() else int(q), v.split("-"))) for v in self.arguments.frame_ranges] # last number regex. I know regex is hacky, but its reliablyhacky(tm). self.imageidxre = re.compile(r'(\d+)(?!.*\d)') for item in batch.iterator(): self.convert(converter, item)
def process(self): # Original & LowMem models go with Adjust or Masked converter # Note: GAN prediction outputs a mask + an image, while other predicts only an image model_name = self.arguments.trainer conv_name = self.arguments.converter self.input_aligned_dir = None model = PluginLoader.get_model(model_name)(get_folder( self.arguments.model_dir)) if not model.load(self.arguments.swap_model): print( 'Model Not Found! A valid model must be provided to continue!') exit(1) input_aligned_dir = Path(self.arguments.input_dir) / Path('aligned') if self.arguments.input_aligned_dir is not None: input_aligned_dir = self.arguments.input_aligned_dir try: self.input_aligned_dir = [ Path(path) for path in get_image_paths(input_aligned_dir) ] if len(self.input_aligned_dir) == 0: print( 'Aligned directory is empty, no faces will be converted!') elif len(self.input_aligned_dir) <= len(self.input_dir) / 3: print( 'Aligned directory contains an amount of images much less than the input, are you sure this is the right directory?' ) except: print( 'Aligned directory not found. All faces listed in the alignments file will be converted.' ) converter = PluginLoader.get_converter(conv_name)( model.converter(False), trainer=self.arguments.trainer, blur_size=self.arguments.blur_size, seamless_clone=self.arguments.seamless_clone, mask_type=self.arguments.mask_type, erosion_kernel_size=self.arguments.erosion_kernel_size, match_histogram=self.arguments.match_histogram, smooth_mask=self.arguments.smooth_mask, avg_color_adjust=self.arguments.avg_color_adjust) batch = BackgroundGenerator(self.prepare_images(), 1) # frame ranges stuff... self.frame_ranges = None # split out the frame ranges and parse out "min" and "max" values minmax = { "min": 0, # never any frames less than 0 "max": float("inf") } if self.arguments.frame_ranges: self.frame_ranges = [ tuple( map(lambda q: minmax[q] if q in minmax.keys() else int(q), v.split("-"))) for v in self.arguments.frame_ranges ] # last number regex. I know regex is hacky, but its reliablyhacky(tm). self.imageidxre = re.compile(r'(\d+)(?!.*\d)') for item in batch.iterator(): self.convert(converter, item)