AdrielAmoguis commited on
Commit
2cf5554
·
1 Parent(s): 355835e
Files changed (2) hide show
  1. app.py +14 -3
  2. requirements.txt +2 -1
app.py CHANGED
@@ -2,6 +2,8 @@ import numpy as np
2
  from PIL import Image
3
  import gradio as gr
4
  from ultralytics import YOLO
 
 
5
 
6
  # Load the YOLO model
7
  m_raw_model = YOLO("M-Raw.pt")
@@ -22,10 +24,19 @@ def snap(image, model, conf, iou):
22
  results = s_raw_model(image, conf=conf, iou=iou)
23
 
24
  # Convert the results list into an output image
25
- print(results)
 
 
 
 
 
 
 
 
 
26
 
27
  # Convert the resulting image to a PIL image
28
- resulting_image = Image.fromarray(resulting_image)
29
 
30
  # Get the labels
31
  labels = results.pandas().xyxy[0]["name"].values
@@ -38,7 +49,7 @@ def snap(image, model, conf, iou):
38
 
39
  demo = gr.Interface(
40
  snap,
41
- [gr.Image(source="webcam", tool=None, streaming=True), gr.inputs.Radio(["M-Raw", "S-Raw", "N-Raw"]), gr.Slider(0, 1, value=0.6, label="Classifier Confidence Threshold"), gr.Slider(0, 1, value=0.7, label="IoU Threshold")],
42
  ["image"],
43
  title="Baybayin Instance Detection"
44
  )
 
2
  from PIL import Image
3
  import gradio as gr
4
  from ultralytics import YOLO
5
+ from ultralytics.yolo.utils.ops import scale_image
6
+ import cv2
7
 
8
  # Load the YOLO model
9
  m_raw_model = YOLO("M-Raw.pt")
 
24
  results = s_raw_model(image, conf=conf, iou=iou)
25
 
26
  # Convert the results list into an output image
27
+ for result in results:
28
+ classes = result.boxes.cls.cpu().numpy()
29
+ probs = result.boxes.conf.cpu().numpy()
30
+ boxes = result.boxes.xyxy[0].cpu().numpy()
31
+
32
+ for i in range(len(boxes)):
33
+ x1, y1, x2, y2 = boxes[i]
34
+ x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
35
+ cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)
36
+ cv2.putText(image, f"{classes[i]} {probs[i]:.2f}", (x1, y1), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
37
 
38
  # Convert the resulting image to a PIL image
39
+ resulting_image = Image.fromarray(image)
40
 
41
  # Get the labels
42
  labels = results.pandas().xyxy[0]["name"].values
 
49
 
50
  demo = gr.Interface(
51
  snap,
52
+ [gr.Image(source="webcam", tool=None, streaming=True), gr.inputs.Radio(["M-Raw", "S-Raw", "N-Raw"], value="M-Raw"), gr.Slider(0, 1, value=0.6, label="Classifier Confidence Threshold"), gr.Slider(0, 1, value=0.7, label="IoU Threshold")],
53
  ["image"],
54
  title="Baybayin Instance Detection"
55
  )
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  numpy
2
  Pillow
3
  ultralytics==8.0.21
4
- gradio
 
 
1
  numpy
2
  Pillow
3
  ultralytics==8.0.21
4
+ gradio
5
+ opencv-python