Add metadata and improve model card
#1
by nielsr HF Staff - opened
README.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
<div align="center">
|
| 2 |
|
| 3 |
<h1>VGGT-Segmentor: Geometry-Enhanced Cross-View Segmentation</h1>
|
|
@@ -47,6 +52,7 @@
|
|
| 47 |
|
| 48 |
</div>
|
| 49 |
|
|
|
|
| 50 |
|
| 51 |
## 📢 News
|
| 52 |
|
|
@@ -122,305 +128,13 @@ hf download zbbhhh/VGGT-S main_exp.pth --local-dir official_ckpts # Download che
|
|
| 122 |
|
| 123 |
### Modify VGGT Track Head
|
| 124 |
|
| 125 |
-
To extract VGGT encoder feature maps for downstream correspondence learning, please modify the `forward` function in:
|
| 126 |
-
|
| 127 |
-
```text
|
| 128 |
-
third_party/vggt_main/vggt/heads/track_head.py
|
| 129 |
-
```
|
| 130 |
-
|
| 131 |
-
Replace the original `forward` function (around Line 72) with the following implementation:
|
| 132 |
-
|
| 133 |
-
```python
|
| 134 |
-
def forward(self, aggregated_tokens_list, images, patch_start_idx, query_points=None, iters=None, feat=False):
|
| 135 |
-
"""
|
| 136 |
-
Forward pass of the TrackHead.
|
| 137 |
-
|
| 138 |
-
Args:
|
| 139 |
-
aggregated_tokens_list (list): List of aggregated tokens from the backbone.
|
| 140 |
-
images (torch.Tensor): Input images of shape (B, S, C, H, W), where:
|
| 141 |
-
B = batch size,
|
| 142 |
-
S = sequence length.
|
| 143 |
-
patch_start_idx (int): Starting index for patch tokens.
|
| 144 |
-
query_points (torch.Tensor, optional): Initial query points to track.
|
| 145 |
-
If None, points are initialized automatically.
|
| 146 |
-
iters (int, optional): Number of refinement iterations.
|
| 147 |
-
If None, uses self.iters.
|
| 148 |
-
feat (bool, optional): Whether to additionally return feature maps.
|
| 149 |
-
|
| 150 |
-
Returns:
|
| 151 |
-
tuple:
|
| 152 |
-
- coord_preds (torch.Tensor): Predicted coordinates.
|
| 153 |
-
- vis_scores (torch.Tensor): Visibility scores.
|
| 154 |
-
- conf_scores (torch.Tensor): Confidence scores.
|
| 155 |
-
- feature_maps (torch.Tensor, optional): Extracted VGGT feature maps.
|
| 156 |
-
"""
|
| 157 |
-
|
| 158 |
-
B, S, _, H, W = images.shape
|
| 159 |
-
|
| 160 |
-
# Extract feature maps from VGGT tokens
|
| 161 |
-
# Shape: (B, S, C, H//2, W//2)
|
| 162 |
-
feature_maps = self.feature_extractor(
|
| 163 |
-
aggregated_tokens_list,
|
| 164 |
-
images,
|
| 165 |
-
patch_start_idx
|
| 166 |
-
)
|
| 167 |
-
|
| 168 |
-
# Use default iterations if not specified
|
| 169 |
-
if iters is None:
|
| 170 |
-
iters = self.iters
|
| 171 |
-
|
| 172 |
-
# Tracking
|
| 173 |
-
coord_preds, vis_scores, conf_scores = self.tracker(
|
| 174 |
-
query_points=query_points,
|
| 175 |
-
fmaps=feature_maps,
|
| 176 |
-
iters=iters
|
| 177 |
-
)
|
| 178 |
-
|
| 179 |
-
if feat:
|
| 180 |
-
return coord_preds, vis_scores, conf_scores, feature_maps
|
| 181 |
-
|
| 182 |
-
return coord_preds, vis_scores, conf_scores
|
| 183 |
-
```
|
| 184 |
-
|
| 185 |
-
#### Optional
|
| 186 |
-
|
| 187 |
-
We observe that VGGT recomputes the 2D positional embeddings during every forward pass, even when the input image resolution remains unchanged. To accelerate both training and inference, we adapt the implementation by precomputing the 2D positional embeddings offline and loading them directly at runtime, thereby avoiding redundant computations.
|
| 188 |
-
|
| 189 |
-
1. Generate the 2D positional embeddings using `gen_pos_embed.py`:
|
| 190 |
-
|
| 191 |
-
```bash
|
| 192 |
-
python gen_pos_embed.py --img_H 518 --img_W 518
|
| 193 |
-
```
|
| 194 |
-
|
| 195 |
-
We also provide precomputed positional embeddings for various commonly used image resolutions on [Hugging Face](https://huggingface.co/zbbhhh/VGGT-S).
|
| 196 |
-
|
| 197 |
-
2. Modify the VGGT tracking head to use the precomputed embeddings.
|
| 198 |
-
|
| 199 |
-
Open:
|
| 200 |
-
|
| 201 |
-
```text
|
| 202 |
-
third_party/vggt_main/vggt/heads/track_modules/base_track_predictor.py
|
| 203 |
-
```
|
| 204 |
-
|
| 205 |
-
Add the following line at the end of the `__init__` method in the `BaseTrackerPredictor` class, around [base_track_predictor.py#L81](https://github.com/facebookresearch/vggt/blob/main/vggt/heads/track_modules/base_track_predictor.py#L81):
|
| 206 |
-
|
| 207 |
-
```python
|
| 208 |
-
self.pos_embed = None
|
| 209 |
-
```
|
| 210 |
-
|
| 211 |
-
This attribute is used to cache the loaded positional embeddings.
|
| 212 |
-
|
| 213 |
-
Then, replace the following line in [base_track_predictor.py#L149](https://github.com/facebookresearch/vggt/blob/main/vggt/heads/track_modules/base_track_predictor.py#L149):
|
| 214 |
-
|
| 215 |
-
```python
|
| 216 |
-
pos_embed = get_2d_sincos_pos_embed(self.transformer_dim, grid_size=(HH, WW)).to(query_points.device)
|
| 217 |
-
```
|
| 218 |
-
|
| 219 |
-
with:
|
| 220 |
-
|
| 221 |
-
```python
|
| 222 |
-
pos_emb_pt = (
|
| 223 |
-
f"vggt_main/pos_embed/"
|
| 224 |
-
f"pos_embed_{self.transformer_dim}_{HH}_{WW}.pt"
|
| 225 |
-
)
|
| 226 |
-
|
| 227 |
-
assert os.path.exists(pos_emb_pt), (
|
| 228 |
-
f"[BUG] Positional embedding file not found: {pos_emb_pt}"
|
| 229 |
-
)
|
| 230 |
-
|
| 231 |
-
if self.pos_embed is None:
|
| 232 |
-
self.pos_embed = torch.load(pos_emb_pt).to(query_points.device)
|
| 233 |
-
|
| 234 |
-
pos_embed = self.pos_embed
|
| 235 |
-
```
|
| 236 |
|
| 237 |
---
|
| 238 |
|
| 239 |
### Dataset Preparation
|
| 240 |
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
Please follow the official [SegSwap Ego-Exo4D correspondence pipeline](https://github.com/EGO4D/ego-exo4d-relation/tree/main/correspondence/SegSwap) to:
|
| 244 |
-
|
| 245 |
-
1. Download the Ego-Exo4D dataset
|
| 246 |
-
2. Extract video frames into images
|
| 247 |
-
3. Generate correspondence pairs
|
| 248 |
-
|
| 249 |
-
After preprocessing, the dataset should be organized as:
|
| 250 |
-
|
| 251 |
-
```text
|
| 252 |
-
data_root/
|
| 253 |
-
├── take_id_01/
|
| 254 |
-
│ ├── ego_cam/
|
| 255 |
-
│ │ ├── 0.jpg
|
| 256 |
-
│ │ ├── ...
|
| 257 |
-
│ │ └── n.jpg
|
| 258 |
-
│ ├── exo_cam/
|
| 259 |
-
│ │ ├── 0.jpg
|
| 260 |
-
│ │ ├── ...
|
| 261 |
-
│ │ └── n.jpg
|
| 262 |
-
│ └── annotation.json
|
| 263 |
-
├── ...
|
| 264 |
-
├── take_id_n/
|
| 265 |
-
└── split.json
|
| 266 |
-
```
|
| 267 |
-
|
| 268 |
-
Then run the official SegSwap pair-generation script:
|
| 269 |
-
|
| 270 |
-
[create_pairs.py](https://github.com/EGO4D/ego-exo4d-relation/blob/main/correspondence/SegSwap/data/create_pairs.py)
|
| 271 |
-
|
| 272 |
-
This will generate:
|
| 273 |
-
|
| 274 |
-
```text
|
| 275 |
-
train_egoexo_pairs.json
|
| 276 |
-
train_exoego_pairs.json
|
| 277 |
-
val_egoexo_pairs.json
|
| 278 |
-
val_exoego_pairs.json
|
| 279 |
-
```
|
| 280 |
-
|
| 281 |
-
---
|
| 282 |
-
|
| 283 |
-
#### Configure Dataset Path
|
| 284 |
-
|
| 285 |
-
If the Ego-Exo4D dataset has already been downloaded, modify:
|
| 286 |
-
|
| 287 |
-
```text
|
| 288 |
-
src/dataloader.py
|
| 289 |
-
```
|
| 290 |
-
|
| 291 |
-
and set:
|
| 292 |
-
|
| 293 |
-
```python
|
| 294 |
-
EGOEXO4D_ROOT = "your/data/path"
|
| 295 |
-
```
|
| 296 |
-
|
| 297 |
-
---
|
| 298 |
-
|
| 299 |
-
### Data Preprocessing
|
| 300 |
-
> We provide all intermediate result files generated from the following preprocessing steps. Therefore, if you have already downloaded the Ego-Exo4D dataset, you can directly use the provided files without rerunning the preprocessing pipeline. Nevertheless, we still release the complete data preprocessing code to support further community research and help readers better understand our pipeline and methodology.
|
| 301 |
-
|
| 302 |
-
#### Generate Scene JSON
|
| 303 |
-
This step reorganizes the dataset structure and converts the pair_json to the following hierarchical JSON format:
|
| 304 |
-
|
| 305 |
-
```text
|
| 306 |
-
scene
|
| 307 |
-
└── [obj_info]
|
| 308 |
-
├── ego_info
|
| 309 |
-
│ ├── ego_rgb
|
| 310 |
-
│ └── ego_mask
|
| 311 |
-
└── exo_info
|
| 312 |
-
├── exo_rfb
|
| 313 |
-
└── exo_mask
|
| 314 |
-
```
|
| 315 |
-
|
| 316 |
-
where each `scene` contains multiple object annotations (`obj_info`), and each object stores the corresponding ego-view and exo-view information, including RGB frames (`*_rgb`) and segmentation masks (`*_mask`). Meanwhile, only objects that simultaneously appear in both ego and exo views are retained.
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
```bash
|
| 320 |
-
cd data
|
| 321 |
-
python gen_scenes.py
|
| 322 |
-
|
| 323 |
-
# Or, downloading from huggingface
|
| 324 |
-
huggingface-cli download zbbhhh/VGGT-S train_scenes.json --local-dir data
|
| 325 |
-
```
|
| 326 |
-
|
| 327 |
-
Outputs:
|
| 328 |
-
|
| 329 |
-
```text
|
| 330 |
-
train_scenes.json
|
| 331 |
-
val_scenes.json
|
| 332 |
-
```
|
| 333 |
-
|
| 334 |
-
---
|
| 335 |
-
|
| 336 |
-
#### Generate Single-Object JSON
|
| 337 |
-
This step converts `train_scenes.json` and `val_scenes.json` into a sample-based format, where each individual object instance is treated as a training sample for convenient dataloader indexing and loading.
|
| 338 |
-
|
| 339 |
-
Each sample follows the format:
|
| 340 |
-
|
| 341 |
-
```text
|
| 342 |
-
scene_id//ego_cam//exo_cam//object//frame_id
|
| 343 |
-
```
|
| 344 |
-
|
| 345 |
-
For example:
|
| 346 |
-
|
| 347 |
-
```text
|
| 348 |
-
c9e0bbae-4092-4ab1-95cd-16b905709a0e//aria01_214-1//gp01//white spatula_0//002160
|
| 349 |
-
```
|
| 350 |
-
|
| 351 |
-
which represents:
|
| 352 |
-
|
| 353 |
-
* `scene_id`: `c9e0bbae-4092-4ab1-95cd-16b905709a0e`
|
| 354 |
-
* `ego_cam`: `aria01_214-1`
|
| 355 |
-
* `exo_cam`: `gp01`
|
| 356 |
-
* `object`: `white spatula_0`
|
| 357 |
-
* `frame_id`: `002160`
|
| 358 |
-
|
| 359 |
-
```bash
|
| 360 |
-
python gen_one_object.py
|
| 361 |
-
|
| 362 |
-
# Or, downloading from huggingface
|
| 363 |
-
huggingface-cli download zbbhhh/VGGT-S train_obj.json --local-dir data
|
| 364 |
-
```
|
| 365 |
-
|
| 366 |
-
Outputs:
|
| 367 |
-
|
| 368 |
-
```text
|
| 369 |
-
train_obj.json
|
| 370 |
-
val_obj.json
|
| 371 |
-
```
|
| 372 |
-
|
| 373 |
-
---
|
| 374 |
-
|
| 375 |
-
#### Generate VGGT Projected Points
|
| 376 |
-
This step precomputes the VGGT projected points as the first-stage mapping points and saves them offline. By caching these mappings in advance, the training and inference stages can directly perform the second-stage mapping without rerunning the initial VGGT projection process, significantly reducing computation time.
|
| 377 |
-
|
| 378 |
-
Optionally, the first-stage mapping can also be performed online if needed.
|
| 379 |
-
|
| 380 |
-
##### Ego → Exo
|
| 381 |
-
|
| 382 |
-
```bash
|
| 383 |
-
python extract_point_g2x.py
|
| 384 |
-
```
|
| 385 |
-
|
| 386 |
-
Outputs:
|
| 387 |
-
|
| 388 |
-
```text
|
| 389 |
-
train_obj_wp_g2x.json
|
| 390 |
-
val_obj_wp_g2x.json
|
| 391 |
-
```
|
| 392 |
-
|
| 393 |
-
##### Exo → Ego
|
| 394 |
-
|
| 395 |
-
```bash
|
| 396 |
-
python extract_point_x2g.py
|
| 397 |
-
```
|
| 398 |
-
|
| 399 |
-
Outputs:
|
| 400 |
-
|
| 401 |
-
```text
|
| 402 |
-
train_obj_wp_x2g.json
|
| 403 |
-
val_obj_wp_x2g.json
|
| 404 |
-
```
|
| 405 |
-
|
| 406 |
-
---
|
| 407 |
-
|
| 408 |
-
#### Merge Point Annotations
|
| 409 |
-
This step merges the projected points generated in the previous step and produces the final data annotation JSON file used for training and inference.
|
| 410 |
-
|
| 411 |
-
```bash
|
| 412 |
-
python merge_point.py
|
| 413 |
-
|
| 414 |
-
# Or, downloading from huggingface
|
| 415 |
-
huggingface-cli download zbbhhh/VGGT-S train_obj_wp.json --local-dir data
|
| 416 |
-
```
|
| 417 |
-
|
| 418 |
-
Final outputs:
|
| 419 |
-
|
| 420 |
-
```text
|
| 421 |
-
train_obj_wp.json
|
| 422 |
-
val_obj_wp.json
|
| 423 |
-
```
|
| 424 |
|
| 425 |
---
|
| 426 |
|
|
@@ -443,10 +157,8 @@ python -m torch.distributed.run \
|
|
| 443 |
--config hybrid.yaml
|
| 444 |
```
|
| 445 |
|
| 446 |
-
> Training and validation only require modifying the parameters in `hybrid.yaml`, where all configuration parameters are carefully explained.
|
| 447 |
---
|
| 448 |
|
| 449 |
-
|
| 450 |
## 📝 Citation
|
| 451 |
|
| 452 |
If you find this work useful, please consider citing our paper:
|
|
@@ -466,11 +178,4 @@ This project is licensed under the Apache-2.0 License. See [LICENSE](LICENSE.txt
|
|
| 466 |
|
| 467 |
## 🙏 Acknowledgement
|
| 468 |
|
| 469 |
-
This project is built upon several excellent open-source projects:
|
| 470 |
-
|
| 471 |
-
* [VGGT](https://github.com/facebookresearch/vggt)
|
| 472 |
-
* [EgoExo4d](https://github.com/EGO4D/ego-exo4d-relation)
|
| 473 |
-
* [SAM2](https://github.com/facebookresearch/sam2)
|
| 474 |
-
|
| 475 |
-
We thank the authors for releasing their code and models to the community.
|
| 476 |
-
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
pipeline_tag: image-segmentation
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
<div align="center">
|
| 7 |
|
| 8 |
<h1>VGGT-Segmentor: Geometry-Enhanced Cross-View Segmentation</h1>
|
|
|
|
| 52 |
|
| 53 |
</div>
|
| 54 |
|
| 55 |
+
This repository contains the official weights for the paper [VGGT-Segmentor: Geometry-Enhanced Cross-View Segmentation](https://arxiv.org/abs/2604.13596).
|
| 56 |
|
| 57 |
## 📢 News
|
| 58 |
|
|
|
|
| 128 |
|
| 129 |
### Modify VGGT Track Head
|
| 130 |
|
| 131 |
+
To extract VGGT encoder feature maps for downstream correspondence learning, please modify the `forward` function in `third_party/vggt_main/vggt/heads/track_head.py`. Replace the original `forward` function with the implementation provided in the [official GitHub repository](https://github.com/buaa-colalab/VGGT-S).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
---
|
| 134 |
|
| 135 |
### Dataset Preparation
|
| 136 |
|
| 137 |
+
Please follow the official [SegSwap Ego-Exo4D correspondence pipeline](https://github.com/EGO4D/ego-exo4d-relation/tree/main/correspondence/SegSwap) to download and preprocess the Ego-Exo4D dataset.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
---
|
| 140 |
|
|
|
|
| 157 |
--config hybrid.yaml
|
| 158 |
```
|
| 159 |
|
|
|
|
| 160 |
---
|
| 161 |
|
|
|
|
| 162 |
## 📝 Citation
|
| 163 |
|
| 164 |
If you find this work useful, please consider citing our paper:
|
|
|
|
| 178 |
|
| 179 |
## 🙏 Acknowledgement
|
| 180 |
|
| 181 |
+
This project is built upon several excellent open-source projects: [VGGT](https://github.com/facebookresearch/vggt), [EgoExo4d](https://github.com/EGO4D/ego-exo4d-relation), and [SAM2](https://github.com/facebookresearch/sam2).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|