Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,94 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
+
tags:
|
| 4 |
+
- object-detection
|
| 5 |
+
- vision
|
| 6 |
+
datasets:
|
| 7 |
+
- DocLayNet
|
| 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 trained on DocLayNet
|
| 18 |
+
|
| 19 |
+
Deformable DEtection TRansformer (DETR), trained on DocLayNet (including 80k annotated pages in 11 classes).
|
| 20 |
+
|
| 21 |
+
## Model description
|
| 22 |
+
|
| 23 |
+
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
|
| 24 |
+
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
|
| 25 |
+
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
|
| 28 |
+
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
|
| 29 |
+
"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
|
| 30 |
+
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
|
| 31 |
+
used to optimize the parameters of the model.
|
| 32 |
+
|
| 33 |
+

|
| 34 |
+
|
| 35 |
+
## Intended uses & limitations
|
| 36 |
+
|
| 37 |
+
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
|
| 38 |
+
Deformable DETR models.
|
| 39 |
+
|
| 40 |
+
### How to use
|
| 41 |
+
|
| 42 |
+
Here is how to use this model:
|
| 43 |
+
|
| 44 |
+
```python
|
| 45 |
+
from transformers import AutoImageProcessor, DeformableDetrForObjectDetection
|
| 46 |
+
import torch
|
| 47 |
+
from PIL import Image
|
| 48 |
+
import requests
|
| 49 |
+
|
| 50 |
+
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
| 51 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 52 |
+
|
| 53 |
+
processor = AutoImageProcessor.from_pretrained("facebook/deformable-detr-detic")
|
| 54 |
+
model = DeformableDetrForObjectDetection.from_pretrained("facebook/deformable-detr-detic")
|
| 55 |
+
|
| 56 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 57 |
+
outputs = model(**inputs)
|
| 58 |
+
|
| 59 |
+
# convert outputs (bounding boxes and class logits) to COCO API
|
| 60 |
+
# let's only keep detections with score > 0.7
|
| 61 |
+
target_sizes = torch.tensor([image.size[::-1]])
|
| 62 |
+
results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.7)[0]
|
| 63 |
+
|
| 64 |
+
for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
|
| 65 |
+
box = [round(i, 2) for i in box.tolist()]
|
| 66 |
+
print(
|
| 67 |
+
f"Detected {model.config.id2label[label.item()]} with confidence "
|
| 68 |
+
f"{round(score.item(), 3)} at location {box}"
|
| 69 |
+
)
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
## Evaluation results
|
| 73 |
+
|
| 74 |
+
This model achieves 57.1 box mAP on DocLayNet.
|
| 75 |
+
|
| 76 |
+
## Training data
|
| 77 |
+
|
| 78 |
+
The Deformable DETR model was trained on DocLayNet. It was introduced in the paper [DocLayNet: A Large Human-Annotated Dataset for
|
| 79 |
+
Document-Layout Analysis](https://arxiv.org/abs/2206.01062) by Pfitzmann et al. and first released in [this repository](https://github.com/DS4SD/DocLayNet).
|
| 80 |
+
|
| 81 |
+
### BibTeX entry and citation info
|
| 82 |
+
|
| 83 |
+
```bibtex
|
| 84 |
+
@misc{https://doi.org/10.48550/arxiv.2010.04159,
|
| 85 |
+
doi = {10.48550/ARXIV.2010.04159},
|
| 86 |
+
url = {https://arxiv.org/abs/2010.04159},
|
| 87 |
+
author = {Zhu, Xizhou and Su, Weijie and Lu, Lewei and Li, Bin and Wang, Xiaogang and Dai, Jifeng},
|
| 88 |
+
keywords = {Computer Vision and Pattern Recognition (cs.CV), FOS: Computer and information sciences, FOS: Computer and information sciences},
|
| 89 |
+
title = {Deformable DETR: Deformable Transformers for End-to-End Object Detection},
|
| 90 |
+
publisher = {arXiv},
|
| 91 |
+
year = {2020},
|
| 92 |
+
copyright = {arXiv.org perpetual, non-exclusive license}
|
| 93 |
+
}
|
| 94 |
+
```
|