liuhongwei-2026/VisualQuality-R1-7B
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

VisualQuality-R1-7B — 昇腾 NPU 部署

VisualQuality-R1-7B 首个基于强化学习推理(RL2R)增强的**无参考图像质量评估(NR-IQA)**模型,基于 Qwen2.5-VL-7B-Instruct 微调,支持通过视觉推理对图片进行质量评分(1-5 分)。

  • 原始论文:https://arxiv.org/abs/2505.14460
  • 原始代码:https://github.com/TianheWu/VisualQuality-R1
  • 原始权重:https://huggingface.co/TianheWu/VisualQuality-R1-7B
  • 本仓库:https://ai.atomgit.com/liuhongwei-2026/VisualQuality-R1-7B

环境要求

组件版本
Python≥ 3.11
torch_npu2.9.0.post1
CANN8.5.1
vLLM0.18.0
vLLM-Ascend0.18.0
Transformers4.57.6

快速部署

1. 下载模型权重

# 方式一:从 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 脚本
"

2. 启动 vLLM-Ascend 服务

# 设置 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。

3. 验证服务

# 检查服务状态
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

4. 图片质量评估推理

# 使用推理脚本
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.tool

项目结构

VisualQuality-R1-7B/
├── inference.py      # 推理脚本(使用 vLLM OpenAI 兼容 API)
├── README.md         # 部署说明文档(本文件)
├── requirements.txt  # 环境依赖清单
└── assets/           # 截图素材文件夹
    ├── agent_workflow.png    # 部署流程图
    ├── npu_device_call.png   # NPU 设备调用截图
    └── model_result.png      # 推理结果截图

推理示例

非思考模式(Non-Thinking)

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}
}