          extractor_name = "Align" # TODO Pass as argument
          self.extractor = PluginLoader.get_extractor(extractor_name)()
          self.faces_detected = 0
          processes = self.arguments.processes
          if processes != 1:
              files = list(self.read_directory())
              for _ in tqdm(pool_process(self.processFiles, files, processes=processes), total = len(files)):
                  self.faces_detected +=1
          else:
              try:
                  for filename in tqdm(self.read_directory()):
                      self.handleImage(filename)
  
              except Exception as e:
                  print('Failed to extract from image: {}. Reason: {}'.format(filename, e))
  
      def processFiles(self, filename):
          try:
              return self.handleImage(filename)
          except Exception as e:
 
</s> remove         self.faces_detected = 0
 </s> add  </s> remove         
 </s> add     def read_alignments(self):

        fn = os.path.join(self.arguments.input_dir,"alignments.{}".format(self.serializer.ext))
        if self.arguments.alignments_path is not None:
            fn = self.arguments.alignments_path

        try:
            print("Reading alignments from: {}".format(fn))
            with open(fn, self.serializer.roptions) as f:
                self.faces_detected = self.serializer.unmarshal(f.read())
        except Exception as e:
            print("{} not read!".format(fn))
            print(str(e))
            self.faces_detected = dict()

    def write_alignments(self):

        fn = os.path.join(self.output_dir,"alignments.{}".format(self.serializer.ext))
        if self.arguments.alignments_path is not None:
            fn = self.arguments.alignments_path
        try:
            print("Writing alignments to: {}".format(fn))
            with open(fn, self.serializer.woptions) as fh:
                fh.write(self.serializer.marshal(self.faces_detected))
        except Exception as e:
            print("{} not written!".format(fn))
            print(str(e))
            self.faces_detected = dict()
 </s> remove     
    def get_faces(self, image):
 </s> add     def have_face(self, filename):
        return filename in self.faces_detected

    def get_faces_alignments(self, filename): </s> remove             yield filename, image, self.get_faces(image)
 </s> add             if self.have_face(filename):
                faces = self.get_faces_alignments(filename)
            else:
                faces = self.get_faces(image)
            yield filename, image, faces
        try:
            if processes != 1:
                files = list(self.read_directory())
                for fn, faces in tqdm(pool_process(self.processFiles, files, processes=processes), total = len(files)):
                    self.num_faces_detected += 1
                    self.faces_detected[fn] = faces
            else:
                try:
                    for filename in tqdm(self.read_directory()):
                         self.faces_detected[filename] = self.handleImage(filename)[1]
                except Exception as e:
                    print('Failed to extract from image: {}. Reason: {}'.format(filename, e))
        finally:
            self.write_alignments()
          extractor_name = "Align" # TODO Pass as argument
          self.extractor = PluginLoader.get_extractor(extractor_name)()
          self.faces_detected = 0
          processes = self.arguments.processes
        try:
            if processes != 1:
                files = list(self.read_directory())
                for fn, faces in tqdm(pool_process(self.processFiles, files, processes=processes), total = len(files)):
                    self.num_faces_detected += 1
                    self.faces_detected[fn] = faces
            else:
                try:
                    for filename in tqdm(self.read_directory()):
                         self.faces_detected[filename] = self.handleImage(filename)[1]
                except Exception as e:
                    print('Failed to extract from image: {}. Reason: {}'.format(filename, e))
        finally:
            self.write_alignments()
        try:
            if processes != 1:
                files = list(self.read_directory())
                for fn, faces in tqdm(pool_process(self.processFiles, files, processes=processes), total = len(files)):
                    self.num_faces_detected += 1
                    self.faces_detected[fn] = faces
            else:
                try:
                    for filename in tqdm(self.read_directory()):
                         self.faces_detected[filename] = self.handleImage(filename)[1]
                except Exception as e:
                    print('Failed to extract from image: {}. Reason: {}'.format(filename, e))
        finally:
            self.write_alignments()
        try:
            if processes != 1:
                files = list(self.read_directory())
                for fn, faces in tqdm(pool_process(self.processFiles, files, processes=processes), total = len(files)):
                    self.num_faces_detected += 1
                    self.faces_detected[fn] = faces
            else:
                try:
                    for filename in tqdm(self.read_directory()):
                         self.faces_detected[filename] = self.handleImage(filename)[1]
                except Exception as e:
                    print('Failed to extract from image: {}. Reason: {}'.format(filename, e))
        finally:
            self.write_alignments()
        try:
            if processes != 1:
                files = list(self.read_directory())
                for fn, faces in tqdm(pool_process(self.processFiles, files, processes=processes), total = len(files)):
                    self.num_faces_detected += 1
                    self.faces_detected[fn] = faces
            else:
                try:
                    for filename in tqdm(self.read_directory()):
                         self.faces_detected[filename] = self.handleImage(filename)[1]
                except Exception as e:
                    print('Failed to extract from image: {}. Reason: {}'.format(filename, e))
        finally:
            self.write_alignments()
        try:
            if processes != 1:
                files = list(self.read_directory())
                for fn, faces in tqdm(pool_process(self.processFiles, files, processes=processes), total = len(files)):
                    self.num_faces_detected += 1
                    self.faces_detected[fn] = faces
            else:
                try:
                    for filename in tqdm(self.read_directory()):
                         self.faces_detected[filename] = self.handleImage(filename)[1]
                except Exception as e:
                    print('Failed to extract from image: {}. Reason: {}'.format(filename, e))
        finally:
            self.write_alignments()
        try:
            if processes != 1:
                files = list(self.read_directory())
                for fn, faces in tqdm(pool_process(self.processFiles, files, processes=processes), total = len(files)):
                    self.num_faces_detected += 1
                    self.faces_detected[fn] = faces
            else:
                try:
                    for filename in tqdm(self.read_directory()):
                         self.faces_detected[filename] = self.handleImage(filename)[1]
                except Exception as e:
                    print('Failed to extract from image: {}. Reason: {}'.format(filename, e))
        finally:
            self.write_alignments()
        try:
            if processes != 1:
                files = list(self.read_directory())
                for fn, faces in tqdm(pool_process(self.processFiles, files, processes=processes), total = len(files)):
                    self.num_faces_detected += 1
                    self.faces_detected[fn] = faces
            else:
                try:
                    for filename in tqdm(self.read_directory()):
                         self.faces_detected[filename] = self.handleImage(filename)[1]
                except Exception as e:
                    print('Failed to extract from image: {}. Reason: {}'.format(filename, e))
        finally:
            self.write_alignments()
        try:
            if processes != 1:
                files = list(self.read_directory())
                for fn, faces in tqdm(pool_process(self.processFiles, files, processes=processes), total = len(files)):
                    self.num_faces_detected += 1
                    self.faces_detected[fn] = faces
            else:
                try:
                    for filename in tqdm(self.read_directory()):
                         self.faces_detected[filename] = self.handleImage(filename)[1]
                except Exception as e:
                    print('Failed to extract from image: {}. Reason: {}'.format(filename, e))
        finally:
            self.write_alignments()
        try:
            if processes != 1:
                files = list(self.read_directory())
                for fn, faces in tqdm(pool_process(self.processFiles, files, processes=processes), total = len(files)):
                    self.num_faces_detected += 1
                    self.faces_detected[fn] = faces
            else:
                try:
                    for filename in tqdm(self.read_directory()):
                         self.faces_detected[filename] = self.handleImage(filename)[1]
                except Exception as e:
                    print('Failed to extract from image: {}. Reason: {}'.format(filename, e))
        finally:
            self.write_alignments()
        try:
            if processes != 1:
                files = list(self.read_directory())
                for fn, faces in tqdm(pool_process(self.processFiles, files, processes=processes), total = len(files)):
                    self.num_faces_detected += 1
                    self.faces_detected[fn] = faces
            else:
                try:
                    for filename in tqdm(self.read_directory()):
                         self.faces_detected[filename] = self.handleImage(filename)[1]
                except Exception as e:
                    print('Failed to extract from image: {}. Reason: {}'.format(filename, e))
        finally:
            self.write_alignments()
        try:
            if processes != 1:
                files = list(self.read_directory())
                for fn, faces in tqdm(pool_process(self.processFiles, files, processes=processes), total = len(files)):
                    self.num_faces_detected += 1
                    self.faces_detected[fn] = faces
            else:
                try:
                    for filename in tqdm(self.read_directory()):
                         self.faces_detected[filename] = self.handleImage(filename)[1]
                except Exception as e:
                    print('Failed to extract from image: {}. Reason: {}'.format(filename, e))
        finally:
            self.write_alignments()
  
      def processFiles(self, filename):
          try:
              return self.handleImage(filename)
          except Exception as e:
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 Added serializers.

This speeds up convert speed x4 on my machine. 
scripts/extract.py