  """ The master faceswap.py script """
  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")
 
</s> remove from lib.cli import FullHelpArgumentParser

from scripts.extract import ExtractTrainingData
from scripts.train import TrainingProcessor
from scripts.convert import ConvertImage
from scripts.gui import TKGui
 </s> add  </s> remove         extractor_name = "Align" # TODO Pass as argument
        self.extractor = PluginLoader.get_extractor(extractor_name)()
        processes = self.arguments.processes
        try:
            if processes != 1:
                files = list(self.read_directory())
                for filename, faces in tqdm(pool_process(self.processFiles, files, processes=processes), total = len(files)):
                    self.num_faces_detected += 1
                    self.faces_detected[os.path.basename(filename)] = faces
            else:
                for filename in tqdm(self.read_directory()):
                    try:
                        image = cv2.imread(filename)
                        self.faces_detected[os.path.basename(filename)] = self.handleImage(image, filename)
                    except Exception as e:
                        if self.arguments.verbose:
                            print('Failed to extract from image: {}. Reason: {}'.format(filename, e))
                        pass
        finally:
            self.write_alignments()

    def processFiles(self, filename):
 </s> add         """ Perform the extraction process """
        print('Starting, this may take a while...')
        Utils.set_verbosity(self.args.verbose)

        if hasattr(self.args, 'processes') and self.args.processes > 1:
            self.extract_multi_process()
        else:
            self.extract_single_process()

        self.alignments.write_alignments(self.faces.faces_detected)

        images, faces = Utils.finalize(self.images.images_found,
                                       self.faces.num_faces_detected,
                                       self.faces.verify_output)
        self.images.images_found = images
        self.faces.num_faces_detected = faces

    def extract_single_process(self):
        """ Run extraction in a single process """
        for filename in tqdm(self.images.input_images):
            filename, faces = self.process_single_image(filename)
            self.faces.faces_detected[os.path.basename(filename)] = faces

    def extract_multi_process(self):
        """ Run the extraction on the correct number of processes """
        for filename, faces in tqdm(pool_process(self.process_single_image,
                                                 self.images.input_images,
                                                 processes=self.args.processes),
                                    total=self.images.images_found):
            self.faces.num_faces_detected += 1
            self.faces.faces_detected[os.path.basename(filename)] = faces

    def process_single_image(self, filename):
        """ Detect faces in an image. Rotate the image the specified amount
            until at least one face is found, or until image rotations are
            depleted.
            Once at least one face has been detected, pass to process_single_face
            to process the individual faces """
        retval = filename, list() </s> remove import cv2
import numpy
import time
 </s> add #!/usr/bin python3
""" The script to run the training process of faceswap """ </s> remove # DLIB is a GPU Memory hog, so the following modules should only be imported when required
detect_faces = None
DetectedFace = None
FaceFilter = None

def import_faces_detect():
    ''' Import the faces_detect module only when it is required '''
    global detect_faces
    global DetectedFace
    if detect_faces is None or DetectedFace is None:
        import lib.faces_detect 
        detect_faces = lib.faces_detect.detect_faces
        DetectedFace = lib.faces_detect.DetectedFace
 </s> add from plugins.PluginLoader import PluginLoader

class ScriptExecutor(object):
    """ Loads the relevant script modules and executes the script.
        This class is initialised in each of the argparsers for the relevant command,
        then execute script is called within their set_default function """

    def __init__(self, command, subparsers=None):
        self.command = command.lower()
        self.subparsers = subparsers

    def import_script(self):
        """ Only import a script's modules when running that script."""
        if self.command == 'extract':
            from scripts.extract import Extract as script
        elif self.command == 'train':
            from scripts.train import Train as script
        elif self.command == 'convert':
            from scripts.convert import Convert as script
        elif self.command == 'gui':
            from scripts.gui import Gui as script
        else:
            script = None
        return script
import lib.cli as cli

  """ 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")
keep add keep keep keep keep
 cli/scripts Refactor (#367)

* Refactor for PEP 8 and split process function

* Remove backwards compatibility for skip frames

* Split optional functions into own class. Make functions more modular

* Conform scripts folder to PEP 8

* train.py - Fix write image bug. Make more modular

* extract.py - Make more modular, Put optional actions into own class

* cli.py - start PEP 8

* cli,py - Pep 8. Refactor and make modular. Bugfixes

* 1st round refactor. Completely untested and probably broken.

* convert.py: Extract alignments from frames if they don't exist

* BugFix: SkipExisting broken since face name refactor

* Extract.py tested

* Minor formatting

* convert.py + train.py amended not tested

* train.py - Semi-fix for hang on reaching target iteration. Now quits on preview mode
Make tensorflow / system warning less verbose

* 2nd pass refactor. Semi tested

bugfixes

* Remove obsolete code. imread/write to Utils

* rename inout.py to fsmedia.py

* Final bugfixes 
faceswap.py