Spaces:
Running
Running
dont know
Browse files
app.py
CHANGED
@@ -5,70 +5,39 @@ import os
|
|
5 |
|
6 |
import torch
|
7 |
import ultralytics
|
8 |
-
from ultralytics import YOLO
|
9 |
|
10 |
|
11 |
-
|
12 |
-
|
13 |
|
14 |
-
model = YOLO("yolov5_0.65map_exp7_best.pt")
|
15 |
model.conf = 0.20 # NMS confidence threshold
|
16 |
|
17 |
path = [['img/test-image.jpg'], ['img/test-image-2.jpg']]
|
18 |
|
19 |
-
# def show_preds_image(image_path):
|
20 |
-
# image = cv2.imread(image_path)
|
21 |
-
# # outputs = model(source=image_path)
|
22 |
-
# # results = outputs[0].cpu().numpy()
|
23 |
-
# results = model(image_path)
|
24 |
-
# results.xyxy[0] # img1 predictions (tensor)
|
25 |
-
# results.numpy().xyxy[0] # img1 predictions (pandas)
|
26 |
-
# predictions = results.pred[0]
|
27 |
-
# for i, det in enumerate(results.boxes.xyxy):
|
28 |
-
# cv2.rectangle(
|
29 |
-
# image,
|
30 |
-
# (int(det[0]), int(det[1])),
|
31 |
-
# (int(det[2]), int(det[3])),
|
32 |
-
# color=(0, 0, 255),
|
33 |
-
# thickness=2,
|
34 |
-
# lineType=cv2.LINE_AA
|
35 |
-
# )
|
36 |
-
# return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
37 |
-
|
38 |
def show_preds_image(image_path):
|
39 |
image = cv2.imread(image_path)
|
40 |
-
outputs = model
|
41 |
-
results = outputs[0].cpu().numpy()
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
#
|
54 |
-
#
|
55 |
-
#
|
56 |
-
#
|
57 |
-
#
|
58 |
-
#
|
59 |
-
|
60 |
-
# results.xyxy[0] # img1 predictions (tensor)
|
61 |
-
# results.pandas().xyxy[0] # img1 predictions (pandas)
|
62 |
-
|
63 |
-
# # parse results
|
64 |
-
# predictions = results.pred[0]
|
65 |
-
# boxes = predictions[:, :4] # x1, y1, x2, y2
|
66 |
-
# scores = predictions[:, 4]
|
67 |
-
# categories = predictions[:, 5]
|
68 |
|
69 |
-
# return results.show()
|
70 |
|
71 |
-
|
72 |
|
73 |
inputs_image = [
|
74 |
gr.components.Image(type="filepath", label="Input Image"),
|
|
|
5 |
|
6 |
import torch
|
7 |
import ultralytics
|
|
|
8 |
|
9 |
|
10 |
+
model = torch.hub.load("ultralytics/yolov5", "custom", path="yolov5_0.65map_exp7_best.pt",
|
11 |
+
force_reload=False)
|
12 |
|
|
|
13 |
model.conf = 0.20 # NMS confidence threshold
|
14 |
|
15 |
path = [['img/test-image.jpg'], ['img/test-image-2.jpg']]
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
def show_preds_image(image_path):
|
18 |
image = cv2.imread(image_path)
|
19 |
+
# outputs = model(source=image_path)
|
20 |
+
# results = outputs[0].cpu().numpy()
|
21 |
+
results = model(image_path)
|
22 |
+
results.xyxy[0] # img1 predictions (tensor)
|
23 |
+
results.pandas().xyxy[0] # img1 predictions (pandas)
|
24 |
+
predictions = results.pred[0]
|
25 |
+
boxes = predictions[:, :4] # x1, y1, x2, y2
|
26 |
+
scores = predictions[:, 4]
|
27 |
+
categories = predictions[:, 5]
|
28 |
+
|
29 |
+
# for i, det in enumerate(results.boxes.xyxy):
|
30 |
+
# cv2.rectangle(
|
31 |
+
# image,
|
32 |
+
# (int(det[0]), int(det[1])),
|
33 |
+
# (int(det[2]), int(det[3])),
|
34 |
+
# color=(0, 0, 255),
|
35 |
+
# thickness=2,
|
36 |
+
# lineType=cv2.LINE_AA
|
37 |
+
# )
|
38 |
+
return results.show()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
42 |
inputs_image = [
|
43 |
gr.components.Image(type="filepath", label="Input Image"),
|