mostafapasha commited on
Commit
8d0de00
·
1 Parent(s): c252043

updates files

Browse files
Files changed (2) hide show
  1. app.py +23 -8
  2. requirements.txt +6 -2
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import tensorflow as tf
2
  import numpy as np
3
  import gradio as gr
 
4
  from huggingface_hub import from_pretrained_keras
5
  import os
6
  import sys
@@ -8,17 +9,31 @@ import sys
8
  print('Loading model...')
9
  model = from_pretrained_keras("mostafapasha/ribs-segmentation-model", compile=False)
10
  print('Successfully loaded model...')
11
- examples = ['VinDr_RibCXR_train_008.png', 'VinDr_RibCXR_train_013.png']
12
 
13
 
14
- def segment(img_arr):
15
- if np.ndim(img_arr) != 2:
16
- img_arr = img_arr[:, :, 1]
17
- image = img_arr[np.newaxis, :, :, np.newaxis]
18
- threshold = 0.5
19
- logits = model(image)
20
  prob = tf.sigmoid(logits)
21
  pred = tf.cast(prob > threshold, dtype=tf.float32)
22
  pred = np.array(pred.numpy())[0,:,:,0]
23
  return pred
24
- iface = gr.Interface(fn=segment, inputs=gr.inputs.Image(shape=(512, 512)), outputs="image", examples=examples, flagging_dir="flagged").launch(cache_examples=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import tensorflow as tf
2
  import numpy as np
3
  import gradio as gr
4
+ import matplotlib.pyplot as plt
5
  from huggingface_hub import from_pretrained_keras
6
  import os
7
  import sys
 
9
  print('Loading model...')
10
  model = from_pretrained_keras("mostafapasha/ribs-segmentation-model", compile=False)
11
  print('Successfully loaded model...')
12
+ examples = ['examples/VinDr_RibCXR_train_008.png', 'examples/VinDr_RibCXR_train_013.png']
13
 
14
 
15
+ def infer(img, threshold):
16
+ if np.ndim(img) != 2:
17
+ img = img[:, :, 1]
18
+ img = img.reshape(1, img.shape[0], img.shape[1], 1)
19
+ logits = model(img, training=False)
 
20
  prob = tf.sigmoid(logits)
21
  pred = tf.cast(prob > threshold, dtype=tf.float32)
22
  pred = np.array(pred.numpy())[0,:,:,0]
23
  return pred
24
+
25
+ gr_input = [
26
+ gr.inputs.Image(label="Image", type="numpy", shape=(512, 512))
27
+ ,gr.inputs.Slider(minimum=0, maximum=1, step=0.05, default=0.5, label="Segmentation Threshold")
28
+ ]
29
+
30
+ gr_output = [
31
+ gr.outputs.Image(type="pil",label="Segmentation Mask"),
32
+ # gr.outputs.Image(type="pil",label="Filtered Image"),
33
+ ]
34
+
35
+ iface = gr.Interface(fn=infer,
36
+ title = 'ribs segmentation model',
37
+ description = 'Keras implementation of ResUNET++ for xray ribs segmentation',
38
+ inputs=gr_input,
39
+ outputs=gr_output, examples=examples, flagging_dir="flagged").launch(cache_examples=True)
requirements.txt CHANGED
@@ -1,2 +1,6 @@
1
- tensorflow
2
- keras
 
 
 
 
 
1
+ gradio==2.9.4
2
+ huggingface_hub==0.6.0
3
+ matplotlib==3.5.1
4
+ numpy==1.22.3
5
+ tensorflow==2.9.0
6
+ tensorflow_macos==2.8.0