EoMT in one breath
Before the attributes make sense, the host model: EoMT is a DINOv2-with-registers ViT whose last few transformer blocks are augmented with a fixed set of learnable queries (the Mask2Former idea). Each query is one "slot" that learns to latch onto one object instance.
After the encoder runs, every query produces a single vector — the per-query embedding, shape [B, Q, hidden] (batch × queries × width). The whole model is essentially "turn that embedding into predictions":
- the class head (
class_predictor) turns it into a primary label, - the mask head (or a box head, in the
detectfamily) turns it into geometry.
It's NMS-free: two overlapping instances stay two distinct queries instead of being merged by non-max suppression. That property is what lets attributes stay attached to the right instance.
| size | backbone | hidden | queries |
|---|---|---|---|
s | DINOv2-small | 384 | 100 |
b | DINOv2-base | 768 | 200 |
l | DINOv2-large | 1024 | 200 |
Two families share all of the above and differ only in the geometry head: instance → masks, detect → boxes. Everything about attributes applies identically to both.
The label space explodes
A normal detector has one flat list of classes. So when an object has a class and several orthogonal attributes, the only way to express it is the Cartesian product: class × attribute #1 × attribute #2 × …. That blows up combinatorially, starves each leaf class of examples, and multiplies the targets the Hungarian matcher has to assign.
attr-eomt factorizes instead. Keep the primary taxonomy small and general (class #1, class #2, …); push each orthogonal attribute into its own independent head that adds, not multiplies. Drag the sliders — this is the entire argument for the feature:
Because the heads are independent, the model can predict an attribute value on a class it never co-occurred with during training — it composes attribute × class combinations a flat label space cannot even represent.
The heads tap the same embedding
The key implementation idea: the attribute heads don't get a new feature extractor. They read the exact same per-query embedding that feeds class_predictor — captured non-invasively with a PyTorch forward hook. The detector doesn't even know they're there.
In code it's about as small as it sounds. Each head is built by _build_aux_head — a bare linear probe, or a tiny MLP if you ask for more layers:
# model.py — one head per attribute spec, sharing one arch self.aux_heads = nn.ModuleDict({ s.name: _build_aux_head(hidden, s.num_classes, arch) # Linear, or small MLP for s in self.aux_specs }) # non-invasive: grab the embedding feeding the class head self.eomt.class_predictor.register_forward_hook(self._capture_query_embed) def _capture_query_embed(self, _m, inputs, _out): self._query_embed = inputs[0] # [B, Q, hidden]
Default head arch is a 2-layer MLP (Linear → LayerNorm → GELU → Linear); layers=1 makes it a pure linear probe. The arch is stored in the checkpoint, so reloading rebuilds identical modules.
It rides on the detector's own matching
The clever part of training is that attributes never run their own matcher. Detection already solves "which query is responsible for which ground-truth object" via the Hungarian matcher. Attributes simply reuse that same query→GT assignment, then read the answer off the matched queries.
- MatchReuse
model.eomt.criterion.matcheron the model's geometry (masks forinstance, boxes fordetect) to get(query_idx, gt_idx)pairs — the same assignment the detection loss used. - Gate (optional)The matcher pairs every GT, even barely-overlapping ones (common early on).
gate_indicesdrops pairs whose predicted↔GT IoU is below a threshold, so attributes only learn from queries that actually localize the object. - Gather
_gather_matchedpulls just the matched rows out ofquery_embed→ a tight[N, hidden]tensor of "real" instances. - LossEach head runs on that tensor; cross-entropy against the per-instance attribute labels, summed across heads, scaled by
aux_w(default 1.0), and added to the detector loss. Missing labels useignore_indexand contribute nothing. - Graph-safe zeroIf no query matched in a batch, it returns
embed.sum()*0— a real zero that keeps autograd happy instead of crashing.
# aux_cls.py — the whole supervision, condensed indices = match_queries(model, out, geom_labels, class_labels) # reuse Hungarian indices = gate_indices(out, indices, ..., iou_thr=0.5) # keep well-localized matched = gather_matched(out, indices) # [N, hidden] for name, head in model.aux_heads.items(): logits = head(matched) loss += w * F.cross_entropy(logits, gt[name], ignore_index=-100)
The attribute "rides along for free": it reuses the backbone and the detector's matched queries, adding only a thin head and one CE term — not a second model or a second pass.
It never hijacks model selection
Per-head matched-query accuracy is printed live and written to metrics.csv, but it never drives which checkpoint becomes best.pt — that's still segm/mAP (or bbox/mAP). The attribute genuinely tags along without changing the detector's training contract.
Attributes live inside the COCO annotations
Because every COCO annotation is already a per-instance object, alignment is automatic — pycocotools still parses the file untouched. Two additions define the heads; no YAML changes, the heads (count, classes, names) are discovered straight from the JSON, just like nc.
1 · a top-level attributes list (the vocabulary)
"attributes": [
{"name": "attribute_1", "categories": [
{"id": 1, "name": "value_a"}, {"id": 2, "name": "value_b"}, {"id": 3, "name": "value_c"}]},
{"name": "attribute_2", "categories": [
{"id": 0, "name": "value_x"}, {"id": 1, "name": "value_y"}, {"id": 2, "name": "value_z"}]}
]
2 · a per-annotation attributes map
{ "id": 1, "image_id": 42, "category_id": 1, "bbox": [...], "segmentation": [...],
"attributes": {"attribute_1": 3, "attribute_2": 0} }
Raw ids are remapped to a contiguous 0..n-1 per head (so attribute_1's 1/2/3 → 0/1/2). A missing or unknown value is ignored by that head's loss (never trained as class 0), so a partly tagged dataset works; a JSON with no attributes is just instance segmentation.
At inference
Each kept detection gets an aux = {head: {"ids", "probs"}} entry, and predict(plot=True) renders every attribute next to the class label, using the names stored in the checkpoint — the primary class on the first row, each attribute + its confidence on the row beneath.
eomt.visualize.draw_instances (primary class on the first row, each attribute + its confidence beneath).
The same idea links instances across photos: a set matcher reads the per-query embedding and mask box of every detected instance of the photos, lets them attend to each other within and across photos, and gives every two instances of two photos a probability of being the same, trained on the matched queries of photos of one subject (multiview: {matching: true}); EoMT.match() turns that into one identity per instance.
The training recipe, and the knobs
Defaults follow the reference EoMT recipe. Each piece is a keyword argument to train().
- Effective batch via gradient accumulation — LR/WD/clip are tuned for an effective batch of 16; EoMT is a ViT (LayerNorm, no BatchNorm), so accumulation ≈ a true large batch at a fraction of the memory.
- EMA weights are validated and saved as
best.pt;last.ptholds live weights + optimizer + EMA state for exact resume. - Large-Scale Jitter for training, letterbox for eval/inference (the mode is stored per-checkpoint so
val/predictmatch training automatically). - AdamW at
1e-4with no weight decay on norms/biases/embeddings. Layer-wise LR decay0.8on the encoder with the top block at the full LR (the last blocks process the queries, so there is no backbone multiplier), and a polynomial decay to 0 after a two-stage warmup: the head first, with the ViT held at 0, then the ViT. - Masked-attention annealing
1 → 0, one query block after the other, so the final sixth of training is mask-free and matches efficient (mask-less) inference.
Every setting has the reference recipe as its default and lives in one section of the run config (or a keyword of
train(); a mapping is merged over the YAML's section key by key):
| section | what it holds |
|---|---|
train | epochs, batch (per GPU) / nominal_batch (16, the rest accumulated), imgsz, workers, seed, init_weights, project / name |
model | architecture and loss weights of a new model: fpn_scales, num_upscale_blocks, iou_aware_cls, quality_weight, the attribute heads' shape |
optim | lr0 (1e-4), llrd (0.8), warmup_steps ((500, 1000)), poly_power (0.9), ema_decay (0.9999), mask_anneal (on) |
aux | how the attribute heads train: w, per_head, class_weights, the IoU / class gate |
aug | every augmentation knob (AugConfig): flip, Large-Scale Jitter, rotate / shear / perspective, gamma, grayscale, blur, noise, JPEG, glare, safe erasing; mosaic / mixup / copy-paste and the instance-aware crop are off |
val | interval, imgsz, group_by, best_key |
multiview | a post-training on photos of one subject: xview, matching, gate, trainable, sets |
Orientation gotcha. If an attribute encodes orientation, train with aug: {flip_prob: 0}, or mark the attribute flip_aware — a horizontal flip mirrors the pixels but not the label, silently corrupting it. The same goes for vflip_prob / rot90_prob (off by default) and, to a lesser degree, the small rotations (rotate_prob).
Half the file, the same predictions
Inference runs in bf16 on a GPU by default. save(path, dtype="bf16") (or scripts/export.py) stores the Linear and Conv weights in bf16, about half the checkpoint, and scores like the fp32 one.
m = EoMT("runs/train/eomt-l") m.save("best_bf16.pt", dtype="bf16") EoMT("best_bf16.pt").predict("images/", batch=16, stream=True)
Factorize the labels, tap the embedding, reuse the match
Keep the primary taxonomy small and well-populated. For every orthogonal axis — each an independent attribute — attach an independent head that reads the per-query embedding the detector already produces, supervise it on the detector's own Hungarian match, and add a cross-entropy term. You get composable, generalizing per-instance attributes for almost no extra compute, and the primary detection metric stays exactly as it was.