Spaces:
Runtime error
Runtime error
Commit
•
f804b19
1
Parent(s):
ca2e173
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import random
|
3 |
+
from keras.models import load_model
|
4 |
+
import gradio as gr
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
+
import numpy as np
|
7 |
+
def jaccard_coef(y_true, y_pred):
|
8 |
+
y_true_flatten = K.flatten(y_true)
|
9 |
+
y_pred_flatten = K.flatten(y_pred)
|
10 |
+
intersection = K.sum(y_true_flatten * y_pred_flatten)
|
11 |
+
final_coef_value = (intersection + 1.0) / (K.sum(y_true_flatten) + K.sum(y_pred_flatten) - intersection + 1.0)
|
12 |
+
return final_coef_value
|
13 |
+
|
14 |
+
model = load_model('/content/drive/MyDrive/S_model.h5',custom_objects=({"jaccard_coef":jaccard_coef}))
|
15 |
+
image = gr.inputs.Image(shape = (256,256))
|
16 |
+
def predict_image(image):
|
17 |
+
test_image_input = np.expand_dims(image, 0)
|
18 |
+
prediction = model.predict(test_image_input)
|
19 |
+
predicted_image = np.argmax(prediction, axis=3)
|
20 |
+
predicted_image = predicted_image[0,:,:]
|
21 |
+
fig = plt.figure()
|
22 |
+
plt.imshow(predicted_image)
|
23 |
+
|
24 |
+
return fig
|
25 |
+
|
26 |
+
gr.Interface(fn = predict_image,inputs = image, outputs=['plot'],interpretation = 'default').launch(share = True)
|