This model is capable of evaluating the quality of human faces in input images.
It takes aligned face images (112x112) as input and returns a quality score for the face (ranging from 0 to 1, with higher scores indicating higher quality).
1
2class face_quality_assessment():
3 def __init__(self, path):
4 # Initialize model
5 self.net = cv2.dnn.readNet(path)
6 self.input_height = 112
7 self.input_width = 112
8
9 def classify(self, srcimg):
10 input_img = cv2.resize(cv2.cvtColor(srcimg, cv2.COLOR_BGR2RGB), (self.input_width, self.input_height))
11 input_img = (input_img.astype(np.float32) / 255.0 - 0.5) / 0.5
12
13 blob = cv2.dnn.blobFromImage(input_img.astype(np.float32))
14 self.net.setInput(blob)
15 outputs = self.net.forward(self.net.getUnconnectedOutLayersNames())
16 return outputs[0].reshape(-1)
17
18fqa = face_quality_assessment("weights/face-quality-assessment.onnx")
19fqa_probs = fqa.classify(img)