58 json파일 이름으로 json 파일이 저장된 폴더와 이미지 폴더를 만드는 기능
60 json_file_name (str): json 파일 이름
61 ret_img_folder (bool): 이미지 폴더 반환 여부
62 json_version (bool): json 파일 버전, 설정하지 않으면 json 파일 이름으로 json 파일 버전을 확인함
63 return (str): json 파일이 저장된 폴더경로, 이미지 경로
65 if json_version
is None:
68 path_format = PATH_FORMAT[json_version]
69 dataset_path_list = []
70 for pf
in path_format:
71 filename_re = re.compile(pf)
72 str_format = filename_re.search(json_file_name).group()
73 dataset_path_list.append(str_format)
75 json_path_list = dataset_path_list[:2]
76 json_folder =
join(json_path_list)
77 image_folder =
join(dataset_path_list)
81 return json_folder, image_folder
87 데이터셋이 저장된 기본 경로를 생성하는 기능
89 json 파일 저장 경로 : base_path/annotation/P/C/json_name
90 이미지 파일 저장 경로 : base_path/images/P/C/A/R/img_name
92 json_version (int): json 파일 버전
93 anno_path (str): json 파일 경로
95 base_path : 데이터(json, 이미지)가 저장된 폴더
96 image_base_path : 이미지가 저장된 기본 경로(base_path/images)
98 split_dataset = anno_path.split(
"/")
99 json_file_name = split_dataset[-1]
100 if json_version == 10:
101 base_path_list = split_dataset[:-3]
102 image_base_path_list = copy.deepcopy(base_path_list)
103 elif json_version == 11:
104 base_path_list = split_dataset[:-4]
105 image_base_path_list = copy.deepcopy(base_path_list)
106 image_base_path_list.append(
'images')
108 path_format = PATH_FORMAT[json_version]
109 for pf
in path_format:
110 filename_re = re.compile(pf)
111 str_format = filename_re.search(json_file_name).group()
112 image_base_path_list.append(str_format)
114 if platform.system().lower() ==
'windows':
115 image_base_path =
"/".
join(image_base_path_list)
116 base_path =
"/".
join(base_path_list)
118 image_base_path = os.path.join(
"/", *image_base_path_list)
119 base_path = os.path.join(
"/", *base_path_list)
121 return base_path, image_base_path
125 어노테이션 파일에 대응하는 이미지가 저장된 경로를 생성하는 기능
126 image_base_path 뒤에 붙는 폴더
128 json_version (int): json 파일 버전
129 anno_path (str): json 파일 경로
131 image_folder_path : 이미지가 저장된 폴더
133 split_dataset = anno_path.split(
"/")
134 json_file_name = split_dataset[-1]
136 image_folder_path_list = []
137 path_format = PATH_FORMAT[json_version]
138 for pf
in path_format:
139 filename_re = re.compile(pf)
140 str_format = filename_re.search(json_file_name).group()
141 image_folder_path_list.append(str_format)
143 if platform.system().lower() ==
'windows':
144 image_folder_path =
"/".
join(image_folder_path_list)
146 image_folder_path = os.path.join(*image_folder_path_list)
148 return image_folder_path
153 어노테이션 파일을 로드해서 기본 정보를 반환하는 기능
155 anno_path (str): json 파일 경로
157 json_version (int): json 파일 버전
158 label_map_version (int): 레이블맵 버전
159 base_path (str): 데이터가 저장된 기본 경로
160 image_base_path (str): 이미지가 저장된 기본 경로
161 dataset (dict): 어노테이션 데이터
163 with open(anno_path,
"r")
as json_file:
164 dataset = json.load(json_file)
166 json_version = int(float(dataset[
"info"][
"version"])*10)
167 label_map_version = int(float(dataset[
"info"][
"label_map_version"])*10)
169 dataset =
check_and_init_dataset(dataset, CHECK_LIST[json_version][
"keys"], CHECK_LIST[json_version][
"default_value"])
171 return json_version, label_map_version, base_path, image_base_path, dataset
234 anno_id (int): 어노테이션 아이디
235 image_id (int): 이미지 아이디
236 track_id (int): 추적 아이디
237 return (dict): 더미 데이터
241 "image_id": image_id,
245 [178.87325418994442, 168.6456005586591, 1.0],
246 [197.7807262569836, 135.67562849162016, 1.0],
247 [149.12639664804487, 140.08938547486025, 1.0],
248 [241.84322625698292, 161.00872905027938, 1.0],
249 [121.84322625698292, 161.00872905027938, 1.0],
250 [218.3100558659221, 205.59811452513907, 1.0],
251 [151.26187150837973, 209.51885474860308, 1.0],
252 [274.60125698323964, 257.7213687150835, 1.0],
253 [112.21508379888269, 268.0677374301673, 1.0],
254 [320.4018854748606, 337.25139664804476, 1.0],
255 [87.6002094972066, 346.36592178770945, 1.0],
256 [246.41445530726241, 379.5006983240222, 1.0],
257 [175.2807262569836, 380.26012569832403, 1.0],
258 [283.3463687150843, 503.20949720670353, 1.0],
259 [168.83449720670387, 514.8495111731842, 1.0],
260 [316.25453910614533, 637.7988826815641, 1.0],
261 [157.21508379888246, 641.4738128491614, 1.0],
264 "bbox": [32.3882681564246, 17.625698324022324, 391.0, 710.0],
268 "uppercolor": [255.0, 255.0, 255.0],
270 "lowercolor": [255.0, 255.0, 255.0],
272 "hatcolor": [-1.0, -1.0, -1.0],
274 "bagcolor": [-1.0, -1.0, -1.0],
275 "action_id": {
'action': 0,
'pose':0,
'hand':0,
'foot':0},
277 "mutual_action_target": [],
279 "dangerzone": [0, 0, 0, 0, 0, 0, 0, 0],
280 "track_id": track_id,
283 return tmp_annotation
299 file_name = LABEL_FILE_INFO[label_map_ver][label_key][
'file_name']
300 splitStr = LABEL_FILE_INFO[label_map_ver][label_key][
'keys']
301 path = os.path.join(LABEL_BASE, file_name)
303 labels = dict.fromkeys(splitStr)
304 with open(path,
"r", encoding=
'UTF-8')
as txt_file:
305 lines = txt_file.readlines()
319 labels[key].append(line)
321 return labels, splitStr