Paolo-Fraccaro commited on
Commit
888c7e3
1 Parent(s): 5f99c38

remove try

Browse files
Files changed (1) hide show
  1. app.py +27 -31
app.py CHANGED
@@ -133,37 +133,33 @@ def inference_on_file(target_image, model, custom_test_pipeline):
133
 
134
  # output_image = target_image.replace('.tif', '_pred.tif')
135
  time_taken=-1
136
- try:
137
- st = time.time()
138
- print('Running inference...')
139
- result = inference_segmentor(model, target_image, custom_test_pipeline)
140
- print("Output has shape: " + str(result[0].shape))
141
-
142
- ##### get metadata mask
143
- mask = open_tiff(target_image)
144
- # rgb = mask[[2, 1, 0], :, :].transpose((1,2,0))
145
- rgb1 = mask[[2, 1, 0], :, :].transpose((1,2,0))
146
- rgb2 = mask[[8, 7, 6], :, :].transpose((1,2,0))
147
- rgb3 = mask[[14, 13, 12], :, :].transpose((1,2,0))
148
- meta = get_meta(target_image)
149
- mask = np.where(mask == meta['nodata'], 1, 0)
150
- mask = np.max(mask, axis=0)[None]
151
-
152
- result[0] = np.where(mask == 1, -1, result[0])
153
-
154
- ##### Save file to disk
155
- meta["count"] = 1
156
- meta["dtype"] = "int16"
157
- meta["compress"] = "lzw"
158
- meta["nodata"] = -1
159
- print('Saving output...')
160
- # write_tiff(result[0], output_image, meta)
161
- et = time.time()
162
- time_taken = np.round(et - st, 1)
163
- print(f'Inference completed in {str(time_taken)} seconds')
164
-
165
- except:
166
- print(f'Error on image {target_image} \nContinue to next input')
167
 
168
  return rgb1,rgb2,rgb3, result[0][0]
169
 
 
133
 
134
  # output_image = target_image.replace('.tif', '_pred.tif')
135
  time_taken=-1
136
+ st = time.time()
137
+ print('Running inference...')
138
+ result = inference_segmentor(model, target_image, custom_test_pipeline)
139
+ print("Output has shape: " + str(result[0].shape))
140
+
141
+ ##### get metadata mask
142
+ mask = open_tiff(target_image)
143
+ # rgb = mask[[2, 1, 0], :, :].transpose((1,2,0))
144
+ rgb1 = mask[[2, 1, 0], :, :].transpose((1,2,0))
145
+ rgb2 = mask[[8, 7, 6], :, :].transpose((1,2,0))
146
+ rgb3 = mask[[14, 13, 12], :, :].transpose((1,2,0))
147
+ meta = get_meta(target_image)
148
+ mask = np.where(mask == meta['nodata'], 1, 0)
149
+ mask = np.max(mask, axis=0)[None]
150
+
151
+ result[0] = np.where(mask == 1, -1, result[0])
152
+
153
+ ##### Save file to disk
154
+ meta["count"] = 1
155
+ meta["dtype"] = "int16"
156
+ meta["compress"] = "lzw"
157
+ meta["nodata"] = -1
158
+ print('Saving output...')
159
+ # write_tiff(result[0], output_image, meta)
160
+ et = time.time()
161
+ time_taken = np.round(et - st, 1)
162
+ print(f'Inference completed in {str(time_taken)} seconds')
 
 
 
 
163
 
164
  return rgb1,rgb2,rgb3, result[0][0]
165