README.md 3.78 KB
Newer Older
chenych's avatar
chenych committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# DETR
## 论文
[End-to-End Object Detection with Transformers](https://arxiv.org/abs/2005.12872)

## 模型结构

使用传统的CNN主干来学习输入图像的2D表示。该模型对其进行平坦化,并在将其传递到转换器编码器之前用位置编码对其进行补充。然后,转换器解码器将少量固定数量的学习位置嵌入作为输入,称之为对象查询,并额外处理编码器输出。将解码器的每个输出嵌入传递到共享前馈网络(FFN),该网络预测检测(类和边界框)或“无对象”类。

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

## 算法原理
DETR将目标检测看作一种set prediction问题,并提出了一个十分简洁的目标检测pipeline,即CNN提取基础特征,送入Transformer做关系建模,得到的输出通过二分图匹配算法与图片上的ground truth做匹配。

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

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

### Docker(方法一)

```
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:1.13.1-centos7.6-dtk-23.04-py38-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
pip install git+https://github.com/cocodataset/panopticapi.git
```

### 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
pip install git+https://github.com/cocodataset/panopticapi.git
```

### Anaconda(方法三)

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

```
DTK软件栈:dtk23.04
python:python3.8
torch:1.13.1
torchvision:0.14.1
```

Tips:以上dtk软件栈、python、torch等DCU相关工具版本需要严格一一对应

2、其他非特殊库直接按照下面步骤进行安装

```
pip install -r requirements.txt
pip install git+https://github.com/cocodataset/panopticapi.git
```

## 数据集

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)

数据集的目录结构如下:

```
├── images
│   ├── train2017
│   ├── val2017
│   └── test2017
├── annotations
│   ├── instances_train2017.json
│   └── instances_val2017.json
```

训练/验证集数据准备:

训练/验证集都是采用的COCO的数据格式,如果使用自己的标注数据,请先将标注数据转换成COCO的格式,并按照上面的目录结构进行存放

## 训练

### 单机单卡

```
bash train.sh
```

### 单机多卡

```
bash train_multi.sh
```

## 推理
```
sh xxx.sh 或python xxx.py
```
## result


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

### 精度


根据测试结果情况填写表格:
| xxx | xxx | xxx | xxx | xxx |
| :------: | :------: | :------: | :------: |:------: |
| xxx | xxx | xxx | xxx | xxx  |
| xxx | xx | xxx | xxx | xxx |


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

### 热点应用行业
教育,交通,公安

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

## 参考资料
https://github.com/facebookresearch/detr.git