flashdet 1.0.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.
- flashdet-1.0.0/LICENSE +21 -0
- flashdet-1.0.0/PKG-INFO +473 -0
- flashdet-1.0.0/README.md +414 -0
- flashdet-1.0.0/flashdet/__init__.py +23 -0
- flashdet-1.0.0/flashdet/analytics/__init__.py +19 -0
- flashdet-1.0.0/flashdet/analytics/benchmark.py +156 -0
- flashdet-1.0.0/flashdet/analytics/plots.py +226 -0
- flashdet-1.0.0/flashdet/analytics/profiler.py +199 -0
- flashdet-1.0.0/flashdet/cfg/__init__.py +5 -0
- flashdet-1.0.0/flashdet/cfg/config.py +236 -0
- flashdet-1.0.0/flashdet/cli.py +296 -0
- flashdet-1.0.0/flashdet/data/__init__.py +27 -0
- flashdet-1.0.0/flashdet/data/dataloader.py +127 -0
- flashdet-1.0.0/flashdet/data/dataset.py +210 -0
- flashdet-1.0.0/flashdet/data/prepare.py +872 -0
- flashdet-1.0.0/flashdet/data/transforms.py +345 -0
- flashdet-1.0.0/flashdet/engine/__init__.py +6 -0
- flashdet-1.0.0/flashdet/engine/callbacks.py +152 -0
- flashdet-1.0.0/flashdet/engine/exporter.py +141 -0
- flashdet-1.0.0/flashdet/engine/predictor.py +319 -0
- flashdet-1.0.0/flashdet/engine/trainer.py +585 -0
- flashdet-1.0.0/flashdet/engine/validator.py +176 -0
- flashdet-1.0.0/flashdet/losses/__init__.py +21 -0
- flashdet-1.0.0/flashdet/losses/chunked_loss.py +116 -0
- flashdet-1.0.0/flashdet/losses/focal_loss.py +162 -0
- flashdet-1.0.0/flashdet/losses/iou_loss.py +117 -0
- flashdet-1.0.0/flashdet/losses/kd_loss.py +234 -0
- flashdet-1.0.0/flashdet/models/__init__.py +50 -0
- flashdet-1.0.0/flashdet/models/assignment/__init__.py +3 -0
- flashdet-1.0.0/flashdet/models/assignment/dsl_assigner.py +187 -0
- flashdet-1.0.0/flashdet/models/backbone/__init__.py +3 -0
- flashdet-1.0.0/flashdet/models/backbone/shufflenet.py +168 -0
- flashdet-1.0.0/flashdet/models/detector.py +437 -0
- flashdet-1.0.0/flashdet/models/head/__init__.py +9 -0
- flashdet-1.0.0/flashdet/models/head/aux_head.py +117 -0
- flashdet-1.0.0/flashdet/models/head/nanodet_head.py +536 -0
- flashdet-1.0.0/flashdet/models/lora.py +869 -0
- flashdet-1.0.0/flashdet/models/neck/__init__.py +11 -0
- flashdet-1.0.0/flashdet/models/neck/conv_module.py +78 -0
- flashdet-1.0.0/flashdet/models/neck/ghost_pan.py +304 -0
- flashdet-1.0.0/flashdet/nn/__init__.py +4 -0
- flashdet-1.0.0/flashdet/registry.py +96 -0
- flashdet-1.0.0/flashdet/solutions/__init__.py +19 -0
- flashdet-1.0.0/flashdet/solutions/analytics_dashboard.py +262 -0
- flashdet-1.0.0/flashdet/solutions/distance_calculator.py +214 -0
- flashdet-1.0.0/flashdet/solutions/heatmap.py +146 -0
- flashdet-1.0.0/flashdet/solutions/live_inference.py +270 -0
- flashdet-1.0.0/flashdet/solutions/object_counter.py +152 -0
- flashdet-1.0.0/flashdet/solutions/parking_manager.py +241 -0
- flashdet-1.0.0/flashdet/solutions/queue_manager.py +178 -0
- flashdet-1.0.0/flashdet/solutions/region_counter.py +156 -0
- flashdet-1.0.0/flashdet/solutions/security_alarm.py +221 -0
- flashdet-1.0.0/flashdet/solutions/speed_estimator.py +144 -0
- flashdet-1.0.0/flashdet/solutions/workout_monitor.py +203 -0
- flashdet-1.0.0/flashdet/trackers/__init__.py +7 -0
- flashdet-1.0.0/flashdet/trackers/bot_sort.py +420 -0
- flashdet-1.0.0/flashdet/trackers/byte_tracker.py +312 -0
- flashdet-1.0.0/flashdet/trackers/sort_tracker.py +270 -0
- flashdet-1.0.0/flashdet/utils/__init__.py +22 -0
- flashdet-1.0.0/flashdet/utils/box_utils.py +203 -0
- flashdet-1.0.0/flashdet/utils/checkpoint.py +276 -0
- flashdet-1.0.0/flashdet/utils/logger.py +106 -0
- flashdet-1.0.0/flashdet/utils/metrics.py +229 -0
- flashdet-1.0.0/flashdet/utils/torchtune_optim.py +300 -0
- flashdet-1.0.0/flashdet/utils/visualization.py +253 -0
- flashdet-1.0.0/flashdet.egg-info/PKG-INFO +473 -0
- flashdet-1.0.0/flashdet.egg-info/SOURCES.txt +75 -0
- flashdet-1.0.0/flashdet.egg-info/dependency_links.txt +1 -0
- flashdet-1.0.0/flashdet.egg-info/entry_points.txt +2 -0
- flashdet-1.0.0/flashdet.egg-info/requires.txt +38 -0
- flashdet-1.0.0/flashdet.egg-info/top_level.txt +1 -0
- flashdet-1.0.0/pyproject.toml +61 -0
- flashdet-1.0.0/setup.cfg +4 -0
- flashdet-1.0.0/tests/test_callbacks.py +47 -0
- flashdet-1.0.0/tests/test_models.py +50 -0
- flashdet-1.0.0/tests/test_registry.py +59 -0
- flashdet-1.0.0/tests/test_trackers.py +56 -0
flashdet-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Gaurav Goswami
|
|
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.
|
flashdet-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: flashdet
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: FlashDet: Ultra-lightweight real-time object detection with LoRA fine-tuning and Knowledge Distillation
|
|
5
|
+
Author: FlashVision
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/FlashVision/FlashDet
|
|
8
|
+
Project-URL: Repository, https://github.com/FlashVision/FlashDet
|
|
9
|
+
Project-URL: Issues, https://github.com/FlashVision/FlashDet/issues
|
|
10
|
+
Keywords: object-detection,computer-vision,deep-learning,pytorch,lora,knowledge-distillation,nanodet,edge-ai,onnx,quantization
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Image Recognition
|
|
23
|
+
Requires-Python: >=3.8
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: torch>=2.0.0
|
|
27
|
+
Requires-Dist: torchvision>=0.15.0
|
|
28
|
+
Requires-Dist: numpy>=1.24.0
|
|
29
|
+
Requires-Dist: opencv-python>=4.8.0
|
|
30
|
+
Requires-Dist: Pillow>=9.0.0
|
|
31
|
+
Requires-Dist: pycocotools>=2.0.6
|
|
32
|
+
Requires-Dist: PyYAML>=6.0
|
|
33
|
+
Requires-Dist: tqdm>=4.65.0
|
|
34
|
+
Provides-Extra: export
|
|
35
|
+
Requires-Dist: onnx>=1.14.0; extra == "export"
|
|
36
|
+
Requires-Dist: onnxruntime>=1.15.0; extra == "export"
|
|
37
|
+
Requires-Dist: onnxsim>=0.4.0; extra == "export"
|
|
38
|
+
Provides-Extra: tracker
|
|
39
|
+
Requires-Dist: scipy>=1.10.0; extra == "tracker"
|
|
40
|
+
Requires-Dist: lap>=0.4.0; extra == "tracker"
|
|
41
|
+
Provides-Extra: solutions
|
|
42
|
+
Requires-Dist: scipy>=1.10.0; extra == "solutions"
|
|
43
|
+
Provides-Extra: analytics
|
|
44
|
+
Requires-Dist: matplotlib>=3.7.0; extra == "analytics"
|
|
45
|
+
Requires-Dist: pandas>=2.0.0; extra == "analytics"
|
|
46
|
+
Provides-Extra: all
|
|
47
|
+
Requires-Dist: onnx>=1.14.0; extra == "all"
|
|
48
|
+
Requires-Dist: onnxruntime>=1.15.0; extra == "all"
|
|
49
|
+
Requires-Dist: onnxsim>=0.4.0; extra == "all"
|
|
50
|
+
Requires-Dist: scipy>=1.10.0; extra == "all"
|
|
51
|
+
Requires-Dist: lap>=0.4.0; extra == "all"
|
|
52
|
+
Requires-Dist: matplotlib>=3.7.0; extra == "all"
|
|
53
|
+
Requires-Dist: pandas>=2.0.0; extra == "all"
|
|
54
|
+
Provides-Extra: dev
|
|
55
|
+
Requires-Dist: pytest; extra == "dev"
|
|
56
|
+
Requires-Dist: ruff; extra == "dev"
|
|
57
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
58
|
+
Dynamic: license-file
|
|
59
|
+
|
|
60
|
+
<p align="center">
|
|
61
|
+
<img src="https://img.shields.io/badge/PyTorch-2.0+-ee4c2c?logo=pytorch&logoColor=white" alt="PyTorch">
|
|
62
|
+
<img src="https://img.shields.io/badge/Python-3.8+-3776ab?logo=python&logoColor=white" alt="Python">
|
|
63
|
+
<img src="https://img.shields.io/badge/ONNX-Export-005CED?logo=onnx&logoColor=white" alt="ONNX">
|
|
64
|
+
<img src="https://img.shields.io/badge/LoRA-Fine_Tuning-ff6b6b" alt="LoRA">
|
|
65
|
+
<img src="https://img.shields.io/badge/License-MIT-green.svg" alt="License">
|
|
66
|
+
</p>
|
|
67
|
+
|
|
68
|
+
<h1 align="center">FlashDet</h1>
|
|
69
|
+
|
|
70
|
+
<p align="center">
|
|
71
|
+
<b>Ultra-lightweight real-time object detection with LoRA fine-tuning, knowledge distillation, tracking, and analytics</b>
|
|
72
|
+
</p>
|
|
73
|
+
|
|
74
|
+
<p align="center">
|
|
75
|
+
<a href="#installation">Install</a> •
|
|
76
|
+
<a href="#usage">Usage</a> •
|
|
77
|
+
<a href="#models">Models</a> •
|
|
78
|
+
<a href="#examples">Examples</a> •
|
|
79
|
+
<a href="#solutions">Solutions</a> •
|
|
80
|
+
<a href="#trackers">Trackers</a> •
|
|
81
|
+
<a href="#training">Training</a> •
|
|
82
|
+
<a href="#contributing">Contributing</a>
|
|
83
|
+
</p>
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## What is FlashDet?
|
|
88
|
+
|
|
89
|
+
FlashDet is an end-to-end object detection framework built for **speed and efficiency**. Based on the NanoDet-Plus architecture with a ShuffleNetV2 backbone, it delivers real-time inference with models as small as 0.49M parameters.
|
|
90
|
+
|
|
91
|
+
It ships as a `pip`-installable Python package with a CLI, a high-level Python API, and built-in solutions for counting, tracking, speed estimation, and more — similar to how you'd use Ultralytics YOLO.
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
pip install -e .
|
|
95
|
+
flashdet train --model-size m --epochs 100 --device cuda --train-images data/train --val-images data/val
|
|
96
|
+
flashdet predict --model best.pth --source video.mp4
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Installation
|
|
102
|
+
|
|
103
|
+
### pip (recommended)
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# Install from GitHub
|
|
107
|
+
pip install git+https://github.com/FlashVision/FlashDet.git
|
|
108
|
+
|
|
109
|
+
# With all extras (tracking, analytics, ONNX export)
|
|
110
|
+
pip install "flashdet[all] @ git+https://github.com/FlashVision/FlashDet.git"
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### From source (for development)
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
git clone https://github.com/FlashVision/FlashDet.git
|
|
117
|
+
cd FlashDet
|
|
118
|
+
pip install -e ".[all]"
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Optional extras
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
pip install -e ".[export]" # ONNX export support
|
|
125
|
+
pip install -e ".[tracker]" # ByteTracker, SORT, BoTSORT
|
|
126
|
+
pip install -e ".[solutions]" # Counting, speed, heatmaps
|
|
127
|
+
pip install -e ".[analytics]" # Benchmarking, plots
|
|
128
|
+
pip install -e ".[all]" # Everything
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Verify installation
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
flashdet check # runs full health check
|
|
135
|
+
flashdet settings # shows Python, PyTorch, CUDA, GPU info
|
|
136
|
+
flashdet version # prints version
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Usage
|
|
142
|
+
|
|
143
|
+
### Python API
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from flashdet import FlashDet, Trainer, Predictor, Exporter
|
|
147
|
+
|
|
148
|
+
# Train a model
|
|
149
|
+
trainer = Trainer(
|
|
150
|
+
model_size="m",
|
|
151
|
+
train_images="data/train",
|
|
152
|
+
val_images="data/val",
|
|
153
|
+
epochs=100,
|
|
154
|
+
device="cuda",
|
|
155
|
+
use_lora=True,
|
|
156
|
+
pretrained_coco=True,
|
|
157
|
+
)
|
|
158
|
+
trainer.train()
|
|
159
|
+
|
|
160
|
+
# Run inference
|
|
161
|
+
predictor = Predictor(model_path="workspace/best.pth", device="cuda")
|
|
162
|
+
results = predictor.predict("photo.jpg")
|
|
163
|
+
|
|
164
|
+
# Export to ONNX
|
|
165
|
+
exporter = Exporter(model_path="workspace/best.pth")
|
|
166
|
+
exporter.export(output="model.onnx", simplify=True)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### CLI
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
# Train
|
|
173
|
+
flashdet train --model-size m --epochs 100 --device cuda \
|
|
174
|
+
--train-images data/train --val-images data/val --pretrained-coco
|
|
175
|
+
|
|
176
|
+
# Predict
|
|
177
|
+
flashdet predict --model best.pth --source image.jpg --conf 0.25
|
|
178
|
+
|
|
179
|
+
# Validate
|
|
180
|
+
flashdet val --model best.pth --val-images data/val
|
|
181
|
+
|
|
182
|
+
# Export
|
|
183
|
+
flashdet export --model best.pth --output model.onnx --simplify
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Standalone Scripts
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
# Full training with LoRA
|
|
190
|
+
python train.py --lora --lora-rank 8 --epochs 50 --device cuda
|
|
191
|
+
|
|
192
|
+
# Knowledge Distillation
|
|
193
|
+
python train_kd.py --teacher-checkpoint teacher.pth --teacher-size m-1.5x --model-size m-0.5x
|
|
194
|
+
|
|
195
|
+
# Inference
|
|
196
|
+
python test.py --model best.pth --image photo.jpg
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## Models
|
|
202
|
+
|
|
203
|
+
| Model | Params | FP16 Size | INT8 Size | mAP (COCO) | GPU (ms) |
|
|
204
|
+
|-------|--------|-----------|-----------|------------|----------|
|
|
205
|
+
| **FlashDet-m-0.5x** | 0.49M | ~1.2 MB | ~0.6 MB | — | 3.8 |
|
|
206
|
+
| **FlashDet-m** | 1.17M | ~2.6 MB | ~1.3 MB | 27.0 | 5.3 |
|
|
207
|
+
| **FlashDet-m-1.5x** | 2.44M | ~5.2 MB | ~2.6 MB | 29.9 | 7.2 |
|
|
208
|
+
|
|
209
|
+
All models auto-download COCO pretrained weights on first use.
|
|
210
|
+
|
|
211
|
+
### Config-driven Training (Model Zoo)
|
|
212
|
+
|
|
213
|
+
Pick a config and train — no code changes needed:
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
flashdet train --config configs/flashdet_m_320_coco.yaml --device cuda
|
|
217
|
+
flashdet train --config configs/flashdet_m_320_lora.yaml --device cuda
|
|
218
|
+
flashdet train --config configs/flashdet_m_320_kd.yaml --device cuda
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Available configs in [`configs/`](configs/):
|
|
222
|
+
| Config | Description |
|
|
223
|
+
|--------|-------------|
|
|
224
|
+
| `flashdet_m_320_coco.yaml` | Standard FlashDet-m training on COCO |
|
|
225
|
+
| `flashdet_m_416_coco.yaml` | FlashDet-m at higher resolution |
|
|
226
|
+
| `flashdet_m15x_320_coco.yaml` | Larger model for better accuracy |
|
|
227
|
+
| `flashdet_m05x_320_coco.yaml` | Ultra-light for edge deployment |
|
|
228
|
+
| `flashdet_m_320_lora.yaml` | LoRA fine-tuning on custom data |
|
|
229
|
+
| `flashdet_m_320_kd.yaml` | Knowledge distillation |
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## Solutions
|
|
234
|
+
|
|
235
|
+
Built-in high-level applications for real-world use cases:
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
from flashdet import Predictor
|
|
239
|
+
from flashdet.solutions import ObjectCounter, SpeedEstimator, Heatmap, ParkingManager
|
|
240
|
+
from flashdet.trackers import ByteTracker
|
|
241
|
+
|
|
242
|
+
predictor = Predictor(model_path="best.pth")
|
|
243
|
+
tracker = ByteTracker()
|
|
244
|
+
|
|
245
|
+
# Count objects crossing a line
|
|
246
|
+
counter = ObjectCounter(predictor, tracker, line_points=[(100, 300), (500, 300)])
|
|
247
|
+
|
|
248
|
+
# Estimate speeds
|
|
249
|
+
estimator = SpeedEstimator(predictor, tracker, pixels_per_meter=8.0)
|
|
250
|
+
|
|
251
|
+
# Generate heatmaps
|
|
252
|
+
heatmap = Heatmap(predictor, decay=0.95)
|
|
253
|
+
|
|
254
|
+
# Monitor parking
|
|
255
|
+
parking = ParkingManager(predictor, spots_file="spots.json")
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
| Solution | Description |
|
|
259
|
+
|----------|-------------|
|
|
260
|
+
| **ObjectCounter** | Count objects crossing lines or entering regions |
|
|
261
|
+
| **SpeedEstimator** | Estimate real-world speed from tracked objects |
|
|
262
|
+
| **Heatmap** | Visualize detection density over time |
|
|
263
|
+
| **RegionCounter** | Count objects in polygon zones |
|
|
264
|
+
| **QueueManager** | Monitor queue lengths and wait times |
|
|
265
|
+
| **DistanceCalculator** | Measure real-world distances between objects |
|
|
266
|
+
| **ParkingManager** | Track parking spot occupancy |
|
|
267
|
+
| **SecurityAlarm** | Alert on intrusions into restricted zones |
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## Trackers
|
|
272
|
+
|
|
273
|
+
Multi-object tracking with persistent IDs across frames:
|
|
274
|
+
|
|
275
|
+
```python
|
|
276
|
+
from flashdet.trackers import ByteTracker, SORTTracker, BoTSORT
|
|
277
|
+
|
|
278
|
+
tracker = ByteTracker(max_age=30, min_hits=3, iou_threshold=0.3)
|
|
279
|
+
tracks = tracker.update(detections) # [x1,y1,x2,y2,track_id,score,cls]
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
| Tracker | Method | Best For |
|
|
283
|
+
|---------|--------|----------|
|
|
284
|
+
| **ByteTracker** | IoU + Kalman filter | General purpose, fast |
|
|
285
|
+
| **SORTTracker** | Simple Kalman + Hungarian | Speed-critical applications |
|
|
286
|
+
| **BoTSORT** | Appearance + motion | Crowded scenes, re-identification |
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## Training
|
|
291
|
+
|
|
292
|
+
### Standard Training
|
|
293
|
+
|
|
294
|
+
```bash
|
|
295
|
+
python train.py --model-size m --epochs 100 --batch-size 32 --device cuda --pretrained-coco
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### LoRA / QLoRA Fine-Tuning
|
|
299
|
+
|
|
300
|
+
Parameter-efficient — freeze backbone, train only low-rank adapters:
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
# LoRA (6 variants: standard, dora, lora_plus, adalora, ortho, lora_fa)
|
|
304
|
+
python train.py --lora --lora-variant dora --lora-rank 8 --lora-alpha 16
|
|
305
|
+
|
|
306
|
+
# QLoRA (quantized base weights + LoRA)
|
|
307
|
+
python train.py --qlora --qlora-dtype nf4 --lora-rank 8
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### Knowledge Distillation
|
|
311
|
+
|
|
312
|
+
Train a small student from a larger teacher:
|
|
313
|
+
|
|
314
|
+
```bash
|
|
315
|
+
python train_kd.py \
|
|
316
|
+
--teacher-checkpoint workspace/teacher/best.pth \
|
|
317
|
+
--teacher-size m-1.5x \
|
|
318
|
+
--model-size m-0.5x \
|
|
319
|
+
--kd-temperature 4.0
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### Mixed Precision & Multi-GPU
|
|
323
|
+
|
|
324
|
+
```bash
|
|
325
|
+
python train.py --amp --multi-gpu --device cuda
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
## Analytics
|
|
331
|
+
|
|
332
|
+
```python
|
|
333
|
+
from flashdet.analytics import Benchmark, Profiler
|
|
334
|
+
|
|
335
|
+
# Benchmark model speed
|
|
336
|
+
bench = Benchmark(model_path="best.pth", device="cuda")
|
|
337
|
+
results = bench.run() # {'fps': 142.3, 'latency_ms': 7.0, 'params': 1170000, ...}
|
|
338
|
+
|
|
339
|
+
# Profile layer-by-layer
|
|
340
|
+
profiler = Profiler(model_path="best.pth")
|
|
341
|
+
profiler.run() # prints per-layer timing breakdown
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
346
|
+
## Examples
|
|
347
|
+
|
|
348
|
+
Ready-to-run scripts in the [`examples/`](examples/) folder:
|
|
349
|
+
|
|
350
|
+
| Script | What it does |
|
|
351
|
+
|--------|--------------|
|
|
352
|
+
| `train_custom_dataset.py` | Train on your own COCO-format dataset |
|
|
353
|
+
| `train_with_lora.py` | LoRA fine-tuning (DoRA variant) |
|
|
354
|
+
| `predict_image.py` | Detect objects in a single image |
|
|
355
|
+
| `track_objects.py` | Multi-object tracking on video |
|
|
356
|
+
| `count_objects.py` | Count objects crossing a line |
|
|
357
|
+
| `export_onnx.py` | Export to ONNX for deployment |
|
|
358
|
+
| `benchmark_model.py` | Measure FPS and latency |
|
|
359
|
+
|
|
360
|
+
```bash
|
|
361
|
+
cd examples
|
|
362
|
+
python train_custom_dataset.py
|
|
363
|
+
python predict_image.py
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
368
|
+
## Project Structure
|
|
369
|
+
|
|
370
|
+
```
|
|
371
|
+
FlashDet/
|
|
372
|
+
├── flashdet/ # Main package (pip install -e .)
|
|
373
|
+
│ ├── __init__.py # Public API
|
|
374
|
+
│ ├── cli.py # CLI entry point (flashdet command)
|
|
375
|
+
│ ├── registry.py # Pluggable component registry
|
|
376
|
+
│ ├── cfg/ # Configuration + YAML loading
|
|
377
|
+
│ ├── data/ # Datasets, loaders, transforms
|
|
378
|
+
│ ├── engine/ # Trainer, Validator, Predictor, Exporter, Callbacks
|
|
379
|
+
│ ├── models/ # ShuffleNetV2, GhostPAN, NanoDet head, LoRA
|
|
380
|
+
│ ├── losses/ # QFL, GIoU, DFL, KD losses
|
|
381
|
+
│ ├── nn/ # Neural network building blocks
|
|
382
|
+
│ ├── utils/ # Metrics, visualization, checkpoint
|
|
383
|
+
│ ├── trackers/ # ByteTracker, SORT, BoTSORT
|
|
384
|
+
│ ├── solutions/ # Counting, speed, heatmaps, parking, security
|
|
385
|
+
│ └── analytics/ # Benchmark, profiling, plots
|
|
386
|
+
├── configs/ # YAML configs for model zoo (pick & train)
|
|
387
|
+
├── examples/ # Ready-to-run example scripts
|
|
388
|
+
├── tests/ # Unit tests (pytest)
|
|
389
|
+
├── docker/ # Dockerfile + docker-compose
|
|
390
|
+
├── train.py # Training script (LoRA, QLoRA, AMP, multi-GPU)
|
|
391
|
+
├── train_kd.py # Knowledge Distillation script
|
|
392
|
+
├── test.py # Inference script
|
|
393
|
+
├── scripts/ # ONNX export, quantization, data prep
|
|
394
|
+
├── pyproject.toml # Package configuration
|
|
395
|
+
├── CONTRIBUTING.md # How to contribute
|
|
396
|
+
├── CHANGELOG.md # Version history
|
|
397
|
+
└── LICENSE # MIT
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
---
|
|
401
|
+
|
|
402
|
+
## Training Callbacks
|
|
403
|
+
|
|
404
|
+
Extend the training loop without modifying source code:
|
|
405
|
+
|
|
406
|
+
```python
|
|
407
|
+
from flashdet import Trainer
|
|
408
|
+
from flashdet.engine.callbacks import EarlyStopping, CSVLogger, TensorBoardCallback
|
|
409
|
+
|
|
410
|
+
trainer = Trainer(model_size="m", train_images="data/train", val_images="data/val")
|
|
411
|
+
|
|
412
|
+
trainer.add_callback(EarlyStopping(patience=20, metric="val_mAP"))
|
|
413
|
+
trainer.add_callback(CSVLogger("metrics.csv"))
|
|
414
|
+
trainer.add_callback(TensorBoardCallback("runs/exp1"))
|
|
415
|
+
|
|
416
|
+
trainer.train()
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
Built-in callbacks: `EarlyStopping`, `CSVLogger`, `TensorBoardCallback`, `LRSchedulerCallback`.
|
|
420
|
+
|
|
421
|
+
---
|
|
422
|
+
|
|
423
|
+
## Docker
|
|
424
|
+
|
|
425
|
+
```bash
|
|
426
|
+
# Build
|
|
427
|
+
docker build -t flashdet -f docker/Dockerfile .
|
|
428
|
+
|
|
429
|
+
# Run inference
|
|
430
|
+
docker run --gpus all -v $(pwd)/data:/app/data flashdet predict --model best.pth --source data/test.jpg
|
|
431
|
+
|
|
432
|
+
# Or use docker-compose
|
|
433
|
+
cd docker && docker compose up
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
---
|
|
437
|
+
|
|
438
|
+
## Supported Formats
|
|
439
|
+
|
|
440
|
+
| Import | Export |
|
|
441
|
+
|--------|--------|
|
|
442
|
+
| COCO JSON | ONNX |
|
|
443
|
+
| YOLO TXT | FP16 weights |
|
|
444
|
+
| Pascal VOC XML | TorchScript |
|
|
445
|
+
|
|
446
|
+
---
|
|
447
|
+
|
|
448
|
+
## Contributing
|
|
449
|
+
|
|
450
|
+
We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
451
|
+
|
|
452
|
+
```bash
|
|
453
|
+
git clone https://github.com/FlashVision/FlashDet.git
|
|
454
|
+
cd FlashDet
|
|
455
|
+
pip install -e ".[dev,all]"
|
|
456
|
+
ruff check flashdet/
|
|
457
|
+
flashdet check
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
---
|
|
461
|
+
|
|
462
|
+
## License
|
|
463
|
+
|
|
464
|
+
MIT License — see [LICENSE](LICENSE) for details.
|
|
465
|
+
|
|
466
|
+
---
|
|
467
|
+
|
|
468
|
+
<p align="center">
|
|
469
|
+
<a href="https://github.com/FlashVision/FlashDet">
|
|
470
|
+
<b>FlashVision</b>
|
|
471
|
+
</a>
|
|
472
|
+
— Open-source lightweight AI
|
|
473
|
+
</p>
|