273 lines
4.9 KiB
Markdown
Executable File
273 lines
4.9 KiB
Markdown
Executable File
# ByteTrack 训练与评估
|
||
|
||
> 完整训练测试流程
|
||
|
||
---
|
||
|
||
## 1. 数据准备
|
||
|
||
### 转换数据集格式
|
||
|
||
```bash
|
||
# 转换 MOT17
|
||
python3 tools/convert_mot17_to_coco.py
|
||
|
||
# 转换 MOT20
|
||
python3 tools/convert_mot20_to_coco.py
|
||
|
||
# 转换 CrowdHuman
|
||
python3 tools/convert_crowdhuman_to_coco.py
|
||
|
||
# 转换 Cityperson
|
||
python3 tools/convert_cityperson_to_coco.py
|
||
|
||
# 转换 ETHZ
|
||
python3 tools/convert_ethz_to_coco.py
|
||
```
|
||
|
||
### 混合训练数据
|
||
|
||
```bash
|
||
# 基础混合
|
||
python3 tools/mix_data_ablation.py
|
||
|
||
# 生成测试数据
|
||
python3 tools/mix_data_test_mot17.py
|
||
python3 tools/mix_data_test_mot20.py
|
||
```
|
||
|
||
---
|
||
|
||
## 2. 模型训练
|
||
|
||
### 消融实验
|
||
|
||
训练数据:CrowdHuman + MOT17 Half Train
|
||
|
||
```bash
|
||
python3 tools/train.py \
|
||
-f exps/example/mot/yolox_x_ablation.py \
|
||
-d 8 -b 48 --fp16 -o \
|
||
-c pretrained/yolox_x.pth
|
||
```
|
||
|
||
### MOT17 完整训练
|
||
|
||
训练数据:CrowdHuman + MOT17 + Cityperson + ETHZ
|
||
|
||
```bash
|
||
python3 tools/train.py \
|
||
-f exps/example/mot/yolox_x_mix_det.py \
|
||
-d 8 -b 48 --fp16 -o \
|
||
-c pretrained/yolox_x.pth
|
||
```
|
||
|
||
### MOT20 训练
|
||
|
||
训练数据:CrowdHuman + MOT20
|
||
|
||
> ⚠️ **注意**:MOT20 需要裁剪边界框
|
||
|
||
在 `data_augment.py` 第 134-135 行添加裁剪操作:
|
||
```python
|
||
# clip border
|
||
x1 = max(0, x1)
|
||
y1 = max(0, y1)
|
||
```
|
||
|
||
```bash
|
||
python3 tools/train.py \
|
||
-f exps/example/mot/yolox_x_mix_mot20_ch.py \
|
||
-d 8 -b 48 --fp16 -o \
|
||
-c pretrained/yolox_x.pth
|
||
```
|
||
|
||
---
|
||
|
||
## 3. 模型评估
|
||
|
||
### MOT17 Half Val
|
||
|
||
```bash
|
||
# ByteTrack
|
||
python3 tools/track.py \
|
||
-f exps/example/mot/yolox_x_ablation.py \
|
||
-c pretrained/bytetrack_ablation.pth.tar \
|
||
-b 1 -d 1 --fp16 --fuse
|
||
|
||
# 其他 Tracker 对比
|
||
python3 tools/track_sort.py -f exps/example/mot/yolox_x_ablation.py \
|
||
-c pretrained/bytetrack_ablation.pth.tar -b 1 -d 1 --fp16 --fuse
|
||
|
||
python3 tools/track_deepsort.py -f exps/example/mot/yolox_x_ablation.py \
|
||
-c pretrained/bytetrack_ablation.pth.tar -b 1 -d 1 --fp16 --fuse
|
||
|
||
python3 tools/track_motdt.py -f exps/example/mot/yolox_x_ablation.py \
|
||
-c pretrained/bytetrack_ablation.pth.tar -b 1 -d 1 --fp16 --fuse
|
||
```
|
||
|
||
### MOT17 测试集
|
||
|
||
```bash
|
||
# 追踪
|
||
python3 tools/track.py \
|
||
-f exps/example/mot/yolox_x_mix_det.py \
|
||
-c pretrained/bytetrack_x_mot17.pth.tar \
|
||
-b 1 -d 1 --fp16 --fuse
|
||
|
||
# 轨迹插值(提升性能)
|
||
python3 tools/interpolation.py
|
||
```
|
||
|
||
提交 txt 文件到 [MOTChallenge](https://motchallenge.net/) 可获得 **79+ MOTA**。
|
||
|
||
### MOT20 测试集
|
||
|
||
```bash
|
||
# 编辑输入尺寸 (yolox_x_mix_mot20_ch.py)
|
||
# MOT20-04, MOT20-07: 1600 x 896
|
||
# MOT20-06, MOT20-08: 1920 x 736
|
||
|
||
# 追踪
|
||
python3 tools/track.py \
|
||
-f exps/example/mot/yolox_x_mix_mot20_ch.py \
|
||
-c pretrained/bytetrack_x_mot20.pth.tar \
|
||
-b 1 -d 1 --fp16 --fuse \
|
||
--match_thresh 0.7 --mot20
|
||
|
||
# 插值
|
||
python3 tools/interpolation.py
|
||
```
|
||
|
||
---
|
||
|
||
## 4. 使用自己的检测器
|
||
|
||
### 传入检测结果
|
||
|
||
```python
|
||
from yolox.tracker.byte_tracker import BYTETracker
|
||
|
||
# 初始化
|
||
args = # 你的参数
|
||
tracker = BYTETracker(args)
|
||
|
||
# 逐帧处理
|
||
for image in images:
|
||
# 你的检测器
|
||
dets = your_detector(image) # 格式: (N, 5) [x1, y1, x2, y2, score]
|
||
|
||
# 追踪更新
|
||
online_targets = tracker.update(dets, info_imgs, img_size)
|
||
|
||
# 获取结果
|
||
for target in online_targets:
|
||
tlwh = target.tlwh # 轨迹框
|
||
track_id = target.track_id # ID
|
||
score = target.score # 置信度
|
||
```
|
||
|
||
### 参考代码
|
||
|
||
详见 `yolox/evaluators/mot_evaluator.py`
|
||
|
||
---
|
||
|
||
## 5. 视频演示
|
||
|
||
```bash
|
||
# 视频追踪
|
||
python3 tools/demo_track.py video \
|
||
-f exps/example/mot/yolox_x_mix_det.py \
|
||
-c pretrained/bytetrack_x_mot17.pth.tar \
|
||
--fp16 --fuse --save_result
|
||
```
|
||
|
||
结果保存在 `YOLOX_outputs/`
|
||
|
||
---
|
||
|
||
## 6. 参数调优
|
||
|
||
### 关键参数
|
||
|
||
| 参数 | 说明 | 调优建议 |
|
||
|------|------|----------|
|
||
| `track_thresh` | 检测阈值 | 0.5-0.6 效果较好 |
|
||
| `match_thresh` | IoU 匹配阈值 | 0.8 常用 |
|
||
| `match_thresh` (MOT20) | MOT20 阈值 | 0.7 |
|
||
| `track_buffer` | 轨迹缓冲帧数 | 30 |
|
||
| `frame_rate` | 目标帧率 | 30 |
|
||
|
||
### MOT17 测试集优化
|
||
|
||
获得 **80+ MOTA** 的技巧:
|
||
1. 仔细调整每个序列的测试图像尺寸
|
||
2. 调整每个序列的高分检测阈值
|
||
3. 使用轨迹插值
|
||
|
||
---
|
||
|
||
## 7. 自定义数据集
|
||
|
||
### 1. 准备数据(COCO 格式)
|
||
|
||
```bash
|
||
# 转换为 COCO 格式
|
||
python3 tools/convert_mot17_to_coco.py
|
||
```
|
||
|
||
### 2. 创建 Exp 文件
|
||
|
||
参考 `exps/example/mot/yolox_x_ch.py`
|
||
|
||
### 3. 修改配置
|
||
|
||
```python
|
||
class MyExp(YOLOXExp):
|
||
def get_data_loader(self):
|
||
# 返回训练数据加载器
|
||
...
|
||
|
||
def get_eval_loader(self):
|
||
# 返回评估数据加载器
|
||
...
|
||
```
|
||
|
||
### 4. 训练
|
||
|
||
```bash
|
||
python3 tools/train.py \
|
||
-f exps/example/mot/my_exp.py \
|
||
-d 8 -b 48 --fp16 -o \
|
||
-c pretrained/yolox_x.pth
|
||
```
|
||
|
||
---
|
||
|
||
## 8. 部署推理
|
||
|
||
### ONNX 导出
|
||
|
||
详见 `deploy/ONNXRuntime/`
|
||
|
||
### TensorRT 部署
|
||
|
||
```bash
|
||
# Python
|
||
deploy/TensorRT/python/
|
||
|
||
# C++
|
||
deploy/TensorRT/cpp/
|
||
```
|
||
|
||
### DeepStream
|
||
|
||
```bash
|
||
deploy/DeepStream/
|
||
```
|
||
|
||
---
|
||
|
||
> 参考:[ByteTrack GitHub](https://github.com/FoundationVision/ByteTrack)
|