Home

Awesome

Relation DETR

By Xiuquan Hou, Meiqin Liu, Senlin Zhang, Ping Wei, Badong Chen, Xuguang Lan.

This repo is the official implementation of Relation DETR: Exploring Explicit Position Relation Prior for Object Detection accepted to ECCV2024 (score 5444, oral presentation). [Arxiv paper link], [论文介绍], [代码讲解]

💖 If our Relation-DETR or SA-Det-100k dataset is helpful to your researches or projects, please star this repository. Thanks! 🤗

<div align="center"> <img src="images/convergence_curve.png" width=500> </div>

TODO

...Want more features? Open a Feature Request.

Update

SA-Det-100k

SA-Det-100k is a large-scale class-agnostic object detection dataset for Research Purposes only. The dataset is based on a subset of SA-1B (see LICENSE), and all objects belong to the same category objects. Because it contains a large number of scenarios but does not provide class-specific annotations, we believe it may be a good choice to pre-training models for a variety of downstream tasks with different categories. The dataset contains about 100k images, and each image is resized using opencv-python so that the larger one of their height and width is 1333, which is consistent with the data augmentation commonly used to train COCO. The dataset can be found in:

Model ZOO

COCO

ModelBackboneEpochDownloadmAPAP<sub>50AP<sub>75AP<sub>SAP<sub>MAP<sub>L
Relation DETRResNet5012config / checkpoint / log51.769.156.336.155.666.1
Relation DETRSwin-L<sub>(IN-22K)12config / checkpoint57.876.162.941.262.174.4
Relation DETRResNet5024config / checkpoint / log52.169.756.636.156.066.5
Relation DETRSwin-L<sub>(IN-22K)24config / checkpoint / log58.176.463.541.863.073.5
Relation-DETR<sup>Focal-L<sub>(IN-22K)4+24config / o365_checkpoint / checkpoint63.580.869.147.266.977.0

† means finetuned model on COCO after pretraining on Object365.

[Other DETR variants:] We integrate our position relation into existing DETR variants and generate enhanced versions of them. Note some of these weights are newly trained and may produce slightly different results from those reported in our paper. We mark these variants with ++ in the name to distinguish them from their original versions.

ModelBackboneEpochDownloadmAPAP<sub>50AP<sub>75AP<sub>SAP<sub>MAP<sub>L
DINO++ResNet5012config / checkpoint50.167.854.933.353.963.5

SA-Det-100k

ModelBackboneEpochDownloadmAPAP<sub>50AP<sub>75AP<sub>SAP<sub>MAP<sub>L
DINO with VFLResNet5012——43.752.047.75.843.061.5
Relation DETRResNet5012config / checkpoint45.053.148.96.044.462.9

Get started

<details> <summary>1. Installation</summary>

We use the environment same as Salience-DETR. You can skip the step if you have run Salience-DETR.

  1. Clone the repository:
```shell
git clone https://github.com/xiuqhou/Relation-DETR
cd Relation-DETR
```

2. Install Pytorch and torchvision:

```shell
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.3 -c pytorch
```

3. Install other requirements:

```shell
pip install -r requirements.txt
```
</details> <details> <summary>2. Prepare datasets</summary>

Download COCO2017 (and SA-Det-100k optionally), put them in data/ following the structure:


data/
  ├─coco/
  │  ├── train2017/
  │  ├── val2017/
  │  └── annotations/
  │         ├── instances_train2017.json
  │         └── instances_val2017.json
  │
  └─sa_det_100k/
      ├── train2017/
      ├── val2017/
      └── annotations/
</details> <details> <summary>3. Evaluate pretrained models</summary>

To evaluate a model with one or more GPUs, specify CUDA_VISIBLE_DEVICES, dataset, model and checkpoint.

CUDA_VISIBLE_DEVICES=<gpu_ids> accelerate launch test.py --coco-path /path/to/coco --model-config /path/to/model.py --checkpoint /path/to/checkpoint.pth

For example, run the following shell to evaluate Relation-DETR with ResNet-50 (1x) on COCO, You can expect to get the final AP about 51.7.

CUDA_VISIBLE_DEVICES=0 accelerate launch test.py \
  --coco-path data/coco \
  --model-config configs/relation_detr/relation_detr_resnet50_800_1333.py \
  --checkpoint https://github.com/xiuqhou/Relation-DETR/releases/download/v1.0.0/relation_detr_resnet50_800_1333_coco_1x.pth
</details> <details> <summary>4. Evaluate exported json results</summary> To evaluate a json results, specify `dataset` and `result`. The evaluation only needs CPU so you don't need to specify `CUDA_VISIBLE_DEVICES`.
accelerate launch test.py --coco-path /path/to/coco --result /path/to/result.json
</details> <details> <summary>5. Train a model</summary>

Use CUDA_VISIBLE_DEVICES to specify GPU/GPUs and run the following script to start training. If not specified, the script will use all available GPUs on the node to train. Before start training, modify parameters in configs/train_config.py.

CUDA_VISIBLE_DEVICES=0 accelerate launch main.py    # train with 1 GPU
CUDA_VISIBLE_DEVICES=0,1 accelerate launch main.py  # train with 2 GPUs
</details> <details> <summary>5. Benchmark a model</summary>

To test the inference speed, memory cost and parameters of a model, use tools/benchmark_model.py.

python tools/benchmark_model.py --model-config configs/relation_detr/relation_detr_resnet50_800_1333.py
</details> <details> <summary>6. Export an ONNX model</summary>

For advanced users who want to deploy our model, we provide a script to export an ONNX file.

python tools/pytorch2onnx.py \
    --model-config /path/to/model.py \
    --checkpoint /path/to/checkpoint.pth \
    --save-file /path/to/save.onnx \
    --simplify \  # use onnxsim to simplify the exported onnx file
    --verify  # verify the error between onnx model and pytorch model

For inference using the ONNX file, see ONNXDetector in tools/pytorch2onnx.py

</details>

License

Relation-DETR is released under the Apache 2.0 license. Please see the LICENSE file for more information.

Bibtex

If you find our work helpful for your research, please consider citing:

@inproceedings{hou2024relation,
  title={Relation DETR: Exploring Explicit Position Relation Prior for Object Detection},
  author={Hou, Xiuquan and Liu, Meiqin and Zhang, Senlin and Wei, Ping and Chen, Badong and Lan, Xuguang},
  booktitle={European conference on computer vision},
  year={2024},
  organization={Springer}
}

@InProceedings{Hou_2024_CVPR,
    author    = {Hou, Xiuquan and Liu, Meiqin and Zhang, Senlin and Wei, Ping and Chen, Badong},
    title     = {Salience DETR: Enhancing Detection Transformer with Hierarchical Salience Filtering Refinement},
    booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
    month     = {June},
    year      = {2024},
    pages     = {17574-17583}
}