Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# DETR (DEtection TRansformer) for Object Detection
|
2 |
+
|
3 |
+
## Model Description
|
4 |
+
|
5 |
+
This model is a pre-trained DETR model for object detection. It uses a Transformer architecture to predict bounding boxes and class labels for each object in an image. It was trained on the COCO dataset and is capable of detecting a wide variety of objects in real-world images.
|
6 |
+
|
7 |
+
## Model Details
|
8 |
+
|
9 |
+
- Model: `facebook/detr-resnet-50`
|
10 |
+
- Framework: PyTorch
|
11 |
+
- Task: Object Detection
|
12 |
+
- Input: Image (H, W, C)
|
13 |
+
- Output: Bounding boxes and class labels for detected objects
|
14 |
+
- License: MIT
|
15 |
+
|
16 |
+
## How to Use
|
17 |
+
|
18 |
+
```python
|
19 |
+
from transformers import DetrForObjectDetection, DetrImageProcessor
|
20 |
+
from PIL import Image
|
21 |
+
import torch
|
22 |
+
|
23 |
+
# Load the processor and model
|
24 |
+
processor = DetrImageProcessor.from_pretrained("your-username/detr-object-detection")
|
25 |
+
model = DetrForObjectDetection.from_pretrained("your-username/detr-object-detection")
|
26 |
+
|
27 |
+
# Prepare the image
|
28 |
+
image = Image.open("path_to_image.jpg")
|
29 |
+
|
30 |
+
# Process the image
|
31 |
+
inputs = processor(images=image, return_tensors="pt")
|
32 |
+
outputs = model(**inputs)
|
33 |
+
|
34 |
+
# Post-process and display the results
|
35 |
+
target_sizes = torch.tensor([image.size[::-1]])
|
36 |
+
results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.9)[0]
|
37 |
+
|
38 |
+
# Print and visualize detected objects
|
39 |
+
for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
|
40 |
+
box = [round(i, 2) for i in box.tolist()]
|
41 |
+
print(f"Detected {model.config.id2label[label.item()]} with confidence {round(score.item(), 3)} at location {box}")
|