Files
yolov26_3d/eval_tools/docs/ROI_FIX_GUIDE.md
2026-06-24 09:35:46 +08:00

147 lines
3.4 KiB
Markdown
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ROI坐标转换问题解决方案
## 问题描述
评测结果中precision和recall都为0经过诊断发现是**ROI坐标转换问题**。
## 根本原因
1. **检测结果使用ROI坐标系**:保存在`txt_results`中的检测框坐标是在ROI裁剪区域的坐标系中尺寸: 704x352
2. **Ground Truth使用原图坐标系**GT标注使用的是归一化的原图坐标尺寸: 1920x1080
3. **坐标不匹配导致IoU=0**两个坐标系不一致所有框的IoU都是0无法匹配
## ROI参数
针对`evalset_roi0`数据集:
- **ROI区域**: [0, 120, 1920, 1080] (xyxy格式)
- **ROI输入尺寸**: 704 x 352 (模型输入尺寸)
- **原图尺寸**: 1920 x 1080
### 坐标转换公式
检测框从ROI坐标转换到原图坐标
```python
# 1. 缩放
scale_x = (1920 - 0) / 704 = 2.7273
scale_y = (1080 - 120) / 352 = 2.7273
x1_scaled = x1 * scale_x
x2_scaled = x2 * scale_x
y1_scaled = y1 * scale_y
y2_scaled = y2 * scale_y
# 2. 偏移
x1_final = x1_scaled + 0
x2_final = x2_scaled + 0
y1_final = y1_scaled + 120
y2_final = y2_scaled + 120
```
## 解决方案
### 1. 修改DetectionParser
`parser.py`中添加ROI缩放和偏移支持
```python
def __init__(self, roi_offset=None, roi_scale=None):
self.roi_offset = roi_offset or (0, 0)
self.roi_scale = roi_scale or (1.0, 1.0)
```
在解析2D框时应用转换
```python
# 先缩放
x1 *= self.roi_scale[0]
x2 *= self.roi_scale[0]
y1 *= self.roi_scale[1]
y2 *= self.roi_scale[1]
# 再偏移
x1 += self.roi_offset[0]
y1 += self.roi_offset[1]
x2 += self.roi_offset[0]
y2 += self.roi_offset[1]
```
### 2. 更新Evaluator和eval.py
添加`roi_offset``roi_scale`参数传递。
### 3. 更新命令行参数
```bash
--roi 0 120 1920 1080 # ROI区域
--roi-input-size 704 352 # ROI输入尺寸
```
## 验证结果
### 修复前
```
GT bbox range: x=[18.0, 1919.0], y=[465.0, 751.0]
Det bbox range: x=[9.5, 704.6], y=[126.1, 236.8]
IoU: 0.0000
Matches: 0
```
### 修复后
```
GT bbox range: x=[18.0, 1919.0], y=[465.0, 751.0]
Det bbox range (scaled): x=[25.9, 1921.6], y=[463.9, 765.8]
Matches: 16/20
First match IoU: 0.8397
```
### 评测结果100帧测试
```
2D Metrics:
Precision: 0.9141
Recall: 0.6105
mAP: 0.2066
3D Metrics:
pedestrian: Lat=0.795m, Long=1.726m, Head=1.140rad (n=8)
vehicle: Lat=0.987m, Long=1.731m, Head=0.247rad (n=995)
```
## 使用方法
### 完整评测81443帧
```bash
bash eval_tools/run_evaluation_example.sh
```
### 快速测试100帧
```bash
bash eval_tools/run_evaluation_quick_test.sh
```
### 手动运行
```bash
python eval_tools/eval.py \
--det-path /path/to/detections \
--gt-path /path/to/gt \
--output-dir results \
--img-width 1920 \
--img-height 1080 \
--roi 0 120 1920 1080 \
--roi-input-size 704 352
```
## 注意事项
1. **ROI1的参数不同**如果评测ROI1的结果需要修改ROI参数
2. **不同模型的输入尺寸可能不同**:根据实际模型调整`--roi-input-size`
3. **大数据集评测耗时**81443帧约需10-20分钟建议先用quick test验证
## 相关文件
- `eval_tools/evaluator/parser.py` - 添加ROI转换逻辑
- `eval_tools/evaluator/evaluator.py` - 传递ROI参数
- `eval_tools/eval.py` - 命令行参数处理
- `eval_tools/run_evaluation_example.sh` - 完整评测脚本
- `eval_tools/run_evaluation_quick_test.sh` - 快速测试脚本