Commit
·
ea4122a
1
Parent(s):
90dad3e
update README.md
Browse files
README.md
CHANGED
|
@@ -70,6 +70,7 @@ pip install -r requirements.txt
|
|
| 70 |
```python
|
| 71 |
from datasets import load_dataset
|
| 72 |
from transformers import AutoProcessor, AutoModel
|
|
|
|
| 73 |
|
| 74 |
# Load the validation split (or 'train')
|
| 75 |
ds = load_dataset("Laudando-Associates-LLC/pucks", split="test")
|
|
@@ -87,11 +88,21 @@ inputs = processor(image)
|
|
| 87 |
# Run inference
|
| 88 |
outputs = model(**inputs, conf_threshold=0.4)
|
| 89 |
|
| 90 |
-
#
|
|
|
|
|
|
|
| 91 |
for result in outputs:
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
```
|
| 96 |
|
| 97 |
## How to Use
|
|
|
|
| 70 |
```python
|
| 71 |
from datasets import load_dataset
|
| 72 |
from transformers import AutoProcessor, AutoModel
|
| 73 |
+
from PIL import ImageDraw, ImageFont
|
| 74 |
|
| 75 |
# Load the validation split (or 'train')
|
| 76 |
ds = load_dataset("Laudando-Associates-LLC/pucks", split="test")
|
|
|
|
| 88 |
# Run inference
|
| 89 |
outputs = model(**inputs, conf_threshold=0.4)
|
| 90 |
|
| 91 |
+
# Draw boxes
|
| 92 |
+
draw = ImageDraw.Draw(image)
|
| 93 |
+
font = ImageFont.truetype("DejaVuSans-Bold.ttf", size=24)
|
| 94 |
for result in outputs:
|
| 95 |
+
boxes = result["boxes"]
|
| 96 |
+
labels = result["labels"]
|
| 97 |
+
scores = result["scores"]
|
| 98 |
+
|
| 99 |
+
for box, label, score in zip(boxes, labels, scores):
|
| 100 |
+
x1, y1, x2, y2 = box.tolist()
|
| 101 |
+
draw.rectangle([x1, y1, x2, y2], outline="blue", width=5)
|
| 102 |
+
draw.text((x1, max(0, y1 - 25)), f"{score:.2f}", fill="blue", font=font)
|
| 103 |
+
|
| 104 |
+
# Save result
|
| 105 |
+
image.save("output.jpg")
|
| 106 |
```
|
| 107 |
|
| 108 |
## How to Use
|