"src/targets/gpu/vscode:/vscode.git/clone" did not exist on "3272b22e95ac6b1b4b5fe48aa8fe32f0dd1e912f"
README.md 6.79 KB
Newer Older
chenych's avatar
chenych committed
1
2
# HDETR
## 论文
3
4
`DETRs with Hybrid Matching`
- https://arxiv.org/abs/2207.13080
chenych's avatar
chenych committed
5
6

## 模型结构
7
基于DETR结构,在匹配阶段加入一对多的匹配分支。
chenych's avatar
chenych committed
8
9
10
11
12
13

<div align=center>
    <img src="./doc/hybrid.png"/>
</div>

## 算法原理
14
H-DETR引入一对多匹配分支,将原始的一对一匹配分支与一个辅助的一对多匹配分支结合起来,允许多个查询分配给每个正样本,增加正样本查询数量,提高训练效果。此外,H-DETR在推理过程中仍然使用原始的一对一匹配分支,以保持DETR的优势。
chenych's avatar
chenych committed
15
16
17
18
19
20
21

<div align=center>
    <img src="./doc/methods.png"/>
</div>

## 环境配置
### Docker(方法一)
22
-v 路径、docker_name和imageID根据实际情况修改
chenych's avatar
chenych committed
23

24
```bash
shantf's avatar
shantf committed
25
26
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.1.0-ubuntu20.04-dtk24.04.1-py3.10
docker run -it -v /path/your_code_data/:/path/your_code_data/ --shm-size=80G --privileged=true --device=/dev/kfd --device=/dev/dri/ -v /opt/hyhal:/opt/hyhal:ro --group-add video --name docker_name imageID bash
chenych's avatar
chenych committed
27

chenych's avatar
chenych committed
28
cd /your_code_path/hdetr_pytorch
chenych's avatar
chenych committed
29
pip install -r requirements.txt
30
31
32
33

pip install openmim
mim install mmcv-full  (注意版本是不是1.7.1)
pip install mmdet==2.26.0 (对应mmcv 1.7.1)
chenych's avatar
chenych committed
34
35
36
```

### Dockerfile(方法二)
37
38
-v 路径、docker_name和imageID根据实际情况修改
```bash
chenych's avatar
chenych committed
39
40
41
cd ./docker

docker build --no-cache -t hdetr:latest .
shantf's avatar
shantf committed
42
docker run -it -v /path/your_code_data/:/path/your_code_data/ --shm-size=80G --privileged=true --device=/dev/kfd --device=/dev/dri/ -v /opt/hyhal:/opt/hyhal:ro --group-add video --name docker_name imageID bash
chenych's avatar
chenych committed
43

44
45
cd /your_code_path/hdetr_pytorch
pip install -r requirements.txt
chenych's avatar
chenych committed
46

47
48
49
pip install openmim
mim install mmcv-full  (注意版本是不是1.7.1)
pip install mmdet==2.26.0 (对应mmcv 1.7.1)
chenych's avatar
chenych committed
50
```
51
52
53
54

### Anaconda(方法三)
关于本项目DCU显卡所需的特殊深度学习库可从[光合](https://developer.hpccube.com/tool/)开发者社区下载安装。
```bash
chenych's avatar
chenych committed
55
DTK软件栈: dtk23.04.1
shantf's avatar
shantf committed
56
57
58
python: python3.10
torch: 2.1.0
torchvision: 0.16.0
chenych's avatar
chenych committed
59
```
60
`Tips:以上dtk软件栈、python、torch等DCU相关工具版本需要严格一一对应`
chenych's avatar
chenych committed
61

62
63
64
其他非特殊库直接按照requirements.txt安装:
```bash
pip install -r requirements.txt
chenych's avatar
chenych committed
65

66
67
68
pip install openmim
mim install mmcv-full  (注意版本是不是1.7.1)
pip install mmdet==2.26.0 (对应mmcv 1.7.1)
chenych's avatar
chenych committed
69
70
71
```

## 数据集
72
通过SCNet下载[COCO2017](http://113.200.138.88:18080/aidatasets/coco2017)所需数据集:
chenych's avatar
chenych committed
73

74
[训练数据](http://113.200.138.88:18080/aidatasets/coco2017/-/blob/main/train2017.zip)
chenych's avatar
chenych committed
75

76
[验证数据](http://113.200.138.88:18080/aidatasets/coco2017/-/blob/main/val2017.zip)
chenych's avatar
chenych committed
77

78
[测试数据](http://113.200.138.88:18080/aidatasets/coco2017/-/blob/main/test2017.zip)
chenych's avatar
chenych committed
79

80
[标签数据](http://113.200.138.88:18080/aidatasets/coco2017/-/blob/main/annotations_trainval2017.zip)
chenych's avatar
chenych committed
81

chenych's avatar
chenych committed
82
数据集的目录结构如下:
chenych's avatar
chenych committed
83
84
85

```
├── COCO2017
86
87
88
│   ├── train2017
│   ├── val2017
│   ├── test2017
chenych's avatar
chenych committed
89
90
91
92
93
│   ├── annotations
│       ├── instances_train2017.json
│       └── instances_val2017.json
```

94
训练/验证集数据准备:训练/验证集都是采用的**COCO**的数据格式,如果使用自己的标注数据,请先将标注数据转换成**COCO**的格式,并按照上面的目录结构进行存放。
chenych's avatar
chenych committed
95

96
97
98
99
100
101
102
103
本项目提供了`coco128`数据集可以进行功能验证使用,目录结构如下:
```bash
├── coco128
│   ├── train2017
│   ├── val2017
│   └── annotations
│       └── instances_train2017.json
```
chenych's avatar
chenych committed
104
105

## 训练
106
107
1. 训练之前,需要进行下面步骤编译:
```bash
chenych's avatar
chenych committed
108
109
110
111
112
cd ./models/ops
bash ./make.sh
cd ../../
```

113
2. 选择需要训练的模型的config,`<config path>`为需要训练的模型属性config文件地址,`<coco path>`为当前环境中训练数据对应地址;
chenych's avatar
chenych committed
114

115
116
117
118
3. 其他:
+ 如果有预训练模型,修改config中的`--pretrained_backbone_path`为保存的预训练模型地址,预训练模型可从[#预训练权重](#预训练权重)中;
+ 当前训练默认backbone为`R50`,如果使用backbone为`swin`,可前往[Swin-Transformer](https://github.com/microsoft/Swin-Transformer)择对应的预训练模型后再进行训练步骤;
+ 如果out_of_memory,设置`--batch_size`大小,当前默认为2。
shantf's avatar
shantf committed
119
4. 如果想要使用单卡训练,将train_multi.sh的多卡设置为1,启动单卡即可。
chenych's avatar
chenych committed
120

shantf's avatar
shantf committed
121
### 单机单卡/多卡
122
```bash
chenych's avatar
chenych committed
123
bash ./train_multi.sh
chenych's avatar
chenych committed
124
125
126
```

## 推理
127
1. 验证前需提前准备好预训练模型,可从[#预训练权重](#预训练权重)中提供的模型下载,`<checkpoint path>`为模型地址,`<coco path>`为当前环境中推理数据的对应地址,数据应为COCO数据格式。[#预训练权重](#预训练权重)中提供的模型下载,选择模型对应的config后进行效果验证。
chenych's avatar
chenych committed
128

129
2. 如果想要查看预测效果(预测结果输出到图片上),请执行(其余参数与训练config参数需一致,详情请参考代码里面的参数配置):
130

131
132
3. 执行:
```bash
chenych's avatar
chenych committed
133
134
python test.py --pre_trained_model <checkpoint path> --coco_path <coco path>
```
135
136
137
138
[r50_hybrid_branch_lambda1_group6_t1500_dp0_mqs_lft_deformable_detr_plus_iterative_bbox_refinement_plus_plus_two_stage_12eps.pth](http://113.200.138.88:18080/aimodels/findsource-dependency/hdetr_pytorch/-/blob/main/r50_hybrid_branch_lambda1_group6_t1500_dp0_mqs_lft_deformable_detr_plus_iterative_bbox_refinement_plus_plus_two_stage_12eps.pth)模型为例:
```bash
python test.py --pre_trained_model /path/r50_hybrid_branch_lambda1_group6_t1500_dp0_mqs_lft_deformable_detr_plus_iterative_bbox_refinement_plus_plus_two_stage_12eps.pth --coco_path /path/coco/data --two_stage --num_queries_one2many 1500 --mixed_selection --look_forward_twice
```
chenych's avatar
chenych committed
139
140

#### 多卡推理
141
```bash
chenych's avatar
chenych committed
142
143
144
145
bash val_multi.sh
```

## result
chenych's avatar
chenych committed
146
COCO2017测试集上的单张图像结果展示:
chenych's avatar
chenych committed
147
148
149
150
151
152

<div align=center>
    <img src="./doc/results.jpg"/>
</div>

### 精度
153
测试数据:[COCO-test2017](http://113.200.138.88:18080/aidatasets/coco2017/-/blob/main/test2017.zip),测试模型config:[r50_hybrid_branch_lambda1_group6_t1500_dp0_mqs_lft_deformable_detr_plus_iterative_bbox_refinement_plus_plus_two_stage.sh](./configs/two_stage/deformable-detr-hybrid-branch/12eps/r50_hybrid_branch_lambda1_group6_t1500_dp0_mqs_lft_deformable_detr_plus_iterative_bbox_refinement_plus_plus_two_stage.sh)
chenych's avatar
chenych committed
154
155

结果如下表所示:
156
| Device | Backbone | query | epochs | AP |
chenych's avatar
chenych committed
157
| :--------: | :------: | :------: | :------: | :------: |
158
159
| Z100L | R50 | 300 | 12 | 48.6 |
| V100S | R50 | 300 | 12 | 48.7 |
chenych's avatar
chenych committed
160
161
162
163
164
165
166
167

## 应用场景
### 算法类别
目标检测

### 热点应用行业
网安,交通,政府

168
169
## 预训练权重
- [SCNet AIModels - hdetr_pytorch](http://113.200.138.88:18080/aimodels/findsource-dependency/hdetr_pytorch)
chenych's avatar
chenych committed
170
171

## 源码仓库及问题反馈
172
- https://developer.hpccube.com/codes/modelzoo/hdetr_pytorch
chenych's avatar
chenych committed
173
174

## 参考资料
175
- https://github.com/HDETR/H-Deformable-DETR