Image Segmentation
Transformers
Safetensors
PyTorch
English
tren
feature-extraction
vision
image-feature-extraction
region-tokens
dinov3
custom_code
Instructions to use aryaaan12/T-REN with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use aryaaan12/T-REN with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-segmentation", model="aryaaan12/T-REN", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("aryaaan12/T-REN", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,199 +1,123 @@
|
|
| 1 |
-
--
|
| 2 |
-
library_name: transformers
|
| 3 |
-
tags: []
|
| 4 |
-
---
|
| 5 |
-
|
| 6 |
-
# Model Card for Model ID
|
| 7 |
-
|
| 8 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
## Model Details
|
| 13 |
-
|
| 14 |
-
### Model Description
|
| 15 |
-
|
| 16 |
-
<!-- Provide a longer summary of what this model is. -->
|
| 17 |
-
|
| 18 |
-
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
| 19 |
-
|
| 20 |
-
- **Developed by:** [More Information Needed]
|
| 21 |
-
- **Funded by [optional]:** [More Information Needed]
|
| 22 |
-
- **Shared by [optional]:** [More Information Needed]
|
| 23 |
-
- **Model type:** [More Information Needed]
|
| 24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
| 25 |
-
- **License:** [More Information Needed]
|
| 26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 27 |
-
|
| 28 |
-
### Model Sources [optional]
|
| 29 |
-
|
| 30 |
-
<!-- Provide the basic links for the model. -->
|
| 31 |
-
|
| 32 |
-
- **Repository:** [More Information Needed]
|
| 33 |
-
- **Paper [optional]:** [More Information Needed]
|
| 34 |
-
- **Demo [optional]:** [More Information Needed]
|
| 35 |
-
|
| 36 |
-
## Uses
|
| 37 |
-
|
| 38 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 39 |
-
|
| 40 |
-
### Direct Use
|
| 41 |
-
|
| 42 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
| 43 |
-
|
| 44 |
-
[More Information Needed]
|
| 45 |
-
|
| 46 |
-
### Downstream Use [optional]
|
| 47 |
-
|
| 48 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
| 49 |
-
|
| 50 |
-
[More Information Needed]
|
| 51 |
-
|
| 52 |
-
### Out-of-Scope Use
|
| 53 |
-
|
| 54 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
| 55 |
-
|
| 56 |
-
[More Information Needed]
|
| 57 |
-
|
| 58 |
-
## Bias, Risks, and Limitations
|
| 59 |
-
|
| 60 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
| 61 |
-
|
| 62 |
-
[More Information Needed]
|
| 63 |
-
|
| 64 |
-
### Recommendations
|
| 65 |
-
|
| 66 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
| 67 |
-
|
| 68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
| 69 |
-
|
| 70 |
-
## How to Get Started with the Model
|
| 71 |
|
| 72 |
-
|
| 73 |
|
| 74 |
-
[
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
### Training Data
|
| 79 |
-
|
| 80 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
| 81 |
-
|
| 82 |
-
[More Information Needed]
|
| 83 |
-
|
| 84 |
-
### Training Procedure
|
| 85 |
-
|
| 86 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
| 87 |
-
|
| 88 |
-
#### Preprocessing [optional]
|
| 89 |
-
|
| 90 |
-
[More Information Needed]
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
#### Training Hyperparameters
|
| 94 |
-
|
| 95 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
| 96 |
-
|
| 97 |
-
#### Speeds, Sizes, Times [optional]
|
| 98 |
-
|
| 99 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
| 100 |
-
|
| 101 |
-
[More Information Needed]
|
| 102 |
-
|
| 103 |
-
## Evaluation
|
| 104 |
-
|
| 105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
| 106 |
-
|
| 107 |
-
### Testing Data, Factors & Metrics
|
| 108 |
-
|
| 109 |
-
#### Testing Data
|
| 110 |
-
|
| 111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
| 112 |
-
|
| 113 |
-
[More Information Needed]
|
| 114 |
-
|
| 115 |
-
#### Factors
|
| 116 |
-
|
| 117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 118 |
-
|
| 119 |
-
[More Information Needed]
|
| 120 |
-
|
| 121 |
-
#### Metrics
|
| 122 |
-
|
| 123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 124 |
-
|
| 125 |
-
[More Information Needed]
|
| 126 |
-
|
| 127 |
-
### Results
|
| 128 |
-
|
| 129 |
-
[More Information Needed]
|
| 130 |
-
|
| 131 |
-
#### Summary
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
|
|
|
| 134 |
|
| 135 |
-
##
|
| 136 |
|
| 137 |
-
|
|
|
|
|
|
|
| 138 |
|
| 139 |
-
|
| 140 |
|
| 141 |
-
|
| 142 |
|
| 143 |
-
|
| 144 |
|
| 145 |
-
|
| 146 |
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
- **Compute Region:** [More Information Needed]
|
| 151 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 152 |
|
| 153 |
-
##
|
| 154 |
|
| 155 |
-
|
| 156 |
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
-
|
| 160 |
|
| 161 |
-
|
| 162 |
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
-
|
|
|
|
| 166 |
|
| 167 |
-
#
|
|
|
|
| 168 |
|
| 169 |
-
|
| 170 |
|
| 171 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
-
|
|
|
|
|
|
|
| 174 |
|
| 175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
-
|
| 178 |
|
| 179 |
-
|
|
|
|
| 180 |
|
| 181 |
-
[
|
| 182 |
|
| 183 |
-
|
|
|
|
| 184 |
|
| 185 |
-
|
|
|
|
| 186 |
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
-
|
| 190 |
|
| 191 |
-
|
| 192 |
|
| 193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
|
| 195 |
-
|
| 196 |
|
| 197 |
-
##
|
| 198 |
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# T-REN: Text-Aligned Region Encoder Network
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
**Authors**: [Savya Khosla](https://savya08.github.io/), [Sethuraman TV](https://github.com/sethuramanio), [Aryan Chadha](https://www.linkedin.com/in/aryan-chadha/), [Alex Schwing](https://www.alexander-schwing.de/), [Derek Hoiem](https://dhoiem.cs.illinois.edu/)
|
| 4 |
|
| 5 |
+
[](https://github.com/savya08/T-REN)
|
| 6 |
|
| 7 |
+
T-REN (**T**ext-aligned **R**egion **E**ncoder **N**etwork) is an image encoder that produces region-level tokens aligned with text, built on top of [DINOv3](https://github.com/facebookresearch/dinov3) ViT-L/16. Compared to its patch-based backbone, T-REN delivers:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
- **+5.9 mIoU** on ADE20K open-vocabulary segmentation
|
| 10 |
+
- **+18.4% recall** on COCO object-level text-image retrieval
|
| 11 |
+
- **+15.6% recall** on Ego4D video object localization (VQ2D)
|
| 12 |
+
- **+17.6% mIoU** on VSPW video scene parsing
|
| 13 |
+
- **24× fewer tokens** per image, **187× fewer** per video
|
| 14 |
|
| 15 |
+
---
|
| 16 |
|
| 17 |
+
## What's in this repo
|
| 18 |
|
| 19 |
+
This HuggingFace repo contains:
|
| 20 |
+
- `model.safetensors` — the trained `RegionEncoder` head weights (~1.2 GB)
|
| 21 |
+
- `configuration_tren.py`, `modeling_tren.py`, `model.py`, `task_utils.py` — source code for `trust_remote_code`
|
| 22 |
|
| 23 |
+
**The DINOv3 ViT-L/16 backbone is NOT included here** — it belongs to Facebook Research and must be obtained separately (see below).
|
| 24 |
|
| 25 |
+
---
|
| 26 |
|
| 27 |
+
## Quickstart
|
| 28 |
|
| 29 |
+
### Step 1 — Install dependencies
|
| 30 |
|
| 31 |
+
```bash
|
| 32 |
+
pip install transformers torch torchvision kornia
|
| 33 |
+
```
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
### Step 2 — Get the DINOv3 weights
|
| 36 |
|
| 37 |
+
T-REN's backbone is DINOv3 ViT-L/16 with a DINOtxt text-alignment head. You need two weight files from the [DINOv3 release](https://github.com/facebookresearch/dinov3):
|
| 38 |
|
| 39 |
+
| File | Description |
|
| 40 |
+
|------|-------------|
|
| 41 |
+
| `dinov3_vitl16_pretrain_lvd1689m-8aa4cbdd.pth` | DINOv3 ViT-L/16 backbone |
|
| 42 |
+
| `dinov3_vitl16_dinotxt_vision_head_and_text_encoder-a442d8f5.pth` | DINOtxt vision head + text encoder |
|
| 43 |
|
| 44 |
+
Place both files in the same directory, e.g. `/path/to/dinov3_weights/`.
|
| 45 |
|
| 46 |
+
### Step 3 — Load and run T-REN
|
| 47 |
|
| 48 |
+
```python
|
| 49 |
+
import torch
|
| 50 |
+
import torchvision.transforms as T
|
| 51 |
+
from PIL import Image
|
| 52 |
+
from transformers import AutoModel
|
| 53 |
|
| 54 |
+
# Load model (downloads T-REN weights from this repo automatically)
|
| 55 |
+
model = AutoModel.from_pretrained("aryaaan12/T-REN", trust_remote_code=True)
|
| 56 |
|
| 57 |
+
# Load the DINOv3 backbone from your local directory
|
| 58 |
+
model.load_backbone("/path/to/dinov3_weights/")
|
| 59 |
|
| 60 |
+
model.eval()
|
| 61 |
|
| 62 |
+
# Prepare an image — resize to 512x512, values in [0, 1]
|
| 63 |
+
transform = T.Compose([
|
| 64 |
+
T.Resize((512, 512)),
|
| 65 |
+
T.ToTensor(),
|
| 66 |
+
])
|
| 67 |
+
image = transform(Image.open("your_image.jpg").convert("RGB"))
|
| 68 |
+
image = image.unsqueeze(0) # (1, 3, 512, 512)
|
| 69 |
|
| 70 |
+
# Run T-REN
|
| 71 |
+
with torch.no_grad():
|
| 72 |
+
outputs = model(image)
|
| 73 |
|
| 74 |
+
# Outputs
|
| 75 |
+
region_tokens = outputs["text_aligned_tokens"] # list of (N, 1024) per image
|
| 76 |
+
region_masks = outputs["region_masks"] # list of (N, 32, 32) per image
|
| 77 |
+
class_token = outputs["class_tokens"] # (1, 1024) image-level token
|
| 78 |
+
print(f"Number of region tokens: {len(region_tokens[0])}")
|
| 79 |
+
```
|
| 80 |
|
| 81 |
+
### Text-guided region matching
|
| 82 |
|
| 83 |
+
```python
|
| 84 |
+
import torch.nn.functional as F
|
| 85 |
|
| 86 |
+
texts = ["sky", "car", "building", "tree", "road"]
|
| 87 |
|
| 88 |
+
with torch.no_grad():
|
| 89 |
+
outputs = model(image, texts=texts)
|
| 90 |
|
| 91 |
+
region_tokens = outputs["text_aligned_tokens"][0] # (N, 1024)
|
| 92 |
+
text_tokens = outputs["text_encodings"] # (5, 1024)
|
| 93 |
|
| 94 |
+
# Cosine similarity: which text label fits each region best?
|
| 95 |
+
sim = F.normalize(region_tokens, dim=-1) @ F.normalize(text_tokens, dim=-1).T
|
| 96 |
+
best_labels = sim.argmax(dim=-1)
|
| 97 |
+
print([texts[i] for i in best_labels])
|
| 98 |
+
```
|
| 99 |
|
| 100 |
+
---
|
| 101 |
|
| 102 |
+
## Model details
|
| 103 |
|
| 104 |
+
| | |
|
| 105 |
+
|---|---|
|
| 106 |
+
| Architecture | RegionEncoder (cross-attention decoder) over DINOv3 ViT-L/16 features |
|
| 107 |
+
| Trainable parameters | 31.5M (RegionEncoder head only; backbone is frozen) |
|
| 108 |
+
| Input resolution | 512 × 512 |
|
| 109 |
+
| Output token dim | 1024 |
|
| 110 |
+
| Multiscale regions | 3 scales per prompt point |
|
| 111 |
+
| Text embedding space | DINOtxt (aligned with DINOv3 text encoder) |
|
| 112 |
|
| 113 |
+
---
|
| 114 |
|
| 115 |
+
## Citation
|
| 116 |
|
| 117 |
+
```bibtex
|
| 118 |
+
@misc{khosla2026tren,
|
| 119 |
+
title={T-REN: Learning Text-Aligned Region Tokens Improves Dense Vision-Language Alignment and Scalability},
|
| 120 |
+
author={Savya Khosla and Sethuraman T V and Aryan Chadha and Alexander Schwing and Derek Hoiem},
|
| 121 |
+
year={2026},
|
| 122 |
+
}
|
| 123 |
+
```
|