Spaces:
Runtime error
Runtime error
roxas010394
commited on
Commit
•
9ac55f5
1
Parent(s):
1e4d149
app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from ultralytics import YOLO
|
2 |
+
import matplotlib.pyplot as plt
|
3 |
+
import gradio as gr
|
4 |
+
import cv2
|
5 |
+
|
6 |
+
import seaborn as sns
|
7 |
+
|
8 |
+
def predict(path:str):
|
9 |
+
model = YOLO("yolov8n.yaml")
|
10 |
+
model = YOLO("best.pt")
|
11 |
+
image = cv2.imread(path)
|
12 |
+
|
13 |
+
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
14 |
+
results = model.predict(source=path)
|
15 |
+
paleta= sns.color_palette("bright", 17)
|
16 |
+
fig = plt.figure()
|
17 |
+
vectObjs = results[0].masks.xy
|
18 |
+
resNumClase = results[0].boxes.cls.numpy().astype(int)
|
19 |
+
conf = results[0].boxes.conf.numpy()
|
20 |
+
for i in range(len(vectObjs)):
|
21 |
+
objDet = vectObjs[i].astype(int)
|
22 |
+
color = (paleta[i][0]*255, paleta[i][1]*255, paleta[i][2]*255)
|
23 |
+
image = cv2.polylines(image, [objDet], True, color, 4)
|
24 |
+
plt.text(objDet[0][0], objDet[0][1], results[0].names[resNumClase[i]]+" "+ str(conf[i]), bbox=dict(facecolor=paleta[i], alpha=0.5))
|
25 |
+
|
26 |
+
plt.imshow(image)
|
27 |
+
plt.axis('off')
|
28 |
+
return plt
|
29 |
+
gr.Interface(fn=predict,
|
30 |
+
inputs=gr.components.Image(type="filepath", label="Input"),
|
31 |
+
outputs=gr.Plot(label="Resultado de detección de objetos con regularizacion")).launch()
|
32 |
+
#outputs=gr.components.Image(type="pil", label="Output")).launch()
|