Eval bug: Qwen 3 VL provides incorrect bounding boxes on sizes that are not 1000x1000px / non-square

用户运行 llama-server ,加载 Qwen 3 VL (Qwen3-VL-30B-A3B-Instruct) 的 GGUF 模型和 mmproj 权重文件,通过 API 上传图片请求目标检测(bounding box),并期望返回的坐标( bbox_2d )直接适用于原始图像,但格式上存在

Eval bug: Qwen 3 VL provides incorrect bounding boxes on sizes that are not 1000x1000px / non-square

Eval bug: Qwen 3 VL provides incorrect bounding boxes on sizes that are not 1000x1000px / non-square

快速结论:此问题出现在使用 llama.cpp 的 llama-server 调用 Qwen 3 VL 模型进行 2D 目标检测,但输出边界框坐标直接用于不同尺寸(尤其非 1000×1000 像素)的图像时。优先排查:确认后端是否自动将坐标转换为以 1000 为基准的相对坐标,而非绝对像素坐标。

问题场景

用户运行 llama-server,加载 Qwen 3 VL (Qwen3-VL-30B-A3B-Instruct) 的 GGUF 模型和 mmproj 权重文件,通过 API 上传图片请求目标检测(bounding box),并期望返回的坐标(bbox_2d)直接适用于原始图像,但格式上存在系统性偏移或比例错误。

报错原文

Eval bug: Qwen 3 VL provides incorrect bounding boxes on sizes that are not 1000x1000px / non-square

Expected bounding boxes are accurate without any adjustments of the pixel coordinates. However in reality for the square image we need to resize the image to be 1.25x so that the bounding box coordinates match the bounding box output.

原因分析

Qwen 3 VL 默认的坐标系采用 相对坐标,范围固定为 0 到 1000(无论输入图像的实际尺寸是多少)。这与 Qwen 2.5 VL 使用的绝对像素坐标不同。因此,直接从模型输出的 bbox_2d(如 [x0, y0, x1, y1])是 以 1000 为分母的比例值,如果直接当绝对像素绘制,对于不是 1000×1000 像素的图片,就会产生缩放或比例失调的问题。

环境排查

  • llama-server 版本:Issue 中测试了 build 6887 和 6891,行为一致。
  • 模型文件:来自 unsloth 的 Qwen3-VL-30B-A3B-Instruct GGUF 以及对应的 mmproj 文件。
  • 后端:CPU 后端(Intel Ice Lake)。
  • 操作系统:Linux。
  • 涉及 API 调用:通过 llama.cpp 的 OpenAI 兼容 API(/v1/chat/completions)进行流式调用,解析输出中的 JSON。
  • 参考文档:Qwen 官方关于该坐标系的说明位于 Qwen3-VL/cookbooks/2d_grounding.ipynb

解决步骤

  1. 确认模型返回的坐标范围:Qwen 3 VL 输出的 bbox_2d 数组中的四个值,均在 0~1000 之间(即相对于 1000×1000 的虚拟画布)。
  2. 将相对坐标转换为原始图像像素坐标:假设 size = 1000,按照以下公式转换:
    x0_pixel = x0 / size * image.width
    y0_pixel = y0 / size * image.height
    x1_pixel = x1 / size * image.width
    y1_pixel = y1 / size * image.height
  3. 如果使用测试用的 HTML 注释工具(如 Issue #16207 中提供的),需在 JS 中手动调整坐标的缩放逻辑。可优先尝试重写 bboxes.forEach 回调,加入类似 Python 转换公式的代码,用 imgWidthimgHeight 动态获取原始图片尺寸。

验证方法

选取一张非 1000×1000 像素的图片,用 llama-server API 获取边界框坐标后,用上述转换公式重新映射到图片实际像素坐标,并与人工标注或预期框进行比对。如果使用 HTML 可视化工具,确认在输入图片实际宽高后,框的位置与目标物体吻合。

参考来源

ggml-org/llama.cpp #16880

GamsGo AI

AI 工具推荐

想把多个 AI 模型放在一个入口?

GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。

了解 GamsGo AI

推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。

celebrityanime
celebrityanime
文章: 13294

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注