Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
tags:
|
4 |
+
- object-detection
|
5 |
+
- vision
|
6 |
+
- detic
|
7 |
+
datasets:
|
8 |
+
- lvis
|
9 |
+
widget:
|
10 |
+
- src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/savanna.jpg
|
11 |
+
example_title: Savanna
|
12 |
+
- src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/football-match.jpg
|
13 |
+
example_title: Football Match
|
14 |
+
- src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/airport.jpg
|
15 |
+
example_title: Airport
|
16 |
+
---
|
17 |
+
|
18 |
+
# Deformable DETR model trained on LVIS
|
19 |
+
|
20 |
+
Deformable DEtection TRansformer (DETR), trained on LVIS (including 1203 classes). It was introduced in the paper [Detecting Twenty-thousand Classes using Image-level Supervision](https://arxiv.org/abs/2201.02605) by Zhou et al. and first released in [this repository](https://github.com/facebookresearch/Detic).
|
21 |
+
|
22 |
+
This model corresponds to the "Box-Supervised_DeformDETR_R50_4x" checkpoint released in the original repository.
|
23 |
+
|
24 |
+
Disclaimer: The team releasing Detic did not write a model card for this model so this model card has been written by the Hugging Face team.
|
25 |
+
|
26 |
+
## Model description
|
27 |
+
|
28 |
+
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.
|
29 |
+
|
30 |
+
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.
|
31 |
+
|
32 |
+
![model image](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/deformable_detr_architecture.png)
|
33 |
+
|
34 |
+
## Intended uses & limitations
|
35 |
+
|
36 |
+
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.
|
37 |
+
|
38 |
+
### How to use
|
39 |
+
|
40 |
+
Here is how to use this model:
|
41 |
+
|
42 |
+
```python
|
43 |
+
from transformers import AutoImageProcessor, DeformableDetrForObjectDetection
|
44 |
+
import torch
|
45 |
+
from PIL import Image
|
46 |
+
import requests
|
47 |
+
|
48 |
+
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
49 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
50 |
+
|
51 |
+
processor = AutoImageProcessor.from_pretrained("facebook/deformable-detr-box-supervised")
|
52 |
+
model = DeformableDetrForObjectDetection.from_pretrained("facebook/deformable-detr-box-supervised")
|
53 |
+
|
54 |
+
inputs = processor(images=image, return_tensors="pt")
|
55 |
+
outputs = model(**inputs)
|
56 |
+
|
57 |
+
# convert outputs (bounding boxes and class logits) to COCO API
|
58 |
+
# let's only keep detections with score > 0.7
|
59 |
+
target_sizes = torch.tensor([image.size[::-1]])
|
60 |
+
results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.7)[0]
|
61 |
+
|
62 |
+
for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
|
63 |
+
box = [round(i, 2) for i in box.tolist()]
|
64 |
+
print(
|
65 |
+
f"Detected {model.config.id2label[label.item()]} with confidence "
|
66 |
+
f"{round(score.item(), 3)} at location {box}"
|
67 |
+
)
|
68 |
+
```
|
69 |
+
|
70 |
+
## Evaluation results
|
71 |
+
|
72 |
+
This model achieves 31.7 box mAP and 21.4 mAP (rare classes) on LVIS.
|
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 |
+
```
|