Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
from skimage import data
|
4 |
-
from ultralytics.data import utils
|
5 |
import ultralytics
|
6 |
from pathlib import Path
|
7 |
from torchkeras import plots
|
@@ -9,17 +9,16 @@ from torchkeras import plots
|
|
9 |
model = ultralytics.YOLO('yolov8n.pt')
|
10 |
|
11 |
#load class_names
|
12 |
-
yaml_path = str('coco128.yaml')
|
13 |
class_names = utils.yaml_load(yaml_path)['names']
|
14 |
|
15 |
def detect(img):
|
16 |
if isinstance(img,str):
|
17 |
img = get_url_img(img) if img.startswith('http') else Image.open(img).convert('RGB')
|
18 |
result = model.predict(source=img)
|
19 |
-
if len(result[0].boxes.
|
20 |
-
|
21 |
-
|
22 |
-
print(result[0].boxes)
|
23 |
else:
|
24 |
vis = img
|
25 |
return vis
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
from skimage import data
|
4 |
+
from ultralytics.yolo.data import utils
|
5 |
import ultralytics
|
6 |
from pathlib import Path
|
7 |
from torchkeras import plots
|
|
|
9 |
model = ultralytics.YOLO('yolov8n.pt')
|
10 |
|
11 |
#load class_names
|
12 |
+
yaml_path = str(Path(ultralytics.__file__).parent/'datasets/coco128.yaml')
|
13 |
class_names = utils.yaml_load(yaml_path)['names']
|
14 |
|
15 |
def detect(img):
|
16 |
if isinstance(img,str):
|
17 |
img = get_url_img(img) if img.startswith('http') else Image.open(img).convert('RGB')
|
18 |
result = model.predict(source=img)
|
19 |
+
if len(result[0].boxes.boxes)>0:
|
20 |
+
vis = plots.plot_detection(img,boxes=result[0].boxes.boxes,
|
21 |
+
class_names=class_names, min_score=0.2)
|
|
|
22 |
else:
|
23 |
vis = img
|
24 |
return vis
|