VisualQuality-R1-7B 首个基于强化学习推理(RL2R)增强的**无参考图像质量评估(NR-IQA)**模型,基于 Qwen2.5-VL-7B-Instruct 微调,支持通过视觉推理对图片进行质量评分(1-5 分)。
| 组件 | 版本 |
|---|---|
| Python | ≥ 3.11 |
| torch_npu | 2.9.0.post1 |
| CANN | 8.5.1 |
| vLLM | 0.18.0 |
| vLLM-Ascend | 0.18.0 |
| Transformers | 4.57.6 |
# 方式一:从 gitcode LFS 下载(推荐)
# 需要先安装 git-lfs
git lfs clone https://gitcode.com/hf_mirrors/TianheWu/VisualQuality-R1-7B.git /path/to/model
# 方式二:使用 Python 脚本下载
python3 -c "
import requests, os, hashlib
TOKEN = '你的AtomGit令牌'
auth = requests.auth.HTTPBasicAuth('token', TOKEN)
# 参考仓库中的 download_weights.py 脚本
"# 设置 NPU 设备(默认 npu:0)
export ASCEND_RT_VISIBLE_DEVICES=0
# 启动服务
vllm serve /path/to/VisualQuality-R1-7B \
--port 8000 \
--dtype bfloat16 \
--max-model-len 32768 \
--max-num-seqs 8 \
--enforce-eager \
--limit-mm-per-prompt '{"image": 1, "video": 0}' \
--gpu-memory-utilization 0.95注意:Qwen2.5-VL-7B 在 bf16 下约需 14-16GB HBM,请确保 NPU 空闲 HBM 充足。 如果遇到
open device failed 507033错误,说明设备被其他进程占用,换用export ASCEND_RT_VISIBLE_DEVICES=1。
# 检查服务状态
curl -sf http://127.0.0.1:8000/v1/models | python3 -m json.tool
# 简单文本推理测试
curl -s http://127.0.0.1:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{
"model": "VisualQuality-R1-7B",
"messages": [{"role": "user", "content": "say hi"}],
"temperature": 0.1,
"max_tokens": 16
}' | python3 -m json.tool# 使用推理脚本
python3 inference.py --image /path/to/test.jpg --verbose
# 或直接调用 API
curl -s http://127.0.0.1:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{
"model": "VisualQuality-R1-7B",
"messages": [
{
"role": "user",
"content": [
{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,..."}},
{"type": "text", "text": "You are doing the image quality assessment task. Here is the question: What is your overall rating on the quality of this picture? The rating should be a float between 1 and 5, rounded to two decimal places, with 1 representing very poor quality and 5 representing excellent quality. Please only output the final answer with only one score in <answer> </answer> tags."}
]
}
],
"temperature": 0.1,
"max_tokens": 2048,
"top_p": 0.001,
"top_k": 1
}' | python3 -m json.toolVisualQuality-R1-7B/
├── inference.py # 推理脚本(使用 vLLM OpenAI 兼容 API)
├── README.md # 部署说明文档(本文件)
├── requirements.txt # 环境依赖清单
└── assets/ # 截图素材文件夹
├── agent_workflow.png # 部署流程图
├── npu_device_call.png # NPU 设备调用截图
└── model_result.png # 推理结果截图VisualQuality-R1 作为评估模型时,使用非思考模式以最小的推理时间输出单一评分:
# 评分格式:<answer>4.25</answer>模型输出形如 <answer>3.85</answer> 的标签,从中提取数值即为图片质量评分(1-5 分)。
| 指标 | 数值 |
|---|---|
| 模型参数量 | 7B(Qwen2.5-VL-7B 基座) |
| 权重精度 | bfloat16 |
| 权重大小 | ~16.6 GB(4 个分片) |
| 推理精度 | FP16/BF16 |
| NPU 类型 | Ascend 910B/910C |
| 单次推理耗时 | 约 2-5s(取决于图片分辨率) |
@article{wu2025visualquality,
title={VisualQuality-R1: Improving Visual Quality Assessment with Reasoning RL},
author={Wu, Tianhe and others},
journal={arXiv preprint arXiv:2505.14460},
year={2025}
}