nielsr HF staff commited on
Commit
9e9a9e2
1 Parent(s): 8374845

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +87 -0
README.md ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ tags:
4
+ - object-detection
5
+ - vision
6
+ datasets:
7
+ - coco
8
+ widget:
9
+ - src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/savanna.jpg
10
+ example_title: Savanna
11
+ - src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/football-match.jpg
12
+ example_title: Football Match
13
+ - src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/airport.jpg
14
+ example_title: Airport
15
+ ---
16
+
17
+ # Deformable DETR model with ResNet-50 backbone, with box refinement and two stage
18
+
19
+ Deformable DEtection TRansformer (DETR), with box refinement and two stage model trained end-to-end on COCO 2017 object detection (118k annotated images). It was introduced in the paper [Deformable DETR: Deformable Transformers for End-to-End Object Detection](https://arxiv.org/abs/2010.04159) by Zhu et al. and first released in [this repository](https://github.com/fundamentalvision/Deformable-DETR).
20
+
21
+ Disclaimer: The team releasing Deformable DETR did not write a model card for this model so this model card has been written by the Hugging Face team.
22
+
23
+ ## Model description
24
+
25
+ The DETR model is an encoder-decoder transformer with a convolutional backbone. Two heads are added on top of the decoder outputs in order to perform object detection: a linear layer for the class labels and a MLP (multi-layer perceptron) for the bounding boxes. The model uses so-called object queries to detect objects in an image. Each object query looks for a particular object in the image. For COCO, the number of object queries is set to 100.
26
+
27
+ The model is trained using a "bipartite matching loss": one compares the predicted classes + bounding boxes of each of the N = 100 object queries to the ground truth annotations, padded up to the same length N (so if an image only contains 4 objects, 96 annotations will just have a "no object" as class and "no bounding box" as bounding box). The Hungarian matching algorithm is used to create an optimal one-to-one mapping between each of the N queries and each of the N annotations. Next, standard cross-entropy (for the classes) and a linear combination of the L1 and generalized IoU loss (for the bounding boxes) are used to optimize the parameters of the model.
28
+
29
+ ![model image](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/deformable_detr_architecture.png)
30
+
31
+ ## Intended uses & limitations
32
+
33
+ You can use the raw model for object detection. See the [model hub](https://huggingface.co/models?search=sensetime/deformable-detr) to look for all available Deformable DETR models.
34
+
35
+ ### How to use
36
+
37
+ Here is how to use this model:
38
+
39
+ ```python
40
+ from transformers import AutoFeatureExtractor, DeformableDetrForObjectDetection
41
+ import torch
42
+ from PIL import Image
43
+ import requests
44
+
45
+ url = "http://images.cocodataset.org/val2017/000000039769.jpg"
46
+ image = Image.open(requests.get(url, stream=True).raw)
47
+
48
+ feature_extractor = AutoFeatureExtractor.from_pretrained("SenseTime/deformable-detr-with-box-refine-two-stage")
49
+ model = DeformableDetrForObjectDetection.from_pretrained("SenseTime/deformable-detr-with-box-refine-two-stage")
50
+
51
+ inputs = feature_extractor(images=image, return_tensors="pt")
52
+ outputs = model(**inputs)
53
+
54
+ # convert outputs (bounding boxes and class logits) to COCO API
55
+ target_sizes = torch.tensor([image.size[::-1]])
56
+ results = feature_extractor.post_process(outputs, target_sizes=target_sizes)[0]
57
+
58
+ for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
59
+ box = [round(i, 2) for i in box.tolist()]
60
+ # let's only keep detections with score > 0.7
61
+ if score > 0.7:
62
+ print(
63
+ f"Detected {model.config.id2label[label.item()]} with confidence "
64
+ f"{round(score.item(), 3)} at location {box}"
65
+ )
66
+ ```
67
+
68
+ Currently, both the feature extractor and model support PyTorch.
69
+
70
+ ## Training data
71
+
72
+ The Deformable DETR model was trained on [COCO 2017 object detection](https://cocodataset.org/#download), a dataset consisting of 118k/5k annotated images for training/validation respectively.
73
+
74
+ ### BibTeX entry and citation info
75
+
76
+ ```bibtex
77
+ @misc{https://doi.org/10.48550/arxiv.2010.04159,
78
+ doi = {10.48550/ARXIV.2010.04159},
79
+ url = {https://arxiv.org/abs/2010.04159},
80
+ author = {Zhu, Xizhou and Su, Weijie and Lu, Lewei and Li, Bin and Wang, Xiaogang and Dai, Jifeng},
81
+ keywords = {Computer Vision and Pattern Recognition (cs.CV), FOS: Computer and information sciences, FOS: Computer and information sciences},
82
+ title = {Deformable DETR: Deformable Transformers for End-to-End Object Detection},
83
+ publisher = {arXiv},
84
+ year = {2020},
85
+ copyright = {arXiv.org perpetual, non-exclusive license}
86
+ }
87
+ ```