Commit 63098752 authored by Rayyyyy's avatar Rayyyyy
Browse files

Add icon and SCNet,coco128 tiny datasets

parent 7a81732e
# HDETR
## 论文
[DETRs with Hybrid Matching](https://arxiv.org/abs/2207.13080)
`DETRs with Hybrid Matching`
- https://arxiv.org/abs/2207.13080
## 模型结构
基于DETR结构, 在匹配阶段加入一对多的匹配分支。
基于DETR结构在匹配阶段加入一对多的匹配分支。
<div align=center>
<img src="./doc/hybrid.png"/>
</div>
## 算法原理
H-DETR引入一对多匹配分支, 将原始的一对一匹配分支与一个辅助的一对多匹配分支结合起来, 允许多个查询分配给每个正样本, 增加正样本查询数量, 提高训练效果。此外, H-DETR在推理过程中仍然使用原始的一对一匹配分支, 以保持DETR的优势。
H-DETR引入一对多匹配分支将原始的一对一匹配分支与一个辅助的一对多匹配分支结合起来允许多个查询分配给每个正样本增加正样本查询数量提高训练效果。此外H-DETR在推理过程中仍然使用原始的一对一匹配分支以保持DETR的优势。
<div align=center>
<img src="./doc/methods.png"/>
</div>
## 环境配置
注意:requirements.txt安装完成后,还需要额外安装下列包
```
pip install openmim
mim install mmcv-full (注意版本是不是1.7.1)
pip install mmdet==2.26.0 (对应mmcv 1.7.1)
```
-v 路径、docker_name和imageID根据实际情况修改
### Docker(方法一)
-v 路径、docker_name和imageID根据实际情况修改
```
```bash
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:1.13.1-centos7.6-dtk-23.04.1-py38-latest
docker run -it -v /path/your_code_data/:/path/ your_code_data/ --shm-size=80G --privileged=true --device=/dev/kfd --device=/dev/dri/ --group-add video --name docker_name imageID bash
docker run -it -v /path/your_code_data/:/path/your_code_data/ --shm-size=80G --privileged=true --device=/dev/kfd --device=/dev/dri/ --group-add video --name docker_name imageID bash
cd /your_code_path/hdetr_pytorch
pip install -r requirements.txt
pip install openmim
mim install mmcv-full (注意版本是不是1.7.1)
pip install mmdet==2.26.0 (对应mmcv 1.7.1)
```
### Dockerfile(方法二)
```
-v 路径、docker_name和imageID根据实际情况修改
```bash
cd ./docker
cp ../requirements.txt requirements.txt
docker build --no-cache -t hdetr:latest .
docker run -it -v /path/your_code_data/:/path/your_code_data/ --shm-size=80G --privileged=true --device=/dev/kfd --device=/dev/dri/ --group-add video --name docker_name imageID bash
```
### Anaconda(方法三)
1、关于本项目DCU显卡所需的特殊深度学习库可从光合开发者社区下载安装: https://developer.hpccube.com/tool/
cd /your_code_path/hdetr_pytorch
pip install -r requirements.txt
pip install openmim
mim install mmcv-full (注意版本是不是1.7.1)
pip install mmdet==2.26.0 (对应mmcv 1.7.1)
```
### Anaconda(方法三)
关于本项目DCU显卡所需的特殊深度学习库可从[光合](https://developer.hpccube.com/tool/)开发者社区下载安装。
```bash
DTK软件栈: dtk23.04.1
python: python3.8
torch: 1.13.1
torchvision: 0.14.1
```
`Tips:以上dtk软件栈、python、torch等DCU相关工具版本需要严格一一对应`
Tips:以上dtk软件栈、python、torch等DCU相关工具版本需要严格一一对应
2、其他非特殊库直接按照requirements.txt安装
其他非特殊库直接按照requirements.txt安装:
```bash
pip install -r requirements.txt
```
pip3 install -r requirements.txt
pip install openmim
mim install mmcv-full (注意版本是不是1.7.1)
pip install mmdet==2.26.0 (对应mmcv 1.7.1)
```
## 数据集
通过SCNet下载[COCO2017](http://113.200.138.88:18080/aidatasets/coco2017)所需数据集:
COCO2017
[训练数据](http://images.cocodataset.org/zips/train2017.zip)
[训练数据](http://113.200.138.88:18080/aidatasets/coco2017/-/blob/main/train2017.zip)
[验证数据](http://images.cocodataset.org/zips/val2017.zip)
[验证数据](http://113.200.138.88:18080/aidatasets/coco2017/-/blob/main/val2017.zip)
[测试数据](http://images.cocodataset.org/zips/test2017.zip)
[测试数据](http://113.200.138.88:18080/aidatasets/coco2017/-/blob/main/test2017.zip)
[标签数据](https://github.com/ultralytics/yolov5/releases/download/v1.0/coco2017labels.zip)
[标签数据](http://113.200.138.88:18080/aidatasets/coco2017/-/blob/main/annotations_trainval2017.zip)
数据集的目录结构如下:
```
├── COCO2017
│ ├── images
│ ├── train2017
│ ├── val2017
│ └── test2017
│ ├── train2017
│ ├── val2017
│ ├── test2017
│ ├── annotations
│ ├── instances_train2017.json
│ └── instances_val2017.json
```
训练/验证集数据准备:
训练/验证集数据准备:训练/验证集都是采用的**COCO**的数据格式,如果使用自己的标注数据,请先将标注数据转换成**COCO**的格式,并按照上面的目录结构进行存放。
训练/验证集都是采用的COCO的数据格式, 如果使用自己的标注数据, 请先将标注数据转换成COCO的格式, 并按照上面的目录结构进行存放。
本项目提供了`coco128`数据集可以进行功能验证使用,目录结构如下:
```bash
├── coco128
│ ├── train2017
│ ├── val2017
│ └── annotations
│ └── instances_train2017.json
```
## 训练
训练前的准备工作:
1. 进行下面步骤编译
```
1. 训练之前,需要进行下面步骤编译:
```bash
cd ./models/ops
bash ./make.sh
cd ../../
```
2. 选择需要训练的模型的config, config path 为需要训练的模型属性config文件地址, coco path 为当前环境中训练数据对应地址
Tips:
2. 选择需要训练的模型的config,`<config path>`为需要训练的模型属性config文件地址,`<coco path>`为当前环境中训练数据对应地址;
1. 如果有预训练模型, 修改config中的 --pretrained_backbone_path 为保存的预训练模型地址
2. 如果使用backbone为swin, 可前往 https://github.com/microsoft/Swin-Transformer 选择对应的预训练模型后再进行训练步骤
3. 如果out_of_memory, 设置--batch_size大小, 当前默认为2
3. 其他:
+ 如果有预训练模型,修改config中的`--pretrained_backbone_path`为保存的预训练模型地址,预训练模型可从[#预训练权重](#预训练权重)中;
+ 当前训练默认backbone为`R50`,如果使用backbone为`swin`,可前往[Swin-Transformer](https://github.com/microsoft/Swin-Transformer)择对应的预训练模型后再进行训练步骤;
+ 如果out_of_memory,设置`--batch_size`大小,当前默认为2。
### 单机单卡
```
```bash
bash ./train.sh
```
### 单机多卡
```
```bash
bash ./train_multi.sh
```
## 推理
1. 验证前需提前准备好预训练模型,可从[#预训练权重](#预训练权重)中提供的模型下载,`<checkpoint path>`为模型地址,`<coco path>`为当前环境中推理数据的对应地址,数据应为COCO数据格式。[#预训练权重](#预训练权重)中提供的模型下载,选择模型对应的config后进行效果验证。
验证前需提前准备好预训练模型, checkpoint path 为模型地址, coco path 为当前环境中推理数据的对应地址, 数据应为COCO数据格式。
如没有预训练模型, 可从 参考资料 中提供的模型下载, 选择模型对应的config后进行效果验证。
如果想要查看预测效果(预测结果输出到图片上), 请执行(其余参数与训练config参数需一致, 详情请参考代码里面的参数配置):
2. 如果想要查看预测效果(预测结果输出到图片上),请执行(其余参数与训练config参数需一致,详情请参考代码里面的参数配置):
以 r50_hybrid_branch_lambda1_group6_t1500_dp0_mqs_lft_deformable_detr_plus_iterative_bbox_refinement_plus_plus_two_stage_12eps 为例:
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
```
3. 执行:
```bash
python test.py --pre_trained_model <checkpoint path> --coco_path <coco path>
```
[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
```
#### 多卡推理
```
```bash
bash val_multi.sh
```
## result
COCO2017测试集上的单张图像结果展示:
<div align=center>
......@@ -160,16 +154,13 @@ COCO2017测试集上的单张图像结果展示:
</div>
### 精度
在COCO2017的测试集上进行单卡测试, 测试模型config: ./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
测试数据:[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)
结果如下表所示:
| Name | Backbone | query | epochs | AP |
| Device | Backbone | query | epochs | AP |
| :--------: | :------: | :------: | :------: | :------: |
| H-Deformable-DETR + tricks(our) | R50 | 300 | 12 | 48.6 |
| H-Deformable-DETR + tricks | R50 | 300 | 12 | 48.7 |
| Z100L | R50 | 300 | 12 | 48.6 |
| V100S | R50 | 300 | 12 | 48.7 |
## 应用场景
### 算法类别
......@@ -178,9 +169,11 @@ COCO2017测试集上的单张图像结果展示:
### 热点应用行业
网安,交通,政府
## 预训练权重
- [SCNet AIModels - hdetr_pytorch](http://113.200.138.88:18080/aimodels/findsource-dependency/hdetr_pytorch)
## 源码仓库及问题反馈
https://developer.hpccube.com/codes/modelzoo/hdetr_pytorch
- https://developer.hpccube.com/codes/modelzoo/hdetr_pytorch
## 参考资料
https://github.com/HDETR/H-Deformable-DETR
- https://github.com/HDETR/H-Deformable-DETR
This diff is collapsed.
# Introduction
This directory contains software developed by Ultralytics LLC, and **is freely available for redistribution under the GPL-3.0 license**. For more information please visit https://www.ultralytics.com.
# Description
The https://github.com/ultralytics/COCO2YOLO repo contains code to convert JSON datasets into YOLO (darknet) format. The code works on Linux, MacOS and Windows.
# Requirements
Python 3.7 or later with the following `pip3 install -U -r requirements.txt` packages:
- `numpy`
- `tqdm`
# Citation
[![DOI](https://zenodo.org/badge/186122711.svg)](https://zenodo.org/badge/latestdoi/186122711)
# Contact
Issues should be raised directly in the repository. For additional questions or comments please email Glenn Jocher at glenn.jocher@ultralytics.com or visit us at https://contact.ultralytics.com.
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
45 0.479492 0.688771 0.955609 0.5955
45 0.736516 0.247188 0.498875 0.476417
50 0.637063 0.732938 0.494125 0.510583
45 0.339438 0.418896 0.678875 0.7815
49 0.646836 0.132552 0.118047 0.0969375
49 0.773148 0.129802 0.0907344 0.0972292
49 0.668297 0.226906 0.131281 0.146896
49 0.642859 0.0792187 0.148063 0.148062
23 0.770336 0.489695 0.335891 0.697559
23 0.185977 0.901608 0.206297 0.129554
58 0.519219 0.451121 0.39825 0.75729
75 0.501188 0.592138 0.26 0.456192
22 0.346211 0.493259 0.689422 0.892118
25 0.475759 0.414523 0.951518 0.672422
0 0.671279 0.617945 0.645759 0.726859
16 0.606687 0.341381 0.544156 0.51
17 0.597835 0.63755 0.342283 0.36886
17 0.324291 0.64808 0.219711 0.3164
0 0.620039 0.5939 0.172415 0.14608
0 0.385525 0.58557 0.14937 0.12586
0 0.328898 0.70199 0.0313386 0.06714
58 0.622546 0.89961 0.185932 0.09446
0 0.760577 0.69423 0.0285564 0.05486
0 0.510709 0.69215 0.0187927 0.04682
0 0.929554 0.67602 0.0388451 0.01844
0 0.445688 0.480615 0.075125 0.117295
0 0.640086 0.471742 0.0508281 0.0814344
20 0.643211 0.558852 0.129828 0.097623
20 0.459703 0.592121 0.22175 0.159242
0 0.435383 0.45832 0.0534531 0.111025
2 0.292792 0.729031 0.367417 0.246281
7 0.239438 0.599242 0.259542 0.0929219
11 0.279896 0.412773 0.077125 0.117453
74 0.394146 0.184914 0.321458 0.237984
2 0.752648 0.525833 0.0433594 0.033216
2 0.835727 0.538498 0.0380469 0.028169
2 0.700875 0.521455 0.0364375 0.0202347
2 0.937398 0.559777 0.0424219 0.0335915
6 0.452477 0.576408 0.755359 0.280892
2 0.794984 0.538779 0.0368125 0.0261502
2 0.953469 0.514906 0.026125 0.012723
7 0.539727 0.464061 0.0373281 0.0238967
7 0.58518 0.471397 0.0379844 0.0165962
2 0.982555 0.572371 0.0348906 0.0300469
2 0.767367 0.531279 0.0373906 0.0296948
2 0.617961 0.476373 0.0250156 0.0100704
2 0.588344 0.471491 0.0307812 0.0183333
2 0.560102 0.471303 0.0302344 0.0119953
2 0.796047 0.521796 0.0299687 0.0145775
2 0.734094 0.523427 0.029375 0.02723
23 0.658478 0.592133 0.677002 0.779766
23 0.391581 0.556305 0.546862 0.887391
3 0.497327 0.511852 0.948637 0.952609
3 0.240637 0.217617 0.475398 0.424859
16 0.32825 0.769577 0.463156 0.242207
1 0.128828 0.375258 0.249063 0.733333
0 0.476187 0.289613 0.0287813 0.138099
0 0.52143 0.258251 0.0211719 0.0608685
0 0.569492 0.285235 0.0245469 0.122254
0 0.746734 0.295869 0.0494687 0.0983568
0 0.444961 0.298779 0.0239531 0.110047
0 0.450773 0.271209 0.0182656 0.0569249
0 0.53553 0.308733 0.2069 0.317147
0 0.73609 0.272987 0.18926 0.259413
36 0.13364 0.88656 0.10108 0.06464
36 0.50059 0.413213 0.05466 0.07608
0 0.14666 0.667293 0.194 0.441093
0 0.59734 0.325733 0.0494 0.111253
36 0.73492 0.39656 0.04812 0.0401067
0 0.55563 0.265173 0.04586 0.220053
74 0.762851 0.196119 0.349886 0.385474
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment