dima806/fairface_age_image_detectiongoogle/vit-base-patch16-224-in21kpip install -r requirements.txt
# requirements.txt 包含:
# torch==2.9.0
# torch-npu==2.9.0.post1
# transformers==4.47.0
# pillow>=10.0.0
# numpy>=1.24.0本地权重路径优先: /opt/atomgit/adapt-npu-agent/working/fairface_model_final (由 checkpoint-9376 整合),若不存在则自动尝试 dima806/fairface_age_image_detection 的 snapshot_download 缓存。
默认命令 (NPU):
python inference.py其他模式:
python inference.py --mode validate # 一致性验证
python inference.py --mode benchmark # 性能压测模型加载: ViTForImageClassification.from_pretrained(local_dir).to("npu:0"), dtype float32, 无 trust_remote_code。
基于固定随机种子 42 生成的合成肤色人脸图像 (224x224) 的真实 NPU 推理输出 (本次执行):
model_dir: /opt/atomgit/adapt-npu-agent/working/fairface_model_final
processor: ViTImageProcessor size={'height': 224, 'width': 224} mean=[0.5, 0.5, 0.5]
input: synthetic face image 224x224 RGB, pixel_values shape [1,3,224,224]
CPU logits: [-0.3259, 0.0325, 0.0690, 0.2547, 0.2786, 0.0106, -0.2148, -0.2940, -0.5244]
NPU logits: [-0.3266, 0.0322, 0.0686, 0.2543, 0.2808, 0.0127, -0.2158, -0.2966, -0.5259]
CPU probs: [0.0840, 0.1202, 0.1247, 0.1501, 0.1537, 0.1176, 0.0938, 0.0867, 0.0688]
NPU probs: [0.0839, 0.1201, 0.1246, 0.1500, 0.1541, 0.1178, 0.0937, 0.0865, 0.0687]
NPU pred: 4 -> 30-39 (prob 0.1541)Top-9 排序 (NPU):
1. 30-39 : 0.1541 (logit 0.2808)
2. 20-29 : 0.1500 (logit 0.2543)
3. 10-19 : 0.1246 (logit 0.0686)
4. 3-9 : 0.1201 (logit 0.0322)
5. 40-49 : 0.1178 (logit 0.0127)
6. 50-59 : 0.0937 (logit -0.2158)
7. 60-69 : 0.0865 (logit -0.2966)
8. 0-2 : 0.0839 (logit -0.3266)
9. more than 70 : 0.0687 (logit -0.5259)输出契约: logits shape [1,9], probs shape [1,9], 任务专属为分类 Top-9 排序与 argmax。
测试条件: batch_size=1, image 224x224, dtype float32, 设备 npu:0, 预热 3 次, 正式 10 次, 计时区间包含 torch.npu.synchronize()。
本次结果:
NPU latency (single): 6.83 ms
avg: 6.73 ms
min: 6.62 ms
max: 6.93 ms
p50: 6.69 ms
p90: 6.84 ms
p95: 6.88 ms
throughput: 148.68 images/s
CPU latency: 689.32 ms (对比, 单次)
NPU speedup vs CPU: ~102x
npu_mem_free: 61908.6 MB, total: 62740.0 MB
peak weight memory: ~328 MB (model.safetensors)环境差异会导致小幅波动,但量级应在 5-10ms。
三张证据图由 scripts/render_xterm_evidence.mjs 从真实日志渲染 (raw 模式):
assets/agent_workflow.png - 下载、侦察、加载、NPU 推理、验证与性能全流程assets/npu_device_call.png - npu-smi、torch.npu.is_available、device_name、显存信息assets/model_result.png - python inference.py 真实输出、排序、一致性与性能snapshot_download 下载 (约 328MB),已整合 checkpoint-9376 为最终权重 (best_metric 1.001)生成时间: 2026-08-21 适配脚本: inference.py (支持 default/validate/benchmark) 仓库类型: model (公开)