mostafapasha commited on
Commit
a6546e9
β€’
1 Parent(s): 0bcc244

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from layers import BilinearUpSampling2D
2
+ from tensorflow.keras.models import load_model
3
+ from utils import load_images, predict
4
+ import matplotlib.pyplot as plt
5
+ import numpy as np
6
+ import gradio as gr
7
+ from huggingface_hub import from_pretrained_keras
8
+ import os
9
+ import sys
10
+
11
+ print('Loading model...')
12
+ model = from_pretrained_keras("mostafapasha/ribs-segmentation-model", compile=False)
13
+ print('Successfully loaded model...')
14
+ examples = ['examples/VinDr_RibCXR_val_008.png', 'examples/VinDr_RibCXR_val_013.png']
15
+
16
+
17
+ def infer(image):
18
+ inputs = load_images([image])[..., 1:2]
19
+ logits = predict(model, inputs)
20
+ plasma = plt.get_cmap('plasma')
21
+ threshold = 0.5
22
+ prob = tf.sigmoid(logits)
23
+ pred = tf.cast(prob > threshold, dtype=tf.float32)
24
+ pred = pred.numpy())[0,:,:,0]
25
+ image_out = plasma(rescaled)[:, :, :3]
26
+ return image_out
27
+
28
+ iface = gr.Interface(
29
+ fn=infer,
30
+ title="ribs segmentation",
31
+ description = "Keras Implementation of Unet++ architecture for ribs segmentation πŸ“",
32
+ inputs=[gr.inputs.Image(label="image", type="numpy", shape=(640, 480))],
33
+ outputs="image",
34
+ examples=examples).launch(debug=True, cache_examples=True)