Robbyant/lingbot-vision

GitHub: Robbyant/lingbot-vision

LingBot-Vision 通过以边界为中心的掩码建模自监督预训练方法,为密集空间感知任务提供高质量的视觉主干网络。

Stars: 446 | Forks: 14

LingBot-Vision:用于密集空间感知的视觉预训练

[![PDF](https://img.shields.io/static/v1?label=Paper&message=PDF&color=red&logo=adobeacrobatreader)](https://github.com/Robbyant/lingbot-vision/blob/main/paper.pdf) [![arXiv](https://img.shields.io/static/v1?label=Paper&message=arXiv&color=lightgrey&logo=arxiv)](https://arxiv.org/abs/2607.05247) [![项目](https://img.shields.io/badge/Project-Website-blue)](https://technology.robbyant.com/lingbot-vision) [![HuggingFace](https://img.shields.io/static/v1?label=%F0%9F%A4%97%20Model&message=HuggingFace&color=orange)](https://huggingface.co/collections/robbyant/lingbot-vision) [![ModelScope](https://img.shields.io/static/v1?label=%F0%9F%A4%96%20Model&message=ModelScope&color=purple)](https://www.modelscope.cn/collections/Robbyant/LingBot-Vision) [![许可证](https://img.shields.io/badge/License-Apache--2.0-green)](LICENSE)
### 🔭 体验 LingBot-Vision!一系列用于密集空间感知的自监督 ViT 主干网络! 🖼️📐 **LingBot-Vision** 是一系列用于密集空间感知的自监督 Vision Transformer 主干网络,涵盖从 ViT-S/16 到拥有 11 亿参数的 ViT-g/16。其旗舰模型采用 **masked boundary modeling** 进行预训练 —— 这是一种以边界为中心的目标函数,在保留强大语义表征的同时,鼓励生成具有空间结构的 patch 特征。 ![以边界为中心的掩码建模](https://static.pigsec.cn/wp-content/uploads/repos/cas/a9/a9d9bdfb4bdeb17af9c7bd2cc2c449ae3028d754363f5191587948ab3945095a.png) **以边界为中心的掩码建模。** 每一行依次展示了输入图像、冻结 patch tokens 的 PCA 投影、教师模型发现的 boundary tokens,以及选定 boundary-token 查询的余弦相似度图。这些特征能够同时捕捉语义分组和几何结构。 LingBot-Vision 同时学习了边界、形状和语义区域,使其成为密集下游任务的即插即用视觉编码器: - 🎨 **密集特征可视化** — 冻结 patch tokens 的 PCA 图揭示了连贯的目标区域和清晰的边界 - 📏 **深度估计** — 冻结的 patch tokens 为轻量级的密集预测输出了空间结构 - 🧩 **语义分割** — 忠实于边界的特征将区域过渡与目标轮廓对齐 - 🎬 **视频目标分割** — 利用冻结特征进行免训练的 token 匹配与标签传播 - 🤖 **深度补全** — LingBot-Vision 是 LingBot-Depth 2.0 的视觉编码器初始化模型(见下文) ## 🌊 体验 LingBot-Depth 2.0 只需在 ViT-L/16 和 ViT-g/16 规模上简单替换为 LingBot-Vision 编码器,并将精选的 RGB-D 训练语料库从 300 万扩展到 1.5 亿个样本,LingBot-Depth 2.0 就取得了相较于前代及其他系统十分显著的性能提升,详情请参阅技术报告。 ![LingBot-Depth 2.0 在镜面与玻璃场景下的表现](https://static.pigsec.cn/wp-content/uploads/repos/cas/47/47275b2546c94484940773e20b5dce57df757730fd60400251a9dfd0e8bc2c53.jpg) **LingBot-Depth 2.0 在镜面与玻璃场景下的表现。** 每组依次展示了输入的 RGB、原始传感器深度、优化后的深度以及优化后的点云。原始深度在窗格、玻璃护栏和反射性地板等难度较高的表面上会出现缺失。LingBot-Depth 2.0 将这些区域补全为跨帧的稳定且连续的表面。 ## 📦 模型库 我们训练了一个包含约 11 亿参数的 ViT-g/16 教师模型,并从中蒸馏出 ViT-L、ViT-B 和 ViT-S 主干网络,以便用于推理和下游任务。完整的训练和评估细节详见技术报告。 所有发布的权重均为**仅包含主干网络**的 `.pt` 检查点,以 `model.pt` 的形式存储在每个模型仓库中(查看完整的 [Hugging Face 合集](https://huggingface.co/collections/robbyant/lingbot-vision)): | 模型 | 主干网络 | 嵌入维度 | Hugging Face 权重 | ModelScope 权重 | |-------|----------|----------:|----------------------|--------------------| | **LingBot-Vision-Giant**
最高质量的密集特征 | ViT-g/16 · SwiGLU · fp32 RoPE · 4 register tokens | 1536 | [vit-giant](https://huggingface.co/robbyant/lingbot-vision-vit-giant) | [vit-giant](https://www.modelscope.cn/models/Robbyant/lingbot-vision-vit-giant) | | **LingBot-Vision-Large** ⭐
推荐:强大的特征,推理实用性强 | ViT-L/16,从 Giant 蒸馏而来 | 1024 | [vit-large](https://huggingface.co/robbyant/lingbot-vision-vit-large) | [vit-large](https://www.modelscope.cn/models/Robbyant/lingbot-vision-vit-large) | | **LingBot-Vision-Base**
推理开销均衡 | ViT-B/16,从 Giant 蒸馏而来 | 768 | [vit-base](https://huggingface.co/robbyant/lingbot-vision-vit-base) | [vit-base](https://www.modelscope.cn/models/Robbyant/lingbot-vision-vit-base) | | **LingBot-Vision-Small**
适用于轻量级演示和下游任务 | ViT-S/16,从 Giant 蒸馏而来 | 384 | [vit-small](https://huggingface.co/robbyant/lingbot-vision-vit-small) | [vit-small](https://www.modelscope.cn/models/Robbyant/lingbot-vision-vit-small) | 配置文件打包在 `lingbot_vision/configs/` 下,并由 `load_pretrained_backbone` 自动选择。 ## 🔧 安装 **环境要求**: Python ≥ 3.10 · PyTorch ≥ 2.0 · 支持 CUDA 的 GPU(对于大模型推理推荐使用) **1. 克隆仓库** ``` git clone https://github.com/robbyant/lingbot-vision.git cd lingbot-vision ``` **2. 创建 conda 环境** ``` conda create -n lingbot-vision python=3.10 -y conda activate lingbot-vision ``` **3. 安装 lingbot-vision** ``` python -m pip install -r requirements.txt python -m pip install -e . ``` ## 🚀 快速开始 ### 使用 PyTorch 加载 LingBot-Vision 预训练模型 首次使用时,模型会自动从 Hugging Face 下载。此示例使用小模型进行轻量级的冒烟测试;`large` 是默认变体,`giant` 是可用的最大主干网络。 ``` import torch from lingbot_vision import load_pretrained_backbone, extract_patch_tokens, load_image device = "cuda" if torch.cuda.is_available() else "cpu" dtype = torch.bfloat16 if device == "cuda" else torch.float32 # 从 robbyant/lingbot-vision-vit-small 下载 model.pt。 backbone, embed_dim = load_pretrained_backbone( variant="small", device=device, dtype=dtype, ) img_norm, _, _ = load_image( "examples/example.png", size=512, patch_size=backbone.patch_size, mode="square", ) patch_tokens, patch_grid = extract_patch_tokens(backbone, img_norm, device, dtype) print(patch_tokens.shape, patch_grid, embed_dim) # torch.Size([1, 1024, 384]) (32, 32) 384 ``` `patch_tokens` 的形状为 `[B, H * W, C]`,其中 `H` 和 `W` 为 patch 网格的维度。`variant` 可以是 `giant`、`large`、`base` 或 `small`;如果省略,则默认为 `large`。你也可以向 `load_pretrained_backbone` 传递一个本地目录或明确的 Hugging Face 模型仓库。 ### 运行 PCA 演示 从 Hugging Face(或 ModelScope,如果可用)下载主干网络检查点,然后运行: ``` ./scripts/run_pca_demo.sh \ --config-file lingbot_vision/configs/lbot_vision_vitl.yaml \ --ckpt /path/to/model.pt \ --input examples/example.png \ --out outputs/pca_demo \ --size 512 \ --mode square \ --dtype bf16 ``` 图像将被加载为 RGB 格式,根据 `--size` 和 `--mode` 调整大小,对齐到模型 patch 大小,并使用 ImageNet 统计数据进行归一化。该演示将 patch tokens 的前三个 PCA 分量映射为 RGB,并将仅 PCA 的可视化图像和输入/PCA 面板可视化图像输出到输出目录。使用 `--dtype fp32 --device cpu` 进行仅 CPU 的推理。
所有演示选项 | 参数 | 描述 | | --- | --- | | `--config-file` | `lingbot_vision/configs/` 下的模型配置文件。 | | `--ckpt` | 纯主干网络 `.pt` 检查点的本地路径。 | | `--input` | 图像文件或图像目录。 | | `--out` | PCA 可视化的输出目录。 | | `--size` | 目标输入大小。对于 ViT-g/16,512 会生成 32 x 32 的 patch 网格。 | | `--mode` | `square` 调整大小为 `size` x `size`(不保留宽高比);`shortest` 将最短边调整为 `size`,然后中心裁剪出 `size` x `size` 的正方形。 | | `--dtype` | `bf16`、`fp16` 或 `fp32`。 | | `--device` | PyTorch 设备,例如 `cuda` 或 `cpu`。 |
### 检查点格式 发布的检查点是仅包含主干网络权重的 `.pt` 文件 —— 不包含优化器状态、投影头或训练时的 boundary heads。加载器接受原始的 state dict 或带有 `backbone` 条目的字典: ``` state_dict {"backbone": state_dict} ``` 如果检查点键名带有 `backbone.` 前缀,加载器会自动去除该前缀。 ## 📖 引用 ``` @article{lingbot-vision2026, title={Vision Pretraining for Dense Spatial Perception}, author={Fu, Zelin and Tan, Bin and Sun, Changjiang and Liu, Shaohui and Zheng, Kecheng and Xu, Yinghao and Zhu, Xing and Shen, Yujun and Xue, Nan}, journal={arXiv preprint arXiv:2607.05247}, year={2026} } ``` ## 📜 许可证 本项目基于 Apache License 2.0 协议发布。详情请参阅 [LICENSE](LICENSE)。 ## 🙏 致谢 LingBot-Vision 是 LingBot 空间感知项目的一部分。我们感谢 [DINOv2](https://github.com/facebookresearch/dinov2) 和 [DINOv3](https://github.com/facebookresearch/dinov3) 对自监督学习做出的贡献。 ## 📮 联系方式 如有任何问题、讨论或合作意向: - **Issues**: 在 GitHub 上提出 [issue](https://github.com/robbyant/lingbot-vision/issues) - **电子邮件**: 联系 [Zelin Fu](https://github.com/TakuLingFu) (fuzelin.fzl@antgroup.com) 或 [Nan Xue](https://xuenan.net) (xuenan@ieee.org)
标签:凭据扫描, 特征提取, 空间感知, 自监督学习, 视觉 Transformer, 计算机视觉, 逆向工具, 预训练模型