Zengyf-CVer commited on
Commit
321feeb
1 Parent(s): 8799ea7

app update

Browse files
.gitignore ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 图片格式
2
+ *.jpg
3
+ *.jpeg
4
+ *.png
5
+ *.svg
6
+ *.gif
7
+
8
+ # 视频格式
9
+ *.mp4
10
+ *.avi
11
+ .ipynb_checkpoints
12
+ */__pycache__
13
+
14
+ # 日志格式
15
+ *.log
16
+ *.data
17
+ *.txt
18
+ *.csv
19
+
20
+ # 参数文件
21
+ *.yaml
22
+ *.json
23
+
24
+ # 压缩文件格式
25
+ *.zip
26
+ *.tar
27
+ *.tar.gz
28
+ *.rar
29
+
30
+ # 字体格式
31
+ *.ttc
32
+ *.ttf
33
+ *.otf
34
+
35
+ *.pt
36
+ *.db
37
+
38
+ /flagged
39
+ /run
40
+ !requirements.txt
41
+ !cls_name/*
42
+ !model_config/*
43
+ !img_example/*
44
+
45
+ app copy.py
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  title: Gradio_YOLOv5_Det
3
- emoji: 📚
4
  colorFrom: red
5
  colorTo: red
6
  sdk: gradio
@@ -11,3 +11,5 @@ license: gpl-3.0
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
 
 
 
1
  ---
2
  title: Gradio_YOLOv5_Det
3
+ emoji: 🚀
4
  colorFrom: red
5
  colorTo: red
6
  sdk: gradio
 
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
14
+
15
+ 🚀 Project homepage:https://gitee.com/CV_Lab/gradio_yolov5_det
__init__.py ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ __author__ = "曾逸夫(Zeng Yifu)"
2
+ __email__ = "zyfiy1314@163.com"
app.py ADDED
@@ -0,0 +1,461 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Gradio YOLOv5 Det v0.3
2
+ # author: Zeng Yifu(曾逸夫)
3
+ # creation time: 2022-05-09
4
+ # email: zyfiy1314@163.com
5
+ # project homepage: https://gitee.com/CV_Lab/gradio_yolov5_det
6
+
7
+
8
+ import argparse
9
+ import csv
10
+ import json
11
+ import sys
12
+ from collections import Counter
13
+ from pathlib import Path
14
+ import pandas as pd
15
+
16
+ import gradio as gr
17
+ import torch
18
+ import yaml
19
+ from PIL import Image, ImageDraw, ImageFont
20
+
21
+ from util.fonts_opt import is_fonts
22
+ from util.pdf_opt import pdf_generate
23
+
24
+ ROOT_PATH = sys.path[0] # root directory
25
+
26
+ # model path
27
+ model_path = "ultralytics/yolov5"
28
+
29
+ # Gradio YOLOv5 Det version
30
+ GYD_VERSION = "Gradio YOLOv5 Det v0.3"
31
+
32
+ # model name temporary variable
33
+ model_name_tmp = ""
34
+
35
+ # Device temporary variables
36
+ device_tmp = ""
37
+
38
+ # File extension
39
+ suffix_list = [".csv", ".yaml"]
40
+
41
+ # font size
42
+ FONTSIZE = 25
43
+
44
+ # object style
45
+ obj_style = ["Small Object", "Medium Object", "Large Object"]
46
+
47
+
48
+ def parse_args(known=False):
49
+ parser = argparse.ArgumentParser(description="Gradio YOLOv5 Det v0.3")
50
+ parser.add_argument("--source", "-src", default="upload", type=str, help="input source")
51
+ parser.add_argument("--img_tool", "-it", default="editor", type=str, help="input image tool")
52
+ parser.add_argument("--model_name", "-mn", default="yolov5s", type=str, help="model name")
53
+ parser.add_argument(
54
+ "--model_cfg",
55
+ "-mc",
56
+ default="./model_config/model_name_p5_p6_all.yaml",
57
+ type=str,
58
+ help="model config",
59
+ )
60
+ parser.add_argument(
61
+ "--cls_name",
62
+ "-cls",
63
+ default="./cls_name/cls_name_en.yaml",
64
+ type=str,
65
+ help="cls name",
66
+ )
67
+ parser.add_argument(
68
+ "--nms_conf",
69
+ "-conf",
70
+ default=0.5,
71
+ type=float,
72
+ help="model NMS confidence threshold",
73
+ )
74
+ parser.add_argument("--nms_iou", "-iou", default=0.45, type=float, help="model NMS IoU threshold")
75
+ parser.add_argument(
76
+ "--device",
77
+ "-dev",
78
+ default="cpu",
79
+ type=str,
80
+ help="cuda or cpu",
81
+ )
82
+ parser.add_argument("--inference_size", "-isz", default=640, type=int, help="model inference size")
83
+ parser.add_argument("--max_detnum", "-mdn", default=50, type=float, help="model max det num")
84
+ parser.add_argument("--slider_step", "-ss", default=0.05, type=float, help="slider step")
85
+ parser.add_argument(
86
+ "--is_login",
87
+ "-isl",
88
+ action="store_true",
89
+ default=False,
90
+ help="is login",
91
+ )
92
+ parser.add_argument('--usr_pwd',
93
+ "-up",
94
+ nargs='+',
95
+ type=str,
96
+ default=["admin", "admin"],
97
+ help="user & password for login")
98
+ parser.add_argument(
99
+ "--is_share",
100
+ "-is",
101
+ action="store_true",
102
+ default=False,
103
+ help="is login",
104
+ )
105
+
106
+ args = parser.parse_known_args()[0] if known else parser.parse_args()
107
+ return args
108
+
109
+
110
+ # yaml file parsing
111
+ def yaml_parse(file_path):
112
+ return yaml.safe_load(open(file_path, encoding="utf-8").read())
113
+
114
+
115
+ # yaml csv file parsing
116
+ def yaml_csv(file_path, file_tag):
117
+ file_suffix = Path(file_path).suffix
118
+ if file_suffix == suffix_list[0]:
119
+ # model name
120
+ file_names = [i[0] for i in list(csv.reader(open(file_path)))] # csv version
121
+ elif file_suffix == suffix_list[1]:
122
+ # model name
123
+ file_names = yaml_parse(file_path).get(file_tag) # yaml version
124
+ else:
125
+ print(f"{file_path} is not in the correct format! Program exits!")
126
+ sys.exit()
127
+
128
+ return file_names
129
+
130
+
131
+ # model loading
132
+ def model_loading(model_name, device):
133
+
134
+ # load model
135
+ model = torch.hub.load(
136
+ model_path, model_name, force_reload=True, device=device, _verbose=False
137
+ )
138
+
139
+ return model
140
+
141
+
142
+ # check information
143
+ def export_json(results, img_size):
144
+
145
+ return [[{
146
+ "ID": i,
147
+ "CLASS": int(result[i][5]),
148
+ "CLASS_NAME": model_cls_name_cp[int(result[i][5])],
149
+ "BOUNDING_BOX": {
150
+ "XMIN": round(result[i][:4].tolist()[0], 6),
151
+ "YMIN": round(result[i][:4].tolist()[1], 6),
152
+ "XMAX": round(result[i][:4].tolist()[2], 6),
153
+ "YMAX": round(result[i][:4].tolist()[3], 6),},
154
+ "CONF": round(float(result[i][4]), 2),
155
+ "FPS": round(1000 / float(results.t[1]), 2),
156
+ "IMG_WIDTH": img_size[0],
157
+ "IMG_HEIGHT": img_size[1],} for i in range(len(result))] for result in results.xyxyn]
158
+
159
+
160
+ # frame conversion
161
+ def pil_draw(img, countdown_msg, textFont, xyxy, font_size, opt):
162
+
163
+ img_pil = ImageDraw.Draw(img)
164
+
165
+ img_pil.rectangle(xyxy, fill=None, outline="green") # bounding box
166
+
167
+ if "label" in opt:
168
+ text_w, text_h = textFont.getsize(countdown_msg) # Label size
169
+ img_pil.rectangle(
170
+ (xyxy[0], xyxy[1], xyxy[0] + text_w, xyxy[1] + text_h),
171
+ fill="green",
172
+ outline="green",
173
+ ) # label background
174
+ img_pil.multiline_text(
175
+ (xyxy[0], xyxy[1]),
176
+ countdown_msg,
177
+ fill=(205, 250, 255),
178
+ font=textFont,
179
+ align="center",
180
+ )
181
+
182
+ return img
183
+
184
+
185
+ # YOLOv5 image detection function
186
+ def yolo_det(img, device, model_name, infer_size, conf, iou, max_num, model_cls, opt):
187
+
188
+ global model, model_name_tmp, device_tmp
189
+
190
+ # object size num
191
+ s_obj, m_obj, l_obj = 0, 0, 0
192
+ # object area list
193
+ area_obj_all = []
194
+ # cls num stat
195
+ cls_det_stat = []
196
+
197
+ if model_name_tmp != model_name:
198
+ # Model judgment to avoid repeated loading
199
+ model_name_tmp = model_name
200
+ model = model_loading(model_name_tmp, device)
201
+ elif device_tmp != device:
202
+ device_tmp = device
203
+ model = model_loading(model_name_tmp, device)
204
+
205
+ # -------------Model tuning -------------
206
+ model.conf = conf # NMS confidence threshold
207
+ model.iou = iou # NMS IoU threshold
208
+ model.max_det = int(max_num) # Maximum number of detection frames
209
+ model.classes = model_cls # model classes
210
+
211
+ img_size = img.size # frame size
212
+
213
+ results = model(img, size=infer_size) # detection
214
+
215
+ # Data Frame
216
+ dataframe = results.pandas().xyxy[0].round(2)
217
+
218
+ # ----------------Load fonts----------------
219
+ yaml_index = cls_name.index(".yaml")
220
+ cls_name_lang = cls_name[yaml_index - 2:yaml_index]
221
+
222
+ if cls_name_lang == "zh":
223
+ # Chinese
224
+ textFont = ImageFont.truetype(str(f"{ROOT_PATH}/fonts/SimSun.ttf"), size=FONTSIZE)
225
+ elif cls_name_lang in ["en", "ru", "es", "ar"]:
226
+ # English, Russian, Spanish, Arabic
227
+ textFont = ImageFont.truetype(str(f"{ROOT_PATH}/fonts/TimesNewRoman.ttf"), size=FONTSIZE)
228
+ elif cls_name_lang == "ko":
229
+ # Korean
230
+ textFont = ImageFont.truetype(str(f"{ROOT_PATH}/fonts/malgun.ttf"), size=FONTSIZE)
231
+
232
+ for result in results.xyxyn:
233
+ for i in range(len(result)):
234
+ id = int(i) # instance ID
235
+ obj_cls_index = int(result[i][5]) # category index
236
+ obj_cls = model_cls_name_cp[obj_cls_index] # category
237
+ cls_det_stat.append(obj_cls)
238
+
239
+ # ------------ border coordinates ------------
240
+ x0 = float(result[i][:4].tolist()[0])
241
+ y0 = float(result[i][:4].tolist()[1])
242
+ x1 = float(result[i][:4].tolist()[2])
243
+ y1 = float(result[i][:4].tolist()[3])
244
+
245
+ # ------------ Actual coordinates of the border ------------
246
+ x0 = int(img_size[0] * x0)
247
+ y0 = int(img_size[1] * y0)
248
+ x1 = int(img_size[0] * x1)
249
+ y1 = int(img_size[1] * y1)
250
+
251
+ conf = float(result[i][4]) # confidence
252
+ # fps = f"{(1000 / float(results.t[1])):.2f}" # FPS
253
+
254
+ det_img = pil_draw(
255
+ img,
256
+ f"{id}-{obj_cls}:{conf:.2f}",
257
+ textFont,
258
+ [x0, y0, x1, y1],
259
+ FONTSIZE,
260
+ opt,
261
+ )
262
+
263
+ # ----------add object size----------
264
+ w_obj = x1 - x0
265
+ h_obj = y1 - y0
266
+ area_obj = w_obj * h_obj
267
+ area_obj_all.append(area_obj)
268
+
269
+ # ------------JSON generate------------
270
+ det_json = export_json(results, img.size)[0] # Detection information
271
+ det_json_format = json.dumps(det_json, sort_keys=False, indent=4, separators=(",", ":"), ensure_ascii=False) # JSON formatting
272
+
273
+ if "json" not in opt:
274
+ det_json = None
275
+
276
+ # -------PDF generate-------
277
+ report = "./Det_Report.pdf"
278
+ if "pdf" in opt:
279
+ pdf_generate(f"{det_json_format}", report, GYD_VERSION)
280
+ else:
281
+ report = None
282
+
283
+ # --------------object size compute--------------
284
+ for i in range(len(area_obj_all)):
285
+ if (0 < area_obj_all[i] <= 32 ** 2):
286
+ s_obj = s_obj + 1
287
+ elif (32 ** 2 < area_obj_all[i] <= 96 ** 2):
288
+ m_obj = m_obj + 1
289
+ elif (area_obj_all[i] > 96 ** 2):
290
+ l_obj = l_obj + 1
291
+
292
+ sml_obj_total = s_obj + m_obj + l_obj
293
+
294
+ objSize_dict = {obj_style[i]: [s_obj, m_obj, l_obj][i] / sml_obj_total for i in range(3)}
295
+
296
+ # ------------cls stat------------
297
+ clsRatio_dict = {}
298
+ clsDet_dict = Counter(cls_det_stat)
299
+ clsDet_dict_sum = sum(clsDet_dict.values())
300
+
301
+ for k, v in clsDet_dict.items():
302
+ clsRatio_dict[k] = v / clsDet_dict_sum
303
+
304
+
305
+ return det_img, objSize_dict, clsRatio_dict, det_json, report, dataframe
306
+
307
+
308
+ def main(args):
309
+ gr.close_all()
310
+
311
+ global model, model_cls_name_cp, cls_name
312
+
313
+ source = args.source
314
+ img_tool = args.img_tool
315
+ nms_conf = args.nms_conf
316
+ nms_iou = args.nms_iou
317
+ model_name = args.model_name
318
+ model_cfg = args.model_cfg
319
+ cls_name = args.cls_name
320
+ device = args.device
321
+ inference_size = args.inference_size
322
+ max_detnum = args.max_detnum
323
+ slider_step = args.slider_step
324
+ is_login = args.is_login
325
+ usr_pwd = args.usr_pwd
326
+ is_share = args.is_share
327
+
328
+ is_fonts(f"{ROOT_PATH}/fonts") # Check font files
329
+
330
+ # model loading
331
+ model = model_loading(model_name, device)
332
+
333
+ model_names = yaml_csv(model_cfg, "model_names") # model names
334
+ model_cls_name = yaml_csv(cls_name, "model_cls_name") # class name
335
+
336
+ model_cls_name_cp = model_cls_name.copy() # class name
337
+
338
+ # ------------------- Input Components -------------------
339
+ inputs_img = gr.Image(image_mode="RGB", source=source, tool=img_tool, type="pil", label="original image")
340
+ inputs_device = gr.Radio(choices=["cuda:0", "cpu"], value=device, label="device")
341
+ inputs_model = gr.Dropdown(choices=model_names, value=model_name, type="value", label="model")
342
+ inputs_size = gr.Radio(choices=[320, 640, 1280], value=inference_size, label="inference size")
343
+ input_conf = gr.Slider(0, 1, step=slider_step, value=nms_conf, label="confidence threshold")
344
+ inputs_iou = gr.Slider(0, 1, step=slider_step, value=nms_iou, label="IoU threshold")
345
+ inputs_maxnum = gr.Number(value=max_detnum, label="Maximum number of detections")
346
+ inputs_clsName = gr.CheckboxGroup(choices=model_cls_name, value=model_cls_name, type="index", label="category")
347
+ inputs_opt = gr.CheckboxGroup(choices=["label", "pdf", "json"],
348
+ value=["label", "pdf"],
349
+ type="value",
350
+ label="operate")
351
+
352
+ # Input parameters
353
+ inputs = [
354
+ inputs_img, # input image
355
+ inputs_device, # device
356
+ inputs_model, # model
357
+ inputs_size, # inference size
358
+ input_conf, # confidence threshold
359
+ inputs_iou, # IoU threshold
360
+ inputs_maxnum, # maximum number of detections
361
+ inputs_clsName, # category
362
+ inputs_opt, # detect operations
363
+ ]
364
+
365
+ # Output parameters
366
+ outputs_img = gr.Image(type="pil", label="Detection image")
367
+ outputs_json = gr.JSON(label="Detection information")
368
+ outputs_pdf = gr.File(label="Download test report")
369
+ outputs_df = gr.Dataframe(max_rows=5, overflow_row_behaviour="paginate", type="pandas", label="List of detection information")
370
+ outputs_objSize = gr.Label(label="Object size ratio statistics")
371
+ outputs_clsSize = gr.Label(label="Category detection proportion statistics")
372
+
373
+ outputs = [outputs_img, outputs_objSize, outputs_clsSize, outputs_json, outputs_pdf, outputs_df]
374
+
375
+ # title
376
+ title = "Gradio YOLOv5 Det v0.3"
377
+
378
+ # describe
379
+ description = "<div align='center'>Customizable target detection model, easy to install, easy to use</div>"
380
+ # article="https://gitee.com/CV_Lab/gradio_yolov5_det"
381
+
382
+ # example image
383
+ examples = [
384
+ [
385
+ "./img_example/bus.jpg",
386
+ "cpu",
387
+ "yolov5s",
388
+ 640,
389
+ 0.6,
390
+ 0.5,
391
+ 10,
392
+ ["person", "bus"],
393
+ ["label", "pdf"],],
394
+ [
395
+ "./img_example/giraffe.jpg",
396
+ "cpu",
397
+ "yolov5l",
398
+ 320,
399
+ 0.5,
400
+ 0.45,
401
+ 12,
402
+ ["giraffe"],
403
+ ["label", "pdf"],],
404
+ [
405
+ "./img_example/zidane.jpg",
406
+ "cpu",
407
+ "yolov5m",
408
+ 640,
409
+ 0.25,
410
+ 0.5,
411
+ 15,
412
+ ["person", "tie"],
413
+ ["pdf", "json"],],
414
+ [
415
+ "./img_example/Millenial-at-work.jpg",
416
+ "cpu",
417
+ "yolov5s6",
418
+ 1280,
419
+ 0.5,
420
+ 0.5,
421
+ 20,
422
+ ["person", "chair", "cup", "laptop"],
423
+ ["label", "pdf"],],]
424
+
425
+ # interface
426
+ gyd = gr.Interface(
427
+ fn=yolo_det,
428
+ inputs=inputs,
429
+ outputs=outputs,
430
+ title=title,
431
+ description=description,
432
+ # article=article,
433
+ # examples=examples,
434
+ # theme="seafoam",
435
+ # flagging_dir="run", # output directory
436
+ )
437
+
438
+ if not is_login:
439
+ gyd.launch(
440
+ inbrowser=True, # Automatically open default browser
441
+ show_tips=True, # Automatically display the latest features of gradio
442
+ share=is_share, # Project sharing, other devices can access
443
+ favicon_path="./icon/logo.ico", # web icon
444
+ show_error=True, # Display error message in browser console
445
+ quiet=True, # Suppress most print statements
446
+ )
447
+ else:
448
+ gyd.launch(
449
+ inbrowser=True, # Automatically open default browser
450
+ show_tips=True, # Automatically display the latest features of gradio
451
+ auth=usr_pwd, # login interface
452
+ share=is_share, # Project sharing, other devices can access
453
+ favicon_path="./icon/logo.ico", # web icon
454
+ show_error=True, # Display error message in browser console
455
+ quiet=True, # Suppress most print statements
456
+ )
457
+
458
+
459
+ if __name__ == "__main__":
460
+ args = parse_args()
461
+ main(args)
cls_name/cls_name.csv ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ 自行车
3
+ 汽车
4
+ 摩托车
5
+ 飞机
6
+ 公交车
7
+ 火车
8
+ 卡车
9
+
10
+ 红绿灯
11
+ 消防栓
12
+ 停止标志
13
+ 停车收费表
14
+ 长凳
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+ 斑马
24
+ 长颈鹿
25
+ 背包
26
+ 雨伞
27
+ 手提包
28
+ 领带
29
+ 手提箱
30
+ 飞盘
31
+ 滑雪板
32
+ 单板滑雪
33
+ 运动球
34
+ 风筝
35
+ 棒球棒
36
+ 棒球手套
37
+ 滑板
38
+ 冲浪板
39
+ 网球拍
40
+ 瓶子
41
+ 红酒杯
42
+ 杯子
43
+ 叉子
44
+
45
+
46
+
47
+ 香蕉
48
+ 苹果
49
+ 三明治
50
+ 橙子
51
+ 西兰花
52
+ 胡萝卜
53
+ 热狗
54
+ 比萨
55
+ 甜甜圈
56
+ 蛋糕
57
+ 椅子
58
+ 长椅
59
+ 盆栽
60
+
61
+ 餐桌
62
+ 马桶
63
+ 电视
64
+ 笔记本电脑
65
+ 鼠标
66
+ 遥控器
67
+ 键盘
68
+ 手机
69
+ 微波炉
70
+ 烤箱
71
+ 烤面包机
72
+ 洗碗槽
73
+ 冰箱
74
+
75
+ 时钟
76
+ 花瓶
77
+ 剪刀
78
+ 泰迪熊
79
+ 吹风机
80
+ 牙刷
cls_name/cls_name.yaml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ model_cls_name: ['人', '自行车', '汽车', '摩托车', '飞机', '公交车', '火车', '卡车', '船', '红绿灯', '消防栓', '停止标志',
2
+ '停车收费表', '长凳', '鸟', '猫', '狗', '马', '羊', '牛', '象', '熊', '斑马', '长颈鹿', '背包', '雨伞', '手提包', '领带',
3
+ '手提箱', '飞盘', '滑雪板', '单板滑雪', '运动球', '风筝', '棒球棒', '棒球手套', '滑板', '冲浪板', '网球拍', '瓶子', '红酒杯',
4
+ '杯子', '叉子', '刀', '勺', '碗', '香蕉', '苹果', '三明治', '橙子', '西兰花', '胡萝卜', '热狗', '比萨', '甜甜圈', '蛋糕',
5
+ '椅子', '长椅', '盆栽', '床', '餐桌', '马桶', '电视', '笔记本电脑', '鼠标', '遥控器', '键盘', '手机', '微波炉', '烤箱',
6
+ '烤面包机', '洗碗槽', '冰箱', '书', '时钟', '花瓶', '剪刀', '泰迪熊', '吹风机', '牙刷'
7
+ ]
cls_name/cls_name_ar.yaml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ model_cls_name: [" الناس " , " الدراجات " , " السيارات " , " الدراجات النارية " , " الطائرات " , " الحافلات " , " القطارات " , " الشاحنات " , " السفن " , " إشارات المرور " ,
2
+ " صنبور " , " علامة " , " موقف سيارات " , " الجدول " , " مقعد " , " الطيور " , " القط " , " الكلب " , " الحصان " , " الأغنام " , " الثور " , " الفيل " ,
3
+ " الدب " , " حمار وحشي " , " الزرافة " , " حقيبة " , " مظلة " , " حقيبة يد " , " ربطة عنق " , " حقيبة " , " الفريسبي " , " الزلاجات " , " الزلاجات " ,
4
+ " الكرة الرياضية " , " طائرة ورقية " , " مضرب بيسبول " , " قفازات البيسبول " , " لوح التزلج " , " ركوب الأمواج " , " مضرب تنس " , " زجاجة " ,
5
+ " كأس " , " كأس " , " شوكة " , " سكين " , " ملعقة " , " وعاء " , " الموز " , " التفاح " , " ساندويتش " , " البرتقال " , " القرنبيط " ,
6
+ " الجزر " , " الكلاب الساخنة " , " البيتزا " , " دونات " , " كعكة " , " كرسي " , " أريكة " , " بوعاء " , " السرير " , " طاولة الطعام " , " المرحاض " ,
7
+ التلفزيون , الكمبيوتر المحمول , الفأرة , وحدة تحكم عن بعد , لوحة المفاتيح , الهاتف المحمول , فرن الميكروويف , محمصة خبز كهربائية , بالوعة , ثلاجة ,
8
+ " كتاب " , " ساعة " , " زهرية " , " مقص " , " دمية دب " , " مجفف الشعر " , " فرشاة الأسنان "
9
+ ]
cls_name/cls_name_en.yaml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ model_cls_name: ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light',
2
+ 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant',
3
+ 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard',
4
+ 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', 'bottle',
5
+ 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange', 'broccoli',
6
+ 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 'potted plant', 'bed', 'dining table', 'toilet',
7
+ 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator',
8
+ 'book', 'clock', 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'
9
+ ]
cls_name/cls_name_es.yaml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ model_cls_name: ['persona', 'bicicleta', 'coche', 'motocicleta', 'avión', 'autobús', 'tren', 'camión', 'barco', 'semáforo',
2
+ 'boca de incendios', 'señal de alto', 'parquímetro', 'banco', 'pájaro', 'gato', 'perro', 'caballo', 'oveja', 'vaca', 'elefante',
3
+ 'oso', 'cebra', 'jirafa', 'mochila', 'paraguas', 'bolso', 'corbata', 'maleta', 'frisbee', 'esquís', 'snowboard',
4
+ 'pelota deportiva', 'cometa', 'bate de béisbol', 'guante de béisbol', 'monopatín', 'tabla de surf', 'raqueta de tenis', 'botella',
5
+ 'copa de vino', 'taza', 'tenedor', 'cuchillo', 'cuchara', 'tazón', 'plátano', 'manzana', 'sándwich', 'naranja', 'brócoli',
6
+ 'zanahoria', 'perrito caliente', 'pizza', 'rosquilla', 'pastel', 'silla', 'sofá', 'planta en maceta', 'cama', 'mesa de comedor', 'inodoro',
7
+ 'tv', 'laptop', 'ratón', 'control remoto', 'teclado', 'celular', 'microondas', 'horno', 'tostadora', 'fregadero', 'nevera',
8
+ 'libro', 'reloj', 'jarrón', 'tijeras', 'oso de peluche', 'secador de pelo', 'cepillo de dientes'
9
+ ]
cls_name/cls_name_ko.yaml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ model_cls_name: ['사람', '자전거', '자동차', '오토바이', '비행기', '버스', '기차', '트럭', '보트', '신호등',
2
+ '소화전', '정지 신호', '주차 미터기', '벤치', '새', '고양이', '개', '말', '양', '소', '코끼리',
3
+ '곰', '얼룩말', '기린', '배낭', '우산', '핸드백', '타이', '여행가방', '프리스비', '스키', '스노우보드',
4
+ '스포츠 공', '연', '야구 방망이', '야구 글러브', '스케이트보드', '서프보드', '테니스 라켓', '병',
5
+ '와인잔', '컵', '포크', '나이프', '숟가락', '그릇', '바나나', '사과', '샌드위치', '오렌지', '브로콜리',
6
+ '당근', '핫도그', '피자', '도넛', '케이크', '의자', '소파', '화분', '침대', '식탁', '화장실',
7
+ 'tv', '노트북', '마우스', '리모컨', '키보드', '휴대전화', '전자레인지', '오븐', '토스터', '싱크대', '냉장고',
8
+ '책', '시계', '꽃병', '가위', '테디베어', '드라이기', '칫솔'
9
+ ]
cls_name/cls_name_ru.yaml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ model_cls_name: ['человек', 'велосипед', 'автомобиль', 'мотоцикл', 'самолет', 'автобус', 'поезд', 'грузовик', 'лодка', 'светофор',
2
+ 'пожарный гидрант', 'стоп', 'паркомат', 'скамейка', 'птица', 'кошка', 'собака', 'лошадь', 'овца', 'корова', 'слон',
3
+ 'медведь', 'зебра', 'жираф', 'рюкзак', 'зонт', 'сумочка', 'галстук', 'чемодан', 'фрисби', 'лыжи', 'сноуборд',
4
+ 'спортивный мяч', 'воздушный змей', 'бейсбольная бита', 'бейсбольная перчатка', 'скейтборд', 'доска для серфинга', 'теннисная ракетка', 'бутылка',
5
+ 'бокал', 'чашка', 'вилка', 'нож', 'ложка', 'миска', 'банан', 'яблоко', 'бутерброд', 'апельсин', 'брокколи',
6
+ 'морковь', 'хот-дог', 'пицца', 'пончик', 'торт', 'стул', 'диван', 'растение в горшке', 'кровать', 'обеденный стол', 'туалет',
7
+ 'телевизор', 'ноутбук', 'мышь', 'пульт', 'клавиатура', 'мобильный телефон', 'микроволновая печь', 'духовка', 'тостер', 'раковина', 'холодильник',
8
+ 'книга', 'часы', 'ваза', 'ножницы', 'плюшевый мишка', 'фен', 'зубная щетка'
9
+ ]
cls_name/cls_name_zh.yaml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ model_cls_name: ['人', '自行车', '汽车', '摩托车', '飞机', '公交车', '火车', '卡车', '船', '红绿灯', '消防栓', '停止标志',
2
+ '停车收费表', '长凳', '鸟', '猫', '狗', '马', '羊', '牛', '象', '熊', '斑马', '长颈鹿', '背包', '雨伞', '手提包', '领带',
3
+ '手提箱', '飞盘', '滑雪板', '单板滑雪', '运动球', '风筝', '棒球棒', '棒球手套', '滑板', '冲浪板', '网球拍', '瓶子', '红酒杯',
4
+ '杯子', '叉子', '刀', '勺', '碗', '香蕉', '苹果', '三明治', '橙子', '西兰花', '胡萝卜', '热狗', '比萨', '甜甜圈', '蛋糕',
5
+ '椅子', '长椅', '盆栽', '床', '餐桌', '马桶', '电视', '笔记本电脑', '鼠标', '遥控器', '键盘', '手机', '微波炉', '烤箱',
6
+ '烤面包机', '洗碗槽', '冰箱', '书', '时钟', '花瓶', '剪刀', '泰迪熊', '吹风机', '牙刷'
7
+ ]
img_example/Millenial-at-work.jpg ADDED
img_example/bus.jpg ADDED
img_example/giraffe.jpg ADDED
img_example/read.txt ADDED
File without changes
img_example/zidane.jpg ADDED
model_config/model_name_p5_all.csv ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ yolov5n
2
+ yolov5s
3
+ yolov5m
4
+ yolov5l
5
+ yolov5x
model_config/model_name_p5_all.yaml ADDED
@@ -0,0 +1 @@
 
 
1
+ model_names: ["yolov5n", "yolov5s", "yolov5m", "yolov5l", "yolov5x"]
model_config/model_name_p5_n.csv ADDED
@@ -0,0 +1 @@
 
 
1
+ yolov5n
model_config/model_name_p5_n.yaml ADDED
@@ -0,0 +1 @@
 
 
1
+ model_names: ["yolov5n"]
model_config/model_name_p5_p6_all.yaml ADDED
@@ -0,0 +1 @@
 
 
1
+ model_names: ["yolov5n", "yolov5s", "yolov5m", "yolov5l", "yolov5x", "yolov5n6", "yolov5s6", "yolov5m6", "yolov5l6", "yolov5x6"]
model_config/model_name_p6_all.csv ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ yolov5n6
2
+ yolov5s6
3
+ yolov5m6
4
+ yolov5l6
5
+ yolov5x6
model_config/model_name_p6_all.yaml ADDED
@@ -0,0 +1 @@
 
 
1
+ model_names: ["yolov5n6", "yolov5s6", "yolov5m6", "yolov5l6", "yolov5x6"]
model_download/yolov5_model_p5_all.sh ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ cd ./yolov5
2
+
3
+ # 下载YOLOv5模型
4
+ wget -c -t 0 https://github.com/ultralytics/yolov5/releases/download/v6.1/yolov5n.pt
5
+ wget -c -t 0 https://github.com/ultralytics/yolov5/releases/download/v6.1/yolov5s.pt
6
+ wget -c -t 0 https://github.com/ultralytics/yolov5/releases/download/v6.1/yolov5m.pt
7
+ wget -c -t 0 https://github.com/ultralytics/yolov5/releases/download/v6.1/yolov5l.pt
8
+ wget -c -t 0 https://github.com/ultralytics/yolov5/releases/download/v6.1/yolov5x.pt
model_download/yolov5_model_p5_n.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ cd ./yolov5
2
+
3
+ # 下载YOLOv5模型
4
+ wget -c -t 0 https://github.com/ultralytics/yolov5/releases/download/v6.1/yolov5n.pt
model_download/yolov5_model_p6_all.sh ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ cd ./yolov5
2
+
3
+ # 下载YOLOv5模型
4
+ wget -c -t 0 https://github.com/ultralytics/yolov5/releases/download/v6.1/yolov5n6.pt
5
+ wget -c -t 0 https://github.com/ultralytics/yolov5/releases/download/v6.1/yolov5s6.pt
6
+ wget -c -t 0 https://github.com/ultralytics/yolov5/releases/download/v6.1/yolov5m6.pt
7
+ wget -c -t 0 https://github.com/ultralytics/yolov5/releases/download/v6.1/yolov5l6.pt
8
+ wget -c -t 0 https://github.com/ultralytics/yolov5/releases/download/v6.1/yolov5x6.pt
requirements.txt ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Base ----------------------------------------
2
+ matplotlib>=3.2.2
3
+ numpy>=1.18.5
4
+ opencv-python-headless>=4.5.5.64
5
+ Pillow>=7.1.2
6
+ PyYAML>=5.3.1
7
+ requests>=2.23.0
8
+ scipy>=1.4.1
9
+ torch>=1.7.0
10
+ torchvision>=0.8.1
11
+ tqdm>=4.41.0
12
+ wget>=3.2
13
+ rich>=12.2.0
14
+ fpdf>=1.7.2
15
+
16
+ # Logging -------------------------------------
17
+ tensorboard>=2.4.1
18
+ # wandb
19
+
20
+ # Plotting ------------------------------------
21
+ pandas>=1.1.4
22
+ seaborn>=0.11.0
23
+
24
+ # Export --------------------------------------
25
+ # coremltools>=4.1 # CoreML export
26
+ # onnx>=1.9.0 # ONNX export
27
+ # onnx-simplifier>=0.3.6 # ONNX simplifier
28
+ # scikit-learn==0.19.2 # CoreML quantization
29
+ # tensorflow>=2.4.1 # TFLite export
30
+ # tensorflowjs>=3.9.0 # TF.js export
31
+ # openvino-dev # OpenVINO export
32
+
33
+ # Extras --------------------------------------
34
+ # albumentations>=1.0.3
35
+ # Cython # for pycocotools https://github.com/cocodataset/cocoapi/issues/172
36
+ # pycocotools>=2.0 # COCO mAP
37
+ # roboflow
38
+ thop # FLOPs computation
util/fonts_opt.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # font management
2
+ # author: Zeng Yifu(曾逸夫)
3
+ # creation time: 2022-05-01
4
+ # email: zyfiy1314@163.com
5
+ # project homepage: https://gitee.com/CV_Lab/gradio_yolov5_det
6
+
7
+ import os
8
+ import sys
9
+ from pathlib import Path
10
+
11
+ import wget
12
+ from rich.console import Console
13
+
14
+ ROOT_PATH = sys.path[0] # Project root directory
15
+
16
+ # Chinese, English, Russian, Spanish, Arabic, Korean
17
+ fonts_list = ["SimSun.ttf", "TimesNewRoman.ttf", "malgun.ttf"] # font list
18
+ fonts_suffix = ["ttc", "ttf", "otf"] # font suffix
19
+
20
+ data_url_dict = {
21
+ "SimSun.ttf": "https://gitee.com/CV_Lab/gradio_yolov5_det/attach_files/1053539/download/SimSun.ttf",
22
+ "TimesNewRoman.ttf": "https://gitee.com/CV_Lab/gradio_yolov5_det/attach_files/1053537/download/TimesNewRoman.ttf",
23
+ "malgun.ttf": "https://gitee.com/CV_Lab/gradio_yolov5_det/attach_files/1053538/download/malgun.ttf",}
24
+
25
+ console = Console()
26
+
27
+
28
+ # create font library
29
+ def add_fronts(font_diff):
30
+
31
+ global font_name
32
+
33
+ for k, v in data_url_dict.items():
34
+ if k in font_diff:
35
+ font_name = v.split("/")[-1] # font name
36
+ Path(f"{ROOT_PATH}/fonts").mkdir(parents=True, exist_ok=True) # Create a directory
37
+
38
+ file_path = f"{ROOT_PATH}/fonts/{font_name}" # font path
39
+
40
+ try:
41
+ # Download font file
42
+ wget.download(v, file_path)
43
+ except Exception as e:
44
+ print("Path error! Program ended!")
45
+ print(e)
46
+ sys.exit()
47
+ else:
48
+ print()
49
+ console.print(f"{font_name} [bold green]font file download complete![/bold green] has been saved to: {file_path}")
50
+
51
+
52
+ # Determine the font file
53
+ def is_fonts(fonts_dir):
54
+ if os.path.isdir(fonts_dir):
55
+ # if the font library exists
56
+ f_list = os.listdir(fonts_dir) # local font library
57
+
58
+ font_diff = list(set(fonts_list).difference(set(f_list)))
59
+
60
+ if font_diff != []:
61
+ # font does not exist
62
+ console.print("[bold red] font does not exist, loading...[/bold red]")
63
+ add_fronts(font_diff) # Create a font library
64
+ else:
65
+ console.print(f"{fonts_list}[bold green]font already exists![/bold green]")
66
+ else:
67
+ # The font library does not exist, create a font library
68
+ console.print("[bold red]font library does not exist, creating...[/bold red]")
69
+ add_fronts(fonts_list) # Create a font library
util/pdf_opt.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # PDF management
2
+ # author: Zeng Yifu
3
+ # creation time: 2022-05-05
4
+
5
+ from fpdf import FPDF
6
+
7
+
8
+ # PDF generation class
9
+ class PDF(FPDF):
10
+ # Reference: https://pyfpdf.readthedocs.io/en/latest/Tutorial/index.html
11
+ def header(self):
12
+ # Set Chinese font
13
+ self.add_font("SimSun", "", "./fonts/SimSun.ttf", uni=True)
14
+ self.set_font("SimSun", "", 16)
15
+ # Calculate width of title and position
16
+ w = self.get_string_width(title) + 6
17
+ self.set_x((210 - w) / 2)
18
+ # Colors of frame, background and text
19
+ self.set_draw_color(255, 255, 255)
20
+ self.set_fill_color(255, 255, 255)
21
+ self.set_text_color(0, 0, 0)
22
+ # Thickness of frame (1 mm)
23
+ # self.set_line_width(1)
24
+ # Title
25
+ self.cell(w, 9, title, 1, 1, "C", 1)
26
+ # Line break
27
+ self.ln(10)
28
+
29
+ def footer(self):
30
+ # Position at 1.5 cm from bottom
31
+ self.set_y(-15)
32
+ # Set Chinese font
33
+ self.add_font("SimSun", "", "./fonts/SimSun.ttf", uni=True)
34
+ self.set_font("SimSun", "", 12)
35
+ # Text color in gray
36
+ self.set_text_color(128)
37
+ # Page number
38
+ self.cell(0, 10, "Page " + str(self.page_no()), 0, 0, "C")
39
+
40
+ def chapter_title(self, num, label):
41
+ # Set Chinese font
42
+ self.add_font("SimSun", "", "./fonts/SimSun.ttf", uni=True)
43
+ self.set_font("SimSun", "", 12)
44
+ # Background color
45
+ self.set_fill_color(200, 220, 255)
46
+ # Title
47
+ # self.cell(0, 6, 'Chapter %d : %s' % (num, label), 0, 1, 'L', 1)
48
+ self.cell(0, 6, "Test result:", 0, 1, "L", 1)
49
+ # Line break
50
+ self.ln(4)
51
+
52
+ def chapter_body(self, name):
53
+
54
+ # Set Chinese font
55
+ self.add_font("SimSun", "", "./fonts/SimSun.ttf", uni=True)
56
+ self.set_font("SimSun", "", 12)
57
+ # Output justified text
58
+ self.multi_cell(0, 5, name)
59
+ # Line break
60
+ self.ln()
61
+ self.cell(0, 5, "--------------------------------------")
62
+
63
+ def print_chapter(self, num, title, name):
64
+ self.add_page()
65
+ self.chapter_title(num, title)
66
+ self.chapter_body(name)
67
+
68
+
69
+ # pdf generation function
70
+ def pdf_generate(input_file, output_file, title_):
71
+ global title
72
+
73
+ title = title_
74
+ pdf = PDF()
75
+ pdf.set_title(title)
76
+ pdf.set_author("Zeng Yifu")
77
+ pdf.print_chapter(1, "A RUNAWAY REEF", input_file)
78
+ pdf.output(output_file)