Update app.py
Browse files
app.py
CHANGED
@@ -5,24 +5,29 @@ from ultralyticsplus import YOLO, render_result
|
|
5 |
import cv2
|
6 |
import numpy as np
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
#
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
# # im_rgb = Image.fromarray(im_rgb)
|
18 |
|
19 |
-
|
20 |
|
21 |
name = ['grenade','knife','pistol','rifle']
|
22 |
|
23 |
def response2(image: gr.Image = None,image_size: gr.Slider = 640, conf_threshold: gr.Slider = 0.3, iou_threshold: gr.Slider = 0.6):
|
24 |
-
|
25 |
-
model = YOLO('best (1).pt')
|
26 |
|
27 |
results = model.predict(image, conf=conf_threshold, iou=iou_threshold, imgsz=image_size)
|
28 |
|
@@ -30,16 +35,15 @@ def response2(image: gr.Image = None,image_size: gr.Slider = 640, conf_threshold
|
|
30 |
|
31 |
render = render_result(model=model, image=image, result=results[0], rect_th = 1, text_th = 1)
|
32 |
|
33 |
-
text = ""
|
34 |
-
|
35 |
|
36 |
-
|
37 |
-
|
|
|
38 |
# xywh = int(results.boxes.xywh)
|
39 |
# x = xywh[0]
|
40 |
# y = xywh[1]
|
41 |
|
42 |
-
|
43 |
|
44 |
return render,text
|
45 |
|
|
|
5 |
import cv2
|
6 |
import numpy as np
|
7 |
|
8 |
+
model = YOLO('best (1).pt')
|
9 |
+
|
10 |
+
def response(image):
|
11 |
+
print(image)
|
12 |
+
results = model(image)
|
13 |
+
text = ""
|
14 |
+
for i, r in enumerate(results):
|
15 |
|
16 |
+
conf = results.boxes.conf
|
17 |
+
cls = results.boxes.cls
|
18 |
+
# Plot results image
|
19 |
+
im_bgr = r.plot()
|
20 |
+
im_rgb = im_bgr[..., ::-1] # Convert BGR to RGB
|
21 |
+
text += f"Detected {cls} with confidence {conf} at \n"
|
22 |
+
|
23 |
+
# im_rgb = Image.fromarray(im_rgb)
|
24 |
|
|
|
25 |
|
26 |
+
return text
|
27 |
|
28 |
name = ['grenade','knife','pistol','rifle']
|
29 |
|
30 |
def response2(image: gr.Image = None,image_size: gr.Slider = 640, conf_threshold: gr.Slider = 0.3, iou_threshold: gr.Slider = 0.6):
|
|
|
|
|
31 |
|
32 |
results = model.predict(image, conf=conf_threshold, iou=iou_threshold, imgsz=image_size)
|
33 |
|
|
|
35 |
|
36 |
render = render_result(model=model, image=image, result=results[0], rect_th = 1, text_th = 1)
|
37 |
|
|
|
|
|
38 |
|
39 |
+
text = response(image)
|
40 |
+
|
41 |
+
|
42 |
# xywh = int(results.boxes.xywh)
|
43 |
# x = xywh[0]
|
44 |
# y = xywh[1]
|
45 |
|
46 |
+
|
47 |
|
48 |
return render,text
|
49 |
|