Spaces:
Sleeping
Sleeping
testing
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
import cv2
|
| 3 |
import requests
|
| 4 |
import os
|
|
|
|
| 5 |
|
| 6 |
import torch
|
| 7 |
import ultralytics
|
|
@@ -14,36 +15,44 @@ 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 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 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"),
|
| 44 |
]
|
| 45 |
outputs_image = [
|
| 46 |
-
gr.components.Image(type="
|
| 47 |
]
|
| 48 |
interface_image = gr.Interface(
|
| 49 |
fn=show_preds_image,
|
|
|
|
| 2 |
import cv2
|
| 3 |
import requests
|
| 4 |
import os
|
| 5 |
+
from PIL import Image
|
| 6 |
|
| 7 |
import torch
|
| 8 |
import ultralytics
|
|
|
|
| 15 |
|
| 16 |
path = [['img/test-image.jpg'], ['img/test-image-2.jpg']]
|
| 17 |
|
| 18 |
+
# def show_preds_image(image_path):
|
| 19 |
+
# image = cv2.imread(image_path)
|
| 20 |
+
# # outputs = model(source=image_path)
|
| 21 |
+
# # results = outputs[0].cpu().numpy()
|
| 22 |
+
# results = model(image_path)
|
| 23 |
+
# results.xyxy[0] # img1 predictions (tensor)
|
| 24 |
+
# results.pandas().xyxy[0] # img1 predictions (pandas)
|
| 25 |
+
# predictions = results.pred[0]
|
| 26 |
+
# boxes = predictions[:, :4] # x1, y1, x2, y2
|
| 27 |
+
# scores = predictions[:, 4]
|
| 28 |
+
# categories = predictions[:, 5]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
# # for i, det in enumerate(results.boxes.xyxy):
|
| 31 |
+
# # cv2.rectangle(
|
| 32 |
+
# # image,
|
| 33 |
+
# # (int(det[0]), int(det[1])),
|
| 34 |
+
# # (int(det[2]), int(det[3])),
|
| 35 |
+
# # color=(0, 0, 255),
|
| 36 |
+
# # thickness=2,
|
| 37 |
+
# # lineType=cv2.LINE_AA
|
| 38 |
+
# # )
|
| 39 |
+
# return results.show()
|
| 40 |
|
| 41 |
+
def show_preds_image(im, size=640):
|
| 42 |
+
g = (size / max(im.size)) # gain
|
| 43 |
+
im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS) # resize
|
| 44 |
+
|
| 45 |
+
results = model(im) # inference
|
| 46 |
+
results.render() # updates results.imgs with boxes and labels
|
| 47 |
+
results.save()
|
| 48 |
+
os.system("ls")
|
| 49 |
+
return "out.png"
|
| 50 |
|
| 51 |
inputs_image = [
|
| 52 |
gr.components.Image(type="filepath", label="Input Image"),
|
| 53 |
]
|
| 54 |
outputs_image = [
|
| 55 |
+
gr.components.Image(type="file", label="Output Image"),
|
| 56 |
]
|
| 57 |
interface_image = gr.Interface(
|
| 58 |
fn=show_preds_image,
|