add example usage in readme
Browse files
README.md
CHANGED
@@ -1,3 +1,70 @@
|
|
1 |
---
|
2 |
-
license:
|
|
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
license: apache-2.0
|
3 |
+
tags:
|
4 |
+
- object-detection
|
5 |
+
- vision
|
6 |
+
datasets:
|
7 |
+
- sku110k
|
8 |
---
|
9 |
+
|
10 |
+
# DETR (End-to-End Object Detection) model with ResNet-50 backbone trained on SKU110K Dataset with 400 num_queries
|
11 |
+
|
12 |
+
DEtection TRansformer (DETR) model trained end-to-end on SKU110K object detection (8k annotated images). Main difference between the model is it having **400** num_queries and it being pretrained on SKU110K dataset.
|
13 |
+
|
14 |
+
### How to use
|
15 |
+
|
16 |
+
Here is how to use this model. You can download the **IMG_3507.jpg** from HuggingFace files
|
17 |
+
|
18 |
+
```python
|
19 |
+
from transformers import DetrImageProcessor, DetrForObjectDetection
|
20 |
+
import torch
|
21 |
+
from PIL import Image, ImageOps
|
22 |
+
import requests
|
23 |
+
|
24 |
+
url = "IMG_3507.jpg" # You can download this image from HF files
|
25 |
+
image = Image.open(url)
|
26 |
+
ImageOps.exif_transpose(image)
|
27 |
+
|
28 |
+
# you can specify the revision tag if you don't want the timm dependency
|
29 |
+
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50", revision="no_timm")
|
30 |
+
model = DetrForObjectDetection.from_pretrained("isalia99/detr-resnet-50-sku110k")
|
31 |
+
model = model.eval()
|
32 |
+
inputs = processor(images=image, return_tensors="pt")
|
33 |
+
outputs = model(**inputs)
|
34 |
+
|
35 |
+
# convert outputs (bounding boxes and class logits) to COCO API
|
36 |
+
# let's only keep detections with score > 0.9
|
37 |
+
target_sizes = torch.tensor([image.size[::-1]])
|
38 |
+
results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.8)[0]
|
39 |
+
|
40 |
+
for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
|
41 |
+
box = [round(i, 2) for i in box.tolist()]
|
42 |
+
print(
|
43 |
+
f"Detected {model.config.id2label[label.item()]} with confidence "
|
44 |
+
f"{round(score.item(), 3)} at location {box}"
|
45 |
+
)
|
46 |
+
```
|
47 |
+
This should output:
|
48 |
+
```
|
49 |
+
Detected LABEL_1 with confidence 0.983 at location [665.49, 480.05, 708.15, 650.11]
|
50 |
+
Detected LABEL_1 with confidence 0.938 at location [204.99, 1405.9, 239.9, 1546.5]
|
51 |
+
...
|
52 |
+
Detected LABEL_1 with confidence 0.998 at location [772.85, 169.49, 829.67, 372.18]
|
53 |
+
Detected LABEL_1 with confidence 0.999 at location [828.28, 1475.16, 874.37, 1593.43]
|
54 |
+
```
|
55 |
+
|
56 |
+
Currently, both the feature extractor and model support PyTorch.
|
57 |
+
|
58 |
+
## Training data
|
59 |
+
|
60 |
+
The DETR model was trained on [SKU110K Dataset](https://github.com/eg4000/SKU110K_CVPR19), a dataset consisting of **8,219/588/2,936** annotated images for training/validation/test respectively.
|
61 |
+
|
62 |
+
## Training procedure
|
63 |
+
### Training
|
64 |
+
|
65 |
+
The model was trained for 140 epochs on 1 RTX 4060 Ti GPU(Finetuning decoder only) with batch size of 8 and 70 epochs(finetuning the whole network) with batch size of 3 and accumulating gradients for 3 steps.
|
66 |
+
|
67 |
+
## Evaluation results
|
68 |
+
|
69 |
+
This model achieves an mAP (average precision) of **59.0** on SKU110k validation set. Result was calculated with torchmetrics MeanAveragePrecision class.
|
70 |
+
|