intelliarts commited on
Commit
d115356
1 Parent(s): a084c6c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -7
app.py CHANGED
@@ -120,7 +120,7 @@ def merge_segment(pred_segm):
120
  return pred_segm[new_indexes]
121
 
122
 
123
- def inference(image
124
  img = np.array(image)
125
  outputs_damage = predictor_damage(img)
126
  outputs_parts = predictor_parts(img)
@@ -134,6 +134,8 @@ def inference(image
134
  parts_data = outputs_parts["instances"].get_fields()
135
  parts_masks = parts_data['pred_masks']
136
  parts_classes = parts_data['pred_classes']
 
 
137
 
138
  parts_damage_dict = {}
139
  parts_list_damages = []
@@ -151,12 +153,36 @@ def inference(image
151
  parts_damage_dict[metadata_parts.thing_classes[parts_classes[i]]].append('damage')
152
  parts_list_damages.append(f'{metadata_parts.thing_classes[parts_classes[i]]} has damage')
153
  print(f'{metadata_parts.thing_classes[parts_classes[i]]} has damage')
154
-
155
- img1 = np.array(np.random.rand(240,240))
156
- img2 = np.array(np.random.rand(240,240))
157
- img3 = np.array(np.random.rand(240,240))
158
- parts_list_damage = 'test'
159
- return img1, img2, img3, parts_list_damage
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
 
161
  with gr.Blocks() as demo:
162
  with gr.Row():
 
120
  return pred_segm[new_indexes]
121
 
122
 
123
+ def inference(image):
124
  img = np.array(image)
125
  outputs_damage = predictor_damage(img)
126
  outputs_parts = predictor_parts(img)
 
134
  parts_data = outputs_parts["instances"].get_fields()
135
  parts_masks = parts_data['pred_masks']
136
  parts_classes = parts_data['pred_classes']
137
+ new_inst = detectron2.structures.Instances((1024,1024))
138
+ new_inst.set('pred_masks',merge_segment(out_dict['pred_masks']))
139
 
140
  parts_damage_dict = {}
141
  parts_list_damages = []
 
153
  parts_damage_dict[metadata_parts.thing_classes[parts_classes[i]]].append('damage')
154
  parts_list_damages.append(f'{metadata_parts.thing_classes[parts_classes[i]]} has damage')
155
  print(f'{metadata_parts.thing_classes[parts_classes[i]]} has damage')
156
+
157
+ v_d = Visualizer(img[:, :, ::-1],
158
+ metadata=metadata_damage,
159
+ scale=0.5,
160
+ instance_mode=ColorMode.SEGMENTATION # remove the colors of unsegmented pixels. This option is only available for segmentation models
161
+ )
162
+ #v_d = Visualizer(img,scale=1.2)
163
+ #print(outputs["instances"].to('cpu'))
164
+ out_d = v_d.draw_instance_predictions(new_inst)
165
+ img1 = out_d.get_image()[:, :, ::-1]
166
+
167
+ v_s = Visualizer(img[:, :, ::-1],
168
+ metadata=metadata_scratch,
169
+ scale=0.5,
170
+ instance_mode=ColorMode.SEGMENTATION # remove the colors of unsegmented pixels. This option is only available for segmentation models
171
+ )
172
+ #v_s = Visualizer(img,scale=1.2)
173
+ out_s = v_s.draw_instance_predictions(outputs_scratch["instances"])
174
+ img2 = out_s.get_image()[:, :, ::-1]
175
+
176
+ v_p = Visualizer(img[:, :, ::-1],
177
+ metadata=metadata_parts,
178
+ scale=0.5,
179
+ instance_mode=ColorMode.SEGMENTATION # remove the colors of unsegmented pixels. This option is only available for segmentation models
180
+ )
181
+ #v_p = Visualizer(img,scale=1.2)
182
+ out_p = v_p.draw_instance_predictions(outputs_parts["instances"])
183
+ img3 = out_p.get_image()[:, :, ::-1]
184
+
185
+ return img1, img2, img3, parts_list_damages
186
 
187
  with gr.Blocks() as demo:
188
  with gr.Row():