# DETR
## 论文
[End-to-End Object Detection with Transformers](https://arxiv.org/abs/2005.12872)
## 模型结构
使用传统的CNN主干来学习输入图像的2D表示。该模型对其进行平坦化,并在将其传递到转换器编码器之前用位置编码对其进行补充。然后,转换器解码器将少量固定数量的学习位置嵌入作为输入,称之为对象查询,并额外处理编码器输出。将解码器的每个输出嵌入传递到共享前馈网络(FFN),该网络预测检测(类和边界框)或“无对象”类。
## 算法原理
DETR将目标检测看作一种set prediction问题,并提出了一个十分简洁的目标检测pipeline,即CNN提取基础特征,送入Transformer做关系建模,得到的输出通过二分图匹配算法与图片上的ground truth做匹配。
## 环境配置
-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
### 精度
根据测试结果情况填写表格:
| 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