Views
No views yet

We present in this paper a novel query formulation using dynamic anchor boxes for DETR (DEtection TRansformer) and offer a deeper understanding of the role of queries in DETR. This new formulation directly uses box coordinates as queries in Transformer decoders and dynamically updates them layer-by-layer. Using box coordinates not only helps using explicit positional priors to improve the query-to-feature similarity and eliminate the slow training convergence issue in DETR, but also allows us to modulate the positional attention map using the box width and height information. Such a design makes it clear that queries in DETR can be implemented as performing soft ROI pooling layer-by-layer in a cascade manner. As a result, it leads to the best performance on MS-COCO benchmark among the DETR-like detection models under the same setting, e.g., AP 45.7% using ResNet50-DC5 as backbone trained in 50 epochs. We also conducted extensive experiments to confirm our analysis and verify the effectiveness of our methods.
1import torch
2import requests
3
4from PIL import Image
5from transformers import AutoModelForObjectDetection, AutoImageProcessor
6
7url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
8image = Image.open(requests.get(url, stream=True).raw)
9
10image_processor = AutoImageProcessor.from_pretrained("IDEA-Research/dab-detr-resnet-50")
11model = AutoModelForObjectDetection.from_pretrained("IDEA-Research/dab-detr-resnet-50")
12
13inputs = image_processor(images=image, return_tensors="pt")
14
15with torch.no_grad():
16 outputs = model(**inputs)
17
18results = image_processor.post_process_object_detection(outputs, target_sizes=torch.tensor([image.size[::-1]]), threshold=0.3)
19
20for result in results:
21 for score, label_id, box in zip(result["scores"], result["labels"], result["boxes"]):
22 score, label = score.item(), label_id.item()
23 box = [round(i, 2) for i in box.tolist()]
24 print(f"{model.config.id2label[label]}: {score:.2f} {box}")cat: 0.87 [14.7, 49.39, 320.52, 469.28]
remote: 0.86 [41.08, 72.37, 173.39, 117.2]
cat: 0.86 [344.45, 19.43, 639.85, 367.86]
remote: 0.61 [334.27, 75.93, 367.92, 188.81]
couch: 0.59 [-0.04, 1.34, 639.9, 477.09]| Key | Value |
|---|---|
| activation_dropout | 0.0 |
| activation_function | prelu |
| attention_dropout | 0.0 |
| auxiliary_loss | false |
| backbone | resnet50 |
| bbox_cost | 5 |
| bbox_loss_coefficient | 5 |
| class_cost | 2 |
| cls_loss_coefficient | 2 |
| decoder_attention_heads | 8 |
| decoder_ffn_dim | 2048 |
| decoder_layers | 6 |
| dropout | 0.1 |
| encoder_attention_heads | 8 |
| encoder_ffn_dim | 2048 |
| encoder_layers | 6 |
| focal_alpha | 0.25 |
| giou_cost | 2 |
| giou_loss_coefficient | 2 |
| hidden_size | 256 |
| init_std | 0.02 |
| init_xavier_std | 1.0 |
| initializer_bias_prior_prob | null |
| keep_query_pos | false |
| normalize_before | false |
| num_hidden_layers | 6 |
| num_patterns | 0 |
| num_queries | 300 |
| query_dim | 4 |
| random_refpoints_xy | false |
| sine_position_embedding_scale | null |
| temperature_height | 20 |
| temperature_width | 20 |


1@inproceedings{
2 liu2022dabdetr,
3 title={{DAB}-{DETR}: Dynamic Anchor Boxes are Better Queries for {DETR}},
4 author={Shilong Liu and Feng Li and Hao Zhang and Xiao Yang and Xianbiao Qi and Hang Su and Jun Zhu and Lei Zhang},
5 booktitle={International Conference on Learning Representations},
6 year={2022},
7 url={https://openreview.net/forum?id=oMI9PjOb9Jl}
8}