Spaces:
Runtime error
Runtime error
Zengyf-CVer
commited on
Commit
•
d8b8d1c
1
Parent(s):
0ddd663
app update
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
# Gradio YOLOv5 Det v0.5
|
2 |
# author: Zeng Yifu(曾逸夫)
|
3 |
-
# creation time: 2022-
|
4 |
# email: zyfiy1314@163.com
|
5 |
# project homepage: https://gitee.com/CV_Lab/gradio_yolov5_det
|
6 |
|
@@ -24,7 +24,6 @@ import numpy as np
|
|
24 |
import pandas as pd
|
25 |
import plotly.express as px
|
26 |
from matplotlib import font_manager
|
27 |
-
from matplotlib.ticker import MaxNLocator
|
28 |
|
29 |
ROOT_PATH = sys.path[0] # 项目根目录
|
30 |
|
@@ -49,7 +48,7 @@ ROOT_PATH = sys.path[0] # 根目录
|
|
49 |
yolov5_path = "ultralytics/yolov5"
|
50 |
|
51 |
# 本地模型路径
|
52 |
-
|
53 |
|
54 |
# Gradio YOLOv5 Det版本
|
55 |
GYD_VERSION = "Gradio YOLOv5 Det v0.5"
|
@@ -101,7 +100,7 @@ def parse_args(known=False):
|
|
101 |
parser.add_argument(
|
102 |
"--device",
|
103 |
"-dev",
|
104 |
-
default="
|
105 |
type=str,
|
106 |
help="cuda or cpu",
|
107 |
)
|
@@ -154,6 +153,18 @@ def yaml_csv(file_path, file_tag):
|
|
154 |
return file_names
|
155 |
|
156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
# 模型加载
|
158 |
def model_loading(model_name, device, opt=[]):
|
159 |
|
@@ -163,7 +174,7 @@ def model_loading(model_name, device, opt=[]):
|
|
163 |
yolov5_path,
|
164 |
model_name,
|
165 |
device=device,
|
166 |
-
force_reload=[True if "refresh_yolov5" in opt else False][0],
|
167 |
_verbose=True,
|
168 |
)
|
169 |
except Exception as e:
|
@@ -472,7 +483,7 @@ def yolo_det_video(video, device, model_name, infer_size, conf, iou, max_num, mo
|
|
472 |
model.max_det = int(max_num) # 最大检测框数
|
473 |
model.classes = model_cls # 模型类别
|
474 |
|
475 |
-
color_list =
|
476 |
|
477 |
# ---------------- 加载字体 ----------------
|
478 |
yaml_index = cls_name.index(".yaml")
|
@@ -746,7 +757,7 @@ def main(args):
|
|
746 |
# article="https://gitee.com/CV_Lab/gradio_yolov5_det"
|
747 |
|
748 |
# 示例图片
|
749 |
-
|
750 |
[
|
751 |
"./img_examples/bus.jpg",
|
752 |
"cpu",
|
@@ -788,6 +799,41 @@ def main(args):
|
|
788 |
["人", "椅子", "杯子", "笔记本电脑"],
|
789 |
["label", "pdf", "csv", "excel"],],]
|
790 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
791 |
# 接口
|
792 |
gyd_img = gr.Interface(
|
793 |
fn=yolo_det_img,
|
@@ -796,13 +842,13 @@ def main(args):
|
|
796 |
title=title,
|
797 |
description=description,
|
798 |
# article=article,
|
799 |
-
examples=
|
800 |
cache_examples=False,
|
801 |
# theme="seafoam",
|
802 |
# live=True, # 实时变更输出
|
803 |
flagging_dir="run", # 输出目录
|
804 |
-
|
805 |
-
|
806 |
)
|
807 |
|
808 |
gyd_video = gr.Interface(
|
@@ -812,12 +858,13 @@ def main(args):
|
|
812 |
title=title,
|
813 |
description=description,
|
814 |
# article=article,
|
815 |
-
|
|
|
816 |
# theme="seafoam",
|
817 |
# live=True, # 实时变更输出
|
818 |
flagging_dir="run", # 输出目录
|
819 |
-
allow_flagging="
|
820 |
-
|
821 |
)
|
822 |
|
823 |
gyd = gr.TabbedInterface(interface_list=[gyd_img, gyd_video], tab_names=["图片模式", "视频模式"])
|
|
|
1 |
# Gradio YOLOv5 Det v0.5
|
2 |
# author: Zeng Yifu(曾逸夫)
|
3 |
+
# creation time: 2022-08-05
|
4 |
# email: zyfiy1314@163.com
|
5 |
# project homepage: https://gitee.com/CV_Lab/gradio_yolov5_det
|
6 |
|
|
|
24 |
import pandas as pd
|
25 |
import plotly.express as px
|
26 |
from matplotlib import font_manager
|
|
|
27 |
|
28 |
ROOT_PATH = sys.path[0] # 项目根目录
|
29 |
|
|
|
48 |
yolov5_path = "ultralytics/yolov5"
|
49 |
|
50 |
# 本地模型路径
|
51 |
+
local_model_path = f"{ROOT_PATH}/models"
|
52 |
|
53 |
# Gradio YOLOv5 Det版本
|
54 |
GYD_VERSION = "Gradio YOLOv5 Det v0.5"
|
|
|
100 |
parser.add_argument(
|
101 |
"--device",
|
102 |
"-dev",
|
103 |
+
default="cuda:0",
|
104 |
type=str,
|
105 |
help="cuda or cpu",
|
106 |
)
|
|
|
153 |
return file_names
|
154 |
|
155 |
|
156 |
+
# 检查网络连接
|
157 |
+
def check_online():
|
158 |
+
# 参考:https://github.com/ultralytics/yolov5/blob/master/utils/general.py
|
159 |
+
# Check internet connectivity
|
160 |
+
import socket
|
161 |
+
try:
|
162 |
+
socket.create_connection(("1.1.1.1", 443), 5) # check host accessibility
|
163 |
+
return True
|
164 |
+
except OSError:
|
165 |
+
return False
|
166 |
+
|
167 |
+
|
168 |
# 模型加载
|
169 |
def model_loading(model_name, device, opt=[]):
|
170 |
|
|
|
174 |
yolov5_path,
|
175 |
model_name,
|
176 |
device=device,
|
177 |
+
force_reload=[True if "refresh_yolov5" in opt and check_online() else False][0],
|
178 |
_verbose=True,
|
179 |
)
|
180 |
except Exception as e:
|
|
|
483 |
model.max_det = int(max_num) # 最大检测框数
|
484 |
model.classes = model_cls # 模型类别
|
485 |
|
486 |
+
color_list = random_color(len(model_cls_name_cp), True)
|
487 |
|
488 |
# ---------------- 加载字体 ----------------
|
489 |
yaml_index = cls_name.index(".yaml")
|
|
|
757 |
# article="https://gitee.com/CV_Lab/gradio_yolov5_det"
|
758 |
|
759 |
# 示例图片
|
760 |
+
examples_img = [
|
761 |
[
|
762 |
"./img_examples/bus.jpg",
|
763 |
"cpu",
|
|
|
799 |
["人", "椅子", "杯子", "笔记本电脑"],
|
800 |
["label", "pdf", "csv", "excel"],],]
|
801 |
|
802 |
+
examples_video = [
|
803 |
+
[
|
804 |
+
"./video_examples/test01.mp4",
|
805 |
+
"cpu",
|
806 |
+
"yolov5s",
|
807 |
+
640,
|
808 |
+
0.5,
|
809 |
+
0.45,
|
810 |
+
12,
|
811 |
+
["鸟"],
|
812 |
+
["label"],
|
813 |
+
"Matplotlib",],
|
814 |
+
[
|
815 |
+
"./video_examples/test02.mp4",
|
816 |
+
"cpu",
|
817 |
+
"yolov5m",
|
818 |
+
640,
|
819 |
+
0.6,
|
820 |
+
0.5,
|
821 |
+
15,
|
822 |
+
["马"],
|
823 |
+
["label"],
|
824 |
+
"Matplotlib",],
|
825 |
+
[
|
826 |
+
"./video_examples/test03.mp4",
|
827 |
+
"cpu",
|
828 |
+
"yolov5s6",
|
829 |
+
1280,
|
830 |
+
0.5,
|
831 |
+
0.5,
|
832 |
+
20,
|
833 |
+
["人", "风筝"],
|
834 |
+
["label"],
|
835 |
+
"Plotly",],]
|
836 |
+
|
837 |
# 接口
|
838 |
gyd_img = gr.Interface(
|
839 |
fn=yolo_det_img,
|
|
|
842 |
title=title,
|
843 |
description=description,
|
844 |
# article=article,
|
845 |
+
examples=examples_img,
|
846 |
cache_examples=False,
|
847 |
# theme="seafoam",
|
848 |
# live=True, # 实时变更输出
|
849 |
flagging_dir="run", # 输出目录
|
850 |
+
allow_flagging="manual",
|
851 |
+
flagging_options=["good", "generally", "bad"],
|
852 |
)
|
853 |
|
854 |
gyd_video = gr.Interface(
|
|
|
858 |
title=title,
|
859 |
description=description,
|
860 |
# article=article,
|
861 |
+
examples=examples_video,
|
862 |
+
cache_examples=False,
|
863 |
# theme="seafoam",
|
864 |
# live=True, # 实时变更输出
|
865 |
flagging_dir="run", # 输出目录
|
866 |
+
allow_flagging="manual",
|
867 |
+
flagging_options=["good", "generally", "bad"],
|
868 |
)
|
869 |
|
870 |
gyd = gr.TabbedInterface(interface_list=[gyd_img, gyd_video], tab_names=["图片模式", "视频模式"])
|