roman commited on
Commit
cdf6c2a
·
1 Parent(s): 64043f0

clean code

Browse files
Files changed (1) hide show
  1. app.py +62 -60
app.py CHANGED
@@ -140,57 +140,57 @@ def imagename(str):
140
  return str.split('/')[-1]
141
 
142
 
143
- def read_image(im_path, YAML_FILE, path_to_model, THR=0.5, dim=(500, 500),
144
- cat_lst=['pomeranc', 'poteklina']):
145
-
146
- out_dct = {}
147
-
148
- im_name = imagename(im_path)
149
- # img = cv2.imread(os.path.join(root_path, d["file_name"]))
150
- img = cv2.imread(im_path)
151
- out_dct[im_name] = inference_2(image=img, path_to_model=path_to_model,
152
- dataset_name=None, YAML_FILE=YAML_FILE,
153
- cat_lst=cat_lst, thr=THR)
154
- print(im_path)
155
- # print(os.path.join(im_path, d["file_name"]))
156
- labels_list = []
157
- boxes = []
158
- name_dict = {}
159
-
160
- for i in range(len(out_dct[im_name]['cl_lst'])):
161
- box = out_dct[im_name]['box_lst'][i]
162
- box = [int(i) for i in box]
163
- label = out_dct[im_name]['cl_lst'][i]
164
- scores = out_dct[im_name]['scores'][i]
165
- # print(label, scores)
166
- # print(box)
167
- labels_list.append(label)
168
- boxes.append(box[0])
169
-
170
- cv2.rectangle(img, (box[0], box[1]), (box[2], box[3]), (0, 255, 0), 1)
171
- cv2.putText(img, label, (box[0], box[3]), cv2.FONT_HERSHEY_SIMPLEX, 2, (255, 0, 0), 4)
172
- # cv2.putText(img, str(int(scores*100)), (box[0], box[3]),cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2)
173
- # print(d["file_name"])
174
- # print(labels_list)
175
-
176
- for num, name in zip(boxes, labels_list):
177
- name_dict[num] = name
178
-
179
- # print(name_dict)
180
-
181
- od = collections.OrderedDict(sorted(name_dict.items()))
182
- digits_out_sorted = []
183
- for k, v in od.items():
184
- digits_out_sorted.append(v)
185
-
186
- # print(od)
187
-
188
- print(digits_out_sorted)
189
-
190
- # resized = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
191
- im_output_path = ROOT_FOLDER + 'output_images/' + im_path.split('/')[-1]
192
- print(im_output_path)
193
- cv2.imwrite(im_output_path, img)
194
 
195
  def process_one_image(img, im_name, YAML_FILE, path_to_model, THR=0.5, dim=(500, 500),
196
  cat_lst=['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']):
@@ -246,7 +246,9 @@ def process_one_image(img, im_name, YAML_FILE, path_to_model, THR=0.5, dim=(500,
246
 
247
  return img, digits_out_sorted
248
 
249
- ROOT_FOLDER = '/home/roman/PycharmProjects/streamlit/digits/'
 
 
250
 
251
  train_dct1 = {
252
  '10cl':
@@ -292,17 +294,17 @@ if __name__ == '__main__':
292
  YAML_FILE = 'Misc/cascade_mask_rcnn_R_50_FPN_3x.yaml'
293
  # YAML_FILE = 'COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml'
294
 
295
- DATASET_NAME = model_name
296
 
297
- val_dataset_name = DATASET_NAME + "_val_" + str(random.randint(1, 1000))
298
 
299
- num_classes = '10cl' # 'poteklina' # '1cl'
300
- dataset = '16' #
301
 
302
  # MetadataCatalog.get(val_dataset_name).thing_classes = train_dct1['10cl']['cat_lst'] #["person", "dog"]
303
- register_coco_instances(val_dataset_name, {}, train_dct1[num_classes]['val'][dataset]['json'],
304
- train_dct1[num_classes]['val'][dataset]['data'])
305
- dataset_dicts = DatasetCatalog.get(val_dataset_name)
306
 
307
  filenames = []
308
  uploaded_files = st.file_uploader("Choose a images", accept_multiple_files=True, type=["png", "jpg", "jpeg"])
@@ -351,4 +353,4 @@ if __name__ == '__main__':
351
  st.write(file_details)
352
 
353
  st.write('Точність визначення = ', num_ok /(num_ok + num_nok) * 100, ' %')
354
- st.write('NOK = ', num_nok, 'OK = ', num_ok)
 
140
  return str.split('/')[-1]
141
 
142
 
143
+ # def read_image(im_path, YAML_FILE, path_to_model, THR=0.5, dim=(500, 500),
144
+ # cat_lst=['pomeranc', 'poteklina']):
145
+ #
146
+ # out_dct = {}
147
+ #
148
+ # im_name = imagename(im_path)
149
+ # # img = cv2.imread(os.path.join(root_path, d["file_name"]))
150
+ # img = cv2.imread(im_path)
151
+ # out_dct[im_name] = inference_2(image=img, path_to_model=path_to_model,
152
+ # dataset_name=None, YAML_FILE=YAML_FILE,
153
+ # cat_lst=cat_lst, thr=THR)
154
+ # print(im_path)
155
+ # # print(os.path.join(im_path, d["file_name"]))
156
+ # labels_list = []
157
+ # boxes = []
158
+ # name_dict = {}
159
+ #
160
+ # for i in range(len(out_dct[im_name]['cl_lst'])):
161
+ # box = out_dct[im_name]['box_lst'][i]
162
+ # box = [int(i) for i in box]
163
+ # label = out_dct[im_name]['cl_lst'][i]
164
+ # scores = out_dct[im_name]['scores'][i]
165
+ # # print(label, scores)
166
+ # # print(box)
167
+ # labels_list.append(label)
168
+ # boxes.append(box[0])
169
+ #
170
+ # cv2.rectangle(img, (box[0], box[1]), (box[2], box[3]), (0, 255, 0), 1)
171
+ # cv2.putText(img, label, (box[0], box[3]), cv2.FONT_HERSHEY_SIMPLEX, 2, (255, 0, 0), 4)
172
+ # # cv2.putText(img, str(int(scores*100)), (box[0], box[3]),cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2)
173
+ # # print(d["file_name"])
174
+ # # print(labels_list)
175
+ #
176
+ # for num, name in zip(boxes, labels_list):
177
+ # name_dict[num] = name
178
+ #
179
+ # # print(name_dict)
180
+ #
181
+ # od = collections.OrderedDict(sorted(name_dict.items()))
182
+ # digits_out_sorted = []
183
+ # for k, v in od.items():
184
+ # digits_out_sorted.append(v)
185
+ #
186
+ # # print(od)
187
+ #
188
+ # print(digits_out_sorted)
189
+ #
190
+ # # resized = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
191
+ # im_output_path = ROOT_FOLDER + 'output_images/' + im_path.split('/')[-1]
192
+ # print(im_output_path)
193
+ # cv2.imwrite(im_output_path, img)
194
 
195
  def process_one_image(img, im_name, YAML_FILE, path_to_model, THR=0.5, dim=(500, 500),
196
  cat_lst=['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']):
 
246
 
247
  return img, digits_out_sorted
248
 
249
+ # ROOT_FOLDER = '/home/roman/PycharmProjects/streamlit/digits/'
250
+
251
+ ROOT_FOLDER = './'
252
 
253
  train_dct1 = {
254
  '10cl':
 
294
  YAML_FILE = 'Misc/cascade_mask_rcnn_R_50_FPN_3x.yaml'
295
  # YAML_FILE = 'COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml'
296
 
297
+ # DATASET_NAME = model_name
298
 
299
+ # val_dataset_name = DATASET_NAME + "_val_" + str(random.randint(1, 1000))
300
 
301
+ # num_classes = '10cl' # 'poteklina' # '1cl'
302
+ # dataset = '16' #
303
 
304
  # MetadataCatalog.get(val_dataset_name).thing_classes = train_dct1['10cl']['cat_lst'] #["person", "dog"]
305
+ # register_coco_instances(val_dataset_name, {}, train_dct1[num_classes]['val'][dataset]['json'],
306
+ # train_dct1[num_classes]['val'][dataset]['data'])
307
+ # dataset_dicts = DatasetCatalog.get(val_dataset_name)
308
 
309
  filenames = []
310
  uploaded_files = st.file_uploader("Choose a images", accept_multiple_files=True, type=["png", "jpg", "jpeg"])
 
353
  st.write(file_details)
354
 
355
  st.write('Точність визначення = ', num_ok /(num_ok + num_nok) * 100, ' %')
356
+ st.write('NOK = ', num_nok, 'OK = ', num_ok)