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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -15
app.py CHANGED
@@ -14,21 +14,14 @@ 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)
 
14
  examples = ['examples/VinDr_RibCXR_val_008.png', 'examples/VinDr_RibCXR_val_013.png']
15
 
16
 
17
+ def segment(img_arr):
18
+ if np.ndim(img_arr) != 2:
19
+ img_arr = img_arr[:, :, 1]
20
+ image = img_arr[np.newaxis, :, :, np.newaxis]
21
  threshold = 0.5
22
+ logits = model(image)
23
  prob = tf.sigmoid(logits)
24
  pred = tf.cast(prob > threshold, dtype=tf.float32)
25
+ pred = np.array(pred.numpy())[0,:,:,0]
26
+ return pred
27
+ iface = gr.Interface(fn=segment, inputs=gr.inputs.Image(shape=(512, 512)), outputs="image", flagging_dir=os.path.join(sys.path[0], "flagged")).launch(share=True)