raidar 0.1.0a1__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.
Files changed (77) hide show
  1. raidar-0.1.0a1/CHANGELOG.md +39 -0
  2. raidar-0.1.0a1/LICENSE +21 -0
  3. raidar-0.1.0a1/MANIFEST.in +9 -0
  4. raidar-0.1.0a1/PKG-INFO +473 -0
  5. raidar-0.1.0a1/README.md +382 -0
  6. raidar-0.1.0a1/pyproject.toml +272 -0
  7. raidar-0.1.0a1/raidar/__init__.py +76 -0
  8. raidar-0.1.0a1/raidar/_keras.py +16 -0
  9. raidar-0.1.0a1/raidar/_tensorflow.py +26 -0
  10. raidar-0.1.0a1/raidar/cli.py +110 -0
  11. raidar-0.1.0a1/raidar/detection_base.py +178 -0
  12. raidar-0.1.0a1/raidar/detection_keras.py +203 -0
  13. raidar-0.1.0a1/raidar/detection_torch.py +78 -0
  14. raidar-0.1.0a1/raidar/fastai_detector.py +346 -0
  15. raidar-0.1.0a1/raidar/fcos/__init__.py +8 -0
  16. raidar-0.1.0a1/raidar/fcos/flax_fcos.py +165 -0
  17. raidar-0.1.0a1/raidar/fcos/keras_fcos.py +202 -0
  18. raidar-0.1.0a1/raidar/fcos/mlx_fcos.py +165 -0
  19. raidar-0.1.0a1/raidar/fcos/spec.py +483 -0
  20. raidar-0.1.0a1/raidar/fcos/targets.py +143 -0
  21. raidar-0.1.0a1/raidar/fcos/tensorflow_fcos.py +200 -0
  22. raidar-0.1.0a1/raidar/fcos/torch_fcos.py +295 -0
  23. raidar-0.1.0a1/raidar/huggingface_detector.py +378 -0
  24. raidar-0.1.0a1/raidar/huggingface_model.py +144 -0
  25. raidar-0.1.0a1/raidar/jax_detector.py +266 -0
  26. raidar-0.1.0a1/raidar/keras_detector.py +118 -0
  27. raidar-0.1.0a1/raidar/lightning_detector.py +213 -0
  28. raidar-0.1.0a1/raidar/mlx_detector.py +264 -0
  29. raidar-0.1.0a1/raidar/py.typed +0 -0
  30. raidar-0.1.0a1/raidar/rfdetr.py +459 -0
  31. raidar-0.1.0a1/raidar/rfdetr_detector.py +510 -0
  32. raidar-0.1.0a1/raidar/stream_rfdetr_dataset.py +297 -0
  33. raidar-0.1.0a1/raidar/tensorflow_detector.py +198 -0
  34. raidar-0.1.0a1/raidar/torch_detection.py +279 -0
  35. raidar-0.1.0a1/raidar/torch_detector.py +208 -0
  36. raidar-0.1.0a1/raidar/torchvision_detection.py +72 -0
  37. raidar-0.1.0a1/raidar/torchvision_model.py +274 -0
  38. raidar-0.1.0a1/raidar/yolo_sink.py +410 -0
  39. raidar-0.1.0a1/raidar.egg-info/PKG-INFO +473 -0
  40. raidar-0.1.0a1/raidar.egg-info/SOURCES.txt +75 -0
  41. raidar-0.1.0a1/raidar.egg-info/dependency_links.txt +1 -0
  42. raidar-0.1.0a1/raidar.egg-info/entry_points.txt +28 -0
  43. raidar-0.1.0a1/raidar.egg-info/requires.txt +80 -0
  44. raidar-0.1.0a1/raidar.egg-info/top_level.txt +1 -0
  45. raidar-0.1.0a1/setup.cfg +4 -0
  46. raidar-0.1.0a1/tests/test_categories.py +164 -0
  47. raidar-0.1.0a1/tests/test_cli_frameworks.py +208 -0
  48. raidar-0.1.0a1/tests/test_cli_no_sys_path_pollution.py +50 -0
  49. raidar-0.1.0a1/tests/test_coverage_config.py +45 -0
  50. raidar-0.1.0a1/tests/test_detection_confusion_matrix.py +233 -0
  51. raidar-0.1.0a1/tests/test_detection_evaluator.py +225 -0
  52. raidar-0.1.0a1/tests/test_docs_links.py +193 -0
  53. raidar-0.1.0a1/tests/test_entry_points.py +104 -0
  54. raidar-0.1.0a1/tests/test_examples_load.py +55 -0
  55. raidar-0.1.0a1/tests/test_fastai_detector.py +187 -0
  56. raidar-0.1.0a1/tests/test_fcos_spec.py +336 -0
  57. raidar-0.1.0a1/tests/test_huggingface_detector.py +201 -0
  58. raidar-0.1.0a1/tests/test_huggingface_model.py +49 -0
  59. raidar-0.1.0a1/tests/test_jax_detector.py +150 -0
  60. raidar-0.1.0a1/tests/test_keras_detector.py +226 -0
  61. raidar-0.1.0a1/tests/test_lazy_slots.py +77 -0
  62. raidar-0.1.0a1/tests/test_lightning_trainer.py +508 -0
  63. raidar-0.1.0a1/tests/test_mlx_detector.py +139 -0
  64. raidar-0.1.0a1/tests/test_model_refs.py +49 -0
  65. raidar-0.1.0a1/tests/test_packaging.py +134 -0
  66. raidar-0.1.0a1/tests/test_rfdetr.py +390 -0
  67. raidar-0.1.0a1/tests/test_rfdetr_detector.py +325 -0
  68. raidar-0.1.0a1/tests/test_stream_rfdetr_dataset.py +205 -0
  69. raidar-0.1.0a1/tests/test_sweep_config.py +79 -0
  70. raidar-0.1.0a1/tests/test_tensorflow_detector.py +178 -0
  71. raidar-0.1.0a1/tests/test_torch_detection_batching.py +87 -0
  72. raidar-0.1.0a1/tests/test_torch_detector.py +240 -0
  73. raidar-0.1.0a1/tests/test_torch_fcos.py +138 -0
  74. raidar-0.1.0a1/tests/test_torchvision_model.py +285 -0
  75. raidar-0.1.0a1/tests/test_tracking_parity.py +138 -0
  76. raidar-0.1.0a1/tests/test_version.py +14 -0
  77. raidar-0.1.0a1/tests/test_yolo_sink.py +241 -0
@@ -0,0 +1,39 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the versioning is
5
+ [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [0.1.0a1] — 2026-09-28
8
+
9
+ First public pre-release. The surface it ships:
10
+
11
+ ### Backends
12
+ - **Nine training engines over one config**, each a runnable class behind its own extra:
13
+ `LightningDetector` (`[lightning]`, the reference), `TorchDetector` (`[torch]`, a
14
+ hand-written loop), `FastaiDetector` (`[fastai]`), `HuggingFaceDetector` (`[huggingface]`,
15
+ `transformers.Trainer`), `KerasDetector` (`[keras]`), `TensorFlowDetector` (`[tensorflow]`),
16
+ `JaxDetector` (`[jax]`), `MlxDetector` (`[mlx]`, Apple silicon) and `RFDETRDetector`
17
+ (`[rfdetr]`, RF-DETR's own training recipe). Each runnable dispatches on `task`: `fit` /
18
+ `evaluate` / `test` / `predict`.
19
+ - **Backend-free core:** `import raidar` loads no ML framework. Touching a backend that is not
20
+ installed raises an `ImportError` naming the extra to install.
21
+
22
+ ### Models
23
+ - The torchvision detectors (Faster R-CNN, RetinaNet, FCOS, SSD) used as-is, plus
24
+ `TorchVisionDetectionModel` — the same zoo behind one configured wrapper for inference from a
25
+ trained checkpoint.
26
+ - `RFDETRModel` (the RF-DETR family as a torchvision-style module) and
27
+ `HuggingFaceDetectionModel` (any Hub object-detection checkpoint by name).
28
+ - The `raidar.fcos` package: one small FCOS spec with five native implementations
29
+ (`TorchFcos`, `KerasFcos`, `TensorFlowFcos`, `FlaxFcos`, `MlxFcos`), for comparing engines on
30
+ one network.
31
+
32
+ ### Data, metrics and results
33
+ - COCO-style detection metrics (mAP) with per-split additions and a detection confusion matrix.
34
+ - `YoloSink` writes a dataset in the on-disk YOLO layout.
35
+ - RF-DETR trains either from a dataset directory or straight from a record stream in memory.
36
+
37
+ ### Command line
38
+ - `raidar train | evaluate | predict <config.yaml> [--framework <name>]` and `raidar frameworks`;
39
+ the same config also runs under `recordstream run`.
raidar-0.1.0a1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gert Behiels
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,9 @@
1
+ # What the sdist ships BEYOND what setuptools already infers.
2
+ #
3
+ # `readme = "README.md"` and `license-files = ["LICENSE"]` in pyproject already pull those
4
+ # two in, and `packages.find` + `[tool.setuptools.package-data]` pull the package. A
5
+ # CHANGELOG is referenced by nothing, so without this line it is silently absent from the
6
+ # sdist — which is the only copy of it a reader has while the repository is private.
7
+ #
8
+ # Pinned by tests/test_packaging.py::test_the_changelog_is_shipped_in_the_sdist
9
+ include CHANGELOG.md
@@ -0,0 +1,473 @@
1
+ Metadata-Version: 2.4
2
+ Name: raidar
3
+ Version: 0.1.0a1
4
+ Summary: Object detection across training backends, driven by one config (torchvision, RF-DETR, HF detectors).
5
+ Author: Gert Behiels
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Gearlux/raidar
8
+ Project-URL: Repository, https://github.com/Gearlux/raidar.git
9
+ Project-URL: Issues, https://github.com/Gearlux/raidar/issues
10
+ Project-URL: Changelog, https://github.com/Gearlux/raidar/blob/main/CHANGELOG.md
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.12
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: confluid>=0.3.1
25
+ Requires-Dist: recordstream>=0.1.0a2
26
+ Requires-Dist: liquifai>=0.3.0
27
+ Requires-Dist: loggair>=0.2.0
28
+ Requires-Dist: matrainer>=0.1.0a1
29
+ Provides-Extra: torch
30
+ Requires-Dist: matrainer[torch]>=0.1.0a1; extra == "torch"
31
+ Requires-Dist: recordstream[torch]>=0.1.0a2; extra == "torch"
32
+ Requires-Dist: torch; extra == "torch"
33
+ Requires-Dist: torchvision; extra == "torch"
34
+ Requires-Dist: torchmetrics[detection]; extra == "torch"
35
+ Requires-Dist: pycocotools; extra == "torch"
36
+ Provides-Extra: lightning
37
+ Requires-Dist: raidar[torch]; extra == "lightning"
38
+ Requires-Dist: matrainer[lightning]>=0.1.0a1; extra == "lightning"
39
+ Requires-Dist: pytorch-lightning; extra == "lightning"
40
+ Provides-Extra: fastai
41
+ Requires-Dist: raidar[torch]; extra == "fastai"
42
+ Requires-Dist: fastai>=2.7; extra == "fastai"
43
+ Requires-Dist: fastcore<2; extra == "fastai"
44
+ Requires-Dist: fastprogress<1.1; extra == "fastai"
45
+ Provides-Extra: huggingface
46
+ Requires-Dist: raidar[torch]; extra == "huggingface"
47
+ Requires-Dist: transformers>=4.49; extra == "huggingface"
48
+ Requires-Dist: accelerate>=0.30; extra == "huggingface"
49
+ Requires-Dist: timm; extra == "huggingface"
50
+ Requires-Dist: scipy; extra == "huggingface"
51
+ Provides-Extra: keras
52
+ Requires-Dist: keras>=3.0; extra == "keras"
53
+ Requires-Dist: torch; extra == "keras"
54
+ Requires-Dist: recordstream[keras,torch]>=0.1.0a2; extra == "keras"
55
+ Requires-Dist: matrainer[keras]>=0.1.0a1; extra == "keras"
56
+ Provides-Extra: tensorflow
57
+ Requires-Dist: keras>=3.0; extra == "tensorflow"
58
+ Requires-Dist: tensorflow>=2.16; extra == "tensorflow"
59
+ Requires-Dist: torch; extra == "tensorflow"
60
+ Requires-Dist: recordstream[keras,torch]>=0.1.0a2; extra == "tensorflow"
61
+ Requires-Dist: matrainer[keras]>=0.1.0a1; extra == "tensorflow"
62
+ Provides-Extra: jax
63
+ Requires-Dist: jax>=0.4; extra == "jax"
64
+ Requires-Dist: flax>=0.8; extra == "jax"
65
+ Requires-Dist: optax>=0.2; extra == "jax"
66
+ Requires-Dist: torch; extra == "jax"
67
+ Requires-Dist: recordstream[keras,torch]>=0.1.0a2; extra == "jax"
68
+ Requires-Dist: matrainer>=0.1.0a1; extra == "jax"
69
+ Provides-Extra: mlx
70
+ Requires-Dist: mlx>=0.20; (sys_platform == "darwin" and platform_machine == "arm64") and extra == "mlx"
71
+ Requires-Dist: torch; extra == "mlx"
72
+ Requires-Dist: recordstream[keras,torch]>=0.1.0a2; extra == "mlx"
73
+ Requires-Dist: matrainer>=0.1.0a1; extra == "mlx"
74
+ Provides-Extra: rfdetr
75
+ Requires-Dist: rfdetr[loggers,train]>=1.6.0; extra == "rfdetr"
76
+ Requires-Dist: faster-coco-eval; extra == "rfdetr"
77
+ Provides-Extra: mlflow
78
+ Requires-Dist: matrainer[mlflow]>=0.1.0a1; extra == "mlflow"
79
+ Provides-Extra: tensorboard
80
+ Requires-Dist: matrainer[tensorboard]>=0.1.0a1; extra == "tensorboard"
81
+ Provides-Extra: dev
82
+ Requires-Dist: build>=1.0.0; extra == "dev"
83
+ Requires-Dist: twine>=5.0.0; extra == "dev"
84
+ Requires-Dist: black<25.0.0,>=24.0.0; extra == "dev"
85
+ Requires-Dist: isort<6.0.0,>=5.13.0; extra == "dev"
86
+ Requires-Dist: flake8<8.0.0,>=6.0.0; extra == "dev"
87
+ Requires-Dist: mypy<2.0.0,>=1.0.0; extra == "dev"
88
+ Requires-Dist: pytest<9.0.0,>=7.0.0; extra == "dev"
89
+ Requires-Dist: pytest-cov<7.0.0,>=4.0.0; extra == "dev"
90
+ Dynamic: license-file
91
+
92
+ # Raidar
93
+
94
+ Object detection across **ten training backends**, driven by **one config**.
95
+
96
+ ```bash
97
+ raidar train examples/train_cppe5.yaml # the default backend (lightning)
98
+ raidar train examples/train_cppe5.yaml --framework torch # the hand-written control loop
99
+ raidar train examples/train_cppe5.yaml --framework keras # the shared FCOS spec on Keras 3
100
+ raidar evaluate examples/train_cppe5.yaml
101
+ raidar predict examples/train_cppe5.yaml
102
+ raidar frameworks # what the backends are
103
+ ```
104
+
105
+ The training backend is a property of the **config**, not of the CLI: an alternative backend is a
106
+ `!scope:framework=<name>` block in the YAML that overrides only the framework-specific keys, and
107
+ `--framework <name>` activates it. The same flag works on the generic runner
108
+ (`recordstream run cfg.yaml --framework rfdetr`).
109
+
110
+ | framework | what it is | extra |
111
+ |---|---|---|
112
+ | `lightning` | The reference backend — a standard `pytorch_lightning.LightningModule` (`raidar.LightningDetector`) driving torchvision-native models: the torchvision builders, `RFDETRModel`, `TorchFcos`. | `raidar[lightning]` |
113
+ | `torch` | The control experiment — a hand-written loop (`raidar.TorchDetector`), no training framework at all: `zero_grad`/`backward`/`step` in the open, same models, same config. | `raidar[torch]` |
114
+ | `fastai` | A `Learner` with one-cycle scheduling (`raidar.FastaiDetector`) over the same torch stack — the loss-inside-forward contract bridged by a no-op loss. | `raidar[fastai]` |
115
+ | `huggingface` | `transformers.Trainer` (`raidar.HuggingFaceDetector`) fine-tuning any Hub object-detection checkpoint by name through ONE light wrapper (`raidar.HuggingFaceDetectionModel`). | `raidar[huggingface]` |
116
+ | `keras` | Keras 3 (`raidar.KerasDetector`) training the shared FCOS spec on whichever engine `KERAS_BACKEND` names (torch / TF / jax). | `raidar[keras]` |
117
+ | `tensorflow` | A native `tf.data` + `GradientTape` loop (`raidar.TensorFlowDetector`) — traced steps, XLA knob, SavedModel export; drives the spec in **raw `tf.nn`** (`TensorFlowFcos`). | `raidar[tensorflow]` |
118
+ | `jax` | An `nnx.jit`-traced optax loop (`raidar.JaxDetector`) over the spec in `flax.nnx` (`FlaxFcos`). | `raidar[jax]` |
119
+ | `mlx` | Apple's MLX (`raidar.MlxDetector`) — unified memory, lazy arrays; Apple silicon only. | `raidar[mlx]` |
120
+ | `rfdetr` | RF-DETR's **own** PyTorch-Lightning recipe (`raidar.RFDETRDetector`) — COCO-mAP eval, EMA, best-checkpoint saving, LR schedule. Apache-2.0, so it lives in core. | `raidar[rfdetr]` |
121
+ | `ultralytics` | Ultralytics YOLO (AGPL) — lives in a separate package that is not part of this distribution; raidar carries only the table row and the config block. | separate package |
122
+
123
+ ## Installation
124
+
125
+ **The core is backend-free** — `pip install raidar` gives you the CLI and the config surface only.
126
+ A training framework arrives with the backend you select:
127
+
128
+ ```bash
129
+ pip install "raidar[lightning]" # the reference backend
130
+ pip install "raidar[huggingface]" # transformers.Trainer
131
+ pip install "raidar[keras]" # the Keras 3 loop
132
+ pip install "raidar[rfdetr]" # RF-DETR's stack
133
+ ```
134
+
135
+ raidar is on PyPI as a pre-release; pip installs it without `--pre`, because no final release
136
+ exists yet. Leave `--pre` off: it lets pip take pre-releases of *every* dependency too.
137
+
138
+ `[torch]` is the base of the torch-family backends (`lightning` / `fastai` build on it).
139
+
140
+ Every backend-owned name in `raidar/__init__.py` resolves lazily, so `import raidar` pulls no
141
+ framework and touching a missing one raises an `ImportError` naming the exact extra.
142
+
143
+ ### Development
144
+
145
+ ```bash
146
+ git clone https://github.com/Gearlux/raidar.git
147
+ cd raidar
148
+ pip install -e ".[lightning,fastai,huggingface,keras,tensorflow,jax,rfdetr,dev]"
149
+ ```
150
+
151
+ ## The one config
152
+
153
+ [`examples/train_cppe5.yaml`](https://github.com/Gearlux/raidar/blob/main/examples/train_cppe5.yaml) trains on **cppe-5** (the "MNIST of
154
+ object detection": 1000 medical-PPE images, 5 classes, COCO boxes) on every backend, changing only
155
+ the flag. Its shape is the demo:
156
+
157
+ * everything **above** the framework divider is engine-agnostic — the dataset splits, the
158
+ batch/epoch knobs, the run identity;
159
+ * every framework-specific key (`runnable`, `model`, `detection_ops`, `num_classes`,
160
+ `class_names`) is a **top-level sibling**, and each backend's `!scope:framework=` block
161
+ overrides only the ones it must. (Flat on purpose: a scope block replaces a key and takes its
162
+ whole subtree, so a key nested inside `runnable:` would vanish the moment a block swapped the
163
+ runnable.)
164
+
165
+ > ⚠️ **The label convention is the real semantic difference between the backends**, and it is
166
+ > silent when wrong. torchvision (the lightning default) reserves **background at index 0** —
167
+ > `CocoToTorchVisionDetection(label_offset=1)` and `num_classes: 6` on cppe-5. Every other
168
+ > convention here is **0-indexed** (`0..K-1`): RF-DETR (background at index `K`), the HF
169
+ > detectors, ultralytics, and the FCOS spec engines — `label_offset: 0` and `num_classes: 5`.
170
+ > Each backend's block restates both keys; inheriting the wrong shift trains with every label
171
+ > off by one and nothing raising.
172
+
173
+ A typo'd backend is an error, not a silent fall-through: `--framework lightnin` raises a
174
+ `ScopeError` listing the frameworks the config declares.
175
+
176
+ ## The torch-family backends — lightning, torch, fastai
177
+
178
+ `raidar.LightningDetector` is one self-contained standard `pytorch_lightning.LightningModule` —
179
+ its own detection step functions, `configure_optimizers`, and a `run()` that builds the loaders +
180
+ `pl.Trainer` and dispatches on the `task` knob (`fit`/`evaluate`/`test`/`predict`; the CLI verb
181
+ wins over the YAML's `task:`). There is **no adapter layer**: it talks to native detection models
182
+ and raw `torchmetrics` metrics directly.
183
+
184
+ The native model contract is the shape torchvision detectors already speak:
185
+
186
+ * `model.train(); model(images, targets) → Dict[str, Tensor]` — loss dict (summed for the
187
+ optimisation scalar).
188
+ * `model.eval(); model(images) → List[Dict[str, Tensor]]` — per-image
189
+ `{boxes, scores, labels}` (a `recordstream.DetectionOutput` list, fed straight to the metric).
190
+
191
+ `raidar.TorchDetector` removes the training framework entirely and the config still does not
192
+ change — the same dataset, ops, model, torchmetrics and artifacts over a hand-written loop with a
193
+ `device:` knob, a plain-`state_dict` `checkpoint_dir:` and `grad_clip:`. `raidar.FastaiDetector`
194
+ swaps in fastai's `Learner` (one-cycle scheduling): the native contract computes loss INSIDE the
195
+ model's forward, which the backend bridges with a **no-op loss** — the training forward returns
196
+ the summed loss dict as the "prediction" and `loss_func` passes it through, so fastai backprops
197
+ it unchanged in one forward. The recorded `valid_loss` is therefore a meaningless 0; validation
198
+ quality comes from the same torchmetrics as the torch backend, via a callback.
199
+
200
+ ### `num_classes` resolution
201
+
202
+ `initialize()` (run at the top of `run()`) resolves `num_classes` and injects it into a `!lazy:`
203
+ model — so a config can omit it entirely. On a fit: a concrete model's head → the explicit arg →
204
+ a lazy model's pinned kwarg → derived from the train targets (`max(label) + 1`, a full pass —
205
+ announced). On an eval task it is **model-driven**: the model is flowed first (it loaded its own
206
+ checkpoint) and the count is read off the live head, best-effort — the default mAP metric is
207
+ class-count-agnostic.
208
+
209
+ ### Metrics — shared set + per-split additions
210
+
211
+ `metrics:` is what every **eval** split measures (defaulting to
212
+ `MeanAveragePrecision(iou_type="bbox")` — a sentinel `None` means "not chosen", so an explicitly
213
+ wired metric is never replaced); `val_metrics:` / `test_metrics:` add to one split, merged over
214
+ the shared set by name (`matrainer.metric_slots.merge_metric_specs` — the same rule as every
215
+ other task in the workspace). There is deliberately **no `train_metrics` slot**: a native model in
216
+ train mode returns only the loss dict, so there are no train-split predictions to score.
217
+
218
+ ```yaml
219
+ val_metrics:
220
+ # Per-class AP/AR — [C] vectors, reported through the trackers' TEXT channel as a
221
+ # worst-first table (plot_metrics: true adds a bar chart; class_names: labels the rows).
222
+ map: !lazy:torchmetrics.detection.MeanAveragePrecision { iou_type: bbox, class_metrics: true }
223
+ # TP/FP/FN + precision/recall/F1 at fixed IoU/score thresholds:
224
+ confusion: !lazy:raidar.DetectionConfusionMatrix { iou_threshold: 0.5 }
225
+ ```
226
+
227
+ A non-scalar metric value never goes through Lightning's `log_dict` (which raises on it): scalars
228
+ are logged under the canonical `<split>/<name>` names (`train/loss`, `val/map`, …), per-class
229
+ vectors are rendered as tables/figures to the log and to every tracker's text/figure channel.
230
+
231
+ ### Where the results go
232
+
233
+ `trackers:` is the whole of a run's output wiring — there is **no `logger:` slot**. Each matrainer
234
+ tracker is adapted to Lightning's logger interface (or hooked through the plain provenance
235
+ functions / the Keras callback, per backend), so per-step metrics land in the same backends
236
+ as the git provenance, the resolved config, the run manifest and the metrics sidecar
237
+ (`metrics_sidecar_path:`). `metric_names:` re-spells the recorded names for another engine's
238
+ vocabulary when you need it.
239
+
240
+ ```yaml
241
+ trackers:
242
+ - !class:matrainer.MlflowTracker
243
+ experiment_name: !ref:experiment_name
244
+ - !class:matrainer.TensorBoardTracker
245
+ ```
246
+
247
+ ## The huggingface backend
248
+
249
+ `raidar.HuggingFaceDetector` runs `transformers.Trainer` over any Hub object-detection checkpoint
250
+ named as a STRING through the one generic wrapper — the model computes its own DETR-family loss
251
+ from `labels=`, so there is no loss to wire:
252
+
253
+ ```yaml
254
+ huggingface: !scope:framework=huggingface
255
+ runnable: !class:raidar.HuggingFaceDetector
256
+ learning_rate: 5e-5 # a fine-tuning LR — we start from real weights
257
+ model: !lazy:raidar.HuggingFaceDetectionModel
258
+ model_name: ustc-community/dfine-small-coco # any Hub detection checkpoint
259
+ detection_ops:
260
+ - !class:recordstream.ops.target.CocoToTorchVisionDetection { bbox_format: xywh, label_offset: 0 }
261
+ num_classes: 5
262
+ ```
263
+
264
+ The ops only shape the TARGET (0-indexed labels): images stay RAW — the checkpoint's own image
265
+ processor does the resize / pad / normalize and the box conversion. `TrainingArguments` defaults
266
+ are derived at run time as a FLOOR (`remove_unused_columns=False` included); a key your config
267
+ pins wins. With `num_classes != 80` the pretrained class head is re-initialised
268
+ (`ignore_mismatched_sizes=True`) while everything else stays pretrained.
269
+
270
+ ## The shared FCOS spec — keras, tensorflow, jax, mlx
271
+
272
+ Every detection zoo raidar wraps is torch-only, so a cross-framework comparison built on zoos
273
+ would compare different networks. The [`raidar/fcos/`](https://github.com/Gearlux/raidar/tree/main/raidar/fcos) package is the answer: a
274
+ tiny single-level anchor-free FCOS-style detector (~110K parameters) **specified once**
275
+ ([`spec.py`](https://github.com/Gearlux/raidar/blob/main/raidar/fcos/spec.py)) and implemented natively per framework — `TorchFcos` (serves
276
+ lightning / torch / fastai too), `KerasFcos`, `TensorFlowFcos` (raw `tf.nn`), `FlaxFcos`,
277
+ `MlxFcos` — each checked against the spec's DERIVED parameter count, so "the same network" is a
278
+ claim the tests enforce rather than an aspiration. For real work prefer a zoo model; this is the
279
+ control, not the recommendation.
280
+
281
+ The spec also ships the **numpy reference algorithms** every implementation shares: FCOS
282
+ center-sampling target assignment, dense-grid decode + NMS, and AP50/precision/recall — the
283
+ scoring the non-torch engines report (torchmetrics is torch-only). Only the LOSS is per-engine
284
+ (it must be differentiable): sigmoid focal + `1 − IoU` + centerness BCE.
285
+
286
+ Two structural changes in a spec engine's config block:
287
+
288
+ * the ops chain gains `ResizeDetection` (dense targets need ONE fixed grid) and ends in
289
+ `raidar.fcos.targets.FcosTargets`, which encodes each record's boxes into fixed-shape dense
290
+ maps — that is what lets `collate_records` stack detection batches with no ragged tensors;
291
+ * labels are 0-indexed (the class map has no background slot).
292
+
293
+ ```yaml
294
+ detection_ops:
295
+ - !class:recordstream.ops.target.CocoToTorchVisionDetection { bbox_format: xywh, label_offset: 0 }
296
+ - !class:recordstream.ops.target.ResizeDetection { width: 256, height: 256 }
297
+ - !class:recordstream.ops.image.ConvertMode { mode: RGB }
298
+ - !class:recordstream.ops.numpy.Scale {}
299
+ - !class:recordstream.ops.torch.ToTensor {}
300
+ - !class:raidar.fcos.targets.FcosTargets { num_classes: 5, input_shape: [256, 256, 3] }
301
+ ```
302
+
303
+ **Resize with `ResizeDetection`, not an image-only resize.** Three knobs must agree — the resize's
304
+ `width`/`height`, the op's `input_shape`, and the model's — and note the ordering: the resize takes
305
+ `(width, height)` while `input_shape` is `(H, W, C)`. `ResizeDetection` moves the image AND the
306
+ boxes; an image-only resize (`ConvertToImage` and friends) moves only the pixels and leaves the
307
+ boxes in the source frame, which every shape check downstream would accept. Both mistakes are
308
+ caught for you at the first record:
309
+
310
+ ```
311
+ the boxes reach (426.0, 426.0) but the frame is 128x128 (W x H) — they are not in this frame …
312
+ FcosTargets: the target's boxes are in a (256, 256) (H, W) frame but this op assigns against (128, 128) …
313
+ ```
314
+
315
+ Engine notes: `keras` runs on whichever engine `KERAS_BACKEND` names and never sets it;
316
+ `tensorflow` pins it (via `raidar._tensorflow`) and must run in a fresh process — Keras 3 binds
317
+ one engine per process at first import; `jax` jits its steps ONCE (`jit: false` to read a
318
+ traceback); `mlx` is Apple-silicon only, with the extra's platform marker keeping the install
319
+ valid elsewhere.
320
+
321
+ Every spec model takes a `seed` (default `0`) applied before its weights are built, so a config
322
+ reproduces its run — two identical runs land on the same loss to the last digit. Change it to
323
+ sample a different initialization:
324
+
325
+ ```yaml
326
+ model: !lazy:raidar.fcos.keras_fcos.KerasFcos { input_shape: [256, 256, 3], seed: 7 }
327
+ ```
328
+
329
+ ## The rfdetr backend
330
+
331
+ `raidar.RFDETRDetector` hands off to RF-DETR's **own** training recipe (`RFDETRModelModule` +
332
+ `build_trainer`) — one class, train and eval, dispatched on the same `task` knob. Two input modes
333
+ (mutually exclusive):
334
+
335
+ ```yaml
336
+ # Disk mode — a COCO/YOLO/Roboflow dataset directory → RF-DETR's native loaders
337
+ runnable: !class:raidar.RFDETRDetector
338
+ data: /data/my_coco_dataset
339
+ dataset_file: roboflow
340
+ variant: small # nano | small | medium | large
341
+ epochs: 50
342
+ ```
343
+
344
+ ```yaml
345
+ # Stream mode — a RecordStream pipeline, fed IN-MEMORY (no disk materialization)
346
+ runnable: !class:raidar.RFDETRDetector
347
+ variant: small
348
+ num_classes: 5 # K foreground classes; labels 0-indexed 0..K-1
349
+ class_names: {0: Coverall, 1: Face_Shield, 2: Gloves, 3: Goggles, 4: Mask}
350
+ train_set: !ref:train_set # any recordstream Stream yielding {boxes xyxy-px, labels}
351
+ val_set: !ref:val_set
352
+ epochs: 50
353
+ ```
354
+
355
+ Beyond the ergonomic knobs, **`train_config:` reaches every RF-DETR parameter**: the mapping is
356
+ handed verbatim to RF-DETR's own config builder, whose pydantic `TrainConfig` validates it — so
357
+ any knob an RF-DETR release adds is immediately configurable with no raidar edit. Raidar-derived
358
+ values are a FLOOR; a key you pin wins.
359
+
360
+ **Pin a seed if you want a run you can compare against itself** — RF-DETR's `TrainConfig.seed`
361
+ defaults to `None`, i.e. it seeds nothing:
362
+
363
+ ```yaml
364
+ runnable: !class:raidar.RFDETRDetector
365
+ train_config: { seed: 7 }
366
+ device: cpu # see below
367
+ ```
368
+
369
+ Seeded, two runs land identically **on cpu**. On mps they still differ — that residual is Apple's
370
+ MPS backend rather than the config, so mps is the faster option and cpu is the reproducible one.
371
+
372
+ `raidar evaluate --framework rfdetr` runs RF-DETR's native validation/test loop over a trained
373
+ checkpoint (`weights:`). The wired `trackers:` receive the run's **record** (provenance, config,
374
+ manifest, log file, final-metrics sidecar); RF-DETR's own per-step curves stay with its native
375
+ `mlflow:` / `tensorboard:` knobs. There is no `predict` here — prediction runs through the
376
+ lightning backend with `raidar.RFDETRModel` (the native model module, which also loads RF-DETR
377
+ checkpoints for evaluation under `LightningDetector`).
378
+
379
+ ## Detector catalogue
380
+
381
+ | Model | Notes |
382
+ |---|---|
383
+ | `torchvision.models.detection.fasterrcnn_*` / `retinanet_*` / `fcos_*` / `ssd*` | Used **raw** — they conform to the native forward contract directly. Registered as `detection_model` builders (below). |
384
+ | `raidar.TorchVisionDetectionModel` | The same torchvision zoo behind ONE configured wrapper — pretrained `weights` as a plain value, an eval-time `score_threshold`, a `label_indexing` knob, and a `checkpoint_path` to load a trained model back for inference (below). |
385
+ | `raidar.RFDETRModel` | RF-DETR family as a native torchvision-style model module. |
386
+ | `raidar.HuggingFaceDetectionModel` | ONE light wrapper — `model_name:` reaches any Hub object-detection checkpoint (D-FINE, RT-DETRv2, DETR, Deformable-DETR, …). |
387
+ | `raidar.fcos.*` | The shared spec's five native implementations (above). |
388
+
389
+ The Ultralytics-backed YOLO26 + RT-DETR native models live in a separate package that is not
390
+ part of this distribution (Ultralytics is AGPL).
391
+
392
+ `raidar.torch_detection` is the torch ENGINE's module — the batch plumbing every torch-family
393
+ backend shares, plus that engine's registered metrics:
394
+
395
+ | Symbol | Role |
396
+ |---|---|
397
+ | `native_batch` | The ONE torch-contract adapter: reads a collated batch into the `(List[Tensor], per-image targets)` pair torchvision's forward takes. **Batching itself is recordstream's** — the loaders declare `collate_fn=collate_list` (the unstacked batch the native contract needs), and `batch_boxes` / `batch_metadata` read it back. Override `collate_fn` for a model wanting one stacked tensor. |
398
+ | `DetectionOutput` / `DetectionPredictions` | Task-agnostic per-image prediction schema (re-exported from recordstream). |
399
+ | the `torchmetrics.detection` family + `DetectionConfusionMatrix` | The engine's registered metrics (TP / FP / FN + precision / recall / F1 for the last). |
400
+
401
+ `raidar.torchvision_detection` registers the torchvision zoo's builder **functions** separately —
402
+ one module per upstream library, both named in the `lightning` / `torch` / `fastai` rows of the
403
+ `FRAMEWORKS` table.
404
+
405
+ ### Using a torchvision detector for inference — `TorchVisionDetectionModel`
406
+
407
+ The raw builders are the TRAINING spelling (a `!lazy:` slot the trainer flows with the
408
+ dataset-derived `num_classes`). For inference — a prediction chain, a visual review pipeline —
409
+ `raidar.TorchVisionDetectionModel` puts every decision in plain config values:
410
+
411
+ ```yaml
412
+ model: !class:raidar.torchvision_model.TorchVisionDetectionModel()
413
+ variant: fasterrcnn_resnet50_fpn # one of the nine registered zoo members
414
+ weights: DEFAULT # DEFAULT / COCO_V1 (COCO, 91 classes) / none
415
+ score_threshold: 0.5 # torchvision itself reports every box above 0.05
416
+ label_indexing: zero_based # emitted labels 0..K-1 (default) — one_based keeps 1..K
417
+ ```
418
+
419
+ For a model you trained yourself, start from random init and load the checkpoint —
420
+ `weights: none` and `checkpoint_path: <a Lightning .ckpt or plain state dict>`. The head size
421
+ is read off the checkpoint itself (the class count is baked into its classification-head
422
+ shapes), so `num_classes` stays unset; set it only to build a FRESH random head without a
423
+ checkpoint, and note an explicit value that disagrees with the checkpoint fails the load
424
+ loudly. Keys retarget to the wrapped detector automatically; missing keys are logged.
425
+ `RFDETRModel` follows the same rule: `checkpoint_path` alone is enough — its head size comes
426
+ off the checkpoint's own `class_embed` shape, and with no checkpoint at all the pretrained
427
+ COCO detector keeps its own 90-class head instead of being silently re-headed. It accepts
428
+ RF-DETR's own `.pth` in either shape rfdetr writes (the older `model`/`optimizer`/`epoch` file
429
+ and the current one) — those load through rfdetr's own loader — as well as a `.ckpt` from the
430
+ lightning backend or a plain state dict.
431
+ Eval output follows the native contract after two adaptations: rows below `score_threshold`
432
+ and background rows (label 0) are dropped, and labels are renumbered per `label_indexing` —
433
+ `zero_based` matches what the other model wrappers here emit. A `weights` name the chosen
434
+ variant's zoo does not publish logs a warning and builds with random init instead (the
435
+ constructor already refuses names outside the declared set). Training still works through the
436
+ wrapper (the loss dict passes through untouched), but the example config deliberately keeps
437
+ the raw builders for that role.
438
+
439
+ ## Discovery
440
+
441
+ Detection `@configurable` classes carry `task` / `role` / `framework` tags — every backend
442
+ runnable is `(detection, trainer, <framework>)` (their evaluate/test/predict capabilities are
443
+ declared by `@entrypoint` markers on the same class), the model wrappers and spec implementations
444
+ are `(detection, model)`, and `raidar.torchvision_detection` registers the torchvision builder
445
+ **functions** (Faster R-CNN ×4, RetinaNet ×2, FCOS, SSD ×2) as `detection_model` with
446
+ `lazy=True`, so a discovery service or visual editor enumerates them beside the wrapper classes
447
+ and a deferred builder still gets the dataset-derived `num_classes` injected at run time.
448
+ Mask R-CNN / Keypoint R-CNN are intentionally not registered — they need instance-mask /
449
+ keypoint targets, not the `{boxes, labels}` shape `recordstream.batch_boxes` yields. Discovery runs
450
+ off the `confluid.configurables` entry points (one per registering module); there are no
451
+ hand-written manifest files.
452
+
453
+ ## What the run record says about the model
454
+
455
+ Every model wrapper here names the weight artifacts it loads, so a run's manifest points at them
456
+ instead of leaving a reader to work out which registry resolves a bare architecture name. Nothing
457
+ has to be called for it — the tracking layer walks the configured graph and records what it finds:
458
+
459
+ ```yaml
460
+ models:
461
+ - {kind: hf, name: ustc-community/dfine-small-coco, role: pretrained, slot: model,
462
+ url: 'https://huggingface.co/ustc-community/dfine-small-coco'}
463
+ ```
464
+
465
+ **One wrapper may report several**, each with the `role` it played: `pretrained` for weights that
466
+ came from outside the run, `checkpoint` for weights a previous run wrote. A model trained from
467
+ scratch loaded no artifact and records nothing. Reading the identity is free and never builds the
468
+ model; adding one to your own wrapper is a single `model_refs` property — see
469
+ [matrainer's `uri` module](https://github.com/Gearlux/matrainer).
470
+
471
+ ## License
472
+
473
+ MIT.