Exemple #1
0
        def on_initialize(self, client_dict):
            self.type         = client_dict['type']
            self.image_size   = client_dict['image_size']
            self.face_type    = client_dict['face_type']
            self.max_faces_from_image = client_dict['max_faces_from_image']
            self.device_idx   = client_dict['device_idx']
            self.cpu_only     = client_dict['device_type'] == 'CPU'
            self.final_output_path  = Path(client_dict['final_output_dir']) if 'final_output_dir' in client_dict.keys() else None
            self.debug_dir    = client_dict['debug_dir']
            
            #transfer and set stdin in order to work code.interact in debug subprocess
            stdin_fd         = client_dict['stdin_fd']
            if stdin_fd is not None and DEBUG:
                sys.stdin = os.fdopen(stdin_fd)

            self.cached_image = (None, None)

            self.e = None
            device_config = nnlib.DeviceConfig ( cpu_only=self.cpu_only, force_gpu_idx=self.device_idx, allow_growth=True)
            self.device_vram = device_config.gpu_vram_gb[0]

            intro_str = 'Running on %s.' % (client_dict['device_name'])
            if not self.cpu_only and self.device_vram <= 2:
                intro_str += " Recommended to close all programs using this device."

            self.log_info (intro_str)

            if 'rects' in self.type:
                if self.type == 'rects-mt':
                    nnlib.import_all (device_config)
                    self.e = facelib.MTCExtractor()
                elif self.type == 'rects-dlib':
                    nnlib.import_dlib (device_config)
                    self.e = facelib.DLIBExtractor(nnlib.dlib)
                elif self.type == 'rects-s3fd':
                    nnlib.import_all (device_config)
                    self.e = facelib.S3FDExtractor()
                else:
                    raise ValueError ("Wrong type.")

                if self.e is not None:
                    self.e.__enter__()

            elif self.type == 'landmarks':
                nnlib.import_all (device_config)
                self.e = facelib.FANExtractor()
                self.e.__enter__()
                if self.device_vram >= 2:
                    self.second_pass_e = facelib.S3FDExtractor()
                    self.second_pass_e.__enter__()
                else:
                    self.second_pass_e = None
                    
            elif self.type == 'fanseg':
                nnlib.import_all (device_config)
                self.e = TernausNet(256, FaceType.toString(FaceType.FULL) )
                self.e.__enter__()
                    
            elif self.type == 'final':
                pass
Exemple #2
0
        def on_initialize(self, client_dict):
            self.type = client_dict['type']
            self.image_size = client_dict['image_size']
            self.face_type = client_dict['face_type']
            self.device_idx = client_dict['device_idx']
            self.cpu_only = client_dict['device_type'] == 'CPU'
            self.final_output_path = Path(
                client_dict['final_output_dir']
            ) if 'final_output_dir' in client_dict.keys() else None
            self.debug_dir = client_dict['debug_dir']

            self.cached_image = (None, None)

            self.e = None

            device_config = nnlib.DeviceConfig(cpu_only=self.cpu_only,
                                               force_gpu_idx=self.device_idx,
                                               allow_growth=True)
            self.device_vram = device_config.gpu_vram_gb[0]

            intro_str = 'Running on %s.' % (client_dict['device_name'])
            if not self.cpu_only and self.device_vram <= 2:
                intro_str += " Recommended to close all programs using this device."

            self.log_info(intro_str)

            if 'rects' in self.type:
                if self.type == 'rects-mt':
                    nnlib.import_all(device_config)
                    self.e = facelib.MTCExtractor()
                elif self.type == 'rects-dlib':
                    nnlib.import_dlib(device_config)
                    self.e = facelib.DLIBExtractor(nnlib.dlib)
                elif self.type == 'rects-s3fd':
                    nnlib.import_all(device_config)
                    self.e = facelib.S3FDExtractor()
                else:
                    raise ValueError("Wrong type.")

                if self.e is not None:
                    self.e.__enter__()

            elif self.type == 'landmarks':
                nnlib.import_all(device_config)
                self.e = facelib.LandmarksExtractor(nnlib.keras)
                self.e.__enter__()
                if self.device_vram >= 2:
                    self.second_pass_e = facelib.S3FDExtractor()
                    self.second_pass_e.__enter__()
                else:
                    self.second_pass_e = None

            elif self.type == 'final':
                pass
        def on_initialize(self, client_dict):
            self.log_info('Running on %s.' % (client_dict['device_name']))

            self.type = client_dict['type']
            self.image_size = client_dict['image_size']
            self.face_type = client_dict['face_type']
            self.device_idx = client_dict['device_idx']
            self.cpu_only = client_dict['device_type'] == 'CPU'
            self.output_path = Path(
                client_dict['output_dir']) if 'output_dir' in client_dict.keys(
                ) else None
            self.debug_dir = client_dict['debug_dir']
            self.detector = client_dict['detector']
            self.accurate_landmarks_extractor = client_dict[
                'accurate_landmarks_extractor']

            self.cached_image = (None, None)

            self.e = None
            device_config = nnlib.DeviceConfig(cpu_only=self.cpu_only,
                                               force_gpu_idx=self.device_idx,
                                               allow_growth=True)
            if self.type == 'rects':
                if self.detector is not None:
                    if self.detector == 'mt':
                        nnlib.import_all(device_config)
                        self.e = facelib.MTCExtractor()
                    elif self.detector == 'dlib':
                        nnlib.import_dlib(device_config)
                        self.e = facelib.DLIBExtractor(nnlib.dlib)
                    elif self.detector == 's3fd':
                        nnlib.import_all(device_config)
                        self.e = facelib.S3FDExtractor()
                    else:
                        raise ValueError("Wrong detector type.")

                    if self.e is not None:
                        self.e.__enter__()

            elif self.type == 'landmarks':
                nnlib.import_all(device_config)
                self.e = facelib.LandmarksExtractor(nnlib.keras)
                self.e.__enter__()
                if self.accurate_landmarks_extractor and device_config.gpu_vram_gb[
                        0] >= 2:
                    self.second_pass_e = facelib.S3FDExtractor()
                    self.second_pass_e.__enter__()
                else:
                    self.second_pass_e = None

            elif self.type == 'final':
                pass
Exemple #4
0
        def on_initialize(self, client_dict):
            self.type                 = client_dict['type']
            self.image_size           = client_dict['image_size']
            self.face_type            = client_dict['face_type']
            self.max_faces_from_image = client_dict['max_faces_from_image']
            self.device_idx           = client_dict['device_idx']
            self.cpu_only             = client_dict['device_type'] == 'CPU'
            self.final_output_path    = client_dict['final_output_path']
            self.output_debug_path    = client_dict['output_debug_path']

            #transfer and set stdin in order to work code.interact in debug subprocess
            stdin_fd         = client_dict['stdin_fd']
            if stdin_fd is not None and DEBUG:
                sys.stdin = os.fdopen(stdin_fd)

            if self.cpu_only:
                device_config = nn.DeviceConfig.CPU()
                place_model_on_cpu = True
            else:
                device_config = nn.DeviceConfig.GPUIndexes ([self.device_idx])
                place_model_on_cpu = device_config.devices[0].total_mem_gb < 4

            if self.type == 'all' or 'rects' in self.type or 'landmarks' in self.type:
                nn.initialize (device_config)

            self.log_info (f"Running on {client_dict['device_name'] }")

            if self.type == 'all' or self.type == 'rects-s3fd' or 'landmarks' in self.type:
                self.rects_extractor = facelib.S3FDExtractor(place_model_on_cpu=place_model_on_cpu)

            if self.type == 'all' or 'landmarks' in self.type:
                self.landmarks_extractor = facelib.FANExtractor(place_model_on_cpu=place_model_on_cpu)

            self.cached_image = (None, None)
Exemple #5
0
        def on_initialize(self, client_dict):
            self.type = client_dict["type"]
            self.image_size = client_dict["image_size"]
            self.face_type = client_dict["face_type"]
            self.device_idx = client_dict["device_idx"]
            self.cpu_only = client_dict["device_type"] == "CPU"
            self.final_output_path = (Path(client_dict["final_output_dir"])
                                      if "final_output_dir"
                                      in client_dict.keys() else None)
            self.debug_dir = client_dict["debug_dir"]

            # transfer and set stdin in order to work code.interact in debug subprocess
            stdin_fd = client_dict["stdin_fd"]
            if stdin_fd is not None and DEBUG:
                sys.stdin = os.fdopen(stdin_fd)

            self.cached_image = (None, None)

            self.e = None
            device_config = nnlib.DeviceConfig(cpu_only=self.cpu_only,
                                               force_gpu_idx=self.device_idx,
                                               allow_growth=True)
            self.device_vram = device_config.gpu_vram_gb[0]

            intro_str = "Running on %s." % (client_dict["device_name"])
            if not self.cpu_only and self.device_vram <= 2:
                intro_str += " Recommended to close all programs using this device."

            self.log_info(intro_str)

            if "rects" in self.type:
                if self.type == "rects-mt":
                    nnlib.import_all(device_config)
                    self.e = facelib.MTCExtractor()
                elif self.type == "rects-dlib":
                    nnlib.import_dlib(device_config)
                    self.e = facelib.DLIBExtractor(nnlib.dlib)
                elif self.type == "rects-s3fd":
                    nnlib.import_all(device_config)
                    self.e = facelib.S3FDExtractor()
                else:
                    raise ValueError("Wrong type.")

                if self.e is not None:
                    self.e.__enter__()

            elif self.type == "landmarks":
                nnlib.import_all(device_config)
                self.e = facelib.LandmarksExtractor(nnlib.keras)
                self.e.__enter__()
                if self.device_vram >= 2:
                    self.second_pass_e = facelib.S3FDExtractor()
                    self.second_pass_e.__enter__()
                else:
                    self.second_pass_e = None

            elif self.type == "fanseg":
                nnlib.import_all(device_config)
                self.e = facelib.FANSegmentator(
                    256, FaceType.toString(FaceType.FULL))
                self.e.__enter__()

            elif self.type == "final":
                pass