fairface age image detection
简介
核心亮点
- 专注于人脸年龄预测,具备跨族群的泛化能力
- 有效降低人种偏差,提升全球用户识别精度
- 适用场景广泛,涵盖用户画像与智能分类
- Apache-2.0 协议,对商业集成非常友好
使用方法
# 安装 Hugging Face transformers
pip install transformers torch
# 使用 transformers 加载模型
from transformers import AutoModel, AutoTokenizer
model = AutoModel.from_pretrained("dima806/fairface_age_image_detection")
tokenizer = AutoTokenizer.from_pretrained("dima806/fairface_age_image_detection")
Hugging Face 下载
我们推荐使用命令行或者 Hugging Face Hub SDK 来进行模型的下载。
操作指引:在下载前,请先通过如下命令安装 huggingface_hub:
pip install -U huggingface_hub
命令行下载
下载完整模型库
huggingface-cli download dima806/fairface_age_image_detection
下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)
huggingface-cli download dima806/fairface_age_image_detection config.json --local-dir ./dir
SDK 下载
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('dima806/fairface_age_image_detection')
Git 下载
请确保 lfs 已经被正确安装
git lfs install
git clone https://huggingface.co/dima806/fairface_age_image_detection
如果您希望跳过 lfs 大文件下载,可以使用如下命令
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/dima806/fairface_age_image_detection
模型文件托管在 Hugging Face Hub,使用 HF CLI / SDK / Git 直接下载,不经过本站。
PyTorch / Transformers 使用
安装 Transformers
pip install -U transformers torch
模型加载和推理
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained('dima806/fairface_age_image_detection')
tokenizer = AutoTokenizer.from_pretrained('dima806/fairface_age_image_detection')
模型下载
我们推荐使用命令行或者 ModelScope SDK 来进行模型的下载。
操作指引:在下载前,请先通过如下命令安装 ModelScope:
pip install modelscope
命令行下载
下载完整模型库
modelscope download --model dima806/fairface_age_image_detection
下载单个文件到指定本地文件夹(以下载 README.md 到当前路径下 dir 目录为例)
modelscope download --model dima806/fairface_age_image_detection README.md --local_dir ./dir
SDK 下载
# 模型下载
from modelscope import snapshot_download
model_dir = snapshot_download('dima806/fairface_age_image_detection')
Git 下载
请确保 lfs 已经被正确安装
git lfs install
git clone https://www.modelscope.cn/dima806/fairface_age_image_detection.git
如果您希望跳过 lfs 大文件下载,可以使用如下命令
GIT_LFS_SKIP_SMUDGE=1 git clone https://www.modelscope.cn/dima806/fairface_age_image_detection.git
ModelScope 模型页直接下载模型文件;无需将模型文件放在本站服务器。
Notebook 快速开发
下载并安装 ModelScope library
pip install "modelscope[audio,cv,nlp,multi-modal,science]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html
模型加载和推理
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
p = pipeline('text-generation', 'dima806/fairface_age_image_detection')
完整文档
---
license: apache-2.0
metrics:
- accuracy
- f1
base_model:
- google/vit-base-patch16-224-in21k
pipeline_tag: image-classification
library_name: transformers
datasets:
- nateraw/fairface
---
Detects age group with about 59% accuracy based on an image.
See https://www.kaggle.com/code/dima806/age-group-image-classification-vit for details.
Classification report:
precision recall f1-score support
0-2 0.7803 0.7500 0.7649 180
3-9 0.7998 0.7998 0.7998 1249
10-19 0.5361 0.4236 0.4733 1086
20-29 0.6402 0.7221 0.6787 3026
30-39 0.4935 0.5083 0.5008 2099
40-49 0.4848 0.4386 0.4606 1238
50-59 0.5000 0.4814 0.4905 725
60-69 0.4497 0.4685 0.4589 286
more than 70 0.6897 0.1802 0.2857 111
accuracy 0.5892 10000
macro avg 0.5971 0.5303 0.5459 10000
weighted avg 0.5863 0.5892 0.5844 10000