Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,16 @@ from ultralytics import ASSETS, YOLO
|
|
7 |
model_path = 'new_data_improved_object_detector.pt'
|
8 |
model = YOLO(model_path)
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
def predict_image(img, conf_threshold, iou_threshold):
|
11 |
"""Predicts and plots labeled objects in an image using YOLOv8 model with adjustable confidence and IOU thresholds."""
|
12 |
# Convert the input image to grayscale
|
@@ -22,33 +32,15 @@ def predict_image(img, conf_threshold, iou_threshold):
|
|
22 |
)
|
23 |
|
24 |
im_arrays = []
|
25 |
-
all_model_result=[]
|
26 |
-
all_xywh = []
|
27 |
-
all_clss = []
|
28 |
-
all_names = []
|
29 |
-
all_confidence = []
|
30 |
-
all_xyxy =[]
|
31 |
|
32 |
for r in results:
|
33 |
-
model_result =results[0]
|
34 |
-
xywh = r.boxes.xywh.cpu().tolist()
|
35 |
-
clss = r.boxes.cls.cpu().tolist()
|
36 |
-
names = [r.names[cls] for cls in clss] # Convert class indices to names
|
37 |
-
confidence = r.boxes.conf.cpu().tolist()
|
38 |
-
xyxy = r.boxes.cpu().xyxy.tolist()
|
39 |
-
|
40 |
im_array = r.plot()
|
41 |
im = Image.fromarray(im_array[..., ::-1])
|
42 |
im_arrays.append(im)
|
43 |
-
|
44 |
-
all_model_result.extend(model_result)
|
45 |
-
all_xywh.extend(xywh)
|
46 |
-
all_clss.extend(clss)
|
47 |
-
all_names.extend(names)
|
48 |
-
all_confidence.extend(confidence)
|
49 |
-
all_xyxy.extend(xyxy)
|
50 |
|
51 |
-
|
|
|
|
|
52 |
|
53 |
iface = gr.Interface(
|
54 |
fn=predict_image,
|
@@ -59,10 +51,8 @@ iface = gr.Interface(
|
|
59 |
],
|
60 |
outputs=[
|
61 |
gr.Gallery(label="Result Images"),
|
62 |
-
gr.JSON(label="Detection Bounding Boxes (model_result)"),
|
63 |
gr.JSON(label="Detection Bounding Boxes (xywh)"),
|
64 |
gr.JSON(label="Detection Class Indices"),
|
65 |
-
gr.JSON(label="Detection Class Names"),
|
66 |
gr.JSON(label="Detection Confidence Scores"),
|
67 |
gr.JSON(label="Detection Bounding Boxes (xyxy)")
|
68 |
],
|
|
|
7 |
model_path = 'new_data_improved_object_detector.pt'
|
8 |
model = YOLO(model_path)
|
9 |
|
10 |
+
def Get_logo_xywh(model_result_input):
|
11 |
+
model_result = model_result_input[0]
|
12 |
+
xywh = model_result.boxes.xywh.cpu().tolist()
|
13 |
+
clss = model_result.boxes.cls.cpu().tolist()
|
14 |
+
# names = model_result_input[0].names
|
15 |
+
confidence = model_result.boxes.conf.cpu().tolist()
|
16 |
+
xyxy = model_result.boxes.cpu().xyxy.tolist()
|
17 |
+
|
18 |
+
return xywh, clss, confidence, xyxy
|
19 |
+
|
20 |
def predict_image(img, conf_threshold, iou_threshold):
|
21 |
"""Predicts and plots labeled objects in an image using YOLOv8 model with adjustable confidence and IOU thresholds."""
|
22 |
# Convert the input image to grayscale
|
|
|
32 |
)
|
33 |
|
34 |
im_arrays = []
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
for r in results:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
im_array = r.plot()
|
38 |
im = Image.fromarray(im_array[..., ::-1])
|
39 |
im_arrays.append(im)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
+
xywh, clss, confidence, xyxy = Get_logo_xywh(results)
|
42 |
+
|
43 |
+
return im_arrays, xywh, clss, confidence, xyxy
|
44 |
|
45 |
iface = gr.Interface(
|
46 |
fn=predict_image,
|
|
|
51 |
],
|
52 |
outputs=[
|
53 |
gr.Gallery(label="Result Images"),
|
|
|
54 |
gr.JSON(label="Detection Bounding Boxes (xywh)"),
|
55 |
gr.JSON(label="Detection Class Indices"),
|
|
|
56 |
gr.JSON(label="Detection Confidence Scores"),
|
57 |
gr.JSON(label="Detection Bounding Boxes (xyxy)")
|
58 |
],
|