Zengyf-CVer commited on
Commit
12da3ca
1 Parent(s): 448468b

v03 update

Browse files
Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -12,6 +12,7 @@ import argparse
12
  import csv
13
  import json
14
  import sys
 
15
  from pathlib import Path
16
  import pandas as pd
17
 
@@ -175,6 +176,8 @@ def yolo_det(img, device, model_name, inference_size, conf, iou, max_num, model_
175
  s_obj, m_obj, l_obj = 0, 0, 0
176
  # object area list
177
  area_obj_all = []
 
 
178
 
179
  if model_name_tmp != model_name:
180
  # Model judgment to avoid repeated loading
@@ -189,13 +192,14 @@ def yolo_det(img, device, model_name, inference_size, conf, iou, max_num, model_
189
  model.iou = iou # NMS IoU threshold
190
  model.max_det = int(max_num) # Maximum number of detection frames
191
  model.classes = model_cls # model classes
 
 
192
 
193
  results = model(img, size=inference_size) # detection
194
 
 
195
  dataframe = results.pandas().xyxy[0].round(2)
196
 
197
- img_size = img.size # frame size
198
-
199
  # ----------------Load fonts----------------
200
  yaml_index = cls_name.index(".yaml")
201
  cls_name_lang = cls_name[yaml_index - 2:yaml_index]
@@ -271,7 +275,16 @@ def yolo_det(img, device, model_name, inference_size, conf, iou, max_num, model_
271
 
272
  objSize_dict = {obj_style[i]: [s_obj, m_obj, l_obj][i] / sml_obj_total for i in range(3)}
273
 
274
- return det_img, objSize_dict, det_json, report, dataframe
 
 
 
 
 
 
 
 
 
275
 
276
 
277
  def main(args):
@@ -336,8 +349,9 @@ def main(args):
336
  outputs_pdf = gr.outputs.File(label="Download test report")
337
  outputs_df = gr.outputs.Dataframe(max_rows=5, overflow_row_behaviour="paginate", type="pandas", label="List of detection information")
338
  outputs_objSize = gr.outputs.Label(label="Object size ratio statistics")
 
339
 
340
- outputs = [outputs_img, outputs_objSize, outputs_json, outputs_pdf, outputs_df]
341
 
342
  # title
343
  title = "Gradio YOLOv5 Det v0.3"
 
12
  import csv
13
  import json
14
  import sys
15
+ from collections import Counter
16
  from pathlib import Path
17
  import pandas as pd
18
 
 
176
  s_obj, m_obj, l_obj = 0, 0, 0
177
  # object area list
178
  area_obj_all = []
179
+ # cls num stat
180
+ cls_det_stat = []
181
 
182
  if model_name_tmp != model_name:
183
  # Model judgment to avoid repeated loading
 
192
  model.iou = iou # NMS IoU threshold
193
  model.max_det = int(max_num) # Maximum number of detection frames
194
  model.classes = model_cls # model classes
195
+
196
+ img_size = img.size # frame size
197
 
198
  results = model(img, size=inference_size) # detection
199
 
200
+ # Data Frame
201
  dataframe = results.pandas().xyxy[0].round(2)
202
 
 
 
203
  # ----------------Load fonts----------------
204
  yaml_index = cls_name.index(".yaml")
205
  cls_name_lang = cls_name[yaml_index - 2:yaml_index]
 
275
 
276
  objSize_dict = {obj_style[i]: [s_obj, m_obj, l_obj][i] / sml_obj_total for i in range(3)}
277
 
278
+ # ------------cls stat------------
279
+ clsRatio_dict = {}
280
+ clsDet_dict = Counter(cls_det_stat)
281
+ clsDet_dict_sum = sum(clsDet_dict.values())
282
+
283
+ for k, v in clsDet_dict.items():
284
+ clsRatio_dict[k] = v / clsDet_dict_sum
285
+
286
+
287
+ return det_img, objSize_dict, clsRatio_dict, det_json, report, dataframe
288
 
289
 
290
  def main(args):
 
349
  outputs_pdf = gr.outputs.File(label="Download test report")
350
  outputs_df = gr.outputs.Dataframe(max_rows=5, overflow_row_behaviour="paginate", type="pandas", label="List of detection information")
351
  outputs_objSize = gr.outputs.Label(label="Object size ratio statistics")
352
+ outputs_clsSize = gr.outputs.Label(label="Category detection proportion statistics")
353
 
354
+ outputs = [outputs_img, outputs_objSize, outputs_clsSize, outputs_json, outputs_pdf, outputs_df]
355
 
356
  # title
357
  title = "Gradio YOLOv5 Det v0.3"