610265158 / Peppa_Pig_Face_Landmark

A simple face detect and alignment method, which is easy and stable.
Apache License 2.0
525 stars 116 forks source link

face detection accuracy low #22

Closed SaddamBInSyed closed 4 years ago

SaddamBInSyed commented 4 years ago

Thanks for your good work.

When I testing the Tf1 version on ubuntu 18.04 OS then pepa-face engine application some time detecting nonface things as a face like below image

image

  1. Is there any configuration I can increase the threshold for strict face detection?
  2. TF2 version is better than TF1 version implementation ( face detect and landmark detect)?

please advise.

610265158 commented 4 years ago
  1. config.DETECT.thres=0.5 in config.py file and the face detect algorithm is not so good. We shall add a binary classify in the landmark model to fileter some bad faces.
  2. it should be the same, but i am not sure
SaddamBInSyed commented 4 years ago

Thanks for the reply.

The dlib face landmark is not so good when compared with pepa-face engine face landmark, But I am using mtcnn / opencv dnn for face detection and its perfect.

Now the question is

Is it possible to use MTCNN + pepa-face landmark combination?

What are the changes I need to look at?

please advise.

610265158 commented 4 years ago

Take a look at /lib/core/api/face_detector.py,

SaddamBInSyed commented 4 years ago

Hi

I am doing the same now.

I will let you the result soon.

Thanks again

SaddamBInSyed commented 4 years ago

could you please clarify what is use of 'judge_boxs" function ?

after getting the list of bbox it is mandatory to use this "judge_boxs" ()?

please advise

SaddamBInSyed commented 4 years ago

@610265158

FYI.

I have integrated Opencv Dnn face detection and it works fine.

Thank you

610265158 commented 4 years ago

The judge_boxs is to refine the detect results, And you're welcome.

SaddamBInSyed commented 4 years ago

Hi @610265158

as I said , I am using cv dnn for face detection and then I am passing the detected boxes to face landmark method. but the face landmark position is not accurate as compared to faceboxes detection.

`def run(self, image): start = time.time()

run detector

    if self.diff_frames(self.previous_image, image):
        boxes = self.face_detector.get_closest_face_location_dnn(image)
        if boxes is None:
            return None, None, None
        box_only = boxes[0]
        boxes = np.concatenate([boxes, [[0.99]]], axis=1)
        self.previous_image = image
        boxes = self.judge_boxs(self.track_box, boxes)

    else:
        boxes = self.track_box
        self.previous_image = image
    # print('facebox detect cost',time.time()-start)

    if boxes.shape[0] > self.top_k:
        boxes = self.sort(boxes)

    boxes_return = np.array(boxes)

    landmarks, states = self.face_landmark(image, boxes)

    landmarks = self.trace.calculate(image, landmarks)

    if 1:
        track = []
        for i in range(landmarks.shape[0]):
            track.append([np.min(landmarks[i][:, 0]), np.min(landmarks[i][:, 1]), np.max(landmarks[i][:, 0]),
                          np.max(landmarks[i][:, 1])])
        tmp_box = np.array(track)

        self.track_box = self.judge_boxs(boxes_return, tmp_box)
        box_only = self.track_box[0]
        # print(box_only)

    return self.track_box, landmarks, states`

and my face detection (opencv dnn) code below

` def get_closest_face_location_dnn(self, frameOpencvDnn): try: frameOpencvDnn = cv2.cvtColor(frameOpencvDnn, cv2.COLOR_RGB2BGR) frameHeight = frameOpencvDnn.shape[0] frameWidth = frameOpencvDnn.shape[1] blob = cv2.dnn.blobFromImage(frameOpencvDnn, 1.0, (300, 300), [104, 117, 123], False, False) self.net.setInput(blob) detections = self.net.forward() face_locations = [] max_wh = 0 index_value = -1

        for i in range(detections.shape[2]):
            confidence = detections[0, 0, i, 2]
            if confidence > 0.5:
                x1 = int(detections[0, 0, i, 3] * frameWidth)
                y1 = int(detections[0, 0, i, 4] * frameHeight)
                x2 = int(detections[0, 0, i, 5] * frameWidth)
                y2 = int(detections[0, 0, i, 6] * frameHeight)
                # for better face land mark result
                y1, x2 = int(y1 * 1.2), int(x2 * 1.05)
               face_locations.append([x1, y1, x2, y2])
        number_of_faces_in_frame = len(face_locations)
        if number_of_faces_in_frame >= 2:  # more than 1 face then find the closer one.(left, top), (right, bottom)
            return [face_locations[index_value]]
        elif number_of_faces_in_frame == 1:
            return [face_locations[0]]
        else:  # no face found
            return None
    except Exception as error:
        print("error occurred in dnn face detection")
        raise Exception(error)

`

why its different result for different face detection although detected face box value is almost same.

please advise.