<!-- examples/README-deformable-detr.md -->

# Deformable DETR: offline mechanics

Run `python3 deformable_detr.py --smoke` from the examples directory. Python 3.9+ and the standard library are sufficient. The default requirements file is `requirements-deformableDetr.txt`; it declares no external dependencies. Output is deterministic JSON on stdout; no output file is created.

The five named source regions (`sampling`, `interpolation`, `aggregation`, `refinement`, `proposals`) are synchronized into `src/data/deformableDetrCode.mjs` and public downloads by the repository's owning sync script. Region markers use `# region: NAME` and `# endregion: NAME`, as required by `src/lib/sourceRegions.mjs`.

These are authored scalar examples and calculated quantities. They demonstrate point/box reference geometry, rectangular valid-ratio padding, half-pixel bilinear sampling with zero padding, one head's joint level/point softmax, inverse-sigmoid box arithmetic, and valid proposal ranking. They omit learned projections, learned offsets, the full encoder/decoder, matching and training. The proposal scores are authored; the official two-stage implementation ranks encoder class channel zero before gathering detached box coordinates. No NMS is simulated. Deterministic tie-breaking by slot ID is a teaching convention, not a guarantee about upstream topk ties.

The refinement helper computes values only. It cannot establish stop-gradient or training behavior; the official decoder detaches the updated references passed to the next layer. A 2D reference modifies only center logits, while a 4D box modifies all four. The sampling helper takes valid-image references and multiplies them by each target level's valid ratio before applying offsets; it assumes rectangular right/bottom padding. Scalar interpolation does not clamp coordinates or renormalize surviving weights.

Sources: [paper v4, §4 and Appendix A](https://arxiv.org/html/2010.04159v4), [official attention module](https://github.com/fundamentalvision/Deformable-DETR/blob/main/models/ops/modules/ms_deform_attn.py), [PyTorch sampling reference](https://github.com/fundamentalvision/Deformable-DETR/blob/main/models/ops/functions/ms_deform_attn_func.py), and [reference/proposal updates](https://github.com/fundamentalvision/Deformable-DETR/blob/main/models/deformable_transformer.py).

From the repository root, run `node --test test/deformableDetrModel.test.mjs test/deformableDetrPython.test.mjs`. Tests cover exact center and fractional samples, partial and full out-of-bounds reads, per-head normalization, 2D/4D updates, validity filtering, and Python/JavaScript parity. This script does not load a checkpoint, train a model, reproduce COCO AP, or measure latency. Published paper results and released-repository results are distinct, as explained in the review.
