Spaces:
Running
Running
new try
Browse files
app.py
CHANGED
@@ -11,24 +11,42 @@ model = torch.hub.load("ultralytics/yolov5", "custom", path="yolov5_0.65map_exp7
|
|
11 |
force_reload=False)
|
12 |
model.conf = 0.20 # NMS confidence threshold
|
13 |
|
14 |
-
path = [['img/test-image.jpg'], ['img/test-image-2']]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
def show_preds_image(image_path):
|
17 |
-
|
18 |
-
|
19 |
-
results =
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
|
33 |
inputs_image = [
|
34 |
gr.components.Image(type="filepath", label="Input Image"),
|
|
|
11 |
force_reload=False)
|
12 |
model.conf = 0.20 # NMS confidence threshold
|
13 |
|
14 |
+
path = [['img/test-image.jpg'], ['img/test-image-2.jpg']]
|
15 |
+
|
16 |
+
# def show_preds_image(image_path):
|
17 |
+
# image = cv2.imread(image_path)
|
18 |
+
# outputs = model.predict(source=image_path)
|
19 |
+
# results = outputs[0].cpu().numpy()
|
20 |
+
# for i, det in enumerate(results.boxes.xyxy):
|
21 |
+
# cv2.rectangle(
|
22 |
+
# image,
|
23 |
+
# (int(det[0]), int(det[1])),
|
24 |
+
# (int(det[2]), int(det[3])),
|
25 |
+
# color=(0, 0, 255),
|
26 |
+
# thickness=2,
|
27 |
+
# lineType=cv2.LINE_AA
|
28 |
+
# )
|
29 |
+
# return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
30 |
|
31 |
def show_preds_image(image_path):
|
32 |
+
# perform inference
|
33 |
+
image_path = path
|
34 |
+
results = model(image_path, size=640)
|
35 |
+
# Results
|
36 |
+
results.print()
|
37 |
+
|
38 |
+
results.xyxy[0] # img1 predictions (tensor)
|
39 |
+
results.pandas().xyxy[0] # img1 predictions (pandas)
|
40 |
+
|
41 |
+
# parse results
|
42 |
+
predictions = results.pred[0]
|
43 |
+
boxes = predictions[:, :4] # x1, y1, x2, y2
|
44 |
+
scores = predictions[:, 4]
|
45 |
+
categories = predictions[:, 5]
|
46 |
|
47 |
+
return results.show()
|
48 |
|
49 |
+
|
50 |
|
51 |
inputs_image = [
|
52 |
gr.components.Image(type="filepath", label="Input Image"),
|