CoolFace
Modelpublic

IDEA-Research/dab-detr-resnet-50-pat3

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes29downloads
Model Card

Model Card for Model ID

Table of Contents

  1. 1.Model Details
  2. 2.Model Sources
  3. 3.How to Get Started with the Model
  4. 4.Training Details
  5. 5.Evaluation
  6. 6.Model Architecture and Objective
  7. 7.Citation

Model Details

image/png

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.

Model Description

<!-- Provide a longer summary of what this model is. -->

This is the model card of a ๐Ÿค— transformers model that has been pushed on the Hub. This model card has been automatically generated.

  • โ€”Developed by: Shilong Liu, Feng Li, Hao Zhang, Xiao Yang, Xianbiao Qi, Hang Su, Jun Zhu, Lei Zhang
  • โ€”Funded by: IDEA-Research
  • โ€”Shared by: David Hajdu
  • โ€”Model type: DAB-DETR
  • โ€”License: Apache-2.0

Model Sources

<!-- Provide the basic links for the model. -->

  • โ€”Repository: https://github.com/IDEA-Research/DAB-DETR
  • โ€”Paper: https://arxiv.org/abs/2201.12329

How to Get Started with the Model

Use the code below to get started with the model.

python
import torch
import requests

from PIL import Image
from transformers import AutoModelForObjectDetection, AutoImageProcessor

url = 'http://images.cocodataset.org/val2017/000000039769.jpg' 
image = Image.open(requests.get(url, stream=True).raw)

image_processor = AutoImageProcessor.from_pretrained("IDEA-Research/dab-detr-resnet-50-pat3")
model = AutoModelForObjectDetection.from_pretrained("IDEA-Research/dab-detr-resnet-50-pat3")

inputs = image_processor(images=image, return_tensors="pt")

with torch.no_grad():
    outputs = model(**inputs)

results = image_processor.post_process_object_detection(outputs, target_sizes=torch.tensor([image.size[::-1]]), threshold=0.3)

for result in results:
    for score, label_id, box in zip(result["scores"], result["labels"], result["boxes"]):
        score, label = score.item(), label_id.item()
        box = [round(i, 2) for i in box.tolist()]
        print(f"{model.config.id2label[label]}: {score:.2f} {box}")

This should output

cat: 0.85 [12.57, 49.83, 319.89, 472.63]
remote: 0.84 [38.19, 72.69, 176.99, 118.93]
cat: 0.81 [342.33, 20.66, 640.16, 374.93]
couch: 0.62 [-0.02, 1.33, 639.94, 475.61]
remote: 0.59 [334.27, 75.04, 367.96, 189.94]

Training Details

Training Data

<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->

The DAB-DETR model was trained on COCO 2017 object detection, a dataset consisting of 118k/5k annotated images for training/validation respectively.

Training Procedure

Following Deformable DETR and Conditional DETR, we use 300 anchors as queries. We select 300 predicted boxes and labels with the largest classification logits for evaluation as well. We also use focal loss (Lin et al., 2020) with ฮฑ = 0.25, ฮณ = 2 for classification. The same loss terms are used in bipartite matching and final loss calculating, but with different coefficients. Classification loss with coefficient 2.0 is used in pipartite matching but 1.0 in the final loss. L1 loss with coefficient 5.0 and GIOU loss (Rezatofighi et al., 2019) with coefficient 2.0 are consistent in both the matching and the final loss calculation procedures. All models are trained on 16 GPUs with 1 image per GPU and AdamW (Loshchilov & Hutter, 2018) is used for training with weight decay 10โˆ’4. The learning rates for backbone and other modules are set to 10โˆ’5 and 10โˆ’4 respectively. We train our models for 50 epochs and drop the learning rate by 0.1 after 40 epochs. All models are trained on Nvidia A100 GPU. We search hyperparameters with batch size 64 and all results in our paper are reported with batch size 16

Preprocessing

Images are resized/rescaled such that the shortest side is at least 480 and at most 800 pixels and the long size is at most 1333 pixels, and normalized across the RGB channels with the ImageNet mean (0.485, 0.456, 0.406) and standard deviation (0.229, 0.224, 0.225).

Training Hyperparameters

  • โ€”Training regime: <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
**Key****Value**
activation_dropout0.0
activation_functionprelu
attention_dropout0.0
auxiliary_lossfalse
backboneresnet50
bbox_cost5
bbox_loss_coefficient5
class_cost2
cls_loss_coefficient2
decoder_attention_heads8
decoder_ffn_dim2048
decoder_layers6
dropout0.1
encoder_attention_heads8
encoder_ffn_dim2048
encoder_layers6
focal_alpha0.25
giou_cost2
giou_loss_coefficient2
hidden_size256
init_std0.02
init_xavier_std1.0
initializer_bias_prior_probnull
keep_query_posfalse
normalize_beforefalse
num_hidden_layers6
num_patterns0
num_queries300
query_dim4
random_refpoints_xyfalse
sine_position_embedding_scalenull
temperature_height20
temperature_width20

Evaluation

image/png

Model Architecture and Objective

image/png

Overview of DAB-DETR. We extract image spatial features using a CNN backbone followed with Transformer encoders to refine the CNN features. Then dual queries, including positional queries (anchor boxes) and content queries (decoder embeddings), are fed into the decoder to probe the objects which correspond to the anchors and have similar patterns with the content queries. The dual queries are updated layer-by-layer to get close to the target ground-truth objects gradually. The outputs of the final decoder layer are used to predict the objects with labels and boxes by prediction heads, and then a bipartite graph matching is conducted to calculate loss as in DETR.

Citation

<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->

BibTeX:

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

Model Card Authors

David Hajdu