              resized_face = face.aligned_face
              face.hash, img = encode_image_with_hash(resized_face, extension)
              self.save_queue.put((out_filename, img))
              final_faces.append(face.to_alignment())
          self.alignments.data[os.path.basename(filename)] = final_faces
 
</s> remove         for idx, detected_face in enumerate(faces["detected_faces"]):
            output_file = detected_face["file_location"]
            extension = Path(filename).suffix
            out_filename = "{}_{}{}".format(str(output_file), str(idx), extension)

            face = detected_face["face"]
            resized_face = face.aligned_face
            face.hash, img = encode_image_with_hash(resized_face, extension)
            self.save_queue.put((out_filename, img))
 </s> add         filename, extension = os.path.splitext(os.path.basename(faces["filename"]))
        for idx, face in enumerate(faces["detected_faces"]):
            output_filename = "{}_{}{}".format(filename, str(idx), extension)
            face.hash, image = encode_image_with_hash(face.aligned_face, extension)

            saver.save(output_filename, image) </s> remove     def align_face(self, faces, size, filename):
        """ Align the detected face and add the destination file path """
        final_faces = list()
        image = faces["image"]
        detected_faces = faces["detected_faces"]
        for face in detected_faces:
            face.load_aligned(image, size=size)
            final_faces.append({"file_location": self.output_dir / Path(filename).stem,
                                "face": face})
        faces["detected_faces"] = final_faces

    def output_faces(self, filename, faces):
        """ Output faces to save thread """
 </s> add     def _output_faces(self, saver, faces):
        """ Output faces to save thread

        Set the face filename based on the frame name and put the face to the
        :class:`lib.image.ImagesSaver` save queue and add the face information to the alignments
        data.

        Parameters
        ----------
        saver: lib.images.ImagesSaver
            The background saver for saving the image
        faces: dict
            The output dictionary from :class:`plugins.extract.Pipeline.Extractor`
        """
        logger.debug("Save Faces: Start") </s> remove         if not self.verify_output and faces_count > 1:
            self.verify_output = True
 </s> add         if not self._verify_output and faces_count > 1:
            self._verify_output = True </s> remove         self._loader = BackgroundIO(arguments.input,
                                    "load",
                                    load_with_hash=self._input_is_faces,
                                    queue_size=16)
 </s> add         self._loader = ImagesLoader(arguments.input, load_with_hash=self._input_is_faces) </s> remove         self.args = arguments
        Utils.set_verbosity(self.args.loglevel)
        self.output_dir = get_folder(self.args.output_dir)
        logger.info("Output Directory: %s", self.args.output_dir)
        self.images = Images(self.args)
        self.alignments = Alignments(self.args, True, self.images.is_video)
        self.post_process = PostProcess(arguments)
        configfile = self.args.configfile if hasattr(self.args, "configfile") else None
        normalization = None if self.args.normalization == "none" else self.args.normalization
        self.extractor = Extractor(self.args.detector,
                                   self.args.aligner,
                                   self.args.masker,
                                   configfile=configfile,
                                   multiprocess=not self.args.singleprocess,
                                   rotate_images=self.args.rotate_images,
                                   min_size=self.args.min_size,
                                   normalize_method=normalization)
        self.save_queue = queue_manager.get_queue("extract_save")
        self.threads = list()
        self.verify_output = False
        self.save_interval = None
        if hasattr(self.args, "save_interval"):
            self.save_interval = self.args.save_interval
 </s> add         self._args = arguments
        Utils.set_verbosity(self._args.loglevel)

        self._output_dir = str(get_folder(self._args.output_dir))

        logger.info("Output Directory: %s", self._args.output_dir)
        self._images = ImagesLoader(self._args.input_dir, load_with_hash=False, fast_count=True)
        self._alignments = Alignments(self._args, True, self._images.is_video)

        self._existing_count = 0
        self._set_skip_list()

        self._post_process = PostProcess(arguments)
        configfile = self._args.configfile if hasattr(self._args, "configfile") else None
        normalization = None if self._args.normalization == "none" else self._args.normalization
        self._extractor = Extractor(self._args.detector,
                                    self._args.aligner,
                                    self._args.masker,
                                    configfile=configfile,
                                    multiprocess=not self._args.singleprocess,
                                    rotate_images=self._args.rotate_images,
                                    min_size=self._args.min_size,
                                    normalize_method=normalization)
        self._threads = list()
        self._verify_output = False
        self._alignments.data[os.path.basename(faces["filename"])] = final_faces
              resized_face = face.aligned_face
              face.hash, img = encode_image_with_hash(resized_face, extension)
              self.save_queue.put((out_filename, img))
              final_faces.append(face.to_alignment())
        self._alignments.data[os.path.basename(faces["filename"])] = final_faces
keep keep keep keep replace
 scripts.extract - code optimizations

Limit queue sizes to reduce RAM usage
Rename lib.image.BackgroundIO to ImageIO
Create separate ImagesLoader and ImagesSaver classes
Load/Save images from centralized lib.image.ImageIO
scripts.extract documentation 
scripts/extract.py