f
gcw_pCMO8DfP/PickScore_v1
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

PickScore_v1 · 昇腾 NPU 图文偏好评分

PickScore v1 是基于 CLIP (ViT-L/14, 投影维度 1024) 微调的 文本→图像人类偏好评分函数。该仓库为 Ascend 昇腾 NPU (torch_npu) 适配版本,config.json 中 architectures=["CLIPModel"],权重仅包含标准 CLIPModel 键(无自定义 score_head),因此按普通 CLIPModel + AutoProcessor 加载。

评分方式(依据模型卡):对图像与文本 embedding 分别做 L2 归一化后

score = model.logit_scale.exp() * (text_embs @ image_embs.T)

pick_score 越高表示该文本描述与该图像的匹配/偏好度越高;同时输出经 sigmoid 归一化到 [0,1] 的 normalized_score,便于直观比较。

  • 模型: yuvalkirstain/PickScore_v1 (CLIP ViT-L/14)
  • 设备: npu:0 (Ascend910, CANN 8.5.1, torch_npu 2.9.0.post1)
  • 推理精度: bfloat16 (节省 NPU 显存)
  • 无任何 CUDA 依赖

快速开始

# 1. CLI 推理
./.venv/bin/python inference.py \
  --img sample_input.png \
  --prompt "a beautiful photograph of animals in the wild"

# 2. 启动 FastAPI 服务 (默认端口 8114)
./.venv/bin/python inference.py --server --port 8114

首次运行会自动下载权重(约 2.4GB fp32)到本地缓存 ./model_weights/yuvalkirstain/PickScore_v1/(若网络失败会自动重试并切换镜像源)。权重就绪后以离线模式加载,不访问外网。

CLI 输出 JSON 示例

{
  "model": "yuvalkirstain/PickScore_v1",
  "device": "npu:0",
  "image": "sample_input.png",
  "prompt": "a beautiful photograph of animals in the wild",
  "pick_score": 28.6411,
  "normalized_score": 1.0,
  "inference_time_s": 0.412
}

FastAPI 服务

接口方法说明
/GET上传表单(图片文件 + 文本提示)
/healthGET健康检查
/predictPOSTmultipart: file(图片) + prompt(文本) → 评分 JSON

调用示例:

curl -sS -X POST http://127.0.0.1:8114/predict \
  -F file=@sample_input.png \
  -F prompt="a beautiful photograph of animals in the wild"

返回 JSON 同上,额外包含 filename 字段。

环境依赖

  • CANN 8.5.1 / Ascend910 64GB
  • torch 2.9.0+cpu + torch_npu 2.9.0.post1
  • transformers 4.57.6
  • fastapi / uvicorn / python-multipart / pillow / numpy / safetensors

项目结构

PickScore_v1/
├── inference.py            # 昇腾 NPU 推理脚本 (CLI + FastAPI 双模式)
├── README.md
├── sample_input.png        # 测试样例图
├── .gitignore
├── assets/                 # 运行截图
│   ├── agent_workflow.png
│   ├── npu_device_call.png
│   └── model_result.png
└── model_weights/          # 权重缓存 (已 gitignore)
    └── yuvalkirstain/PickScore_v1/

截图

截图说明
assets/agent_workflow.pngNPU 环境部署 · 依赖安装 · 任务启动
assets/npu_device_call.pngPickScore_v1 CLI 推理运行成功
assets/model_result.pngPickScore NPU 偏好评分服务 (HTTP 调用)