개정판 d8e1223c
issue #1366: add save option
Change-Id: I4c1edc9b5132fa8e83383406bc0bffea5d0aaa40
DTI_PID/WebServer/app/recognition/index.py | ||
---|---|---|
61 | 61 |
|
62 | 62 |
boxes = test_doftech_all_images.get_symbol(imgs, data['name'], root_path=data_path, trained_model1=os.path.join(data_path, 'checkpoint', data['name'] + "_only_params.pth"), \ |
63 | 63 |
trained_model2=os.path.dirname(os.path.realpath( |
64 |
__file__)) + '\\..\\..\\symbol_recognition\\MODEL\\doftech_all_class_only_params_opc.pth') |
|
64 |
__file__)) + '\\..\\..\\symbol_recognition\\MODEL\\doftech_all_class_only_params_opc.pth', save=True)
|
|
65 | 65 |
|
66 | 66 |
return jsonify({'symbol_box': boxes[0]}) |
67 | 67 |
|
DTI_PID/WebServer/symbol_recognition/test_doftech_all_images.py | ||
---|---|---|
47 | 47 |
# x, y, width, height |
48 | 48 |
return [self.class_info, self.start_h, self.start_w, self.end_h - self.start_h, self.end_w - self.start_w, self.iou] |
49 | 49 |
|
50 |
def get_symbol(imgs, name=None, root_path=None, trained_model1=None, trained_model2=None): |
|
50 |
def get_symbol(imgs, name=None, root_path=None, trained_model1=None, trained_model2=None, save=False):
|
|
51 | 51 |
global colors, DOFTECH_CLASSES |
52 | 52 |
|
53 | 53 |
parser = argparse.ArgumentParser("You Only Look Once: Unified, Real-Time Object Detection") |
... | ... | |
101 | 101 |
|
102 | 102 |
print("=========> "+ img_name) |
103 | 103 |
|
104 |
save_dir = os.path.dirname(os.path.realpath(__file__)) + '\save/' |
|
105 |
if not os.path.isdir(save_dir): |
|
106 |
os.mkdir(save_dir) |
|
107 |
|
|
108 |
save_dir = os.path.dirname(os.path.realpath(__file__)) + '\save/' + img_name + '/' |
|
109 |
if not os.path.isdir(save_dir): |
|
110 |
os.mkdir(save_dir) |
|
111 |
os.mkdir(save_dir+"a/") |
|
112 |
os.mkdir(save_dir+"b/") |
|
113 |
else: |
|
114 |
shutil.rmtree(save_dir) |
|
115 |
os.mkdir(save_dir) |
|
116 |
os.mkdir(save_dir+"a/") |
|
117 |
os.mkdir(save_dir+"b/") |
|
118 |
|
|
119 |
text_file = open(save_dir+'test_result.txt', mode='wt', encoding='utf-8') |
|
120 |
text_file.write(img_name+" -> Detection Reesult\n") |
|
121 |
text_file.write("================================\n") |
|
104 |
if save: |
|
105 |
try: |
|
106 |
save_dir = os.path.dirname(os.path.realpath(__file__)) + '\save/' |
|
107 |
save_dir_tile = save_dir + save_dir + "a/" |
|
108 |
if not os.path.isdir(save_dir): |
|
109 |
os.mkdir(save_dir) |
|
110 |
|
|
111 |
save_dir = os.path.dirname(os.path.realpath(__file__)) + '\save/' + img_name + '/' |
|
112 |
if not os.path.isdir(save_dir): |
|
113 |
os.mkdir(save_dir) |
|
114 |
os.mkdir(save_dir+"a/") |
|
115 |
#os.mkdir(save_dir+"b/") |
|
116 |
else: |
|
117 |
shutil.rmtree(save_dir) |
|
118 |
os.mkdir(save_dir) |
|
119 |
os.mkdir(save_dir+"a/") |
|
120 |
#os.mkdir(save_dir+"b/") |
|
121 |
except: |
|
122 |
print('save directory error') |
|
123 |
save = False |
|
124 |
save_dir = None |
|
125 |
save_dir_tile = None |
|
126 |
|
|
127 |
if save: |
|
128 |
text_file = open(save_dir+'test_result.txt', mode='wt', encoding='utf-8') |
|
129 |
text_file.write(img_name+" -> Detection Reesult\n") |
|
130 |
text_file.write("================================\n") |
|
122 | 131 |
|
123 | 132 |
# Text File 만들기 |
124 | 133 |
|
... | ... | |
128 | 137 |
print("=========> SMALL OBJECT DETECTION") |
129 | 138 |
for idx_small in range(len(small_object_patch_list)): |
130 | 139 |
patchs = small_object_patch_list[idx_small] |
131 |
total_symbole_list.append(detection_object(patchs, model1, save_dir+"a/", opc=False, opt=opt))
|
|
140 |
total_symbole_list.append(detection_object(patchs, model1, opc=False, opt=opt, save_root=save_dir_tile))
|
|
132 | 141 |
# ---------------------------------------------- |
133 | 142 |
# Large Object Detection (OPC etc.) |
134 | 143 |
# ---------------------------------------------- |
... | ... | |
140 | 149 |
t_image = img_list[idx_img].copy() |
141 | 150 |
count_result = merge_fn(t_image, total_symbole_list, save_dir) |
142 | 151 |
|
143 |
for idx, value in enumerate(count_result): |
|
144 |
text_file.write(DOFTECH_CLASSES[idx]+ " : "+ str(value) + "\n") |
|
152 |
if save: |
|
153 |
for idx, value in enumerate(count_result): |
|
154 |
text_file.write(DOFTECH_CLASSES[idx]+ " : "+ str(value) + "\n") |
|
145 | 155 |
|
146 |
text_file.close() |
|
156 |
text_file.close()
|
|
147 | 157 |
|
148 | 158 |
res = [] |
149 | 159 |
for symbol in total_symbole_list[0]:# + total_symbole_list[1]: |
... | ... | |
155 | 165 |
return total_symbole_lists |
156 | 166 |
|
157 | 167 |
|
158 |
def detection_object(patchs, model, save_root, opc, opt):
|
|
168 |
def detection_object(patchs, model, opc, opt, save_root=None):
|
|
159 | 169 |
global DOFTECH_CLASSES |
160 | 170 |
|
161 | 171 |
symbol_list = [] |
... | ... | |
225 | 235 |
(xmin, ymin + text_size[1] + 4), cv2.FONT_HERSHEY_PLAIN, 1, |
226 | 236 |
(255, 255, 255), 1) |
227 | 237 |
# -----------------------fill king image-------------------------------------- |
228 |
cv2.imwrite(save_root+"{}_prediction.png".format(idx), output_image) |
|
238 |
if save_root: |
|
239 |
cv2.imwrite(save_root+"{}_prediction.png".format(idx), output_image) |
|
229 | 240 |
pil_image.setObjectNum(len(predictions)) |
230 | 241 |
return symbol_list |
231 | 242 |
|
232 |
def merge_fn(total_img, total_symbole_list, save_root): |
|
243 |
def merge_fn(total_img, total_symbole_list, save_root=None):
|
|
233 | 244 |
""" total_img:path -> img file """ |
234 | 245 |
global DOFTECH_CLASSES |
235 | 246 |
|
... | ... | |
258 | 269 |
for index, name in enumerate(DOFTECH_CLASSES): |
259 | 270 |
if name == total_symbole_list[idx_out][idx].class_info : |
260 | 271 |
count_result[index] = count_result[index]+1 |
261 |
cv2.imwrite(save_root+"entire.png", temp_king_img) |
|
272 |
if save_root: |
|
273 |
cv2.imwrite(save_root+"entire.png", temp_king_img) |
|
262 | 274 |
|
263 | 275 |
return count_result |
264 | 276 |
|
내보내기 Unified diff