          Utils.finalize(self.images.images_found,
                         self.faces.num_faces_detected,
                         self.faces.verify_output)
  
      def generate_alignments(self):
          """ Generate an alignments file if one does not already
          exist. Does not save extracted faces """
          print('Alignments file not found. Generating at default values...')
          extract = Extract(self.args)
          extract.export_face = False
          extract.process()
  
      def load_model(self):
          """ Load the model requested for conversion """
          model_name = self.args.trainer
          model_dir = get_folder(self.args.model_dir)
 
</s> remove         Utils.finalize(self.images.images_found,
                       self.faces.num_faces_detected,
                       self.faces.verify_output)
 </s> add         if self.extract_faces:
            queue_manager.terminate_queues() </s> remove         model = PluginLoader.get_model(self.trainer_name)(model_dir, self.args.gpus)
 </s> add         model = PluginLoader.get_model(self.trainer_name)(model_dir,
                                                          self.args.gpus) </s> remove         self.write_alignments()
        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
 </s> add     def load_images(self):
        """ Load the images """
        load_queue = queue_manager.get_queue("load")
        for filename, image in self.images.load():
            imagename = os.path.basename(filename)
            if imagename in self.alignments.data.keys():
                continue
            load_queue.put((filename, image))
        load_queue.put("EOF") </s> remove     @staticmethod
    def load_extractor(extractor_name="Align"):
        """ Load the requested extractor for extraction """
        extractor = PluginLoader.get_extractor(extractor_name)()
 </s> add     def save(self):
        """ Write the serialized alignments file """
        try:
            print("Writing alignments to: {}".format(self.location))
            with open(self.location, self.serializer.woptions) as align:
                align.write(self.serializer.marshal(self.data))
        except Exception as err:
            print("{} not written!".format(self.location))
            print(str(err)) </s> remove     def write_alignments(self):
        """ Save the alignments file """
        self.alignments.write_alignments(self.faces.faces_detected)
 </s> add     def reload_images(self, detected_faces):
        """ Reload the images and pair to detected face """
        load_queue = queue_manager.get_queue("detect")
        for filename, image in self.images.load():
            detect_item = detected_faces.pop(filename, None)
            if not detect_item:
                continue
            detect_item["image"] = image
            load_queue.put(detect_item)
        load_queue.put("EOF")
        Utils.finalize(self.images.images_found,
                       self.faces_count,
                       self.verify_output)

    def load_extractor(self):
        """ Set on the fly extraction """
        print("\nNo Alignments file found. Extracting on the fly.\n"
              "NB: This will use the inferior dlib-hog for extraction "
              "and dlib pose predictor for landmarks.\nIt is recommended "
              "to perfom Extract first for superior results\n")
        for task in ("load", "detect", "align"):
            queue_manager.add_queue(task, maxsize=0)

        detector = PluginLoader.get_detector("dlib_hog")(
            verbose=self.args.verbose)
        aligner = PluginLoader.get_aligner("dlib")(verbose=self.args.verbose)

        d_kwargs = {"in_queue": queue_manager.get_queue("load"),
                    "out_queue": queue_manager.get_queue("detect")}
        a_kwargs = {"in_queue": queue_manager.get_queue("detect"),
                    "out_queue": queue_manager.get_queue("align")}

        d_process = SpawnProcess()
        d_event = d_process.event
        a_process = SpawnProcess()
        a_event = a_process.event

        d_process.in_process(detector.detect_faces, **d_kwargs)
        a_process.in_process(aligner.align, **a_kwargs)
        d_event.wait(10)
        if not d_event.is_set():
            raise ValueError("Error inititalizing Detector")
        a_event.wait(10)
        if not a_event.is_set():
            raise ValueError("Error inititalizing Aligner")

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

    def load_extractor(self):
        """ Set on the fly extraction """
        print("\nNo Alignments file found. Extracting on the fly.\n"
              "NB: This will use the inferior dlib-hog for extraction "
              "and dlib pose predictor for landmarks.\nIt is recommended "
              "to perfom Extract first for superior results\n")
        for task in ("load", "detect", "align"):
            queue_manager.add_queue(task, maxsize=0)

        detector = PluginLoader.get_detector("dlib_hog")(
            verbose=self.args.verbose)
        aligner = PluginLoader.get_aligner("dlib")(verbose=self.args.verbose)

        d_kwargs = {"in_queue": queue_manager.get_queue("load"),
                    "out_queue": queue_manager.get_queue("detect")}
        a_kwargs = {"in_queue": queue_manager.get_queue("detect"),
                    "out_queue": queue_manager.get_queue("align")}

        d_process = SpawnProcess()
        d_event = d_process.event
        a_process = SpawnProcess()
        a_event = a_process.event

        d_process.in_process(detector.detect_faces, **d_kwargs)
        a_process.in_process(aligner.align, **a_kwargs)
        d_event.wait(10)
        if not d_event.is_set():
            raise ValueError("Error inititalizing Detector")
        a_event.wait(10)
        if not a_event.is_set():
            raise ValueError("Error inititalizing Aligner")

        self.extract_faces = True
        Utils.finalize(self.images.images_found,
                       self.faces_count,
                       self.verify_output)

    def load_extractor(self):
        """ Set on the fly extraction """
        print("\nNo Alignments file found. Extracting on the fly.\n"
              "NB: This will use the inferior dlib-hog for extraction "
              "and dlib pose predictor for landmarks.\nIt is recommended "
              "to perfom Extract first for superior results\n")
        for task in ("load", "detect", "align"):
            queue_manager.add_queue(task, maxsize=0)

        detector = PluginLoader.get_detector("dlib_hog")(
            verbose=self.args.verbose)
        aligner = PluginLoader.get_aligner("dlib")(verbose=self.args.verbose)

        d_kwargs = {"in_queue": queue_manager.get_queue("load"),
                    "out_queue": queue_manager.get_queue("detect")}
        a_kwargs = {"in_queue": queue_manager.get_queue("detect"),
                    "out_queue": queue_manager.get_queue("align")}

        d_process = SpawnProcess()
        d_event = d_process.event
        a_process = SpawnProcess()
        a_event = a_process.event

        d_process.in_process(detector.detect_faces, **d_kwargs)
        a_process.in_process(aligner.align, **a_kwargs)
        d_event.wait(10)
        if not d_event.is_set():
            raise ValueError("Error inititalizing Detector")
        a_event.wait(10)
        if not a_event.is_set():
            raise ValueError("Error inititalizing Aligner")

        self.extract_faces = True
        Utils.finalize(self.images.images_found,
                       self.faces_count,
                       self.verify_output)

    def load_extractor(self):
        """ Set on the fly extraction """
        print("\nNo Alignments file found. Extracting on the fly.\n"
              "NB: This will use the inferior dlib-hog for extraction "
              "and dlib pose predictor for landmarks.\nIt is recommended "
              "to perfom Extract first for superior results\n")
        for task in ("load", "detect", "align"):
            queue_manager.add_queue(task, maxsize=0)

        detector = PluginLoader.get_detector("dlib_hog")(
            verbose=self.args.verbose)
        aligner = PluginLoader.get_aligner("dlib")(verbose=self.args.verbose)

        d_kwargs = {"in_queue": queue_manager.get_queue("load"),
                    "out_queue": queue_manager.get_queue("detect")}
        a_kwargs = {"in_queue": queue_manager.get_queue("detect"),
                    "out_queue": queue_manager.get_queue("align")}

        d_process = SpawnProcess()
        d_event = d_process.event
        a_process = SpawnProcess()
        a_event = a_process.event

        d_process.in_process(detector.detect_faces, **d_kwargs)
        a_process.in_process(aligner.align, **a_kwargs)
        d_event.wait(10)
        if not d_event.is_set():
            raise ValueError("Error inititalizing Detector")
        a_event.wait(10)
        if not a_event.is_set():
            raise ValueError("Error inititalizing Aligner")

        self.extract_faces = True
        Utils.finalize(self.images.images_found,
                       self.faces_count,
                       self.verify_output)

    def load_extractor(self):
        """ Set on the fly extraction """
        print("\nNo Alignments file found. Extracting on the fly.\n"
              "NB: This will use the inferior dlib-hog for extraction "
              "and dlib pose predictor for landmarks.\nIt is recommended "
              "to perfom Extract first for superior results\n")
        for task in ("load", "detect", "align"):
            queue_manager.add_queue(task, maxsize=0)

        detector = PluginLoader.get_detector("dlib_hog")(
            verbose=self.args.verbose)
        aligner = PluginLoader.get_aligner("dlib")(verbose=self.args.verbose)

        d_kwargs = {"in_queue": queue_manager.get_queue("load"),
                    "out_queue": queue_manager.get_queue("detect")}
        a_kwargs = {"in_queue": queue_manager.get_queue("detect"),
                    "out_queue": queue_manager.get_queue("align")}

        d_process = SpawnProcess()
        d_event = d_process.event
        a_process = SpawnProcess()
        a_event = a_process.event

        d_process.in_process(detector.detect_faces, **d_kwargs)
        a_process.in_process(aligner.align, **a_kwargs)
        d_event.wait(10)
        if not d_event.is_set():
            raise ValueError("Error inititalizing Detector")
        a_event.wait(10)
        if not a_event.is_set():
            raise ValueError("Error inititalizing Aligner")

        self.extract_faces = True
        Utils.finalize(self.images.images_found,
                       self.faces_count,
                       self.verify_output)

    def load_extractor(self):
        """ Set on the fly extraction """
        print("\nNo Alignments file found. Extracting on the fly.\n"
              "NB: This will use the inferior dlib-hog for extraction "
              "and dlib pose predictor for landmarks.\nIt is recommended "
              "to perfom Extract first for superior results\n")
        for task in ("load", "detect", "align"):
            queue_manager.add_queue(task, maxsize=0)

        detector = PluginLoader.get_detector("dlib_hog")(
            verbose=self.args.verbose)
        aligner = PluginLoader.get_aligner("dlib")(verbose=self.args.verbose)

        d_kwargs = {"in_queue": queue_manager.get_queue("load"),
                    "out_queue": queue_manager.get_queue("detect")}
        a_kwargs = {"in_queue": queue_manager.get_queue("detect"),
                    "out_queue": queue_manager.get_queue("align")}

        d_process = SpawnProcess()
        d_event = d_process.event
        a_process = SpawnProcess()
        a_event = a_process.event

        d_process.in_process(detector.detect_faces, **d_kwargs)
        a_process.in_process(aligner.align, **a_kwargs)
        d_event.wait(10)
        if not d_event.is_set():
            raise ValueError("Error inititalizing Detector")
        a_event.wait(10)
        if not a_event.is_set():
            raise ValueError("Error inititalizing Aligner")

        self.extract_faces = True
        Utils.finalize(self.images.images_found,
                       self.faces_count,
                       self.verify_output)

    def load_extractor(self):
        """ Set on the fly extraction """
        print("\nNo Alignments file found. Extracting on the fly.\n"
              "NB: This will use the inferior dlib-hog for extraction "
              "and dlib pose predictor for landmarks.\nIt is recommended "
              "to perfom Extract first for superior results\n")
        for task in ("load", "detect", "align"):
            queue_manager.add_queue(task, maxsize=0)

        detector = PluginLoader.get_detector("dlib_hog")(
            verbose=self.args.verbose)
        aligner = PluginLoader.get_aligner("dlib")(verbose=self.args.verbose)

        d_kwargs = {"in_queue": queue_manager.get_queue("load"),
                    "out_queue": queue_manager.get_queue("detect")}
        a_kwargs = {"in_queue": queue_manager.get_queue("detect"),
                    "out_queue": queue_manager.get_queue("align")}

        d_process = SpawnProcess()
        d_event = d_process.event
        a_process = SpawnProcess()
        a_event = a_process.event

        d_process.in_process(detector.detect_faces, **d_kwargs)
        a_process.in_process(aligner.align, **a_kwargs)
        d_event.wait(10)
        if not d_event.is_set():
            raise ValueError("Error inititalizing Detector")
        a_event.wait(10)
        if not a_event.is_set():
            raise ValueError("Error inititalizing Aligner")

        self.extract_faces = True
        Utils.finalize(self.images.images_found,
                       self.faces_count,
                       self.verify_output)

    def load_extractor(self):
        """ Set on the fly extraction """
        print("\nNo Alignments file found. Extracting on the fly.\n"
              "NB: This will use the inferior dlib-hog for extraction "
              "and dlib pose predictor for landmarks.\nIt is recommended "
              "to perfom Extract first for superior results\n")
        for task in ("load", "detect", "align"):
            queue_manager.add_queue(task, maxsize=0)

        detector = PluginLoader.get_detector("dlib_hog")(
            verbose=self.args.verbose)
        aligner = PluginLoader.get_aligner("dlib")(verbose=self.args.verbose)

        d_kwargs = {"in_queue": queue_manager.get_queue("load"),
                    "out_queue": queue_manager.get_queue("detect")}
        a_kwargs = {"in_queue": queue_manager.get_queue("detect"),
                    "out_queue": queue_manager.get_queue("align")}

        d_process = SpawnProcess()
        d_event = d_process.event
        a_process = SpawnProcess()
        a_event = a_process.event

        d_process.in_process(detector.detect_faces, **d_kwargs)
        a_process.in_process(aligner.align, **a_kwargs)
        d_event.wait(10)
        if not d_event.is_set():
            raise ValueError("Error inititalizing Detector")
        a_event.wait(10)
        if not a_event.is_set():
            raise ValueError("Error inititalizing Aligner")

        self.extract_faces = True
  
      def load_model(self):
          """ Load the model requested for conversion """
          model_name = self.args.trainer
          model_dir = get_folder(self.args.model_dir)
keep keep keep keep replace replace replace replace replace replace replace keep keep keep keep keep
 Extraction - Speed improvements (#522) (#523)

* Extraction - Speed improvements (#522)

* Initial Plugin restructure

* Detectors to plugins. Detector speed improvements

* Re-implement dlib aligner, remove models, FAN to TF. Parallel processing

* Update manual, update convert, implement parallel/serial switching

* linting + fix cuda check (setup.py). requirements update keras 2.2.4

* Add extract size option. Fix dlib hog init

* GUI: Increase tooltip width

* Update alignment tool to support new DetectedFace

* Add skip existing faces option

* Fix sort tool to new plugin structure

* remove old align plugin

* fix convert -skip faces bug

* Fix convert skipping no faces frames

* Convert - draw onto transparent layer

* Fix blur threshold bug

* fix skip_faces convert bug

* Fix training 
scripts/convert.py