"git@developer.sourcefind.cn:OpenDAS/ollama.git" did not exist on "6e0ea5ecc8fa7a162cd63455c8e2319e443c98c4"
README.md 6.34 KB
Newer Older
luopl's avatar
init  
luopl committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# DDQ
## 论文
`Dense Distinct Query for End-to-End Object Detection`
- https://arxiv.org/abs/2303.12776
## 模型结构
DDQ首先像传统检测器一样铺设密集查询,然后选择不同的查询进行一对一分配,融合了传统和最近的端到端检测器的优点,并显着提高了包括 FCN、R-CNN 和 DETR 在内的各种检测器的性能。

<div align=center>
    <img src="./assets/ddq.png"/>
</div>

## 算法原理
DDQ 的流程图如下。 (a) 展示了 DDQ 应用于类似 FCOS 结构的应用,这是一个全卷积网络 (FCN),因此被称为 DDQ FCN。金字塔混合操作分别应用于分类和回归分支的最后两层和最后的卷积层。
类无关的非极大值抑制 (NMS) 用作独特查询的选择操作。最终,只有独特的查询会在计算损失之前被分配标签。 (b) 展示了 DDQ 在 R-CNN 结构中的设计 (DDQ R-CNN)。DDQ FCN 的分类和回归分支的最后特征图被连接并过滤为独特查询。
然后,这些独特查询将与对应的边界框一起发送到精炼头进行处理。 (c) 展示了 DDQ 在 DETR 结构中的设计 (DDQ DETR)。
在选择独特查询之后,编码器中剩余的特征嵌入将通过线性投影到独特查询的内容部分。它们对应的边界框将映射到位置嵌入部分。两个部分将被发送到六个精炼阶段。在如此长的精炼架构中,DQS 将在每个精炼阶段之前应用,以确保独特性。
<div align=center>
    <img src="./assets/ddq_pipeline.png"/>
</div>

## 环境配置
### Docker(方法一)
chenzk's avatar
chenzk committed
23
此处提供[光源](https://www.sourcefind.cn/#/service-details)拉取docker镜像的地址与使用步骤,以及[光合](https://developer.sourcefind.cn/tool/)开发者社区深度学习库下载地址
luopl's avatar
init  
luopl committed
24
```
dcuai's avatar
dcuai 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 --shm-size=128G -v /path/your_code_data/:/path/your_code_data/ -v /opt/hyhal:/opt/hyhal:ro --privileged=true --device=/dev/kfd --device=/dev/dri/ --group-add video --name ddq_mmcv  <your IMAGE ID> bash # <your IMAGE ID>为以上拉取的docker的镜像ID替换
luopl's avatar
init  
luopl committed
27
28
29
30
31
32
33
34
35
36
37
38
cd /path/your_code_data/ddq_mmcv
pip install -r requirements/multimodal.txt -i https://mirrors.aliyun.com/pypi/simple/
pip install mmdet -i https://mirrors.aliyun.com/pypi/simple/

```
### Dockerfile(方法二)
此处提供dockerfile的使用方法
```
docker build --no-cache -t ddq:latest .
docker run -it --shm-size=128G -v /path/your_code_data/:/path/your_code_data/ -v /opt/hyhal:/opt/hyhal:ro --privileged=true --device=/dev/kfd --device=/dev/dri/ --group-add video --name ddq_mmcv  ddq  bash
cd /path/your_code_data/ddq_mmcv
pip install -r requirements/multimodal.txt -i https://mirrors.aliyun.com/pypi/simple/
dcuai's avatar
dcuai committed
39
pip install mmcv-2.0.1+das1.1.gite58da25.abi1.dtk2404.torch2.1.0-cp310-cp310-manylinux_2_31_x86_64.whl
luopl's avatar
init  
luopl committed
40
41
42
43
44
pip install mmdet -i https://mirrors.aliyun.com/pypi/simple/
```
### Anaconda(方法三)
此处提供本地配置、编译的详细步骤,例如:

chenzk's avatar
chenzk committed
45
关于本项目DCU显卡所需的特殊深度学习库可从[光合](https://developer.sourcefind.cn/tool/)开发者社区下载安装。
luopl's avatar
init  
luopl committed
46
```
dcuai's avatar
dcuai committed
47
#DTK驱动:dtk24.04.1
luopl's avatar
init  
luopl committed
48
49
50
51
52
# python:python3.10
# torch: 2.1.0
# torchvision: 0.16.0
conda create -n ddq python=3.10
conda activate ddq
dcuai's avatar
dcuai committed
53
54
55
pip install torch-2.1.0+das1.1.git3ac1bdd.abi1.dtk2404-cp310-cp310-manylinux_2_31_x86_64.whl
pip install torchvision-0.16.0+das1.1.git7d45932.abi1.dtk2404.torch2.1-cp310-cp310-manylinux_2_31_x86_64.whl
pip install mmcv-2.0.1+das1.1.gite58da25.abi1.dtk2404.torch2.1.0-cp310-cp310-manylinux_2_31_x86_64.whl
luopl's avatar
init  
luopl committed
56
57
58
59
60
61
62
63
64
65
66

```
`Tips:以上dtk驱动、python、torch等DCU相关工具版本需要严格一一对应`

其它依赖环境安装如下:
```
cd /path/your_code_data/ddq_mmcv
pip install -r requirements/multimodal.txt -i https://mirrors.aliyun.com/pypi/simple/
pip install mmdet -i https://mirrors.aliyun.com/pypi/simple/
```
## 数据集
chenzk's avatar
chenzk committed
67
[coco2017](https://cocodataset.org/#home)
luopl's avatar
init  
luopl committed
68
69
70
71
72
73
74
75
76
77
78
79
80


```

├── data
│   ├── coco
│   │   ├── annotations
│   │   │      ├──instances_train2017.json
│   │   │      ├──instances_val2017.json
│   │   ├── train2017
│   │   ├── val2017
```

luopl's avatar
luopl committed
81
82
83
84
85
86
87
88
mini数据集供验证使用

```
cd /path/your_code_data/ddq_mmcv
cd data/
unzip  coco_mini.zip

```
luopl's avatar
luopl committed
89
如需要变更数据集目录,请修改ddq_mmcv/configs/_base_/datasets/coco_detection.py 的data_root目录
luopl's avatar
luopl committed
90

luopl's avatar
init  
luopl committed
91
92
93
94
95
96
97
98
99
100
101
102
103
## 训练

### 单机单卡
```
bash ./tools/dist_train.sh configs/ddq/ddq-detr-4scale_r50_8xb2-12e_coco.py 1
```
### 单机多卡
```
bash tools/dist_train.sh configs/ddq/ddq-detr-4scale_r50_8xb2-12e_coco.py 4
```

## 推理

chenzk's avatar
chenzk committed
104
[ddq-detr-4scale_r50_8xb2-12e_coco_20230809_170711-42528127](https://download.openmmlab.com/mmdetection/v3.0/ddq/ddq-detr-4scale_r50_8xb2-12e_coco/ddq-detr-4scale_r50_8xb2-12e_coco_20230809_170711-42528127.pth)
luopl's avatar
init  
luopl committed
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

### 单机单卡

Evaluate:
```
HIP_VISIBLE_DEVICES=0 python tools/test.py configs/ddq/ddq-detr-4scale_r50_8xb2-12e_coco.py path/to/model.pth
```

Inference Demo:
```
python demo/image_demo.py demo/demo.jpg configs/ddq/ddq-detr-4scale_r50_8xb2-12e_coco.py --weights path/to/model.pth --device cuda --out-dir outputs
```


### 多卡推理

```
luopl's avatar
luopl committed
122
bash tools/dist_test.sh configs/ddq/ddq-detr-4scale_r50_8xb2-12e_coco.py path/to/model.pth 4
luopl's avatar
init  
luopl committed
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
```

## result
Inference Demo result:

<div align=center>
    <img src="./assets/demo.jpg"/>
</div>



### 精度
使用四张DCU-K100 AI卡推理

|       Model       | Backbone | Lr schd | Augmentation | box AP(val) |                                 Config                                 |
| :---------------: | :------: | :-----: | :----------: | :---------: |:----------------------------------------------------------------------:|
|  DDQ DETR-4scale  |   R-50   |   12e   |     DETR     |    51.4     |       [config](configs/ddq/ddq-detr-4scale_r50_8xb2-12e_coco.py)       | 
| DDQ DETR-5scale\* |   R-50   |   12e   |     DETR     |    52.1     |       [config](configs/ddq/ddq-detr-5scale_r50_8xb2-12e_coco.py)       | 
| DDQ DETR-4scale\* |  Swin-L  |   30e   |     DETR     |    58.7     |           [config](configs/ddq/ddq-detr-4scale_swinl_8xb2-30e_coco.py)           | 



## 应用场景
### 算法类别
`目标检测`
### 热点应用行业
`科研,制造,医疗,家居,教育`
## 源码仓库及问题反馈
chenzk's avatar
chenzk committed
151
- https://developer.sourcefind.cn/codes/luopl/ddq_mmcv
luopl's avatar
init  
luopl committed
152
153
154
## 参考资料
- https://github.com/open-mmlab/mmdetection/tree/main/configs/ddq