Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ import numpy as np
|
|
6 |
from ultralytics import YOLO
|
7 |
|
8 |
# โหลดโมเดล YOLOv8 ที่ฝึกมาเอง
|
9 |
-
model = YOLO('best_V5.pt') # เปลี่ยน '
|
10 |
|
11 |
def predict(image):
|
12 |
# ทำการทำนาย
|
@@ -15,12 +15,12 @@ def predict(image):
|
|
15 |
# วาด bounding boxes และ labels บนภาพ
|
16 |
for result in results:
|
17 |
boxes = result.boxes.xyxy.cpu().numpy()
|
18 |
-
labels = result.names
|
19 |
confidences = result.boxes.conf.cpu().numpy()
|
|
|
20 |
|
21 |
-
for box, confidence in zip(boxes, confidences):
|
22 |
-
x1, y1, x2, y2 = map(int, box)
|
23 |
-
label =
|
24 |
|
25 |
# วาด bounding box
|
26 |
cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
@@ -34,4 +34,4 @@ def predict(image):
|
|
34 |
return pil_image
|
35 |
|
36 |
demo = gr.Interface(fn=predict, inputs=gr.Image(type="numpy"), outputs="image")
|
37 |
-
demo.launch()
|
|
|
6 |
from ultralytics import YOLO
|
7 |
|
8 |
# โหลดโมเดล YOLOv8 ที่ฝึกมาเอง
|
9 |
+
model = YOLO('best_V5.pt') # เปลี่ยน 'best_V5.pt' เป็นโมเดลของคุณ
|
10 |
|
11 |
def predict(image):
|
12 |
# ทำการทำนาย
|
|
|
15 |
# วาด bounding boxes และ labels บนภาพ
|
16 |
for result in results:
|
17 |
boxes = result.boxes.xyxy.cpu().numpy()
|
|
|
18 |
confidences = result.boxes.conf.cpu().numpy()
|
19 |
+
class_ids = result.boxes.cls.cpu().numpy()
|
20 |
|
21 |
+
for box, confidence, class_id in zip(boxes, confidences, class_ids):
|
22 |
+
x1, y1, x2, y2 = map(int, box[:4])
|
23 |
+
label = result.names[int(class_id)] # ดึง label จาก class_id
|
24 |
|
25 |
# วาด bounding box
|
26 |
cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
|
|
34 |
return pil_image
|
35 |
|
36 |
demo = gr.Interface(fn=predict, inputs=gr.Image(type="numpy"), outputs="image")
|
37 |
+
demo.launch()
|