jadechoghari
commited on
Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,36 @@
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
+
---
|
4 |
+
|
5 |
+
This is the HF transformers implementation for RT-DETRv2
|
6 |
+
|
7 |
+
Model: RT-DETRv2-S
|
8 |
+
RT-DETRv2, an improved Real-Time DEtection TRansformer (RT-DETR). RT-DETRv2 builds upon the previous state-of-the-art real-time detector, RT-DETR, and opens up a set of bag-of-freebies for flexibility and practicality, as well as optimizing the training strategy to achieve enhanced performance. To improve the flexibility, we suggest setting a distinct number of sampling points for features at different scales in the deformable attention to achieve selective multi-scale feature extraction by the decoder.
|
9 |
+
|
10 |
+
Usage:
|
11 |
+
|
12 |
+
```python
|
13 |
+
import torch
|
14 |
+
import requests
|
15 |
+
|
16 |
+
from PIL import Image
|
17 |
+
from transformers import RTDetrForObjectDetection, RTDetrImageProcessor
|
18 |
+
|
19 |
+
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
|
20 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
21 |
+
|
22 |
+
image_processor = RTDetrImageProcessor.from_pretrained("jadechoghari/RT-DETRv2")
|
23 |
+
model = RTDetrForObjectDetection.from_pretrained("jadechoghari/RT-DETRv2")
|
24 |
+
|
25 |
+
inputs = image_processor(images=image, return_tensors="pt")
|
26 |
+
|
27 |
+
with torch.no_grad():
|
28 |
+
outputs = model(**inputs)
|
29 |
+
|
30 |
+
results = image_processor.post_process_object_detection(outputs, target_sizes=torch.tensor([image.size[::-1]]), threshold=0.3)
|
31 |
+
|
32 |
+
for result in results:
|
33 |
+
for score, label_id, box in zip(result["scores"], result["labels"], result["boxes"]):
|
34 |
+
score, label = score.item(), label_id.item()
|
35 |
+
box = [round(i, 2) for i in box.tolist()]
|
36 |
+
print(f"{model.config.id2label[label]}: {score:.2f} {box}")
|