forked from paulxiong/convert2Yolo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
139 lines (97 loc) · 4.38 KB
/
example.py
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# -*-coding:utf-8-*-
import os
from xml.etree.ElementTree import dump
import json
import pprint
import argparse
from Format import VOC, COCO, UDACITY, KITTI, YOLO
parser = argparse.ArgumentParser(description='label Converting example.')
parser.add_argument('--datasets', type=str, help='type of datasets')
parser.add_argument('--img_path', type=str, help='directory of image folder')
parser.add_argument('--label', type=str,
help='directory of label folder or label file path')
parser.add_argument('--convert_output_path', type=str,
help='directory of label folder')
parser.add_argument('--img_type', type=str, help='type of image')
parser.add_argument('--manifest_path', type=str,
help='directory of manipast file', default="./")
parser.add_argument('--cls_list_file', type=str,
help='directory of *.names file', default="./")
args = parser.parse_args()
def main(config):
if config["datasets"] == "VOC":
voc = VOC()
yolo = YOLO(os.path.abspath(config["cls_list"]))
flag, data = voc.parse(config["label"])
if flag == True:
flag, data = yolo.generate(data)
if flag == True:
flag, data = yolo.save(data, config["output_path"], config["img_path"],
config["img_type"], config["manifest_path"])
if flag == False:
print("Saving Result : {}, msg : {}".format(flag, data))
else:
print("YOLO Generating Result : {}, msg : {}".format(flag, data))
else:
print("VOC Parsing Result : {}, msg : {}".format(flag, data))
elif config["datasets"] == "COCO":
coco = COCO()
flag, data, cls_hierarchy = coco.parse(
config["label"], config["img_path"])
yolo = YOLO(os.path.abspath(
config["cls_list"]), cls_hierarchy=cls_hierarchy)
if flag == True:
flag, data = yolo.generate(data)
if flag == True:
flag, data = yolo.save(data, config["output_path"], config["img_path"],
config["img_type"], config["manifest_path"])
if flag == False:
print("Saving Result : {}, msg : {}".format(flag, data))
else:
print("YOLO Generating Result : {}, msg : {}".format(flag, data))
else:
print("COCO Parsing Result : {}, msg : {}".format(flag, data))
elif config["datasets"] == "UDACITY":
udacity = UDACITY()
yolo = YOLO(os.path.abspath(config["cls_list"]))
flag, data = udacity.parse(config["label"])
if flag == True:
flag, data = yolo.generate(data)
if flag == True:
flag, data = yolo.save(data, config["output_path"], config["img_path"],
config["img_type"], config["manifest_path"])
if flag == False:
print("Saving Result : {}, msg : {}".format(flag, data))
else:
print("UDACITY Generating Result : {}, msg : {}".format(flag, data))
else:
print("COCO Parsing Result : {}, msg : {}".format(flag, data))
elif config["datasets"] == "KITTI":
kitti = KITTI()
yolo = YOLO(os.path.abspath(config["cls_list"]))
flag, data = kitti.parse(
config["label"], config["img_path"], img_type=config["img_type"])
if flag == True:
flag, data = yolo.generate(data)
if flag == True:
flag, data = yolo.save(data, config["output_path"], config["img_path"],
config["img_type"], config["manifest_path"])
if flag == False:
print("Saving Result : {}, msg : {}".format(flag, data))
else:
print("YOLO Generating Result : {}, msg : {}".format(flag, data))
else:
print("KITTI Parsing Result : {}, msg : {}".format(flag, data))
else:
print("Unkwon Datasets")
if __name__ == '__main__':
config = {
"datasets": args.datasets,
"img_path": args.img_path,
"label": args.label,
"img_type": args.img_type,
"manifest_path": args.manifest_path,
"output_path": args.convert_output_path,
"cls_list": args.cls_list_file,
}
main(config)