Ascend-SACT/LocateAnything-3B
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

引言

LocateAnything 是基于 NVlabs Eagle 多模态框架构建的视觉定位(Visual Grounding)模型,能够根据自然语言描述在图像中定位目标并输出 <box> 坐标。本文记录了 LocateAnything-3B 在昇腾 910B NPU 上的适配与验证过程。

一、运行环境准备

1、版本配套表

配套版本环境准备指导
Python3.10-
CANN8.5.1-
vllm-ascend 镜像v0.18.0rc1-
torch / torch_npu随镜像内置-
peft0.19.1-
Eaglemain (783f656d)-
LocateAnything-vLLMmain (bee9ce47)-
LocateAnything-3Bmodelscope 权重-

2、环境准备

整机:Atlas 800T A2

NPU:910B 昇腾

部署方式:单卡部署

操作系统:Ubuntu 20.04, ARM

驱动版本:25.5.2


二、推理部署

1、镜像下载

docker pull quay.io/ascend/vllm-ascend:v0.18.0rc1

2、启动容器

export IMAGE=quay.io/ascend/vllm-ascend:v0.18.0rc1

docker run --rm \
--name locate_anything \
--privileged \
--net=host \
--shm-size=1g \
--device /dev/davinci_manager \
--device /dev/devmm_svm \
--device /dev/hisi_hdc \
-v /etc/hccn.conf:/etc/hccn.conf \
-v /usr/local/dcmi:/usr/local/dcmi \
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \
-v /usr/local/Ascend/driver/lib64/:/usr/local/Ascend/driver/lib64/ \
-v /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info \
-v /etc/ascend_install.info:/etc/ascend_install.info \
-v /root/.cache:/root/.cache \
-v /opt/data/models:/opt/data/models \
-it $IMAGE bash

3、安装依赖包

pip install peft==0.19.1

4、部署与验证

4.1 代码适配

4.1.1 源码与权重准备

git clone https://github.com/NVlabs/Eagle.git /workspace/Eagle
cd /workspace/Eagle && git checkout 783f656d && cd -

git clone https://github.com/WuNein/LocateAnything-vLLM.git /workspace/LocateAnything-vLLM
cd /workspace/LocateAnything-vLLM && git checkout bee9ce47 && cd -

git clone https://atomgit.com/Ascend-SACT/LocateAnything-3B.git /workspace/LocateAnything_Transfer

python3 -c "from modelscope import snapshot_download; snapshot_download('nv-community/LocateAnything-3B', local_dir='/workspace/LocateAnything-3B')"

4.1.2 应用昇腾迁移补丁

迁移补丁位于本仓库 patches/ 目录,分别覆盖 Eagle 与 LocateAnything-vLLM 两个仓库:

PATCH_DIR="/workspace/LocateAnything_Transfer/patches/"

cd /workspace/Eagle && git apply "$PATCH_DIR/eagle_ascend_migration.patch" && cd -
cd /workspace/LocateAnything-vLLM && git apply "$PATCH_DIR/vllm_ascend_migration.patch" && cd -

补丁主要为适配昇腾推理平台,处理 transfer_to_npu 注入等。

4.1.3 数据处理依赖可选化

processing_locateanything.py 中的 lmdb、decord 在纯推理场景非必需,将其改为可选导入以避免环境缺包报错:

cd /workspace/LocateAnything-3B
sed -i 's/^import lmdb$/try:\n    import lmdb\nexcept (ImportError, ModuleNotFoundError):\n    lmdb = None/' processing_locateanything.py
sed -i 's/^import decord$/try:\n    import decord\nexcept (ImportError, ModuleNotFoundError):\n    decord = None/' processing_locateanything.py

4.2 离线部署

运行 10 张 demo 图的定位验证脚本(manifest 模式):

export ASCEND_RT_VISIBLE_DEVICES=0
cd /workspace/LocateAnything_Transfer/demo
python3 test_demo_native.py

也支持单图测试:

python3 test_demo_native.py --image images/clean_COCO_train2014_000000576829_0.png --phrase "the bed"

可以修改test_demo_native.py中的LocateAnythingWorker的各参数,进一步实现文字、多目标的定位等定位。 任务类型

4.3 推理结果

在 10 张 COCO demo 图上以 ground_single 任务、hybrid 生成模式进行验证,全部通过,平均 IoU 达 94.53%。首图为推理预热耗时约 6s,已排除预热后单图平均耗时约 476ms:

#类别目标描述Native IoU耗时(ms)
1personPink shirt girl...0.96596045.6
2personlady sitting0.9269393.6
3animalblack cat under sink0.9748469.0
6furnituresheets on the bed (bottom-right)0.9225480.5
7furniturebedspread0.8390609.7
7otherblack-white striped animal (left)0.9666502.7
8animalbutt zebra, cut in half0.9585501.0
8clothingtennis player in white shirt0.9852509.8
9clothingdude in blue shirt tie0.9694469.3
10otherfirst case on left0.9445346.0

原图 测试图片

定位结果 运行结果

4.4 RefCOCOg test 基准性能

在 RefCOCOg test split(共 5023 样本)上以 ground_single 任务、hybrid 生成模式进行完整评测,结果如下:

指标实测 (Ascend 910B3 NPU)
F1 @ IoU=0.5088.39%
F1 @ IoU=0.9541.71%
Mean F1 (0.5:0.05:0.95)76.96%
检测率100% (5023/5023)
Mean IoU82.62%
吞吐1.48 samples/s
总耗时3382s (~57 分钟,含预热)

F1 随 IoU 阈值变化

IoU 阈值0.50.550.60.650.70.750.80.850.90.95
F1 (%)88.3987.3486.0684.8582.9481.0178.0273.9265.3441.71

评测配置

项值说明
WorkerLocateAnythingWorkerEagle 仓库
Taskground_single单实例指代定位
PromptLocate a single instance that matches the following description: [PHRASE].评测模板
generation_modehybrid—
max_new_tokens8192—
temperature0.7—
数据集lmms-lab/RefCOCOg test split5023 样本

评测采用 do_sample=True 存在采样随机性。