attr-eomt 2.1.0__tar.gz → 3.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/.gitignore +5 -0
- attr_eomt-3.1.0/CHANGELOG.md +100 -0
- attr_eomt-3.1.0/PKG-INFO +434 -0
- attr_eomt-3.1.0/README.md +394 -0
- attr_eomt-3.1.0/eomt/__init__.py +50 -0
- attr_eomt-3.1.0/eomt/_log.py +33 -0
- attr_eomt-3.1.0/eomt/api.py +371 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/eomt/aux_cls.py +91 -87
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/eomt/box_loss.py +17 -42
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/eomt/config.py +14 -8
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/eomt/data/__init__.py +1 -5
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/eomt/data/coco.py +10 -5
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/eomt/data/config.py +16 -16
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/eomt/data/download.py +3 -1
- attr_eomt-3.1.0/eomt/data/subjects.py +457 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/eomt/data/transforms.py +8 -1
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/eomt/device.py +5 -3
- attr_eomt-3.1.0/eomt/engine/__init__.py +14 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/eomt/engine/distributed.py +19 -0
- attr_eomt-3.1.0/eomt/engine/match.py +252 -0
- attr_eomt-3.1.0/eomt/engine/predict.py +549 -0
- attr_eomt-3.1.0/eomt/engine/train.py +1266 -0
- attr_eomt-3.1.0/eomt/engine/validate.py +1059 -0
- attr_eomt-3.1.0/eomt/lora.py +84 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/eomt/loss.py +37 -105
- attr_eomt-3.1.0/eomt/matcher.py +216 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/eomt/model.py +225 -336
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/eomt/plotting.py +6 -3
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/eomt/postprocess.py +27 -58
- attr_eomt-3.1.0/eomt/progress.py +72 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/eomt/reid.py +62 -10
- attr_eomt-3.1.0/eomt/serialization.py +498 -0
- {attr_eomt-2.1.0/eomt/engine → attr_eomt-3.1.0/examples}/track.py +15 -3
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/pyproject.toml +1 -1
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/sample_data/run.yaml +29 -17
- attr_eomt-3.1.0/scripts/export.py +30 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/scripts/info.py +1 -1
- attr_eomt-3.1.0/scripts/match.py +47 -0
- attr_eomt-3.1.0/scripts/predict.py +41 -0
- attr_eomt-3.1.0/scripts/train.py +79 -0
- attr_eomt-3.1.0/scripts/val.py +65 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/site/index.html +22 -36
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/tests/test_api.py +46 -14
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/tests/test_architecture.py +82 -153
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/tests/test_augment.py +29 -24
- attr_eomt-3.1.0/tests/test_multiview.py +529 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/tests/test_parity.py +11 -6
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/tests/test_recipe.py +20 -25
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/tests/test_regression_attr.py +20 -5
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/tests/test_reid.py +17 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/tests/test_run_config.py +15 -8
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/tests/test_smoke.py +37 -7
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/tests/test_sweep.py +2 -1
- attr_eomt-2.1.0/PKG-INFO +0 -825
- attr_eomt-2.1.0/README.md +0 -785
- attr_eomt-2.1.0/configs/xview.yaml +0 -26
- attr_eomt-2.1.0/docs/examples/billie_eilish.jpg +0 -0
- attr_eomt-2.1.0/docs/examples/rosalia.jpg +0 -0
- attr_eomt-2.1.0/docs/examples/taylor_swift.jpg +0 -0
- attr_eomt-2.1.0/eomt/__init__.py +0 -63
- attr_eomt-2.1.0/eomt/api.py +0 -553
- attr_eomt-2.1.0/eomt/compress.py +0 -94
- attr_eomt-2.1.0/eomt/data/sets.py +0 -352
- attr_eomt-2.1.0/eomt/data/subjects.py +0 -278
- attr_eomt-2.1.0/eomt/engine/__init__.py +0 -9
- attr_eomt-2.1.0/eomt/engine/match.py +0 -401
- attr_eomt-2.1.0/eomt/engine/predict.py +0 -411
- attr_eomt-2.1.0/eomt/engine/train.py +0 -1773
- attr_eomt-2.1.0/eomt/engine/validate.py +0 -766
- attr_eomt-2.1.0/eomt/serialization.py +0 -508
- attr_eomt-2.1.0/scripts/match.py +0 -83
- attr_eomt-2.1.0/scripts/predict.py +0 -45
- attr_eomt-2.1.0/scripts/track.py +0 -50
- attr_eomt-2.1.0/scripts/train.py +0 -149
- attr_eomt-2.1.0/scripts/train_detect_coco.sh +0 -43
- attr_eomt-2.1.0/scripts/train_multiview.py +0 -47
- attr_eomt-2.1.0/scripts/val.py +0 -88
- attr_eomt-2.1.0/tests/test_compress.py +0 -61
- attr_eomt-2.1.0/tests/test_hires.py +0 -70
- attr_eomt-2.1.0/tests/test_subjects.py +0 -242
- attr_eomt-2.1.0/tests/test_xview.py +0 -415
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/.github/workflows/pages.yml +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/.github/workflows/prerelease.yml +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/.github/workflows/publish.yml +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/.github/workflows/release.yml +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/.github/workflows/tests.yml +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/LICENSE +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/configs/coco.yaml +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/docs/assets/00-hero-banner.png +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/docs/assets/00-hero-banner.svg +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/docs/examples/sample.jpg +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/eomt/ema.py +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/eomt/preprocess.py +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/eomt/tta.py +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/eomt/visualize.py +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/sample_data/README.md +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/sample_data/annotations/instances_train.json +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/sample_data/annotations/instances_val.json +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/sample_data/data.yaml +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/sample_data/images/train/.gitkeep +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/sample_data/images/val/.gitkeep +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/scripts/push_to_hub.py +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/tests/test_ddp.py +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/tests/test_tta.py +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/tools/attr_tagger/README.md +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/tools/attr_tagger/tag.py +0 -0
- {attr_eomt-2.1.0 → attr_eomt-3.1.0}/uv.lock +0 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 3.1.0 (unreleased)
|
|
4
|
+
|
|
5
|
+
The multi-view post-training, rebuilt from what the 3.0 runs showed: the cross-view attention's null token never
|
|
6
|
+
learned (its logit stayed at its starting value), the matching head linked hardly better than plain re-identification
|
|
7
|
+
(link F1 0.68 vs 0.66), and the photos' own features never saw the other photos. **Multi-view checkpoints of 3.0 and
|
|
8
|
+
before are refused** (their single-photo starting checkpoints load as before, with identical predictions).
|
|
9
|
+
|
|
10
|
+
- **Cross-view attention, gated.** Each row's update is gated per head by `tanh` of a learned function of the row,
|
|
11
|
+
starting at 0 (the sublayer starts as the identity), in place of the null token and the LayerScale. The patch tokens,
|
|
12
|
+
pooled 2x2, attend to the other photos too and their update is spread back over the patches, so the mask features see
|
|
13
|
+
the other photos (`xview: {patches, pool}`; ~+3 % per step). One attention call per set. The output projection has no
|
|
14
|
+
bias, so a closed gate adds nothing.
|
|
15
|
+
- **Attention supervision** (`multiview.attn_w`): a loss pointing each linked query's cross-view attention at the same
|
|
16
|
+
instance in the other photos (its mask and its query there).
|
|
17
|
+
- **The set matcher** (`eomt.matcher.SetMatcher`, replaces the matching head, `match_dim`, `match_residual` and the
|
|
18
|
+
sigmoid matching loss): the detected instances of the photos, by their query embedding and mask box, attend to each
|
|
19
|
+
other within and across photos; every two instances of two photos get a probability of being the same (a dual softmax
|
|
20
|
+
with a "no partner in that photo" bin), trained on the `instance_id` links (`multiview.match_w`). Inference links with
|
|
21
|
+
it (the photos predicted together as one set, any other two as a pair) at its calibrated probability threshold.
|
|
22
|
+
- **LoRA** (`multiview.lora: {rank, blocks, alpha}`, `eomt.lora`): the attention of the frozen ViT blocks below the query
|
|
23
|
+
blocks adapts; the trainer's `best.pt` holds the merged weights, and any checkpoint with factors is merged on loading.
|
|
24
|
+
Trainable group `lora`; the `match_head` group is now `matcher`.
|
|
25
|
+
- **Validation**: `sets/{match,reid}_oracle/*`, the links between the annotated instances themselves (linking with
|
|
26
|
+
perfect detection); the blocks below the queries run once per set for the photos alone and together;
|
|
27
|
+
`val.final_epochs` validates every epoch at the end of a run validated every `interval` epochs.
|
|
28
|
+
- **Training**: DDP no longer searches for unused parameters (every trainable parameter joins each step's graph) and
|
|
29
|
+
keeps the gradients in its buckets.
|
|
30
|
+
- `EoMTModel.forward(trunk=..., keep_xview_attn=...)` and `EoMTEncoder.encode_trunk()`.
|
|
31
|
+
- **Groups of a subject's photos** (`eomt.engine.predict`): a photo may be in several groups (predicted in the first,
|
|
32
|
+
context in the others, `group_owners`); `fill=True` (`subject_groups`, `predict_subject`, `predict(subject=True)`,
|
|
33
|
+
`match`, `scripts/match.py --fill`) tops the last default group up with the photos before it, so 5 photos at 4 a
|
|
34
|
+
time are two groups of 4 instead of 4 + 1; `similar_groups(features, max_views)` groups photos by
|
|
35
|
+
`photo_similarity`: the cosine of one or several descriptions of each photo (e.g. a first model's class areas and the
|
|
36
|
+
photo's appearance), averaged with `weights`, optionally `center`ed, filled the same way.
|
|
37
|
+
- **`photo_embed`**: every forward returns each photo's mean final patch token `(B, hidden)` over the photo (the
|
|
38
|
+
letterbox padding left out); `predict_set` results carry it, and `predict_batch(photo_embed=True)`.
|
|
39
|
+
- `predict_batch` / `predict_set` / `predict_subject` take RGB arrays as well as PIL images, already preprocessed inputs
|
|
40
|
+
(`prepared`: numpy or tensors, from `preprocess_numpy` or `preprocess_torch`) and the size each result is returned at
|
|
41
|
+
(`sizes`).
|
|
42
|
+
|
|
43
|
+
## 3.0.0 (2026-11-19)
|
|
44
|
+
|
|
45
|
+
A cleanup for a public release: one way to do each thing, one config per concern, and the options no trained model
|
|
46
|
+
uses removed. **Checkpoints of 2.x load and predict exactly as before** (they are upgraded on load); run configs and
|
|
47
|
+
code written for 2.x need the changes below.
|
|
48
|
+
|
|
49
|
+
### Training: settings by concern
|
|
50
|
+
|
|
51
|
+
`train()` keeps the keywords of the run (data, `size`, `family`, `epochs`, `batch`, `nominal_batch`, `imgsz`, `device`,
|
|
52
|
+
`workers`, `seed`, `project` / `name`, `resume` / `init_weights`, `keep_empty`, `stop_after_epochs`, `logger`) and takes
|
|
53
|
+
the rest by section, each a dataclass or a mapping (and a section of the run config YAML):
|
|
54
|
+
|
|
55
|
+
| 2.x keyword | 3.0 |
|
|
56
|
+
|---|---|
|
|
57
|
+
| `lr0`, `weight_decay`, `llrd`, `backbone_lr_mult`, `poly_power`, `warmup_steps`, `clip_norm`, `ema`, `ema_decay`, `ema_tau` | `optim: {...}` |
|
|
58
|
+
| `mask_anneal`, `mask_anneal_start` / `_end`, `--mask-free` | `optim.mask_anneal` (true: the reference windows; false: mask-free) |
|
|
59
|
+
| `fpn_scales`, `num_upscale_blocks`, loss weights, `iou_aware_cls`, `quality_weight`, `aux_head_*` | `model: {...}` (IoU-aware targets and the quality head now on by default) |
|
|
60
|
+
| `aux_w`, `aux_w_per_head`, `aux_class_weights`, `aux_iou_gate`, `aux_class_gate` | `aux: {w, per_head, class_weights, iou_gate, class_gate}` |
|
|
61
|
+
| `val_interval`, `val_imgsz`, `conf_thres`, `max_det`, `val_group_by`, `best_key` | `val: {interval, imgsz, conf_thres, max_det, group_by, best_key}` |
|
|
62
|
+
| `flip_prob`, `min_scale`, `max_scale`, `train_aug` (YAML) | `aug: {...}` |
|
|
63
|
+
| `accum`, `amp_dtype`, `tf32`, `prefetch`, `letterbox`, `ddp` | removed (from `nominal_batch`; bf16 where supported; always on) |
|
|
64
|
+
|
|
65
|
+
Removed options: `box_head`, `deep_supervision=False`, `hires_*`, `aux_balance`, `aux_w_warmup`, the gradient probe.
|
|
66
|
+
|
|
67
|
+
### Several photos of one subject
|
|
68
|
+
|
|
69
|
+
`multiview` is a post-training on **real** sets (images with `subject_id`, annotations with `instance_id`):
|
|
70
|
+
`{xview, matching, match_w, gate, trainable, sets, val_sets}`. `xview` and `matching` are each optional: the matching
|
|
71
|
+
head trains without cross-view attention too. `trainable` takes the presets `new` and `query_blocks`, or a dict.
|
|
72
|
+
New: `sets.groups` (an image field) trains on the fixed groups of photos an application predicts together, each once
|
|
73
|
+
per epoch, with a `sets.p_random` share of random sets; validation scores those groups.
|
|
74
|
+
|
|
75
|
+
Removed: synthetic sets (`sets.cases`, distractors, mirrored copies, `p_subject`, `focus`), the `real` sub-section (the
|
|
76
|
+
run's own data is the sets' data), the refiner, view types, `xview.keys`, `xview_scale`, the InfoNCE and dustbin
|
|
77
|
+
matching losses (sigmoid only), `match_dim` / `match_residual` / `match_tau` (a residual head at the hidden size),
|
|
78
|
+
`match_neg_conf` (the inference threshold), `match_hard_*`, `linked_w`, `consistency_*`, `harm_w`, `val_synthetic`,
|
|
79
|
+
per-part `val_interval`. The metrics are `val/sets/...` (was `val/real/...`); the link sources are `match` and `reid`.
|
|
80
|
+
|
|
81
|
+
### Inference and API
|
|
82
|
+
|
|
83
|
+
- `EoMT.match()` is the one linking entry point, for any number of photos (`infer_match` is gone);
|
|
84
|
+
`predict_subject(identities=True)` links in code. The grouping modes `partition` / `anchor` are gone (`groups=`).
|
|
85
|
+
- `predict()` batches (`batch=8`), decodes in the background, streams (`stream=True`) and runs in bf16 by default.
|
|
86
|
+
- `val()` defaults to the checkpoint's own validation data.
|
|
87
|
+
- Tracking moved to `examples/track.py`; int8 compression and the auxiliary box head were removed.
|
|
88
|
+
- Checkpoints load with `weights_only=True` and strictly; `eomt.migrate_checkpoint` upgrades 2.x ones.
|
|
89
|
+
- Messages go through the standard `eomt` logger (stdout, INFO) instead of `print`:
|
|
90
|
+
`logging.getLogger("eomt").setLevel(logging.WARNING)` silences them.
|
|
91
|
+
|
|
92
|
+
### Fixes
|
|
93
|
+
|
|
94
|
+
- Unaugmented validation sets are placed as inference letterboxes the photos (they were placed at random): the stored
|
|
95
|
+
link threshold is calibrated on the inputs inference sees, and fixed sets read back reproduce the trainer's numbers.
|
|
96
|
+
- Validation runs in bf16 like training and inference (it ran in fp16), in PyTorch's default numerics.
|
|
97
|
+
- Thin or tiny instances are no longer dropped from the set validation's ground truth.
|
|
98
|
+
- `last.pt` is written before validating; a resumed run reads the best so far from `best.pt` too.
|
|
99
|
+
- No GPU synchronisation per forward pass (masked-attention probabilities) or per training step; the final matching is
|
|
100
|
+
solved once per step; `predict()` keeps no full-resolution float copies of the masks.
|
attr_eomt-3.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: attr-eomt
|
|
3
|
+
Version: 3.1.0
|
|
4
|
+
Summary: Standalone EoMT (Encoder-only Mask Transformer) for instance segmentation, with DINOv2 init, COCO training/validation and inference.
|
|
5
|
+
Project-URL: Homepage, https://github.com/imagra93/attr-eomt
|
|
6
|
+
Project-URL: Documentation, https://imagra93.github.io/attr-eomt
|
|
7
|
+
Project-URL: Repository, https://github.com/imagra93/attr-eomt
|
|
8
|
+
Project-URL: Issues, https://github.com/imagra93/attr-eomt/issues
|
|
9
|
+
Author: attr-eomt contributors
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: coco,dinov2,eomt,instance-segmentation,transformers
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Requires-Dist: huggingface-hub>=0.23.0
|
|
18
|
+
Requires-Dist: matplotlib>=3.5.0
|
|
19
|
+
Requires-Dist: numpy>=1.19.0
|
|
20
|
+
Requires-Dist: opencv-python>=4.8.0
|
|
21
|
+
Requires-Dist: pillow>=9.1.0
|
|
22
|
+
Requires-Dist: pycocotools>=2.0.0
|
|
23
|
+
Requires-Dist: pyyaml>=6.0
|
|
24
|
+
Requires-Dist: requests>=2.25.0
|
|
25
|
+
Requires-Dist: scipy>=1.7.0
|
|
26
|
+
Requires-Dist: supervision<0.30,>=0.22.0
|
|
27
|
+
Requires-Dist: torch>=2.4.0
|
|
28
|
+
Requires-Dist: torchao>=0.7.0
|
|
29
|
+
Requires-Dist: torchvision>=0.19.0
|
|
30
|
+
Requires-Dist: tqdm>=4.65.0
|
|
31
|
+
Requires-Dist: transformers>=5.1.0
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: build>=1.0; extra == 'dev'
|
|
34
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
35
|
+
Requires-Dist: twine>=5.0; extra == 'dev'
|
|
36
|
+
Provides-Extra: logging
|
|
37
|
+
Requires-Dist: tensorboard>=2.10; extra == 'logging'
|
|
38
|
+
Requires-Dist: wandb>=0.15; extra == 'logging'
|
|
39
|
+
Description-Content-Type: text/markdown
|
|
40
|
+
|
|
41
|
+
<div align="center">
|
|
42
|
+
|
|
43
|
+
<img src="https://raw.githubusercontent.com/imagra93/attr-eomt/main/docs/assets/00-hero-banner.png" alt="attr-eomt — one DINOv2 encoder predicts instances plus independent per-instance attribute heads in a single pass, contrasted with flat combinatorial labels and a detector-plus-second-model pipeline" width="100%">
|
|
44
|
+
|
|
45
|
+
<p>
|
|
46
|
+
<a href="https://pypi.org/project/attr-eomt/"><img src="https://img.shields.io/pypi/v/attr-eomt.svg?color=4ec9b0" alt="PyPI version"></a>
|
|
47
|
+
<a href="https://pypi.org/project/attr-eomt/"><img src="https://img.shields.io/pypi/pyversions/attr-eomt.svg" alt="Python versions"></a>
|
|
48
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-blue.svg" alt="License"></a>
|
|
49
|
+
<a href="https://imagra93.github.io/attr-eomt"><img src="https://img.shields.io/badge/docs-annotated%20explainer-e2b341.svg" alt="Annotated explainer"></a>
|
|
50
|
+
</p>
|
|
51
|
+
|
|
52
|
+
**One query embedding, many independent labels.**
|
|
53
|
+
|
|
54
|
+
📖 **[Read the annotated explainer →](https://imagra93.github.io/attr-eomt)**
|
|
55
|
+
|
|
56
|
+
</div>
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## What it is
|
|
61
|
+
|
|
62
|
+
**attr-eomt** is a standalone **EoMT** (Encoder-only Mask Transformer, CVPR 2025) for instance segmentation and
|
|
63
|
+
object detection on a DINOv2 backbone, built around three things:
|
|
64
|
+
|
|
65
|
+
1. **Instances with attributes.** Every detected instance gets its class and any number of **independent attributes** —
|
|
66
|
+
categorical (classify) or real-valued (regress) — read off the same per-query embedding the detector computes. No
|
|
67
|
+
second model, no crops, no combinatorial label space.
|
|
68
|
+
2. **Several photos of one subject, predicted together** (if you have them labelled): cross-view attention lets each
|
|
69
|
+
photo's queries and features take what the other photos show, so an instance that is tiny or ambiguous in one photo
|
|
70
|
+
is found and classified with the help of another.
|
|
71
|
+
3. **Instance matching across photos** (if you have it labelled): a set matcher decides, in the context of all the
|
|
72
|
+
instances of the photos, which ones are the same; `match()` turns a folder of photos into one identity per
|
|
73
|
+
instance.
|
|
74
|
+
|
|
75
|
+
It is a clean-room, Apache-2.0 reimplementation: the weights you train are yours to release.
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from eomt import EoMT
|
|
79
|
+
|
|
80
|
+
model = EoMT("l") # a new large model (DINOv2 backbone)
|
|
81
|
+
model.train(data="run.yaml") # the run config: data, attribute heads, settings
|
|
82
|
+
model = EoMT("runs/train/my-run") # a trained run: everything is read from its checkpoint
|
|
83
|
+
model.val() # on its own validation data
|
|
84
|
+
results = model.predict("images/", plot=True) # masks, boxes, classes and attributes per instance
|
|
85
|
+
identities = model.match("photos/subject_42/") # one identity per physical instance across the photos
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Install
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
pip install attr-eomt # from PyPI
|
|
94
|
+
pip install -e ".[dev]" # from source (editable; [dev] adds pytest)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Python 3.10+, PyTorch 2.4+. Training and inference run in bf16 on GPUs that support it.
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Architecture
|
|
102
|
+
|
|
103
|
+
EoMT is a **DINOv2-with-registers ViT** whose last four transformer blocks also process a fixed set of **learnable
|
|
104
|
+
queries** (the Mask2Former idea): each query latches onto one object instance, and after the encoder every query emits
|
|
105
|
+
one vector, the **per-query embedding** `[B, Q, hidden]`. A class head and a mask head (or a box head for the
|
|
106
|
+
`detect` family) turn it into predictions. It is **NMS-free**, so two overlapping objects stay two queries — which is
|
|
107
|
+
what keeps attributes attached to the right instance.
|
|
108
|
+
|
|
109
|
+
The attribute heads tap the **same embedding**: each is a small MLP, trained on the queries the detector's Hungarian
|
|
110
|
+
matcher assigned to an instance. The optional set matcher reads it too, and the optional cross-view sublayers let the
|
|
111
|
+
queries and features of several photos of one subject attend to each other's tokens.
|
|
112
|
+
|
|
113
|
+
| size | backbone | hidden | layers | queries | params |
|
|
114
|
+
|------|-----------------|--------|--------|---------|--------|
|
|
115
|
+
| `s` | DINOv2-small | 384 | 12 | 100 | 24 M |
|
|
116
|
+
| `b` | DINOv2-base | 768 | 12 | 200 | 94 M |
|
|
117
|
+
| `l` | DINOv2-large | 1024 | 24 | 200 | 317 M |
|
|
118
|
+
|
|
119
|
+
The default input is 644 px (patch-14 aligned, so DINOv2's weights load 1:1). Two families: `instance` (masks, the
|
|
120
|
+
default) and `detect` (boxes only, a DETR-style box head).
|
|
121
|
+
|
|
122
|
+
What differs from the reference EoMT, all on by default and measured on real data:
|
|
123
|
+
|
|
124
|
+
- **Small objects stay visible.** Masked attention max-pools the mask logits onto the patch grid (a query whose mask
|
|
125
|
+
touches no patch attends to all of them, as in Mask2Former), matching scores every query on every cell of the mask
|
|
126
|
+
grid, and dice is computed on every GT pixel — so instances of a few pixels are matched and supervised.
|
|
127
|
+
- **A multi-scale pyramid** (ViTDet-style FPN) that the queries cross-attend to.
|
|
128
|
+
- **Scores that rank masks by quality**: IoU-aware class targets and a mask-quality head (Mask Scoring R-CNN).
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
## Factorizing the label space
|
|
132
|
+
|
|
133
|
+
This is the contribution. Conventional detectors fold every distinction into one flat
|
|
134
|
+
label space: an object's `type × viewpoint × occlusion × …` becomes a Cartesian product of
|
|
135
|
+
leaf classes that explodes combinatorially, starves each leaf of examples, and multiplies
|
|
136
|
+
the Hungarian matcher's targets. **attr-eomt factorizes instead** — a small, general primary
|
|
137
|
+
head plus independent attribute heads that **add, not multiply**.
|
|
138
|
+
|
|
139
|
+
Because the heads are independent, the primary taxonomy stays compact and every class keeps
|
|
140
|
+
its full sample count; attributes ride along for near-zero compute; and the model composes
|
|
141
|
+
`attribute × class` combinations that **never appear in the training data** — combinations a
|
|
142
|
+
flat label space cannot even represent.
|
|
143
|
+
|
|
144
|
+
### Example: clothing with per-instance attributes
|
|
145
|
+
|
|
146
|
+
One model segments each garment (primary classes like `vest_dress` / `short_sleeve_top`
|
|
147
|
+
/ `long_sleeve_dress` / `skirt` / `trousers` …) and, for **every** detection, reads off
|
|
148
|
+
four **independent** attribute heads — `scale` (`small` / `modest` / `large`),
|
|
149
|
+
`occlusion` (`no` / `slight` / `medium`), `zoom_in` (`no` / `medium` / `large`) and
|
|
150
|
+
`viewpoint` (`frontal` / `side` / `back`). The renderer prints the primary class + score
|
|
151
|
+
on the first row and each attribute + its confidence on the rows beneath it.
|
|
152
|
+
|
|
153
|
+

|
|
154
|
+
|
|
155
|
+
The four attributes are *orthogonal* to the garment class — they vary independently —
|
|
156
|
+
which is exactly the case that's awkward to fold into the primary class space. The same
|
|
157
|
+
pattern fits any "class **plus** per-instance sub-labels" task: **retail shelves →
|
|
158
|
+
product + facing**, **documents → element + role**, **cells → type + health**.
|
|
159
|
+
|
|
160
|
+
> Trained on the public **[DeepFashion2](https://github.com/switchablenorms/DeepFashion2)**
|
|
161
|
+
> dataset (13 garment classes + 4 attribute heads) and rendered with the package's own
|
|
162
|
+
> renderer ([`eomt.visualize.draw_instances`](eomt/visualize.py)).
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## Data
|
|
167
|
+
|
|
168
|
+
A COCO instance-segmentation (or detection) JSON. Everything the model needs is read from it: the classes from
|
|
169
|
+
`categories`, the attribute heads from two additions.
|
|
170
|
+
|
|
171
|
+
**1. A top-level `attributes` list**, one entry per attribute, with its categories, or `"type": "regression"`:
|
|
172
|
+
|
|
173
|
+
```jsonc
|
|
174
|
+
"attributes": [
|
|
175
|
+
{"name": "scale", "categories": [{"id": 1, "name": "small"}, {"id": 2, "name": "modest"}, {"id": 3, "name": "large"}]},
|
|
176
|
+
{"name": "price", "type": "regression", "unit": "EUR"}
|
|
177
|
+
]
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
**2. A per-annotation `attributes` map**, `{attribute: value}`:
|
|
181
|
+
|
|
182
|
+
```jsonc
|
|
183
|
+
{"id": 1, "image_id": 42, "category_id": 1, "segmentation": [...], "bbox": [...], "attributes": {"scale": 3, "price": 812.5}}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Raw ids are remapped to `0..n-1` per attribute. A **missing or unknown value is ignored** by that attribute's loss, never
|
|
187
|
+
trained as class 0, so a partly tagged dataset is fine; a JSON without `attributes` is plain instance segmentation.
|
|
188
|
+
The attributes can also live beside a plain COCO file: an `attributes.yaml` schema in the dataset root plus
|
|
189
|
+
`attributes/<split>.json` values keyed by annotation id. [`sample_data/`](sample_data/) holds a tiny example.
|
|
190
|
+
|
|
191
|
+
**Photos of one subject** (for `multiview`) add to the same file:
|
|
192
|
+
|
|
193
|
+
| key | meaning |
|
|
194
|
+
|-----|---------|
|
|
195
|
+
| image `subject_id` | photos with the same id show the same subject; photos without one take no part in the sets |
|
|
196
|
+
| annotation `instance_id` | the same physical instance in every photo of the subject that shows it (a number or a string); the set matcher learns these links |
|
|
197
|
+
| image `supervision` | `full` (default): every instance is annotated. `positives`: only some are, so nothing unannotated is taught as background. `none`: the photo is only input for the others |
|
|
198
|
+
| annotation `iscrowd: 1` | a region left out of the loss: detections there are neither right nor wrong |
|
|
199
|
+
|
|
200
|
+
`eomt.data.subjects_from_file_names` sets `subject_id` from file names that start with the subject (`<subject>_...`).
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## The run config
|
|
205
|
+
|
|
206
|
+
**The dataset holds the data; one YAML holds the run.** Its sections are the settings of `train()`, each with the
|
|
207
|
+
reference recipe as its default, so a run config only says what differs. Start from the commented template
|
|
208
|
+
[`sample_data/run.yaml`](sample_data/run.yaml):
|
|
209
|
+
|
|
210
|
+
```yaml
|
|
211
|
+
path: datasets/garments # data: paths relative to this file
|
|
212
|
+
train_images: images/train
|
|
213
|
+
train_json: annotations/train.json
|
|
214
|
+
val_images: images/val
|
|
215
|
+
val_json: annotations/val.json
|
|
216
|
+
|
|
217
|
+
attributes: # which attributes get a head, and how each learns
|
|
218
|
+
scale:
|
|
219
|
+
side: {flip_aware: {left: right}} # swapped when the augmentation mirrors the photo
|
|
220
|
+
price: {log: true, range: [0, 20000], applies_to: [sofa]}
|
|
221
|
+
|
|
222
|
+
train: {epochs: 12, batch: 4, imgsz: 644}
|
|
223
|
+
aug: {min_scale: 0.4, max_scale: 1.6}
|
|
224
|
+
inference: {conf_thres: 0.3} # saved with the model: the defaults of predict() / match()
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
| section | what it holds (`eomt.engine.train`) |
|
|
228
|
+
|---------|--------------------------------------|
|
|
229
|
+
| `train` | the keywords of `train()`: `epochs`, `batch` (per GPU), `nominal_batch` (16: the rest is accumulated), `imgsz`, `workers`, `seed`, `init_weights`, `project` / `name`, `stop_after_epochs` |
|
|
230
|
+
| `model` | the architecture and loss weights of a new model (`ModelConfig`): `fpn_scales`, `num_upscale_blocks`, `iou_aware_cls`, `quality_weight`, the attribute heads' shape |
|
|
231
|
+
| `optim` | `OptimConfig`: `lr0`, `llrd`, `warmup_steps`, `poly_power`, `clip_norm`, `ema_decay`, `mask_anneal` |
|
|
232
|
+
| `aux` | how the attribute heads train (`AuxConfig`): `w`, `per_head`, `class_weights`, `iou_gate`, `class_gate` |
|
|
233
|
+
| `aug` | the augmentation (`AugConfig`) |
|
|
234
|
+
| `val` | `ValConfig`: `interval`, `imgsz`, `group_by` (metrics per value of an image field), `best_key` |
|
|
235
|
+
| `multiview` | a post-training on photos of one subject (`MultiviewConfig`, below) |
|
|
236
|
+
| `attributes`, `inference` | the heads and how each learns; the predict defaults saved in the checkpoint |
|
|
237
|
+
|
|
238
|
+
Arguments beat the file: a keyword of `EoMT.train()` replaces a `train` value, and a section given as a mapping is merged
|
|
239
|
+
over the YAML's key by key (`model.train(data="run.yaml", optim={"lr0": 5e-5})`). An unknown key stops the run before it
|
|
240
|
+
starts. The resolved run is written to `args.yaml` in the run folder and into every checkpoint.
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
python scripts/train.py --data run.yaml --size l --device 0,1 # the run as its YAML says, two GPUs
|
|
244
|
+
python scripts/train.py --data run.yaml --epochs 1 --set optim.lr0=5e-5 # any setting: --set SECTION.KEY=VALUE
|
|
245
|
+
python scripts/train.py --data run.yaml --weights best.pt --set optim.mask_anneal=false # warm start
|
|
246
|
+
python scripts/train.py --data run.yaml --resume runs/train/my-run # continue a run exactly
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## Attributes
|
|
252
|
+
|
|
253
|
+
- **Categorical** heads train with cross-entropy, **regression** heads with a Huber loss on the standardized value
|
|
254
|
+
(`log1p` first with `log: true`, for heavy-tailed positives); predictions come back in real units (`aux_values`),
|
|
255
|
+
clipped to `range`.
|
|
256
|
+
- **`applies_to`** (class names) scopes a head to some classes: it trains only on them and reports `ids = -1` ("not
|
|
257
|
+
applicable") for the others. Different attributes can attach to different classes in one model.
|
|
258
|
+
- **`flip_aware`** (`{left: right}`) swaps an attribute that encodes a side when the augmentation mirrors the photo,
|
|
259
|
+
and test-time augmentation swaps it back. Keep `vflip_prob` / `rot90_prob` off for such an attribute.
|
|
260
|
+
- **`crop`** (regression): `scale` makes the value follow the share of the instance the augmentation keeps in view (an
|
|
261
|
+
extensive quantity such as a surface), `ignore` drops it below `min_visible` (a property of the whole instance).
|
|
262
|
+
- **`bins`** (regression) reports the errors per GT-value bucket too.
|
|
263
|
+
|
|
264
|
+
Validation reports `aux_acc/<head>` (accuracy) and `aux_mae/<head>` (mean absolute error in real units; a `log` head
|
|
265
|
+
also `aux_logmae` and `aux_ratio`, the median of prediction / GT).
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## Several photos of one subject
|
|
270
|
+
|
|
271
|
+
A **multi-view post-training** adds to a trained single-photo model what you have labelled:
|
|
272
|
+
|
|
273
|
+
- **`xview`** — cross-view attention after each query block: the queries of each photo of a set, and its patch tokens
|
|
274
|
+
pooled 2x2, attend to the tokens of the other photos. Each row's update is gated per head by `tanh` of a learned
|
|
275
|
+
function of the row, starting at 0: the sublayer starts as the identity, a photo alone is predicted exactly as
|
|
276
|
+
before, and each query learns when to use the other photos. `attn_w > 0` adds a loss pointing a query's cross-view
|
|
277
|
+
attention at the same instance in the other photos (its mask and its query there).
|
|
278
|
+
- **`matching`** — a set matcher (SuperGlue / LightGlue style): the detected instances of the photos (their per-query
|
|
279
|
+
embedding and mask box) attend to each other within a photo and across photos, and every two instances of two
|
|
280
|
+
photos get a probability of being the same (a dual softmax, with a "no partner in that photo" bin), trained on the
|
|
281
|
+
`instance_id` links. One threshold on that probability links them. It trains with or without `xview`.
|
|
282
|
+
- **`lora`** — `{rank, blocks}`: LoRA on the attention of the frozen ViT blocks below the query blocks, so the features
|
|
283
|
+
can adapt to the sets; merged into the exported weights (no cost at inference).
|
|
284
|
+
|
|
285
|
+
```yaml
|
|
286
|
+
train: {init_weights: runs/train/my-run/weights/best.pt, epochs: 4, batch: 1} # batch counts sets of photos
|
|
287
|
+
val: {interval: 1}
|
|
288
|
+
multiview:
|
|
289
|
+
xview: true
|
|
290
|
+
matching: true
|
|
291
|
+
gate: [class] # links only between instances of the same class (and listed attributes)
|
|
292
|
+
trainable: new # only the added modules; "query_blocks" also trains the query blocks, slower
|
|
293
|
+
sets: {max_views: 4, sizes: {2: 0.2, 3: 0.2, 4: 0.6}, p_single: 0.3, p_shared: 0.5, p_hard: 0.25}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Every photo of a subject is the anchor of one set per epoch, with companions from the same subject (`p_shared` of the
|
|
297
|
+
sets first take those that show one of its linked instances). The horizontal flip is drawn once per set, so left and
|
|
298
|
+
right never mix within a subject. `p_hard` makes the anchor hard to read alone (shrunk, degraded, a close-up or
|
|
299
|
+
occluded) while its companions stay as they are, so the evidence has to come from them. `trainable` also takes
|
|
300
|
+
`{group or parameter-name prefix: LR multiplier}` (groups `xview`, `matcher`, `lora`, `query_blocks`, `heads`; e.g.
|
|
301
|
+
`{xview: 1.0, aux_heads.price: 0.0}`).
|
|
302
|
+
|
|
303
|
+
When your application predicts fixed groups of photos (decided before the model sees them), train on those groups:
|
|
304
|
+
`sets: {groups: <image field>, p_random: 0.25}` makes the photos of a subject sharing that field's value one set (split
|
|
305
|
+
into sets of `max_views`), each once per epoch, plus a `p_random` share of sets drawn at random as above, as
|
|
306
|
+
augmentation. The model is told nothing about the photos of a set: which photos go together is the data's decision.
|
|
307
|
+
Validation then scores the groups.
|
|
308
|
+
|
|
309
|
+
**Validation** scores fixed sets of the validation photos of each subject, unaugmented and placed exactly as inference
|
|
310
|
+
places them: `sets/segm/mAP_{alone,set}` (each photo predicted alone and with its set; `_linked_` restricted to the
|
|
311
|
+
instances another photo shows, where the others can help), the attributes alone and with the set, and the links:
|
|
312
|
+
`sets/match/{f1,precision,recall,thres}` (what inference links with: the set matcher, else the embedding),
|
|
313
|
+
`sets/reid/*` (the baseline: re-identification of the photos predicted alone), `_gated` within the gate,
|
|
314
|
+
`*_oracle/*` (the same links between the annotated instances themselves: linking with perfect detection),
|
|
315
|
+
`match/f1_stored` at the threshold stored before the validation, and `*/cluster_f1` (B-cubed F1 of the identities over
|
|
316
|
+
each whole subject). The best threshold is stored in the checkpoint: inference links with it. `val.final_epochs`
|
|
317
|
+
validates every epoch at the end of a run validated every `interval` epochs.
|
|
318
|
+
|
|
319
|
+
```python
|
|
320
|
+
EoMT("runs/train/mv").val(multiview=True) # the run's own validation, standalone
|
|
321
|
+
EoMT("other.pt").val(multiview=True, run="runs/train/mv", # another model, scored as that run did,
|
|
322
|
+
sets_file="runs/train/mv/val_sets.json") # on the same fixed sets
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
**Inference.** `predict(source, subject=True)` predicts the photos of each subject together (`source` holds one
|
|
326
|
+
subject's photos, or a subfolder per subject), `max_views` at a time. `match(folder)` links the detections of every
|
|
327
|
+
photo of a subject — any number of photos — into identities, with the stored threshold and gate:
|
|
328
|
+
|
|
329
|
+
```python
|
|
330
|
+
out = EoMT("runs/train/mv").match("photos/subject_42/", groups=[[0, 3, 4], [1, 2]]) # groups: optional
|
|
331
|
+
out["images"][0]["identity_ids"] # an identity per detection of photo 0
|
|
332
|
+
out["identities"][0]["attributes"] # the identity's attributes, voted over its photos (regression: fused)
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
The set matcher matches the photos predicted together as one set, and any other two photos as a pair. A model
|
|
336
|
+
without one links by the per-query embedding (re-identification, nothing trained for it), at 0.7 within the same class
|
|
337
|
+
unless it was calibrated.
|
|
338
|
+
|
|
339
|
+
Groups may share photos: a photo in several groups is predicted in the first and shown to the others in the rest.
|
|
340
|
+
`fill=True` tops the default last group up with the photos before it (5 photos at 4 a time: two groups of 4, not
|
|
341
|
+
4 + 1), and `similar_groups` groups the photos by what they show, so that metadata saying where a photo was taken is
|
|
342
|
+
not needed. It compares one or several descriptions of each photo, averaged with weights: e.g. how much of each class
|
|
343
|
+
a first model finds in it, and its appearance, the mean final patch token over the photo (the letterbox padding left
|
|
344
|
+
out) that every forward returns (`photo_embed`). Two close-ups of one part stay together even when the first model
|
|
345
|
+
reads one of them on the wrong side:
|
|
346
|
+
|
|
347
|
+
```python
|
|
348
|
+
import torch
|
|
349
|
+
from eomt import EoMT
|
|
350
|
+
from eomt.config import INFERENCE_DEFAULTS
|
|
351
|
+
from eomt.engine import predict_batch, predict_subject, similar_groups
|
|
352
|
+
|
|
353
|
+
model = EoMT("runs/train/mv").model
|
|
354
|
+
kw = {k: model.inference.get(k, d) for k, d in INFERENCE_DEFAULTS.items()} # the checkpoint's thresholds, as
|
|
355
|
+
kw.update(device="cuda", imgsz=model.image_size) # EoMT.predict / match use them
|
|
356
|
+
looks = torch.stack([r["photo_embed"] for r in predict_batch(model, photos, photo_embed=True, **kw)])
|
|
357
|
+
# class_areas: (n_photos, n_classes), e.g. how much of each class a first model finds in each photo
|
|
358
|
+
groups = similar_groups([class_areas, looks], max_views=4, weights=[1, 1], center=[False, True]) # every group full
|
|
359
|
+
out = predict_subject(model, photos, groups=groups, identities=True, **kw)
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
`predict_set` / `predict_subject` / `predict_batch` also take photos already preprocessed (`prepared`: one
|
|
363
|
+
`(chw, meta)` per photo from `preprocess_numpy` or `preprocess_torch`, e.g. on the GPU) and return the masks at a
|
|
364
|
+
given size per photo (`sizes`). The model may be a wrapper of the network that passes `set_ids` on.
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
368
|
+
## Training recipe
|
|
369
|
+
|
|
370
|
+
`train()` follows the reference EoMT recipe, checked numerically against the official code: AdamW at `lr0=1e-4` with
|
|
371
|
+
layer-wise LR decay `0.8` (the top ViT block at the full LR: the last blocks process the queries), a two-stage warmup
|
|
372
|
+
(the head first, the ViT held at 0) and polynomial decay to 0, masked attention annealed block by block so the last
|
|
373
|
+
sixth of training is mask-free, and an EMA of the weights. `epochs=12` is the official COCO instance recipe.
|
|
374
|
+
|
|
375
|
+
Validation runs in the regime the model is trained in (masked attention at the epoch's annealing), so `best.pt` — the
|
|
376
|
+
EMA weights, mask-free — is only chosen once the annealing is over. `last.pt` (the trainer state) is written before
|
|
377
|
+
each validation, so a crash there costs only the validation. Every checkpoint records its epoch, metrics row and the
|
|
378
|
+
resolved run, with the warm-start weights and the data files and their SHA-256.
|
|
379
|
+
|
|
380
|
+
A **short fine-tune** wants its own recipe: a lower `optim.lr0`, a shorter `optim.warmup_steps`, a lower
|
|
381
|
+
`optim.ema_decay`, and `optim.mask_anneal: false` for a model deployed mask-free.
|
|
382
|
+
|
|
383
|
+
**Several GPUs**: `device="0,1"` trains with one process per GPU; `batch` is per GPU and `nominal_batch` stays the global
|
|
384
|
+
batch, so the optimizer steps are those of one GPU. Write the training call under `if __name__ == "__main__":` (the
|
|
385
|
+
processes are spawned).
|
|
386
|
+
|
|
387
|
+
---
|
|
388
|
+
|
|
389
|
+
## Inference
|
|
390
|
+
|
|
391
|
+
```python
|
|
392
|
+
m = EoMT("runs/train/my-run")
|
|
393
|
+
for r in m.predict("folder/", batch=16, stream=True): # a generator: a large folder is never held in memory
|
|
394
|
+
r["boxes"], r["scores"], r["classes"], r["masks"], r.get("aux"), r.get("aux_values")
|
|
395
|
+
m.predict("big_photo.jpg", tiles=True) # native-resolution tiles + the whole image, merged
|
|
396
|
+
m.predict("photo.jpg", augment={"flip": True}) # test-time augmentation (flip-aware heads swapped back)
|
|
397
|
+
m.save("best_bf16.pt", dtype="bf16") # half the file, the same scores
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
`conf_thres`, `max_det` and `mask_thresh` default to the checkpoint's `inference` settings. Masks come back at the
|
|
401
|
+
photo's resolution; the network runs in bf16 on a GPU (`amp=False`: fp32). What the library reports goes to the
|
|
402
|
+
standard `eomt` logger (stdout): `logging.getLogger("eomt").setLevel(logging.WARNING)` silences it.
|
|
403
|
+
|
|
404
|
+
## Checkpoints
|
|
405
|
+
|
|
406
|
+
A checkpoint is a self-describing `torch.save` dict: the weights plus everything needed to rebuild and run the model
|
|
407
|
+
(size, classes, attribute heads, input size and preprocessing, link calibration, inference settings, the run). It loads
|
|
408
|
+
with `weights_only=True`, so loading one never runs code. Checkpoints of earlier versions are upgraded on load
|
|
409
|
+
(`eomt.migrate_checkpoint`). `scripts/info.py <ckpt>` prints one.
|
|
410
|
+
|
|
411
|
+
---
|
|
412
|
+
|
|
413
|
+
## Command line
|
|
414
|
+
|
|
415
|
+
| script | does |
|
|
416
|
+
|--------|------|
|
|
417
|
+
| `scripts/train.py` | train from a run config (`--set SECTION.KEY=VALUE` for any setting) |
|
|
418
|
+
| `scripts/val.py` | validate (`--augment`, `--tiles`, `--flip`, `--multiview`, `--run`, `--sets-file`) |
|
|
419
|
+
| `scripts/predict.py` | predict and render images (`--subject`, `--tiles`, `--batch`) |
|
|
420
|
+
| `scripts/match.py` | link the instances of a subject's photos (`--each-subdir`) |
|
|
421
|
+
| `scripts/export.py` | a bf16 copy of a checkpoint |
|
|
422
|
+
| `scripts/info.py` | a checkpoint's metadata |
|
|
423
|
+
|
|
424
|
+
---
|
|
425
|
+
|
|
426
|
+
## Roadmap
|
|
427
|
+
|
|
428
|
+
- Pretrained COCO weights on the Hugging Face Hub (`EoMT.from_pretrained` is in place), a runnable sample dataset, and a
|
|
429
|
+
public multi-photo dataset for `multiview` and matching.
|
|
430
|
+
- ONNX / TensorRT export.
|
|
431
|
+
|
|
432
|
+
## License
|
|
433
|
+
|
|
434
|
+
Apache-2.0. EoMT and DINOv2-with-registers are Apache-2.0 too.
|