Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -84,6 +84,28 @@ def predict_2(image):
|
|
84 |
|
85 |
return out, unpatched_prediction
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
LABEL_NAMES = ["unlabeled",
|
88 |
"paved-area",
|
89 |
"dirt",
|
@@ -194,7 +216,8 @@ with my_app:
|
|
194 |
output_label = gr.Label(label="Predicted Masked Image")
|
195 |
img_output = gr.Image(label="Image Output")
|
196 |
source_image_loader.click(
|
197 |
-
predict_2,
|
|
|
198 |
[
|
199 |
img_source
|
200 |
],
|
|
|
84 |
|
85 |
return out, unpatched_prediction
|
86 |
|
87 |
+
from empatches import EMPatches
|
88 |
+
|
89 |
+
def predict_patches(image):
|
90 |
+
#img = Image.open(image)
|
91 |
+
image = Image.fromarray(image).resize((size,size))
|
92 |
+
image = np.array(image)/255
|
93 |
+
emp = EMPatches()
|
94 |
+
img_patches, indices = emp.extract_patches(image, patchsize=pach_size, overlap=0.2, stride=int(pach_size/2))
|
95 |
+
pred = model.predict(np.array(img_patches))
|
96 |
+
# Postprocess the mask
|
97 |
+
#print(pred)
|
98 |
+
pred = np.argmax(pred, axis=3)
|
99 |
+
merged_img = emp.merge_patches(pred, indices, mode='max').astype("int16")
|
100 |
+
|
101 |
+
#print(merged_img)
|
102 |
+
unpatched_prediction = targets_classes_colors[merged_img]
|
103 |
+
image_classes = []
|
104 |
+
for i in range(targets_classes_colors.shape[0]):
|
105 |
+
image_classes.append(np.sum(np.all(unpatched_prediction == targets_classes_colors[i,:], axis=-1))/(size*size*3))
|
106 |
+
results = dict(zip(LABEL_NAMES, image_classes))
|
107 |
+
return results, unpatched_prediction
|
108 |
+
|
109 |
LABEL_NAMES = ["unlabeled",
|
110 |
"paved-area",
|
111 |
"dirt",
|
|
|
216 |
output_label = gr.Label(label="Predicted Masked Image")
|
217 |
img_output = gr.Image(label="Image Output")
|
218 |
source_image_loader.click(
|
219 |
+
#predict_2,
|
220 |
+
predict_patches,
|
221 |
[
|
222 |
img_source
|
223 |
],
|