dima806/fairface_age_image_detection 是一个基于 ViT 的年龄分类模型
(ViTForImageClassification),9 个年龄段标签:
0-2、3-9、10-19、20-29、30-39、40-49、50-59、60-69、more than 70。
输入图像 224×224,使用 ViTImageProcessor 归一化(mean/std=0.5)。
模型权重分类头 shape 为 [9, 768](9 类),但 config.json 未声明 num_labels。
本项目在内存中将 config.num_labels = len(config.id2label) = 9 后再加载权重,以匹配分类头维度。
2.9.0+cpu,torch_npu 2.9.0.post1,transformers 4.57.xnpu:0 / npu:1)inference.py)适配脚本仅使用 NPU 设备(npu:N),全代码域无任何 CUDA 调用;NPU 不可用时直接报错退出,
不做 CPU/CUDA 回退。权重首次运行从 GitCode HF 镜像自动下载并缓存到
model_weights/dima806/fairface_age_image_detection/,命中缓存时打印 [cache-hit]。
python inference.py --img test_input.png --device npu:0 [--output_json result.json]stdout 输出 JSON,含 model、requested_device、actual_device、npu_name、exit_status、
inference_ms 以及 label_id / label / confidence / logits(9 个)/ probabilities(9 个)。
python inference.py --serve --port 8001
# 另一终端:
curl -s -F "file=@test_input.png" http://127.0.0.1:8001/predictPOST /predict 上传图片文件,返回与 CLI 相同的推理 JSON;GET / 返回服务与设备元信息。
python inference.py --img test_input.png --device npu:0 在 npu:0(Ascend910_9362)上 exit_status:0。8001 启动后 POST /predict 返回推理 JSON。assets/。dima806/fairface_age_image_detectionhttps://ai.gitcode.com/hf_mirrors/dima806/fairface_age_image_detection/resolve/main/<file>config.json、preprocessor_config.json、model.safetensors