Add native transformers support (DINOv3ViT-compatible weights)
#2
by cherubicxn - opened
- README.md +31 -5
- config.json +55 -0
- model.safetensors +3 -0
- preprocessor_config.json +22 -0
README.md
CHANGED
|
@@ -13,7 +13,7 @@ tags:
|
|
| 13 |
- pytorch
|
| 14 |
datasets:
|
| 15 |
- custom
|
| 16 |
-
library_name:
|
| 17 |
pipeline_tag: image-feature-extraction
|
| 18 |
---
|
| 19 |
|
|
@@ -21,7 +21,7 @@ pipeline_tag: image-feature-extraction
|
|
| 21 |
|
| 22 |
**LingBot-Vision** is a family of self-supervised Vision Transformer backbones for dense spatial perception. The models are pretrained with masked boundary modeling, a boundary-centric objective that encourages spatially structured patch features while retaining strong semantic representations.
|
| 23 |
|
| 24 |
-
This Hugging Face repository stores
|
| 25 |
|
| 26 |
## Model Details
|
| 27 |
|
|
@@ -72,6 +72,32 @@ Each checkpoint contains backbone weights only. Training-time heads, optimizer s
|
|
| 72 |
|
| 73 |
## How to Load
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
Install the LingBot-Vision inference repository and dependencies:
|
| 76 |
|
| 77 |
```bash
|
|
@@ -90,13 +116,13 @@ Load a pretrained backbone:
|
|
| 90 |
```python
|
| 91 |
import torch
|
| 92 |
|
| 93 |
-
from
|
| 94 |
|
| 95 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 96 |
dtype = torch.bfloat16 if device == "cuda" else torch.float32
|
| 97 |
|
| 98 |
backbone, embed_dim = load_pretrained_backbone(
|
| 99 |
-
variant="
|
| 100 |
device=device,
|
| 101 |
dtype=dtype,
|
| 102 |
)
|
|
@@ -113,7 +139,7 @@ The `variant` argument can be `giant`, `large`, `base`, or `small`. You can also
|
|
| 113 |
- **Backbone:** Vision Transformer with patch size 16
|
| 114 |
- **Released variants:** ViT-g/16, ViT-L/16, ViT-B/16, ViT-S/16
|
| 115 |
- **Output:** Normalized patch tokens from the frozen backbone
|
| 116 |
-
- **Checkpoint format:**
|
| 117 |
- **Training objective:** Masked boundary modeling with self-distillation
|
| 118 |
|
| 119 |
### Software Requirements
|
|
|
|
| 13 |
- pytorch
|
| 14 |
datasets:
|
| 15 |
- custom
|
| 16 |
+
library_name: transformers
|
| 17 |
pipeline_tag: image-feature-extraction
|
| 18 |
---
|
| 19 |
|
|
|
|
| 21 |
|
| 22 |
**LingBot-Vision** is a family of self-supervised Vision Transformer backbones for dense spatial perception. The models are pretrained with masked boundary modeling, a boundary-centric objective that encourages spatially structured patch features while retaining strong semantic representations.
|
| 23 |
|
| 24 |
+
This Hugging Face repository stores backbone-only weights in two interchangeable formats: a Transformers-format checkpoint (`model.safetensors` + `config.json`, loadable with `AutoModel`) and the reference PyTorch checkpoint `model.pt`. It is intended for inference, feature extraction, PCA visualization, and downstream dense prediction research.
|
| 25 |
|
| 26 |
## Model Details
|
| 27 |
|
|
|
|
| 72 |
|
| 73 |
## How to Load
|
| 74 |
|
| 75 |
+
### With 🤗 Transformers
|
| 76 |
+
|
| 77 |
+
This repository contains Transformers-format weights (`config.json`, `model.safetensors`), converted from the reference `model.pt` and numerically equivalent to it (fp32 max deviation < 1e-5). LingBot-Vision backbones are architecturally compatible with the DINOv3 ViT implementation in `transformers` (>= 4.56), so they load natively — no custom code, no `trust_remote_code`:
|
| 78 |
+
|
| 79 |
+
```python
|
| 80 |
+
import torch
|
| 81 |
+
from PIL import Image
|
| 82 |
+
from transformers import AutoImageProcessor, AutoModel
|
| 83 |
+
|
| 84 |
+
processor = AutoImageProcessor.from_pretrained("robbyant/lingbot-vision-vit-small")
|
| 85 |
+
model = AutoModel.from_pretrained("robbyant/lingbot-vision-vit-small")
|
| 86 |
+
|
| 87 |
+
image = Image.open("example.png").convert("RGB")
|
| 88 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 89 |
+
|
| 90 |
+
with torch.no_grad():
|
| 91 |
+
outputs = model(**inputs)
|
| 92 |
+
|
| 93 |
+
# token layout: [CLS, 4 register tokens, H*W patch tokens]
|
| 94 |
+
num_register_tokens = model.config.num_register_tokens
|
| 95 |
+
cls_token = outputs.pooler_output # [B, C]
|
| 96 |
+
patch_tokens = outputs.last_hidden_state[:, 1 + num_register_tokens :] # [B, H*W, C]
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
### With the reference implementation
|
| 100 |
+
|
| 101 |
Install the LingBot-Vision inference repository and dependencies:
|
| 102 |
|
| 103 |
```bash
|
|
|
|
| 116 |
```python
|
| 117 |
import torch
|
| 118 |
|
| 119 |
+
from lingbot_vision import load_pretrained_backbone
|
| 120 |
|
| 121 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 122 |
dtype = torch.bfloat16 if device == "cuda" else torch.float32
|
| 123 |
|
| 124 |
backbone, embed_dim = load_pretrained_backbone(
|
| 125 |
+
variant="small",
|
| 126 |
device=device,
|
| 127 |
dtype=dtype,
|
| 128 |
)
|
|
|
|
| 139 |
- **Backbone:** Vision Transformer with patch size 16
|
| 140 |
- **Released variants:** ViT-g/16, ViT-L/16, ViT-B/16, ViT-S/16
|
| 141 |
- **Output:** Normalized patch tokens from the frozen backbone
|
| 142 |
+
- **Checkpoint format:** Transformers `model.safetensors` (DINOv3ViT-compatible) and backbone-only `model.pt`
|
| 143 |
- **Training objective:** Masked boundary modeling with self-distillation
|
| 144 |
|
| 145 |
### Software Requirements
|
config.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"apply_layernorm": true,
|
| 3 |
+
"architectures": [
|
| 4 |
+
"DINOv3ViTModel"
|
| 5 |
+
],
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"drop_path_rate": 0.0,
|
| 8 |
+
"dtype": "float32",
|
| 9 |
+
"hidden_act": "gelu",
|
| 10 |
+
"hidden_size": 384,
|
| 11 |
+
"image_size": 512,
|
| 12 |
+
"initializer_range": 0.02,
|
| 13 |
+
"intermediate_size": 1536,
|
| 14 |
+
"key_bias": false,
|
| 15 |
+
"layer_norm_eps": 1e-05,
|
| 16 |
+
"layerscale_value": 1e-05,
|
| 17 |
+
"mlp_bias": true,
|
| 18 |
+
"model_type": "dinov3_vit",
|
| 19 |
+
"num_attention_heads": 6,
|
| 20 |
+
"num_channels": 3,
|
| 21 |
+
"num_hidden_layers": 12,
|
| 22 |
+
"num_register_tokens": 4,
|
| 23 |
+
"out_features": [
|
| 24 |
+
"stage12"
|
| 25 |
+
],
|
| 26 |
+
"out_indices": [
|
| 27 |
+
12
|
| 28 |
+
],
|
| 29 |
+
"patch_size": 16,
|
| 30 |
+
"pos_embed_jitter": null,
|
| 31 |
+
"pos_embed_rescale": 2.0,
|
| 32 |
+
"pos_embed_shift": null,
|
| 33 |
+
"proj_bias": true,
|
| 34 |
+
"query_bias": true,
|
| 35 |
+
"reshape_hidden_states": true,
|
| 36 |
+
"rope_theta": 100.0,
|
| 37 |
+
"stage_names": [
|
| 38 |
+
"stem",
|
| 39 |
+
"stage1",
|
| 40 |
+
"stage2",
|
| 41 |
+
"stage3",
|
| 42 |
+
"stage4",
|
| 43 |
+
"stage5",
|
| 44 |
+
"stage6",
|
| 45 |
+
"stage7",
|
| 46 |
+
"stage8",
|
| 47 |
+
"stage9",
|
| 48 |
+
"stage10",
|
| 49 |
+
"stage11",
|
| 50 |
+
"stage12"
|
| 51 |
+
],
|
| 52 |
+
"transformers_version": "5.5.3",
|
| 53 |
+
"use_gated_mlp": false,
|
| 54 |
+
"value_bias": true
|
| 55 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a037c545ef5c3cc62ffa4f36b5778c3d4f0429200c4344089e4dc6633aafe40e
|
| 3 |
+
size 86406384
|
preprocessor_config.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"image_processor_type": "DINOv3ViTImageProcessorFast",
|
| 3 |
+
"do_resize": true,
|
| 4 |
+
"size": {
|
| 5 |
+
"height": 512,
|
| 6 |
+
"width": 512
|
| 7 |
+
},
|
| 8 |
+
"resample": 2,
|
| 9 |
+
"do_rescale": true,
|
| 10 |
+
"rescale_factor": 0.00392156862745098,
|
| 11 |
+
"do_normalize": true,
|
| 12 |
+
"image_mean": [
|
| 13 |
+
0.485,
|
| 14 |
+
0.456,
|
| 15 |
+
0.406
|
| 16 |
+
],
|
| 17 |
+
"image_std": [
|
| 18 |
+
0.229,
|
| 19 |
+
0.224,
|
| 20 |
+
0.225
|
| 21 |
+
]
|
| 22 |
+
}
|