              kwargs["processes"] = 1
          mp_func = PoolProcess if self.detector.parent_is_pool else SpawnProcess
          self.process_detect = mp_func(self.detector.run, **kwargs)
  
          event = None
          if hasattr(self.process_detect, "event"):
              event = self.process_detect.event
  
          self.process_detect.start()
  
          if event is None:
              logger.debug("Launched Detector")
              return
 
</s> remove             event.wait(60)
 </s> add             for seconds in range(60):
                event.wait(seconds)
                if event.is_set():
                    break
                if error and error.is_set():
                    break </s> remove         super().initialize(*args, **kwargs)
        logger.info("Initializing S3FD Detector...")
        card_id, vram_free, vram_total = self.get_vram_free()
        if vram_free <= self.vram:
            tf_ratio = 1.0
        else:
            tf_ratio = self.vram / vram_total
        logger.verbose("Reserving %s%% of total VRAM per s3fd thread", round(tf_ratio, 2))

        confidence = self.config["confidence"] / 100
        self.model = S3fd(self.model_path, self.target, tf_ratio, card_id, confidence)

        if not self.model.is_gpu:
            alloc = 2048
            logger.warning("Using CPU")
        else:
            logger.debug("Using GPU")
            alloc = vram_free
        logger.debug("Allocated for Tensorflow: %sMB", alloc)

        self.batch_size = int(alloc / self.vram)

        if self.batch_size < 1:
            raise ValueError("Insufficient VRAM available to continue "
                             "({}MB)".format(int(alloc)))

        logger.verbose("Processing in %s threads", self.batch_size)

        self.init.set()
        logger.info("Initialized S3FD Detector.")
 </s> add         try:
            super().initialize(*args, **kwargs)
            logger.info("Initializing S3FD Detector...")
            card_id, vram_free, vram_total = self.get_vram_free()
            if vram_free <= self.vram:
                tf_ratio = 1.0
            else:
                tf_ratio = self.vram / vram_total
            logger.verbose("Reserving %s%% of total VRAM per s3fd thread",
                           round(tf_ratio * 100, 2))

            confidence = self.config["confidence"] / 100
            self.model = S3fd(self.model_path, self.target, tf_ratio, card_id, confidence)

            if not self.model.is_gpu:
                alloc = 2048
                logger.warning("Using CPU")
            else:
                logger.debug("Using GPU")
                alloc = vram_free
            logger.debug("Allocated for Tensorflow: %sMB", alloc)

            self.batch_size = int(alloc / self.vram)

            if self.batch_size < 1:
                raise ValueError("Insufficient VRAM available to continue "
                                 "({}MB)".format(int(alloc)))

            logger.verbose("Processing in %s threads", self.batch_size)

            self.init.set()
            logger.info("Initialized S3FD Detector.")
        except Exception as err:
            self.error.set()
            raise err </s> remove         super().initialize(*args, **kwargs)
        logger.verbose("Initializing Dlib-CNN Detector...")
        self.detector = dlib.cnn_face_detection_model_v1(  # pylint: disable=c-extension-no-member
            self.model_path)
        is_cuda = self.compiled_for_cuda()
        if is_cuda:
            logger.debug("Using GPU")
            _, vram_free, _ = self.get_vram_free()
        else:
            logger.verbose("Using CPU")
            vram_free = 2048
 </s> add         try:
            super().initialize(*args, **kwargs)
            logger.verbose("Initializing Dlib-CNN Detector...")
            self.detector = dlib.cnn_face_detection_model_v1(  # pylint: disable=c-extension-no-member
                self.model_path)
            is_cuda = self.compiled_for_cuda()
            if is_cuda:
                logger.debug("Using GPU")
                _, vram_free, _ = self.get_vram_free()
            else:
                logger.verbose("Using CPU")
                vram_free = 2048 </s> remove         super().initialize(*args, **kwargs)
        logger.info("Initializing MTCNN Detector...")
        is_gpu = False

        # Must import tensorflow inside the spawned process
        # for Windows machines
        import_tensorflow()
        _, vram_free, _ = self.get_vram_free()
        mtcnn_graph = tf.Graph()

        # Windows machines sometimes misreport available vram, and overuse
        # causing OOM. Allow growth fixes that
        config = tf.ConfigProto()
        config.gpu_options.allow_growth = True  # pylint: disable=no-member

        with mtcnn_graph.as_default():  # pylint: disable=not-context-manager
            sess = tf.Session(config=config)
            with sess.as_default():  # pylint: disable=not-context-manager
                pnet, rnet, onet = create_mtcnn(sess, self.model_path)

            if any("gpu" in str(device).lower()
                   for device in sess.list_devices()):
                logger.debug("Using GPU")
                is_gpu = True
        mtcnn_graph.finalize()

        if not is_gpu:
            alloc = 2048
            logger.warning("Using CPU")
        else:
            alloc = vram_free
        logger.debug("Allocated for Tensorflow: %sMB", alloc)
 </s> add         try:
            super().initialize(*args, **kwargs)
            logger.info("Initializing MTCNN Detector...")
            is_gpu = False

            # Must import tensorflow inside the spawned process
            # for Windows machines
            import_tensorflow()
            _, vram_free, _ = self.get_vram_free()
            mtcnn_graph = tf.Graph()

            # Windows machines sometimes misreport available vram, and overuse
            # causing OOM. Allow growth fixes that
            config = tf.ConfigProto()
            config.gpu_options.allow_growth = True  # pylint: disable=no-member

            with mtcnn_graph.as_default():  # pylint: disable=not-context-manager
                sess = tf.Session(config=config)
                with sess.as_default():  # pylint: disable=not-context-manager
                    pnet, rnet, onet = create_mtcnn(sess, self.model_path)

                if any("gpu" in str(device).lower()
                       for device in sess.list_devices()):
                    logger.debug("Using GPU")
                    is_gpu = True
            mtcnn_graph.finalize()

            if not is_gpu:
                alloc = 2048
                logger.warning("Using CPU")
            else:
                alloc = vram_free
            logger.debug("Allocated for Tensorflow: %sMB", alloc)
        event = self.process_detect.event if hasattr(self.process_detect, "event") else None
        error = self.process_detect.error if hasattr(self.process_detect, "error") else None
              kwargs["processes"] = 1
          mp_func = PoolProcess if self.detector.parent_is_pool else SpawnProcess
          self.process_detect = mp_func(self.detector.run, **kwargs)
  
        event = self.process_detect.event if hasattr(self.process_detect, "event") else None
        error = self.process_detect.error if hasattr(self.process_detect, "error") else None
        event = self.process_detect.event if hasattr(self.process_detect, "event") else None
        error = self.process_detect.error if hasattr(self.process_detect, "error") else None
        event = self.process_detect.event if hasattr(self.process_detect, "event") else None
        error = self.process_detect.error if hasattr(self.process_detect, "error") else None
        event = self.process_detect.event if hasattr(self.process_detect, "event") else None
        error = self.process_detect.error if hasattr(self.process_detect, "error") else None
          self.process_detect.start()
  
          if event is None:
              logger.debug("Launched Detector")
              return
keep keep keep keep replace replace replace replace keep keep keep keep keep
 Better extractor error handling on initialization 
scripts/extract.py