mono-aeb 0.1.2__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.
- mono_aeb-0.1.2/LICENSE +201 -0
- mono_aeb-0.1.2/PKG-INFO +352 -0
- mono_aeb-0.1.2/README.md +321 -0
- mono_aeb-0.1.2/aeb/__init__.py +23 -0
- mono_aeb-0.1.2/aeb/calibration.py +163 -0
- mono_aeb-0.1.2/aeb/config.py +151 -0
- mono_aeb-0.1.2/aeb/decision/__init__.py +3 -0
- mono_aeb-0.1.2/aeb/decision/state_machine.py +67 -0
- mono_aeb-0.1.2/aeb/detectors/__init__.py +27 -0
- mono_aeb-0.1.2/aeb/detectors/base.py +14 -0
- mono_aeb-0.1.2/aeb/detectors/dfine_detector.py +138 -0
- mono_aeb-0.1.2/aeb/detectors/yolov8_detector.py +65 -0
- mono_aeb-0.1.2/aeb/distance/__init__.py +4 -0
- mono_aeb-0.1.2/aeb/distance/base.py +14 -0
- mono_aeb-0.1.2/aeb/distance/ground_plane.py +33 -0
- mono_aeb-0.1.2/aeb/ego_speed.py +84 -0
- mono_aeb-0.1.2/aeb/in_path/__init__.py +4 -0
- mono_aeb-0.1.2/aeb/in_path/base.py +12 -0
- mono_aeb-0.1.2/aeb/in_path/fixed_roi.py +58 -0
- mono_aeb-0.1.2/aeb/pipeline.py +94 -0
- mono_aeb-0.1.2/aeb/tracker/__init__.py +4 -0
- mono_aeb-0.1.2/aeb/tracker/base.py +14 -0
- mono_aeb-0.1.2/aeb/tracker/byte_shims/cython_bbox.py +39 -0
- mono_aeb-0.1.2/aeb/tracker/bytetrack.py +113 -0
- mono_aeb-0.1.2/aeb/tracker/vendor/__init__.py +1 -0
- mono_aeb-0.1.2/aeb/tracker/vendor/bytetrack/LICENSE +21 -0
- mono_aeb-0.1.2/aeb/tracker/vendor/bytetrack/__init__.py +1 -0
- mono_aeb-0.1.2/aeb/tracker/vendor/bytetrack/yolox/__init__.py +3 -0
- mono_aeb-0.1.2/aeb/tracker/vendor/bytetrack/yolox/tracker/__init__.py +1 -0
- mono_aeb-0.1.2/aeb/tracker/vendor/bytetrack/yolox/tracker/basetrack.py +52 -0
- mono_aeb-0.1.2/aeb/tracker/vendor/bytetrack/yolox/tracker/byte_tracker.py +328 -0
- mono_aeb-0.1.2/aeb/tracker/vendor/bytetrack/yolox/tracker/kalman_filter.py +270 -0
- mono_aeb-0.1.2/aeb/tracker/vendor/bytetrack/yolox/tracker/matching.py +181 -0
- mono_aeb-0.1.2/aeb/ttc/__init__.py +7 -0
- mono_aeb-0.1.2/aeb/ttc/base.py +15 -0
- mono_aeb-0.1.2/aeb/ttc/fusion.py +39 -0
- mono_aeb-0.1.2/aeb/ttc/history.py +24 -0
- mono_aeb-0.1.2/aeb/ttc/ttc_distance.py +53 -0
- mono_aeb-0.1.2/aeb/ttc/ttc_scale.py +52 -0
- mono_aeb-0.1.2/aeb/types.py +103 -0
- mono_aeb-0.1.2/mono_aeb.egg-info/PKG-INFO +352 -0
- mono_aeb-0.1.2/mono_aeb.egg-info/SOURCES.txt +51 -0
- mono_aeb-0.1.2/mono_aeb.egg-info/dependency_links.txt +1 -0
- mono_aeb-0.1.2/mono_aeb.egg-info/requires.txt +16 -0
- mono_aeb-0.1.2/mono_aeb.egg-info/top_level.txt +1 -0
- mono_aeb-0.1.2/pyproject.toml +86 -0
- mono_aeb-0.1.2/setup.cfg +4 -0
- mono_aeb-0.1.2/tests/test_bytetrack_vendor.py +59 -0
- mono_aeb-0.1.2/tests/test_calibration_horizon_synthetic.py +74 -0
- mono_aeb-0.1.2/tests/test_import_smoke.py +23 -0
- mono_aeb-0.1.2/tests/test_quickstart_demo.py +36 -0
- mono_aeb-0.1.2/tests/test_tracking_synth.py +31 -0
- mono_aeb-0.1.2/tests/test_ttc_synthetic.py +89 -0
mono_aeb-0.1.2/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 mono-aeb contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
mono_aeb-0.1.2/PKG-INFO
ADDED
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mono-aeb
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: 检测器无关的单目 AEB 前向碰撞预警决策链:检测→跟踪→测距→TTC→风险决策(免标定尺度 TTC)
|
|
5
|
+
Author: mono-aeb contributors
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/H12Y10/mono-aeb
|
|
8
|
+
Project-URL: Repository, https://github.com/H12Y10/mono-aeb
|
|
9
|
+
Project-URL: Issues, https://github.com/H12Y10/mono-aeb/issues
|
|
10
|
+
Keywords: AEB,FCW,forward-collision-warning,monocular,time-to-collision,TTC,autonomous-driving
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
License-File: aeb/tracker/vendor/bytetrack/LICENSE
|
|
17
|
+
Requires-Dist: numpy
|
|
18
|
+
Requires-Dist: scipy
|
|
19
|
+
Requires-Dist: lap
|
|
20
|
+
Requires-Dist: opencv-python
|
|
21
|
+
Provides-Extra: yolo
|
|
22
|
+
Requires-Dist: ultralytics; extra == "yolo"
|
|
23
|
+
Provides-Extra: dfine
|
|
24
|
+
Requires-Dist: torch; extra == "dfine"
|
|
25
|
+
Requires-Dist: torchvision; extra == "dfine"
|
|
26
|
+
Requires-Dist: pillow; extra == "dfine"
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest; extra == "dev"
|
|
29
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# mono-aeb
|
|
33
|
+
|
|
34
|
+
[](https://github.com/H12Y10/mono-aeb/actions/workflows/ci.yml)
|
|
35
|
+
[](https://github.com/astral-sh/ruff)
|
|
36
|
+
[](https://github.com/pre-commit/pre-commit)
|
|
37
|
+
|
|
38
|
+
A detector-agnostic monocular **AEB (Autonomous Emergency Braking) / FCW (Forward Collision Warning)** decision chain: detection → tracking → in-path filtering → ranging → TTC → risk decision.
|
|
39
|
+
|
|
40
|
+
The two core strengths are **calibration-free scale TTC** — which relies only on the rate of change of a target's image size and does not depend on camera intrinsics or distortion calibration — and **speed-adaptive risk thresholds**, where the AEB trigger point shifts with ego speed. The detector is pluggable: the YOLOv8 backend (`yolo` extra) and the high-accuracy D-FINE backend (`dfine` extra) both implement the same `BaseDetector` interface, and the decision chain consumes only `[x1, y1, x2, y2, score, class]`.
|
|
41
|
+
|
|
42
|
+
> 中文说明见 [README.zh-CN.md](README.zh-CN.md)。
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Features
|
|
47
|
+
|
|
48
|
+
- **Detector-agnostic contract** — the decision chain is decoupled from any specific detector and works with the 7 AEB classes (person / rider / car / truck / bus / bike / motor).
|
|
49
|
+
- **Calibration-free scale TTC** — `τ = s / ṡ`, estimated via a Theil–Sen robust fit of `(t, 1/s)`; no camera calibration required.
|
|
50
|
+
- **Distance TTC + fusion** — a ground-plane ranging model recovers closing speed, fused with scale TTC by taking the minimum, with a `persist_k` frame hold to suppress jitter.
|
|
51
|
+
- **Speed-adaptive thresholds** — `τ_AEB(v) = t_react + v / (2·a_max)`, with fixed lead margins for FCW / ATTENTION on top; the whole decision gradient shifts with ego speed.
|
|
52
|
+
- **Per-video self-calibration** — jointly estimates the ranging scale `f·H` and the horizon `horizon_y` from GPS ego speed + calibration-free scale TTC, removing the per-video camera-parameter inconsistency in BDD100K.
|
|
53
|
+
- **Bundled ByteTrack** — the tracker is vendored into the package (`aeb/tracker/vendor/bytetrack/`) and distributed with the wheel; no separate installation needed.
|
|
54
|
+
|
|
55
|
+
## Pipeline
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
video frame → detection (YOLOv8 / D-FINE)
|
|
59
|
+
→ tracking (ByteTrack)
|
|
60
|
+
→ in-path filtering (fixed trapezoid ROI, ego-path corridor projection)
|
|
61
|
+
→ ranging (ground-plane model, D = f·H / (y_bottom − horizon))
|
|
62
|
+
→ TTC (scale τ and distance τ fused via min)
|
|
63
|
+
→ decision (state machine NORMAL → ATTENTION → FCW → AEB_WARNING)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The risk state machine only escalates while a target is inside the ego-path corridor (`in_path = True`); targets outside the path stay at `NORMAL`, avoiding false triggers from adjacent-lane vehicles.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Installation
|
|
71
|
+
|
|
72
|
+
Requires Python ≥ 3.10.
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip install -e .
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Runtime dependencies:
|
|
79
|
+
|
|
80
|
+
| Dependency | Purpose | Notes |
|
|
81
|
+
| --- | --- | --- |
|
|
82
|
+
| `numpy` / `scipy` | numeric computation / Theil–Sen fit | `scipy` is also a transitive dependency of ByteTrack |
|
|
83
|
+
| `opencv-python` | image I/O, ROI, visualization | |
|
|
84
|
+
| `lap` | ByteTrack matching (linear assignment) | see below |
|
|
85
|
+
|
|
86
|
+
**About `lap`**: `lap` is the linear-assignment solver used by ByteTrack matching. If no `lap` wheel exists for your platform/Python, install `lapx` instead — it is an alternative distribution of `lap` that ships a module named `lap`:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
pip install lapx
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Note: this project does **not** fall back in code. When `lap` is missing, installing `lapx` as above is enough (it provides the module name `lap`, so no code changes are needed).
|
|
93
|
+
|
|
94
|
+
ByteTrack itself is vendored as a **minimal subset** (`aeb/tracker/vendor/bytetrack/`, MIT License) and installed with the wheel, so both `pip install -e .` and a regular `pip install` work without fetching the upstream repository. To use an external/full ByteTrack instead:
|
|
95
|
+
|
|
96
|
+
| Environment variable | Meaning |
|
|
97
|
+
| --- | --- |
|
|
98
|
+
| `BYTETRACK_ROOT` | ByteTrack repository root (containing `yolox/tracker/`), overriding the bundled vendor default |
|
|
99
|
+
|
|
100
|
+
If `pip install -e .` aborts because no `lap` wheel is available for your platform, install `lapx` first, then install this package while skipping dependency resolution:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
pip install lapx
|
|
104
|
+
pip install -e . --no-deps
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Optional high-accuracy backend D-FINE** additionally requires the PyTorch ecosystem:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
pip install -e ".[dfine]" # torch / torchvision / pillow
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**About Windows**: `torch` requires the Microsoft Visual C++ runtime; on some machines (especially lab/clean-room environments) its absence shows up as `OSError: [WinError 126] ... c10.dll` failing to load. Installing the [VC++ Redistributable (x64)](https://aka.ms/vs/17/release/vc_redist.x64.exe) once resolves it. (The `--demo` zero-data demo does not import torch, so it does not need this.)
|
|
114
|
+
|
|
115
|
+
On Windows consoles whose code page is not UTF-8, non-ASCII text (for example in your own file paths, or in messages coming from third-party libraries) can still raise `UnicodeEncodeError`; run `set PYTHONUTF8=1` first. Linux/macOS and UTF-8 consoles are unaffected.
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Quick start
|
|
120
|
+
|
|
121
|
+
### Zero-data demo (no video / no weights)
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
python examples/quickstart.py --demo
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
This command drives a synthetic detector that generates a target closing at constant speed, and runs the full detection → tracking → ranging → TTC → decision chain, printing state changes frame by frame:
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
[quickstart] ego speed = 12 m/s, AEB threshold = 1.37s
|
|
131
|
+
[quickstart] target closing at a constant 10 m/s; printing the risk state per frame:
|
|
132
|
+
frame 0: NORMAL d= 45.0m ttc= infs
|
|
133
|
+
frame 39: ATTENTION d= 32.0m ttc= 3.36s
|
|
134
|
+
frame 69: FCW d= 22.0m ttc= 2.36s
|
|
135
|
+
frame 99: AEB d= 12.1m ttc= 1.36s
|
|
136
|
+
[quickstart] done, 120 frames
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Available options: `--out video.mp4` (write a visualization video), `--show` (live window), `--frames` / `--fps` / `--v-close`. `--demo` mode does **not** require `ultralytics` / `torch`; it depends only on numpy / scipy / opencv-python / lap.
|
|
140
|
+
|
|
141
|
+
Dependency self-check:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
python examples/quickstart.py --check
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Real video
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
python examples/demo_aeb.py --source video.mp4 --coco --out out.mp4
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
- `--coco`: maps COCO classes to the 7 AEB classes when using COCO-pretrained weights (e.g. `yolov8n.pt`); omit it when using AEB-finetuned weights.
|
|
154
|
+
- `--ego-speed`: ego speed (m/s); when omitted, GPS speed is read from BDD100K `samples-1k/info/*.json` automatically, falling back to `12 m/s` when unavailable.
|
|
155
|
+
- `--detector dfine`: switch to the D-FINE backend (see below).
|
|
156
|
+
|
|
157
|
+
You may also pass an image directory via `--source ./frames_dir`.
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Detector backends
|
|
162
|
+
|
|
163
|
+
### YOLOv8 (optional backend, `yolo` extra)
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
pip install -e ".[yolo]" # ultralytics (AGPL-3.0)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
from aeb.detectors import YOLOv8Detector, COCO_TO_AEB
|
|
171
|
+
|
|
172
|
+
det = YOLOv8Detector(
|
|
173
|
+
"yolov8n.pt", conf=0.25, device="0", class_map=COCO_TO_AEB
|
|
174
|
+
) # class_map=None for finetuned weights
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Optional high-accuracy backend: D-FINE
|
|
178
|
+
|
|
179
|
+
D-FINE depends on its upstream repository, located via environment variables to avoid hardcoding local paths:
|
|
180
|
+
|
|
181
|
+
| Environment variable | Meaning |
|
|
182
|
+
| --- | --- |
|
|
183
|
+
| `DFINE_ROOT` | D-FINE upstream repository root (containing `src/`, `configs/`) |
|
|
184
|
+
| `MONO_AEB_DFINE_WEIGHTS` | path to finetuned weights (`.pth`) |
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
export DFINE_ROOT=/path/to/D-FINE
|
|
188
|
+
export MONO_AEB_DFINE_WEIGHTS=/path/to/best_stg1.pth
|
|
189
|
+
python examples/demo_aeb.py --source video.mp4 --detector dfine
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Or pass the arguments directly in code:
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
from aeb.detectors import DFineDetector
|
|
196
|
+
|
|
197
|
+
det = DFineDetector(weights="/path/to/best_stg1.pth") # config defaults to dfine_hgnetv2_m_aeb.yml
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
> ⚠️ **Note**: D-FINE's finetuned weights are trained on BDD100K and are subject to that dataset's license (see below); they are not distributed with this repository.
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Weights & data
|
|
205
|
+
|
|
206
|
+
> ⚠️ **Compliance note**: this repository does not contain any model weights or BDD100K videos/annotations.
|
|
207
|
+
|
|
208
|
+
- **COCO-pretrained YOLOv8 weights** (e.g. `yolov8n.pt`) are provided by ultralytics and obtained under ultralytics' license.
|
|
209
|
+
- **AEB-finetuned weights** (YOLOv8 or D-FINE) are finetuned on BDD100K, whose license is "academic/non-commercial use only, no redistribution of raw data". These weights are therefore not published here; they are distributed on a restricted basis (on request). Anyone with legitimate data and license access can reproduce them with this repository's training configuration.
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## Project structure
|
|
214
|
+
|
|
215
|
+
```
|
|
216
|
+
mono-aeb/
|
|
217
|
+
├── aeb/
|
|
218
|
+
│ ├── config.py # camera / ego-path / risk thresholds / detection & tracking params
|
|
219
|
+
│ ├── types.py # Detection / Track / RiskFeature / RiskLevel contracts
|
|
220
|
+
│ ├── pipeline.py # AEBPipeline main chain
|
|
221
|
+
│ ├── calibration.py # per-video self-calibration (joint f·H & horizon estimation)
|
|
222
|
+
│ ├── ego_speed.py # GPS speed from BDD100K info/*.json
|
|
223
|
+
│ ├── detectors/ # BaseDetector + YOLOv8 + D-FINE
|
|
224
|
+
│ ├── tracker/ # ByteTrack adapter + cython_bbox numpy shim
|
|
225
|
+
│ │ └── vendor/bytetrack/ # vendored ByteTrack (MIT, minimal subset, shipped with wheel)
|
|
226
|
+
│ ├── distance/ # ground-plane ranging
|
|
227
|
+
│ ├── ttc/ # scale TTC / distance TTC / fusion / track history
|
|
228
|
+
│ ├── in_path/ # fixed trapezoid ROI (ego-path corridor)
|
|
229
|
+
│ └── decision/ # risk state machine
|
|
230
|
+
├── examples/
|
|
231
|
+
│ ├── quickstart.py # one-shot demo (--demo / --check)
|
|
232
|
+
│ ├── demo_aeb.py # offline real-video demo
|
|
233
|
+
│ └── calibrate_video.py # per-video self-calibration CLI
|
|
234
|
+
├── pyproject.toml
|
|
235
|
+
├── LICENSE
|
|
236
|
+
└── README.md
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## Core principles
|
|
242
|
+
|
|
243
|
+
### Ranging (ground-plane model)
|
|
244
|
+
|
|
245
|
+
Assuming a flat ground plane with camera height `H` and focal length `f` (which enter ranging only through their product `f·H`, a scale degeneracy):
|
|
246
|
+
|
|
247
|
+
$$
|
|
248
|
+
D = \frac{f \cdot H}{y_{bottom} - y_{horizon}}
|
|
249
|
+
$$
|
|
250
|
+
|
|
251
|
+
`f·H` and `horizon_y` are calibrated per video (see below), not from global intrinsics.
|
|
252
|
+
|
|
253
|
+
### Calibration-free scale TTC
|
|
254
|
+
|
|
255
|
+
For a target's image size `s` (box height or width), its rate of change is related to closing speed, independent of camera calibration:
|
|
256
|
+
|
|
257
|
+
$$
|
|
258
|
+
\tau_{scale} = \frac{s}{\dot{s}}
|
|
259
|
+
$$
|
|
260
|
+
|
|
261
|
+
In implementation, a Theil–Sen robust linear fit is applied to `(t, 1/s)`, yielding slope `b`, so `τ_scale = −1 / (b · s_now)`. Theil–Sen takes the median of pairwise slopes and has a breakdown point of about `29%` (`1 − 1/√2`), robust to a significant fraction of outliers — better than ordinary least squares, whose breakdown point is `0`.
|
|
262
|
+
|
|
263
|
+
### Distance TTC and fusion
|
|
264
|
+
|
|
265
|
+
From the ranging sequence `(t, D)`, fit the closing speed `v_close = −slope`, then `τ_distance = D / v_close`. The two sources are fused by taking the more conservative one:
|
|
266
|
+
|
|
267
|
+
$$
|
|
268
|
+
\tau_{fused} = \min(\tau_{scale}, \tau_{distance})
|
|
269
|
+
$$
|
|
270
|
+
|
|
271
|
+
with a `persist_k` frame hold to suppress single-frame jitter.
|
|
272
|
+
|
|
273
|
+
### Risk state machine
|
|
274
|
+
|
|
275
|
+
```
|
|
276
|
+
NORMAL(0) → ATTENTION(1) → FCW(2) → AEB_WARNING(3)
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
The AEB trigger threshold adapts to ego speed (`t_react` reaction time, `a_max` emergency-braking max deceleration):
|
|
280
|
+
|
|
281
|
+
$$
|
|
282
|
+
\tau_{AEB}(v) = t_{react} + \frac{v}{2 \cdot a_{max}}
|
|
283
|
+
$$
|
|
284
|
+
|
|
285
|
+
FCW / ATTENTION add fixed lead margins on top (defaults `+1.0s` / `+2.0s`). Escalation is immediate; de-escalation has hysteresis to avoid oscillation around thresholds. Required deceleration (**reserved, not currently wired into the state machine**):
|
|
286
|
+
|
|
287
|
+
$$
|
|
288
|
+
a_{req} = \frac{v_{close}^2}{2 \cdot (D - d_{safe})}
|
|
289
|
+
$$
|
|
290
|
+
|
|
291
|
+
Defaults are in `aeb/config.py` (`t_react=0.5`, `a_max=6.86 m/s²`, `d_safe=5.0 m`, `history_len=10`, `persist_k=3`, `fps=30`).
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
## Per-video calibration
|
|
296
|
+
|
|
297
|
+
BDD100K is crowdsourced, so cameras differ per video and there are no unified intrinsics. This repository provides two calibrations:
|
|
298
|
+
|
|
299
|
+
1. **Ego speed + scale TTC** (primary entry point): for approximately stationary targets `D = v_ego · τ_scale`, then a Theil–Sen line fit over `(1/D, y_bottom)` jointly solves the slope `f·H` and the intercept `horizon_y` (`aeb/calibration.py: estimate_ground_plane`).
|
|
300
|
+
2. **Known target width (reserved)**: `CameraConfig.calibrate_from_known_width()` (currently no call site, kept as a reserved interface) recovers camera height from how pixel width changes with `(y_bottom − horizon)`.
|
|
301
|
+
|
|
302
|
+
CLI:
|
|
303
|
+
|
|
304
|
+
```bash
|
|
305
|
+
python examples/calibrate_video.py --stem 0571873b-faf718b2
|
|
306
|
+
# or
|
|
307
|
+
python examples/calibrate_video.py --video /path/to/samples-1k/videos/xxxx.mov --max-frames 200
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
`--stem` mode locates the video directory via the `BDD100K_VIDEO_DIR` environment variable (defaults to the current directory).
|
|
311
|
+
|
|
312
|
+
---
|
|
313
|
+
|
|
314
|
+
## Development & testing
|
|
315
|
+
|
|
316
|
+
Zero-data test suite: no video, detection weights, or network needed — only the core dependencies (numpy / scipy / opencv-python / lap).
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
pip install -e ".[dev]" # or just pip install pytest
|
|
320
|
+
pytest -q --cov=aeb --cov-report=term-missing
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
| Test | Verifies |
|
|
324
|
+
| --- | --- |
|
|
325
|
+
| `tests/test_ttc_synthetic.py` | synthetic closing scenarios: ranging recovery (median relative error < 10%), dual-source TTC, monotonic four-level state-machine escalation |
|
|
326
|
+
| `tests/test_calibration_horizon_synthetic.py` | joint calibration recovers `horizon_y` (truth 320 / 360 / 400, tolerance 8 px) |
|
|
327
|
+
| `tests/test_bytetrack_vendor.py` | vendored ByteTrack runs without Cython extensions (numpy shim, numpy≥1.24 alias restoration, real tracked output) |
|
|
328
|
+
| `tests/test_import_smoke.py` | import chain, ROI trapezoid derivation, 7-class per-class tracker |
|
|
329
|
+
| `tests/test_quickstart_demo.py` | end-to-end `examples/quickstart.py`, asserting the level progression promised in the README |
|
|
330
|
+
|
|
331
|
+
**Coverage**: the zero-data suite covers **71%** of `aeb/` overall (measured 2026-10-09 on `v0.1.2`); the decision chain itself is well covered — `pipeline.py` 98%, `in_path/fixed_roi.py` 96%, `tracker/bytetrack.py` 96%, `ttc/*` 84–92%, `calibration.py` 85% — while `detectors/*` and `ego_speed.py` report 0% because they need the optional detector backends and real GPS data. CI prints the full per-module table on every run.
|
|
332
|
+
|
|
333
|
+
**Lint / formatting**: [`ruff`](https://github.com/astral-sh/ruff), configured in `pyproject.toml` (the vendored ByteTrack subset is excluded; CJK punctuation in comments is allowed), plus a [`pre-commit`](https://pre-commit.com/) hook set in `.pre-commit-config.yaml`. Run `pip install pre-commit && pre-commit install` to enable it locally; a dedicated CI job runs `ruff check` and `ruff format --check`.
|
|
334
|
+
|
|
335
|
+
CI (`.github/workflows/ci.yml`) runs the above tests and the zero-data demo on Ubuntu / Windows × Python 3.10 / 3.12, plus a dedicated lint job; a further job runs `pip install -e ".[yolo,dev]"`, validating full dependency resolution including the optional detector backend (yolo extra).
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
## License
|
|
340
|
+
|
|
341
|
+
This project's code is released under **Apache-2.0**; see [LICENSE](LICENSE).
|
|
342
|
+
|
|
343
|
+
## Third-party components & acknowledgments
|
|
344
|
+
|
|
345
|
+
| Component | License | Use |
|
|
346
|
+
| --- | --- | --- |
|
|
347
|
+
| [ByteTrack](https://github.com/FoundationVision/ByteTrack) | MIT | multi-object tracking (minimal subset vendored at `aeb/tracker/vendor/bytetrack/`, license text shipped with the wheel) |
|
|
348
|
+
| [D-FINE](https://github.com/Peterande/D-FINE) | Apache-2.0 | optional high-accuracy detection backend |
|
|
349
|
+
| [ultralytics (YOLOv8)](https://github.com/ultralytics/ultralytics) | AGPL-3.0 | optional detection backend (yolo extra) |
|
|
350
|
+
| [BDD100K](https://bdd-data.berkeley.edu/) | academic/non-commercial, no redistribution | training data (weights restricted) |
|
|
351
|
+
|
|
352
|
+
> ⚠️ **License note**: `ultralytics` is AGPL-3.0, which imposes copyleft obligations on derivative works and network-service scenarios. If your distribution needs to avoid those obligations, use the Apache-2.0 D-FINE detector instead (`--detector dfine`). This repository's own code is Apache-2.0.
|