Noeies commited on
Commit
bc640f5
·
verified ·
1 Parent(s): fc77518

Create Phyton

Browse files
Files changed (1) hide show
  1. Phyton +14 -0
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()