Spaces:
Runtime error
Runtime error
Create Phyton
Browse files
Phyton
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
img = Image.open("diagram.png") # ใส่ภาพของคุณ
|
| 2 |
+
inputs = processor(images=img, return_tensors="pt")
|
| 3 |
+
outputs = model(**inputs)
|
| 4 |
+
|
| 5 |
+
# แปลงผลลัพธ์เป็นกรอบและ label
|
| 6 |
+
target_sizes = torch.tensor([img.size[::-1]])
|
| 7 |
+
results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.5)[0]
|
| 8 |
+
|
| 9 |
+
draw = ImageDraw.Draw(img)
|
| 10 |
+
for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
|
| 11 |
+
draw.rectangle(box.tolist(), outline="red", width=2)
|
| 12 |
+
draw.text((box[0], box[1]-10), f"{model.config.id2label[label.item()]}: {score:.2f}", fill="red")
|
| 13 |
+
|
| 14 |
+
img.show()
|