Paolo-Fraccaro
commited on
Commit
•
888c7e3
1
Parent(s):
5f99c38
remove try
Browse files
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 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
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 |
|