Zengyf-CVer commited on
Commit
7291007
1 Parent(s): b59dc48

app update

Browse files
Files changed (1) hide show
  1. app.py +15 -17
app.py CHANGED
@@ -163,14 +163,9 @@ def check_online():
163
  def model_loading(img_path, conf, iou, infer_size, yolo_model="yolov8n.pt"):
164
  model = YOLO(yolo_model)
165
 
166
- results = model.predict(source=img_path, imgsz=infer_size, conf=conf, iou=iou, return_outputs=True)
167
- det = []
168
- for i in results:
169
- det.append(deepcopy(i))
170
-
171
- det_list = det[0]["det"].tolist()
172
-
173
- return det_list
174
 
175
 
176
  # 标签和边界框颜色设置
@@ -246,12 +241,15 @@ def yolo_det_img(img_path, model_name, infer_size, conf, iou):
246
  cls_index_det_stat = [] # 类别索引统计
247
 
248
  # 模型加载
249
- predict_list = model_loading(img_path, conf, iou, infer_size, yolo_model=f"{model_name}.pt")
 
 
 
250
 
251
  color_list = random_color(len(model_cls_name_cp), True)
252
 
253
  # 判断检测对象是否为空
254
- if (predict_list != []):
255
 
256
  # ---------------- 加载字体 ----------------
257
  yaml_index = cls_name.index(".yaml")
@@ -267,23 +265,23 @@ def yolo_det_img(img_path, model_name, infer_size, conf, iou):
267
  # 韩语
268
  textFont = ImageFont.truetype(str(f"{ROOT_PATH}/fonts/malgun.ttf"), size=FONTSIZE)
269
 
270
- for i in range(len(predict_list)):
271
  # id = int(i) # 实例ID
272
- obj_cls_index = int(predict_list[i][5]) # 类别索引
273
  cls_index_det_stat.append(obj_cls_index)
274
 
275
  obj_cls = model_cls_name_cp[obj_cls_index] # 类别
276
  cls_det_stat.append(obj_cls)
277
 
278
  # ------------ 边框坐标 ------------
279
- x0 = int(predict_list[i][0])
280
- y0 = int(predict_list[i][1])
281
- x1 = int(predict_list[i][2])
282
- y1 = int(predict_list[i][3])
283
 
284
  bbox_det_stat.append((x0, y0, x1, y1))
285
 
286
- conf = float(predict_list[i][4]) # 置信度
287
  score_det_stat.append(conf)
288
 
289
  # fps = f"{(1000 / float(results.t[1])):.2f}" # FPS
 
163
  def model_loading(img_path, conf, iou, infer_size, yolo_model="yolov8n.pt"):
164
  model = YOLO(yolo_model)
165
 
166
+ results = model(source=img_path, imgsz=infer_size, conf=conf, iou=iou)
167
+ results = list(results)[0]
168
+ return results
 
 
 
 
 
169
 
170
 
171
  # 标签和边界框颜色设置
 
241
  cls_index_det_stat = [] # 类别索引统计
242
 
243
  # 模型加载
244
+ predict_results = model_loading(img_path, conf, iou, infer_size, yolo_model=f"{model_name}.pt")
245
+ xyxy_list = predict_results.boxes.xyxy.cpu().numpy().tolist()
246
+ conf_list = predict_results.boxes.conf.cpu().numpy().tolist()
247
+ cls_list = predict_results.boxes.cls.cpu().numpy().tolist()
248
 
249
  color_list = random_color(len(model_cls_name_cp), True)
250
 
251
  # 判断检测对象是否为空
252
+ if (xyxy_list != []):
253
 
254
  # ---------------- 加载字体 ----------------
255
  yaml_index = cls_name.index(".yaml")
 
265
  # 韩语
266
  textFont = ImageFont.truetype(str(f"{ROOT_PATH}/fonts/malgun.ttf"), size=FONTSIZE)
267
 
268
+ for i in range(len(xyxy_list)):
269
  # id = int(i) # 实例ID
270
+ obj_cls_index = int(cls_list[i]) # 类别索引
271
  cls_index_det_stat.append(obj_cls_index)
272
 
273
  obj_cls = model_cls_name_cp[obj_cls_index] # 类别
274
  cls_det_stat.append(obj_cls)
275
 
276
  # ------------ 边框坐标 ------------
277
+ x0 = int(xyxy_list[i][0])
278
+ y0 = int(xyxy_list[i][1])
279
+ x1 = int(xyxy_list[i][2])
280
+ y1 = int(xyxy_list[i][3])
281
 
282
  bbox_det_stat.append((x0, y0, x1, y1))
283
 
284
+ conf = float(conf_list[i]) # 置信度
285
  score_det_stat.append(conf)
286
 
287
  # fps = f"{(1000 / float(results.t[1])):.2f}" # FPS