【亲测免费】 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()]
# 检测年龄
登录后查看全文
热门项目推荐
相关项目推荐
atomcodeClaude Code 的开源替代方案。连接任意大模型,编辑代码,运行命令,自动验证 — 全自动执行。用 Rust 构建,极致性能。 | An open-source alternative to Claude Code. Connect any LLM, edit code, run commands, and verify changes — autonomously. Built in Rust for speed. Get StartedRust0251
GLM-5.2智谱开源 GLM-5.2,这是针对长文本任务的最新旗舰模型。相较于前代产品 GLM-5.1,它在长文本任务处理能力上实现了显著飞跃,并且首次在稳定的 100 万 token 上下文中提供这一能力。Jinja00
JoyAI-VL-Interaction-Preview京东开源首个开源、视觉驱动的实时交互模型——它能实时监控视频流,并自主决定何时发言、保持沉默或委托任务。Jinja00
cann-learning-hubCANN 学习中心仓,支持在线互动运行、边学边练,提供教程、示例与优化方案,一站式助力昇腾开发者快速上手。Jupyter Notebook0183
MaxKB强大易用的开源企业级智能体平台Python02
note-gen一款跨平台的 Markdown AI 笔记软件,致力于使用 AI 建立记录和写作的桥梁。TSX011
热门内容推荐
项目优选
收起
暂无描述
Dockerfile
787
5.17 K
本项目是CANN提供的transformer类大模型算子库,实现网络在NPU上加速计算。
C++
900
2.09 K
本项目是CANN提供的神经网络类计算算子库,实现网络在NPU上加速计算。
C++
722
1.45 K
deepin linux kernel
C
32
16
Ascend Extension for PyTorch
Python
768
995
openEuler内核是openEuler操作系统的核心,既是系统性能与稳定性的基石,也是连接处理器、设备与服务的桥梁。
C
472
482
CANN 学习中心仓,支持在线互动运行、边学边练,提供教程、示例与优化方案,一站式助力昇腾开发者快速上手。
Jupyter Notebook
490
183
本项目是CANN提供的数学类基础计算算子库,实现网络在NPU上加速计算。
C++
1.14 K
1.18 K
昇腾LLM分布式训练框架
Python
189
242
华为昇腾面向大规模分布式训练的多模态大模型套件,支撑多模态生成、多模态理解。
Python
157
241