def main(_): args = parser.parse_args() with tf.Session() as sess: model = Face(sess, args) if args.phase == "train": model.train(args) print('train mode')
def _read_face(self): n = self._read_normal() # get face-specific data verts = struct.unpack("<4H", self.data.read(2 * 4)) texture = struct.unpack("<H", self.data.read(2))[0] # skip unknown data self.data.read(2) # construct face dict return Face(verts, n, n.group, texture)
def main(_): args = parser.parse_args() log.init("FaceNeural", logging.DEBUG, log_path="output/log.txt") with tf.Session() as sess: if args.phase == "train": model = Face(sess, args) model.train(args) log.info('train mode') elif args.phase == "inference": log.info("inference") model = Face(sess, args) model.inference(args) elif args.phase == "lightcnn": log.info("light cnn test") elif args.phase == "faceparsing": log.info("faceparsing") elif args.phase == "net": log.info("net start with ports (%d, %d)", 5010, 5011) net = Net(5010, 5011) while True: r_input = raw_input("command: \n") if r_input == "s": msg = raw_input("input: ") net.only_send(msg) elif r_input == 'r': msg = raw_input("input: ") net.send_recv(msg) elif r_input == "q": net.only_send("quit") net.close() break else: log.error("unknown code, quit") net.close() break
def detect(self, image): """ returns a Face object or None if a face does not found """ gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) faces = self.face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5) if len(faces) == 0: if self.num_recovery >= self.max_recovery: self.last_face = None self.num_recovery = 0 if self.last_face is not None: self.num_recovery = self.num_recovery + 1 return self.last_face (x, y, w, h) = faces[0] face = Face(x, y, w, h) self.last_face = face self.num_recovery = 0 return face
def recognize_face(self, img: np.ndarray, face_box: Box) -> Face: shape: dlib.full_object_detection = self.face_shape_predictor( img, face_box.to_dlib_rect()) descriptor: np.ndarray = np.asarray( self.face_recognition_model.compute_face_descriptor(img, shape)) return Face(box=face_box, shape=shape, descriptor=descriptor)