"docs/vscode:/vscode.git/clone" did not exist on "cebf13414afb9aafbe28ff25fe7fcd256051bf07"
README.md 4.08 KB
Newer Older
chenych's avatar
chenych committed
1
2
3
4
5
6
# DETR
## 论文
[End-to-End Object Detection with Transformers](https://arxiv.org/abs/2005.12872)

## 模型结构

chenych's avatar
update  
chenych committed
7
对于输入图像, DETR使用传统的CNN backbone来学习2D特征, 并在将其传递到transformer encoder之前用positional encoding对其进行补充和平滑。然后, transformer decoder将少量固定数量的学习到的positional embeddings(对象查询)作为输入, 额外关注encoder输出。将解码器的每个输出embedding传递到预测检测(类和边界框)或“无对象”类的共享前馈网络(FFN)。
chenych's avatar
chenych committed
8
9
10
11
12
13

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

## 算法原理
chenych's avatar
update  
chenych committed
14
DETR将目标检测看作一种set prediction问题, 并提出了一个十分简洁的目标检测pipeline, 即CNN提取基础特征, 送入Transformer做关系建模, 得到的输出通过二分图匹配算法与图片上的ground truth做匹配。
chenych's avatar
chenych committed
15
16
17
18
19
20
21
22
23
24
25

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

## 环境配置
-v 路径、docker_name和imageID根据实际情况修改

### Docker(方法一)

```
chenych's avatar
chenych committed
26
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:1.13.1-centos7.6-dtk-23.04.1-py38-latest
chenych's avatar
chenych committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

docker run -it -v /path/your_code_data/:/path/ your_code_data/ --shm-size=32G --privileged=true --device=/dev/kfd --device=/dev/dri/ --group-add video --name docker_name imageID bash

cd /your_code_path/detr_pytorch
pip install -r requirements.txt
```

### Dockerfile(方法二)

```
cd ./docker
cp ../requirements.txt requirements.txt

docker build --no-cache -t detr:latest .
docker run -it -v /path/your_code_data/:/path/your_code_data/ --shm-size=32G --privileged=true --device=/dev/kfd --device=/dev/dri/ --group-add video --name docker_name imageID bash

cd /your_code_path/detr_pytorch
pip install -r requirements.txt
```

### Anaconda(方法三)

1、关于本项目DCU显卡所需的特殊深度学习库可从光合开发者社区下载安装: https://developer.hpccube.com/tool/

```
chenych's avatar
update  
chenych committed
52
53
54
55
DTK软件栈: dtk23.04.1
python: python3.8
torch: 1.13.1
torchvision: 0.14.1
chenych's avatar
chenych committed
56
57
```

chenych's avatar
update  
chenych committed
58
Tips: 以上dtk软件栈、python、torch等DCU相关工具版本需要严格一一对应
chenych's avatar
chenych committed
59

chenych's avatar
chenych committed
60
2、其他非特殊库直接按照requirements.txt安装
chenych's avatar
chenych committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

```
pip install -r requirements.txt
```

## 数据集

COCO2017

[训练数据](http://images.cocodataset.org/zips/train2017.zip)

[验证数据](http://images.cocodataset.org/zips/val2017.zip)

[测试数据](http://images.cocodataset.org/zips/test2017.zip)

[标签数据](https://github.com/ultralytics/yolov5/releases/download/v1.0/coco2017labels.zip)

chenych's avatar
update  
chenych committed
78
数据集的目录结构如下:
chenych's avatar
chenych committed
79
80

```
chenych's avatar
chenych committed
81
82
83
84
85
86
87
88
├── COCO2017
│   ├── images
│       ├── train2017
│       ├── val2017
│       └── test2017
│   ├── annotations
│       ├── instances_train2017.json
│       └── instances_val2017.json
chenych's avatar
chenych committed
89
90
```

chenych's avatar
update  
chenych committed
91
训练/验证集数据准备:
chenych's avatar
chenych committed
92

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

## 训练

97
### 单机多卡
chenych's avatar
chenych committed
98
99
100
101
102

```
bash train.sh
```

chenych's avatar
chenych committed
103
104
## 推理

chenych's avatar
update  
chenych committed
105
验证前需提前准备好预训练模型, 可从 参考资料 中提供的模型下载, 并将coco_path设置为当前环境中推理数据的对应地址, 数据应为COCO数据格式。
chenych's avatar
chenych committed
106

chenych's avatar
update  
chenych committed
107
如果想要查看预测效果(预测结果输出到图片上), 请执行(其余参数如backbone等需与训练模型参数需一致, 详情请根据训练参数配置):
chenych's avatar
chenych committed
108
109

```
chenych's avatar
chenych committed
110
python test.py --pre_trained_model <checkpoint path> --coco_path <coco path>
chenych's avatar
chenych committed
111
112
```

chenych's avatar
chenych committed
113
114
#### 单卡推理

chenych's avatar
chenych committed
115
```
chenych's avatar
chenych committed
116
bash val.sh
chenych's avatar
chenych committed
117
```
chenych's avatar
chenych committed
118

chenych's avatar
chenych committed
119
120
121
## result

<div align=center>
chenych's avatar
chenych committed
122
    <img src="./doc/000000001503.jpg"/>
chenych's avatar
chenych committed
123
124
125
126
</div>

### 精度

chenych's avatar
update  
chenych committed
127
在COCO2017的val数据集上进行R50 backbone的单卡测试, 结果如下表所示:
chenych's avatar
chenych committed
128

chenych's avatar
update  
chenych committed
129
130
131
132
| name | backbone | schedule | box AP |
| :------: | :------: | :------: | :------: |
| DETR(our)  | R50 | 500 | 39.8 |
| DETR  | R50 | 500 | 42.0 |
chenych's avatar
chenych committed
133
134
135
136
137
138
139


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

### 热点应用行业
chenych's avatar
chenych committed
140
网安,交通,政府
chenych's avatar
chenych committed
141
142
143
144
145

## 源码仓库及问题反馈
http://developer.hpccube.com/codes/modelzoo/detr_pytorch.git

## 参考资料
chenych's avatar
chenych committed
146
https://github.com/facebookresearch/detr.git