mirror of
https://github.com/modelscope/modelscope.git
synced 2026-07-11 04:50:39 +02:00
[to #42322933]update fer to satisfy demo service requirements
Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/10357094
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
# The implementation is based on MogFace, available at
|
||||
# https://github.com/damo-cv/MogFace
|
||||
import os
|
||||
|
||||
import cv2
|
||||
|
||||
@@ -45,6 +45,9 @@ class FacialExpressionRecognitionPipeline(Pipeline):
|
||||
|
||||
# face detect pipeline
|
||||
det_model_id = 'damo/cv_resnet_facedetection_scrfd10gkps'
|
||||
self.map_list = [
|
||||
'Angry', 'Disgust', 'Fear', 'Happy', 'Sad', 'Surprise', 'Neutral'
|
||||
]
|
||||
self.face_detection = pipeline(
|
||||
Tasks.face_detection, model=det_model_id)
|
||||
|
||||
@@ -122,7 +125,7 @@ class FacialExpressionRecognitionPipeline(Pipeline):
|
||||
labels = result[1].tolist()
|
||||
return {
|
||||
OutputKeys.SCORES: scores,
|
||||
OutputKeys.LABELS: labels,
|
||||
OutputKeys.LABELS: self.map_list[labels]
|
||||
}
|
||||
|
||||
def postprocess(self, inputs: Dict[str, Any]) -> Dict[str, Any]:
|
||||
|
||||
@@ -113,12 +113,7 @@ def draw_face_detection_no_lm_result(img_path, detection_result):
|
||||
|
||||
|
||||
def draw_facial_expression_result(img_path, facial_expression_result):
|
||||
label_idx = facial_expression_result[OutputKeys.LABELS]
|
||||
map_list = [
|
||||
'Angry', 'Disgust', 'Fear', 'Happy', 'Sad', 'Surprise', 'Neutral'
|
||||
]
|
||||
label = map_list[label_idx]
|
||||
|
||||
label = facial_expression_result[OutputKeys.LABELS]
|
||||
img = cv2.imread(img_path)
|
||||
assert img is not None, f"Can't read img: {img_path}"
|
||||
cv2.putText(
|
||||
|
||||
Reference in New Issue
Block a user