模型名称: infinity1096/UFM-Refine-980
模型链接: HuggingFace
AtomGit 镜像: AtomGit
模型描述: UFM (UniFlowMatch) 是一个统一稠密对应模型,端到端预测像素位移场,同时处理光流估计和宽基线匹配任务。UFM-Refine-980 是高分辨率(980p)细化模型。
模型架构: DINOv2 ViT-Large + DPT (Dense Prediction Transformer) + Global Attention + Patch MLP Refinement
参数规模: ~477M (477,760,540)
输入规格:
输出规格:
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch | >= 2.1.0 | PyTorch 框架 |
| torch_npu | >= 2.1.0 | 昇腾 NPU 后端 |
| safetensors | >= 0.4.0 | 安全权重加载 |
| numpy | >= 1.24.0 | 数组计算 |
| Pillow | >= 9.0.0 | 图像处理 |
| opencv-python-headless | >= 4.8.0 | 光流可视化 |
| flow_vis | >= 1.0.0 | 光流颜色映射(可选) |
| uniflowmatch | 源码 | UFM模型实现 (见下方说明) |
| uniception | 源码 | 视觉基础模型库 (见下方说明) |
| 昇腾驱动 | CANN 8.0+ | 推荐 CANN 8.5.1 |
安装命令:
# 1. 安装 PyPI 依赖
pip install torch torch_npu safetensors numpy Pillow opencv-python-headless flow_vis
# 2. 安装 uniception (UniCeption 视觉基础模型库)
git clone https://github.com/cv-rits/UniCeption.git
cd UniCeption && pip install -e .
# 3. 克隆 UFM 模型源码到推理目录
git clone https://github.com/UniFlowMatch/UFM.git# 检查 NPU 设备
npu-smi info
# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"方式一:HuggingFace(推荐)
huggingface-cli download infinity1096/UFM-Refine-980 --local-dir ./weights方式二:AtomGit 镜像(HuggingFace 下载慢时使用)
# 使用 Python 下载(huggingface-cli 版本兼容问题时)
python3 -c "
import urllib.request, os
url = 'https://ai.gitcode.com/hf_mirrors/infinity1096/UFM-Refine-980/resolve/main/model.safetensors'
req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
with urllib.request.urlopen(req, timeout=300) as resp:
with open('./weights/model.safetensors', 'wb') as f:
f.write(resp.read())
"# 确保 uniflowmatch 源码在推理脚本同目录下
# 目录结构:
# inference.py # 推理脚本
# uniflowmatch/ # UFM 模型源码
# weights/ # 模型权重
# config.json
# model.safetensors
# 单对图像推理
python3 inference.py \
--model-path ./weights \
--source image1.jpg \
--target image2.jpg \
--output-dir ./results
# 指定分辨率推理
python3 inference.py \
--model-path ./weights \
--source image1.jpg \
--target image2.jpg \
--resolution 640x420 \
--output-dir ./results| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| --model-path | str | 必填 | 模型权重目录路径 |
| --source/-s | str | 必填 | 源图像路径 |
| --target/-t | str | 必填 | 目标图像路径 |
| --output-dir/-o | str | ./results | 输出目录 |
| --resolution | str | 980x644 | 推理分辨率 (WxH) |
[设备] Ascend910_9362 (npu:0)
[模型] UniFlowMatchClassificationRefinement
[配置] encoder=dinov2, head=dpt
[分辨率] 980x644
[权重] 已加载 670 个 tensor
[参数量] 477,760,540
[输入] 源图像: test_source.jpg
[输入] 目标图像: test_target.jpg
[图像] Source: torch.Size([1, 3, 644, 980]), Target: torch.Size([1, 3, 644, 980])
[推理] 开始推理...
[结果] Flow shape: torch.Size([1, 2, 644, 980])
[结果] Covisibility shape: torch.Size([1, 644, 980])
[结果] Flow range: [3.5683, 13.5002]
[结果] Covisibility range: [0.0623, 0.9997]
[耗时] 0.930s
[统计] Flow平均绝对值: 7.9892
[统计] Covisibility平均值: 0.9430
[状态] SUCCESS[基准测试] 10次推理统计 (980x644):
平均: 0.95s
最小: 0.91s
最大: 1.02s
标准差: 0.03s
P50: 0.93s
P99: 1.01s注意: 推理失败时输出
[状态] FAILED和错误信息。
运行命令:
python3 inference.py \
--model-path ./weights \
--source test_source.jpg \
--target test_target.jpg \
--output-dir ./results输出:
[设备] Ascend910_9362 (npu:0)
[模型] UniFlowMatchClassificationRefinement
[配置] encoder=dinov2, head=dpt
[分辨率] 980x644
[权重] 已加载 670 个 tensor
[参数量] 477,760,540
[推理] 开始推理...
[结果] Flow shape: torch.Size([1, 2, 644, 980])
[结果] Covisibility shape: torch.Size([1, 644, 980])
[结果] Flow range: [3.5683, 13.5002]
[结果] Covisibility range: [0.0623, 0.9997]
[耗时] 0.930s
[统计] Flow平均绝对值: 7.9892
[统计] Covisibility平均值: 0.9430
[状态] SUCCESS输出文件:
results/flow.png — 光流可视化results/covisibility.png — 共视掩码可视化results/flow.npy — 原始光流数组 (1, 2, 644, 980)results/covisibility.npy — 原始共视掩码数组 (1, 644, 980)


测试数据: 自建测试图像对 (几何变换模拟)
评测指标:
| 指标 | 结果 | 说明 |
|---|---|---|
| Flow Mean Abs | 7.99 | 像素位移场平均绝对值 |
| Covisibility Mean | 0.94 | 共视区域平均置信度 |
| 推理耗时 (980×644) | 0.93s | 单对图像,Ascend910 NPU |
评测命令:
python3 inference.py \
--model-path ./weights \
--source test_source.jpg \
--target test_target.jpg \
--output-dir ./results实际输出:
[结果] Flow shape: torch.Size([1, 2, 644, 980])
[结果] Covisibility shape: torch.Size([1, 644, 980])
[结果] Flow range: [3.5683, 13.5002]
[结果] Covisibility range: [0.0623, 0.9997]
[耗时] 0.930s
[统计] Flow平均绝对值: 7.9892
[统计] Covisibility平均值: 0.9430libgl1-mesa-glx。