Zengyf-CVer commited on
Commit
3fb23cc
1 Parent(s): 3c609fb

v03 update

Browse files
Files changed (1) hide show
  1. app.py +32 -7
app.py CHANGED
@@ -43,6 +43,9 @@ suffix_list = [".csv", ".yaml"]
43
  # font size
44
  FONTSIZE = 25
45
 
 
 
 
46
 
47
  def parse_args(known=False):
48
  parser = argparse.ArgumentParser(description="Gradio YOLOv5 Det v0.3")
@@ -168,6 +171,11 @@ def yolo_det(img, device, model_name, inference_size, conf, iou, max_num, model_
168
 
169
  global model, model_name_tmp, device_tmp
170
 
 
 
 
 
 
171
  if model_name_tmp != model_name:
172
  # Model judgment to avoid repeated loading
173
  model_name_tmp = model_name
@@ -232,10 +240,16 @@ def yolo_det(img, device, model_name, inference_size, conf, iou, max_num, model_
232
  opt,
233
  )
234
 
235
- det_json = export_json(results, model, img.size)[0] # Detection information
 
 
 
 
236
 
237
- # JSON formatting
238
- det_json_format = json.dumps(det_json, sort_keys=False, indent=4, separators=(",", ":"), ensure_ascii=False)
 
 
239
 
240
  # -------pdf-------
241
  report = "./Det_Report.pdf"
@@ -244,10 +258,20 @@ def yolo_det(img, device, model_name, inference_size, conf, iou, max_num, model_
244
  else:
245
  report = None
246
 
247
- if "json" not in opt:
248
- det_json = None
 
 
 
 
 
 
 
 
 
 
249
 
250
- return det_img, det_json, report, dataframe
251
 
252
 
253
  def main(args):
@@ -311,8 +335,9 @@ def main(args):
311
  outputs_json = gr.outputs.JSON(label="Detection information")
312
  outputs_pdf = gr.outputs.File(label="Download test report")
313
  outputs_df = gr.outputs.Dataframe(max_rows=5, overflow_row_behaviour="paginate", type="pandas", label="List of detection information")
 
314
 
315
- outputs = [outputs_img, outputs_json, outputs_pdf, outputs_df]
316
 
317
  # title
318
  title = "Gradio YOLOv5 Det v0.3"
 
43
  # font size
44
  FONTSIZE = 25
45
 
46
+ # object style
47
+ obj_style = ["Small Object", "Medium Object", "Large Object"]
48
+
49
 
50
  def parse_args(known=False):
51
  parser = argparse.ArgumentParser(description="Gradio YOLOv5 Det v0.3")
 
171
 
172
  global model, model_name_tmp, device_tmp
173
 
174
+ # object size num
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
181
  model_name_tmp = model_name
 
240
  opt,
241
  )
242
 
243
+ # ----------add object size----------
244
+ w_obj = x1 - x0
245
+ h_obj = y1 - y0
246
+ area_obj = w_obj * h_obj
247
+ area_obj_all.append(area_obj)
248
 
249
+ det_json = export_json(results, model, img.size)[0] # Detection information
250
+ det_json_format = json.dumps(det_json, sort_keys=False, indent=4, separators=(",", ":"), ensure_ascii=False) # JSON formatting
251
+ if "json" not in opt:
252
+ det_json = None
253
 
254
  # -------pdf-------
255
  report = "./Det_Report.pdf"
 
258
  else:
259
  report = None
260
 
261
+ # --------------object size compute--------------
262
+ for i in range(len(area_obj_all)):
263
+ if (0 < area_obj_all[i] <= 32 ** 2):
264
+ s_obj = s_obj + 1
265
+ elif (32 ** 2 < area_obj_all[i] <= 96 ** 2):
266
+ m_obj = m_obj + 1
267
+ elif (area_obj_all[i] > 96 ** 2):
268
+ l_obj = l_obj + 1
269
+
270
+ sml_obj_total = s_obj + m_obj + l_obj
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, det_json, report, dataframe, objSize_dict
275
 
276
 
277
  def main(args):
 
335
  outputs_json = gr.outputs.JSON(label="Detection information")
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_json, outputs_pdf, outputs_df, outputs_objSize]
341
 
342
  # title
343
  title = "Gradio YOLOv5 Det v0.3"