下面介绍下如何通过YOLO进行图片中性别与年龄估计。首先是种族分类,可以参考。
如果想检测图片中人物的性别可以考虑使用iic/cv_resnet34_face-attribute-recognition_fairface模型。如果想使用onnx,则可以分别考虑onnx-community/fairface_gender_image_detection-ONNX和onnx-community/fairface_age_image_detection-ONNX。其他模型可以参考。
其相关代码类似如下:
>>> from modelscope.pipelines import pipeline
>>> from modelscope.utils.constant import Tasks
>>> fair_face_attribute_func = pipeline(Tasks.face_attribute_recognition, 'iic/cv_resnet34_face-attribute-recognition_fairface')
在这个过程中会下载相关的人脸识别模型。之后开始人物的检测:
>>> src_img_path = 'cfa0234006d2b95630a4e026ea6ea721.jpeg'
>>> raw_result = fair_face_attribute_func(src_img_path)
对应的检测结果类似如下:
>>> raw_result
{'scores': [[1.0, 5.469796349188982e-08], [6.387997331103179e-08, 0.00021145127539057285, 0.23208525776863098, 0.738937258720398, 0.028579212725162506, 0.00018610214465297759, 5.655915629176889e-07, 4.1816949902795386e-08, 2.805190246757405e-10]], 'labels': [['Male', 'Female'], ['0-2', '3-9', '10-19', '20-29', '30-39', '40-49', '50-59', '60-69', '70+']]}
我们对其结果按照最大值获取其结果:
>>> labels = raw_result["labels"]
>>> scores = raw_result["scores"]
>>> [max(x) for x in scores]
[1.0, 0.738937258720398]
>>> [x.index(max(x)) for x in scores]
[0, 3]
>>> labels[0][0]
'Male'
>>> labels[1][3]
'20-29'
可以看出其结果准确率还是蛮高的。
参考文章:
https://www.cnblogs.com/odesey/p/16800014.html https://talhassner.github.io/home/publication/2015_CVPR https://zhuanlan.zhihu.com/p/111721652
如果喜欢这篇文章或对您有帮助,可以:[☕] 请我喝杯咖啡 | [💓] 小额赞助

