【亲测免费】 Gender-and-Age-Detection 项目使用教程
2026-01-17 08:43:27作者:齐添朝
1. 项目的目录结构及介绍
Gender-and-Age-Detection/
├── LICENSE
├── README.md
├── _config.yml
├── age_deploy.prototxt
├── age_net.caffemodel
├── detect.py
├── gender_deploy.prototxt
├── gender_net.caffemodel
├── girl1.jpg
├── girl2.jpg
├── kid1.jpg
├── kid2.jpg
├── man1.jpg
├── man2.jpg
├── opencv_face_detector.pbtxt
├── opencv_face_detector_uint8.pb
└── woman1.jpg
目录结构说明
LICENSE: 项目许可证文件。README.md: 项目说明文档。_config.yml: 项目配置文件。age_deploy.prototxt: 年龄检测模型的配置文件。age_net.caffemodel: 年龄检测模型的权重文件。detect.py: 项目的主启动文件,用于检测性别和年龄。gender_deploy.prototxt: 性别检测模型的配置文件。gender_net.caffemodel: 性别检测模型的权重文件。girl1.jpg,girl2.jpg,kid1.jpg,kid2.jpg,man1.jpg,man2.jpg,woman1.jpg: 示例图片文件。opencv_face_detector.pbtxt: 人脸检测模型的配置文件。opencv_face_detector_uint8.pb: 人脸检测模型的权重文件。
2. 项目的启动文件介绍
detect.py
detect.py 是项目的主启动文件,用于检测图片或摄像头中人脸的性别和年龄。以下是该文件的主要功能和使用方法:
import cv2
import numpy as np
import argparse
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument('--image')
args = parser.parse_args()
return args
def main():
args = get_args()
image_path = args.image
# 加载模型和配置文件
age_net = cv2.dnn.readNetFromCaffe('age_deploy.prototxt', 'age_net.caffemodel')
gender_net = cv2.dnn.readNetFromCaffe('gender_deploy.prototxt', 'gender_net.caffemodel')
face_net = cv2.dnn.readNetFromCaffe('opencv_face_detector.pbtxt', 'opencv_face_detector_uint8.pb')
# 读取图片
frame = cv2.imread(image_path)
# 检测人脸
blob = cv2.dnn.blobFromImage(frame, 1.0, (300, 300), [104, 117, 123], True, False)
face_net.setInput(blob)
detections = face_net.forward()
# 处理检测结果
for i in range(detections.shape[2]):
confidence = detections[0, 0, i, 2]
if confidence > 0.7:
box = detections[0, 0, i, 3:7] * np.array([frame.shape[1], frame.shape[0], frame.shape[1], frame.shape[0]])
(x, y, x1, y1) = box.astype("int")
face = frame[y:y1, x:x1]
# 检测性别
blob = cv2.dnn.blobFromImage(face, 1.0, (227, 227), [78.4263377603, 87.7689143744, 114.895847746], swapRB=False)
gender_net.setInput(blob)
gender_preds = gender_net.forward()
gender = gender_list[gender_preds[0].argmax()]
# 检测年龄
登录后查看全文
热门项目推荐
相关项目推荐
GLM-5智谱 AI 正式发布 GLM-5,旨在应对复杂系统工程和长时域智能体任务。Jinja00
GLM-5.1GLM-5.1是智谱迄今最智能的旗舰模型,也是目前全球最强的开源模型。GLM-5.1大大提高了代码能力,在完成长程任务方面提升尤为显著。和此前分钟级交互的模型不同,它能够在一次任务中独立、持续工作超过8小时,期间自主规划、执行、自我进化,最终交付完整的工程级成果。Jinja00
LongCat-AudioDiT-1BLongCat-AudioDiT 是一款基于扩散模型的文本转语音(TTS)模型,代表了当前该领域的最高水平(SOTA),它直接在波形潜空间中进行操作。00- QQwen3.5-397B-A17BQwen3.5 实现了重大飞跃,整合了多模态学习、架构效率、强化学习规模以及全球可访问性等方面的突破性进展,旨在为开发者和企业赋予前所未有的能力与效率。Jinja00
HY-Embodied-0.5这是一套专为现实世界具身智能打造的基础模型。该系列模型采用创新的混合Transformer(Mixture-of-Transformers, MoT) 架构,通过潜在令牌实现模态特异性计算,显著提升了细粒度感知能力。Jinja00
FreeSql功能强大的对象关系映射(O/RM)组件,支持 .NET Core 2.1+、.NET Framework 4.0+、Xamarin 以及 AOT。C#00
项目优选
收起
deepin linux kernel
C
27
14
OpenHarmony documentation | OpenHarmony开发者文档
Dockerfile
657
4.26 K
Ascend Extension for PyTorch
Python
502
606
本项目是CANN提供的数学类基础计算算子库,实现网络在NPU上加速计算。
C++
939
862
Oohos_react_native
React Native鸿蒙化仓库
JavaScript
334
378
openEuler内核是openEuler操作系统的核心,既是系统性能与稳定性的基石,也是连接处理器、设备与服务的桥梁。
C
390
284
AscendNPU-IR是基于MLIR(Multi-Level Intermediate Representation)构建的,面向昇腾亲和算子编译时使用的中间表示,提供昇腾完备表达能力,通过编译优化提升昇腾AI处理器计算效率,支持通过生态框架使能昇腾AI处理器与深度调优
C++
123
195
openGauss kernel ~ openGauss is an open source relational database management system
C++
180
258
🎉 (RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue3 & Vite、Element Plus 的前后端分离权限管理系统
Vue
1.54 K
891
昇腾LLM分布式训练框架
Python
142
168