def doInit(self, use_coeff_filter=True): try: facenet_graph = tf_graph.FaceGraph() self.embs_extractor = face_extractor.FacenetExtractor( facenet_graph, model_path=Config.Model.FACENET_DIR) self.use_coeff_filter = use_coeff_filter if use_coeff_filter: coeff_graph = tf_graph.FaceGraph() self.coeff_extractor = face_extractor.FacenetExtractor( coeff_graph, model_path=Config.Model.COEFF_DIR) except: logger.exception("CUDA out off memory", exc_info=True) print(self.name, '=' * 10)
def init(self): self.bind_dir = os.environ.get('BIND_DIR', '') # below is for mask_glass_classification self.gm_face_detector = face_detector.MTCNNDetector( tf_graph.FaceGraph()) self.gm_preprocessor = preprocess.Preprocessor( algs=preprocess.normalization) self.gm_glasses_classifier = mask_glasses.GlassesClassifier() self.gm_mask_classifier = mask_glasses.MaskClassifier()
def doInit(self): face_graph = tf_graph.FaceGraph() try: self.extractor = face_extractor.FacenetExtractor( face_graph, model_path=Config.Model.COEFF_DIR) except: logger.exception("CUDA out off memory", exc_info=True) self.preprocessor = preprocess.Preprocessor() print(self.name, '=' * 10)
def doInit(self): face_graph = tf_graph.FaceGraph() try: self.extractor = face_extractor.ArcFaceExtractor( model_path=Config.Model.ARCFACE_DIR) except: logger.exception("CUDA out off memory", exc_info=True) print(self.name, '=' * 10)
def doInit(self): face_graph = tf_graph.FaceGraph() try: self.face_detector = face_detector.MTCNNDetector( face_graph, scale_factor=Config.MTCNN.SCALE_FACTOR) except: logger.exception("CUDA device out of memory") super(FaceDetectWorker, self).__init__() self.face_count = 0 self.detected_frame_count = 0 print(self.name, '=' * 10)
def init(self): self.pipeline = self.build_pipeline() self.mtcnn_detector = face_detector.MTCNNDetector(tf_graph.FaceGraph()) pass
def run_demo(self): ''' This is main function ''' # TODO: Move this to pipeline _face_detector = face_detector.MTCNNDetector(tf_graph.FaceGraph()) _preprocessor = preprocess.Preprocessor(algs=preprocess.normalization) glasses_classifier = mask_glasses.GlassesClassifier() mask_classifier = mask_glasses.MaskClassifier() waiting_images = dict_and_list.WaitingImageQueue(2) result_list = dict_and_list.EmbsDict(4) print('Begin') retry = 0 frame_counter = 0 while True: frame, client_id = self.frame_reader.next_frame() if frame is None: retry += 1 print('Retry %s times' % retry) # TODO: a bang want this to run forever, maybe remove in the furture #if retry >= DemoGlassesMaskServer.MAX_RETRY: # break continue # TODO: Try to convert to pipeline frame_counter += 1 if frame_counter % 2 == 0: # skip 1 frame every continue print('Frame', frame_counter, frame.shape) bbs, pts = _face_detector.detect_face(frame) if len(bbs) > 0: preprocessed_frame = _preprocessor.process(frame) waiting_images.put(client_id, preprocessed_frame) if waiting_images.has_enough(client_id): images = waiting_images.get(client_id) images = np.array(images) has_masks = mask_classifier.is_wearing_mask(images) has_glasses = glasses_classifier.is_wearing_glasses(images) results = np.array([has_glasses, has_masks]) result_list.put(client_id, results.T) matching_results = result_list.get(client_id) has_glasses = self.find_most_common(matching_results[:, 0]) has_mask = self.find_most_common(matching_results[:, 1]) result = 'Has glasses %s, has mask %s' % (has_glasses, has_mask) print('Result', result) self.image_socket.put_result(client_id=client_id, status='successful', face_name=result) else: self.image_socket.put_result(client_id=client_id, status='alert', face_name='Detecting') print("No more frame, stop")