Spaces:
Running
Running
Zengyf-CVer
commited on
Commit
·
c7d597c
1
Parent(s):
0184777
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,14 @@
|
|
1 |
-
# Gradio YOLOv8 Det v0.2.
|
2 |
# 创建人:曾逸夫
|
3 |
-
# 创建时间:2023-
|
4 |
|
5 |
import argparse
|
6 |
-
import csv
|
7 |
-
import os
|
8 |
-
import sys
|
9 |
-
|
10 |
-
from ultralytics import YOLO
|
11 |
-
|
12 |
-
csv.field_size_limit(sys.maxsize)
|
13 |
-
|
14 |
import gc
|
15 |
import json
|
|
|
16 |
import random
|
17 |
import shutil
|
|
|
18 |
from collections import Counter
|
19 |
from pathlib import Path
|
20 |
|
@@ -25,6 +19,11 @@ import numpy as np
|
|
25 |
import pandas as pd
|
26 |
import plotly.express as px
|
27 |
from matplotlib import font_manager
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
ROOT_PATH = sys.path[0] # 项目根目录
|
30 |
|
@@ -45,7 +44,7 @@ from util.fonts_opt import is_fonts
|
|
45 |
ROOT_PATH = sys.path[0] # 根目录
|
46 |
|
47 |
# Gradio YOLOv8 Det版本
|
48 |
-
GYD_VERSION = "Gradio YOLOv8 Det v0.2.
|
49 |
|
50 |
# 文件后缀
|
51 |
suffix_list = [".csv", ".yaml"]
|
@@ -58,7 +57,7 @@ obj_style = ["小目标", "中目标", "大目标"]
|
|
58 |
|
59 |
|
60 |
def parse_args(known=False):
|
61 |
-
parser = argparse.ArgumentParser(description="Gradio YOLOv8 Det v0.2.
|
62 |
parser.add_argument("--model_type", "-mt", default="online", type=str, help="model type")
|
63 |
parser.add_argument("--source", "-src", default="upload", type=str, help="image input source")
|
64 |
parser.add_argument("--source_video", "-src_v", default="upload", type=str, help="video input source")
|
@@ -67,7 +66,7 @@ def parse_args(known=False):
|
|
67 |
parser.add_argument(
|
68 |
"--model_cfg",
|
69 |
"-mc",
|
70 |
-
default="./model_config/
|
71 |
type=str,
|
72 |
help="model config",
|
73 |
)
|
@@ -197,11 +196,14 @@ def pil_draw(img, score_l, bbox_l, cls_l, cls_index_l, textFont, color_list):
|
|
197 |
for score, (xmin, ymin, xmax, ymax), label, cls_index in zip(score_l, bbox_l, cls_l, cls_index_l):
|
198 |
img_pil.rectangle([xmin, ymin, xmax, ymax], fill=None, outline=color_list[cls_index], width=2) # 边界框
|
199 |
countdown_msg = f"{id}-{label} {score:.2f}"
|
200 |
-
text_w, text_h = textFont.getsize(countdown_msg) # 标签尺寸
|
201 |
-
|
|
|
|
|
202 |
# 标签背景
|
203 |
img_pil.rectangle(
|
204 |
-
(xmin, ymin, xmin + text_w, ymin + text_h),
|
|
|
205 |
fill=color_list[cls_index],
|
206 |
outline=color_list[cls_index],
|
207 |
)
|
@@ -368,7 +370,6 @@ def main(args):
|
|
368 |
cls_name = args.cls_name
|
369 |
inference_size = args.inference_size
|
370 |
slider_step = args.slider_step
|
371 |
-
is_share = args.is_share
|
372 |
|
373 |
is_fonts(f"{ROOT_PATH}/fonts") # 检查字体文件
|
374 |
|
@@ -405,9 +406,7 @@ def main(args):
|
|
405 |
title = "Gradio YOLOv8 Det"
|
406 |
|
407 |
# 描述
|
408 |
-
description = "<div align='center'
|
409 |
-
<div align='center'>Author: 曾逸夫(Zeng Yifu), Github: https://github.com/Zengyf-CVer, \
|
410 |
-
thanks to <a href='https://github.com/gradio-app/gradio'>Gradio</a> & <a href='https://github.com/ultralytics/ultralytics'>YOLOv8</a></div>"
|
411 |
|
412 |
# 示例图片
|
413 |
examples_imgs = [
|
@@ -462,6 +461,14 @@ def main(args):
|
|
462 |
flagging_options=["good", "generally", "bad"],
|
463 |
)
|
464 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
465 |
gyd_img.launch(
|
466 |
inbrowser=True, # 自动打开默认浏览器
|
467 |
show_tips=True, # 自动显示gradio最新功能
|
@@ -470,8 +477,3 @@ def main(args):
|
|
470 |
show_error=True, # 在浏览器控制台中显示错误信息
|
471 |
quiet=True, # 禁止大多数打印语句
|
472 |
)
|
473 |
-
|
474 |
-
|
475 |
-
if __name__ == "__main__":
|
476 |
-
args = parse_args()
|
477 |
-
main(args)
|
|
|
1 |
+
# Gradio YOLOv8 Det v0.2.4
|
2 |
# 创建人:曾逸夫
|
3 |
+
# 创建时间:2023-08-14
|
4 |
|
5 |
import argparse
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
import gc
|
7 |
import json
|
8 |
+
import os
|
9 |
import random
|
10 |
import shutil
|
11 |
+
import sys
|
12 |
from collections import Counter
|
13 |
from pathlib import Path
|
14 |
|
|
|
19 |
import pandas as pd
|
20 |
import plotly.express as px
|
21 |
from matplotlib import font_manager
|
22 |
+
from ultralytics import YOLO
|
23 |
+
|
24 |
+
# pip_source = "https://pypi.tuna.tsinghua.edu.cn/simple some-package"
|
25 |
+
# os.system(f"pip install gradio --upgrade -i {pip_source}")
|
26 |
+
# os.system(f"pip install ultralytics --upgrade -i {pip_source}")
|
27 |
|
28 |
ROOT_PATH = sys.path[0] # 项目根目录
|
29 |
|
|
|
44 |
ROOT_PATH = sys.path[0] # 根目录
|
45 |
|
46 |
# Gradio YOLOv8 Det版本
|
47 |
+
GYD_VERSION = "Gradio YOLOv8 Det v0.2.3"
|
48 |
|
49 |
# 文件后缀
|
50 |
suffix_list = [".csv", ".yaml"]
|
|
|
57 |
|
58 |
|
59 |
def parse_args(known=False):
|
60 |
+
parser = argparse.ArgumentParser(description="Gradio YOLOv8 Det v0.2.3")
|
61 |
parser.add_argument("--model_type", "-mt", default="online", type=str, help="model type")
|
62 |
parser.add_argument("--source", "-src", default="upload", type=str, help="image input source")
|
63 |
parser.add_argument("--source_video", "-src_v", default="upload", type=str, help="video input source")
|
|
|
66 |
parser.add_argument(
|
67 |
"--model_cfg",
|
68 |
"-mc",
|
69 |
+
default="./model_config/model_name_all.yaml",
|
70 |
type=str,
|
71 |
help="model config",
|
72 |
)
|
|
|
196 |
for score, (xmin, ymin, xmax, ymax), label, cls_index in zip(score_l, bbox_l, cls_l, cls_index_l):
|
197 |
img_pil.rectangle([xmin, ymin, xmax, ymax], fill=None, outline=color_list[cls_index], width=2) # 边界框
|
198 |
countdown_msg = f"{id}-{label} {score:.2f}"
|
199 |
+
# text_w, text_h = textFont.getsize(countdown_msg) # 标签尺寸 pillow 9.5.0
|
200 |
+
# left, top, left + width, top + height
|
201 |
+
# 标签尺寸 pillow 10.0.0
|
202 |
+
text_xmin, text_ymin, text_xmax, text_ymax = textFont.getbbox(countdown_msg)
|
203 |
# 标签背景
|
204 |
img_pil.rectangle(
|
205 |
+
# (xmin, ymin, xmin + text_w, ymin + text_h), # pillow 9.5.0
|
206 |
+
(xmin, ymin, xmin + text_xmax - text_xmin, ymin + text_ymax - text_ymin), # pillow 10.0.0
|
207 |
fill=color_list[cls_index],
|
208 |
outline=color_list[cls_index],
|
209 |
)
|
|
|
370 |
cls_name = args.cls_name
|
371 |
inference_size = args.inference_size
|
372 |
slider_step = args.slider_step
|
|
|
373 |
|
374 |
is_fonts(f"{ROOT_PATH}/fonts") # 检查字体文件
|
375 |
|
|
|
406 |
title = "Gradio YOLOv8 Det"
|
407 |
|
408 |
# 描述
|
409 |
+
description = "<div align='center'>基于YOLOv8的目标检测与图像分割系统</div>"
|
|
|
|
|
410 |
|
411 |
# 示例图片
|
412 |
examples_imgs = [
|
|
|
461 |
flagging_options=["good", "generally", "bad"],
|
462 |
)
|
463 |
|
464 |
+
return gyd_img
|
465 |
+
|
466 |
+
|
467 |
+
if __name__ == "__main__":
|
468 |
+
args = parse_args()
|
469 |
+
gyd_img = main(args)
|
470 |
+
is_share = args.is_share
|
471 |
+
|
472 |
gyd_img.launch(
|
473 |
inbrowser=True, # 自动打开默认浏览器
|
474 |
show_tips=True, # 自动显示gradio最新功能
|
|
|
477 |
show_error=True, # 在浏览器控制台中显示错误信息
|
478 |
quiet=True, # 禁止大多数打印语句
|
479 |
)
|
|
|
|
|
|
|
|
|
|