Spaces:
Running
Running
Zengyf-CVer
commited on
Commit
•
7d2e24b
1
Parent(s):
64a386a
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,9 @@
|
|
1 |
-
# Gradio YOLOv8 Det v0.2.
|
2 |
# 创建人:曾逸夫
|
3 |
-
# 创建时间:2023-
|
4 |
|
5 |
import argparse
|
|
|
6 |
import gc
|
7 |
import json
|
8 |
import os
|
@@ -44,7 +45,7 @@ from util.fonts_opt import is_fonts
|
|
44 |
ROOT_PATH = sys.path[0] # 根目录
|
45 |
|
46 |
# Gradio YOLOv8 Det版本
|
47 |
-
GYD_VERSION = "Gradio YOLOv8 Det v0.2.
|
48 |
|
49 |
# 文件后缀
|
50 |
suffix_list = [".csv", ".yaml"]
|
@@ -57,7 +58,7 @@ obj_style = ["小目标", "中目标", "大目标"]
|
|
57 |
|
58 |
|
59 |
def parse_args(known=False):
|
60 |
-
parser = argparse.ArgumentParser(description="Gradio YOLOv8 Det v0.2.
|
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")
|
@@ -240,13 +241,14 @@ def seg_output(img_path, seg_mask_list, color_list, cls_list):
|
|
240 |
img = cv2.imread(img_path)
|
241 |
img_c = img.copy()
|
242 |
|
243 |
-
w, h = img.shape[1], img.shape[0]
|
244 |
|
245 |
# 获取分割坐标
|
246 |
for seg_mask, cls_index in zip(seg_mask_list, cls_list):
|
247 |
img_mask = []
|
248 |
for i in range(len(seg_mask)):
|
249 |
-
img_mask.append([seg_mask[i][0] * w, seg_mask[i][1] * h])
|
|
|
250 |
|
251 |
polygon_drawing(img_mask, img_c, color_list[int(cls_index)]) # 绘制分割图形
|
252 |
|
@@ -255,7 +257,7 @@ def seg_output(img_path, seg_mask_list, color_list, cls_list):
|
|
255 |
return img_mask_merge
|
256 |
|
257 |
|
258 |
-
#
|
259 |
def yolo_det_img(img_path, model_name, infer_size, conf, iou):
|
260 |
|
261 |
global model, model_name_tmp, device_tmp
|
@@ -281,7 +283,8 @@ def yolo_det_img(img_path, model_name, infer_size, conf, iou):
|
|
281 |
|
282 |
# 图像分割
|
283 |
if (model_name[-3:] == "seg"):
|
284 |
-
masks_list = predict_results.masks.
|
|
|
285 |
img_mask_merge = seg_output(img_path, masks_list, color_list, cls_list)
|
286 |
img = Image.fromarray(cv2.cvtColor(img_mask_merge, cv2.COLOR_BGRA2RGBA))
|
287 |
else:
|
|
|
1 |
+
# Gradio YOLOv8 Det v0.2.5
|
2 |
# 创建人:曾逸夫
|
3 |
+
# 创建时间:2023-10-21
|
4 |
|
5 |
import argparse
|
6 |
+
import csv
|
7 |
import gc
|
8 |
import json
|
9 |
import os
|
|
|
45 |
ROOT_PATH = sys.path[0] # 根目录
|
46 |
|
47 |
# Gradio YOLOv8 Det版本
|
48 |
+
GYD_VERSION = "Gradio YOLOv8 Det v0.2.5"
|
49 |
|
50 |
# 文件后缀
|
51 |
suffix_list = [".csv", ".yaml"]
|
|
|
58 |
|
59 |
|
60 |
def parse_args(known=False):
|
61 |
+
parser = argparse.ArgumentParser(description="Gradio YOLOv8 Det v0.2.5")
|
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")
|
|
|
241 |
img = cv2.imread(img_path)
|
242 |
img_c = img.copy()
|
243 |
|
244 |
+
# w, h = img.shape[1], img.shape[0]
|
245 |
|
246 |
# 获取分割坐标
|
247 |
for seg_mask, cls_index in zip(seg_mask_list, cls_list):
|
248 |
img_mask = []
|
249 |
for i in range(len(seg_mask)):
|
250 |
+
# img_mask.append([seg_mask[i][0] * w, seg_mask[i][1] * h])
|
251 |
+
img_mask.append([seg_mask[i][0], seg_mask[i][1]])
|
252 |
|
253 |
polygon_drawing(img_mask, img_c, color_list[int(cls_index)]) # 绘制分割图形
|
254 |
|
|
|
257 |
return img_mask_merge
|
258 |
|
259 |
|
260 |
+
# YOLOv8图片检测函数
|
261 |
def yolo_det_img(img_path, model_name, infer_size, conf, iou):
|
262 |
|
263 |
global model, model_name_tmp, device_tmp
|
|
|
283 |
|
284 |
# 图像分割
|
285 |
if (model_name[-3:] == "seg"):
|
286 |
+
# masks_list = predict_results.masks.xyn
|
287 |
+
masks_list = predict_results.masks.xy
|
288 |
img_mask_merge = seg_output(img_path, masks_list, color_list, cls_list)
|
289 |
img = Image.fromarray(cv2.cvtColor(img_mask_merge, cv2.COLOR_BGRA2RGBA))
|
290 |
else:
|