File size: 1,127 Bytes
e67f813
 
 
 
 
 
2040dd8
e67f813
 
 
 
 
 
 
 
 
 
 
 
 
2040dd8
e67f813
 
 
 
 
2040dd8
 
 
e67f813
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from skimage.util import montage as montage2d
from utils import load_model, preprocess_image, attempt_download_from_hub
import matplotlib.pyplot as plt

import gradio as gr

model_path = 'deprem-ml/deprem-keras-satellite-semantic-mapping'

def keras_inference(img_data, model_path):
    model_path = attempt_download_from_hub(model_path)
    seg_model = load_model(model_path)
    out_img = preprocess_image(img_data)
    pred_y = seg_model.predict(out_img)

    plt.imshow(montage2d(pred_y[:, :, :, 0]), cmap = 'bone_r')
    plt.savefig('output.png')
    return 'output.png'

inputs = [
    gr.Image(type='filepath', label='Image'),
    gr.Dropdown([model_path], value=model_path, label='Model Path')
]

outputs = gr.Image(label='Segmentation')

examples = [
    ['data/testv1.jpg', model_path],
    ['data/testv2.jpg', model_path],
    ['data/testv3.jpg', model_path],
]

title = 'Segmenting Buildings in Satellite Images with Keras'

demo_app = gr.Interface(
    keras_inference, 
    inputs, 
    outputs, 
    title=title, 
    examples=examples,
    cache_examples=True,
)

demo_app.launch(debug=True, enable_queue=True)