Spaces:
Runtime error
Runtime error
File size: 782 Bytes
e452c35 a6546e9 b503ff5 a6546e9 d93c84c a6546e9 d93c84c a6546e9 d93c84c 1fa2651 |
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 |
import tensorflow as tf
import numpy as np
import gradio as gr
from huggingface_hub import from_pretrained_keras
import os
import sys
print('Loading model...')
model = from_pretrained_keras("mostafapasha/ribs-segmentation-model", compile=False)
print('Successfully loaded model...')
examples = ['VinDr_RibCXR_val_008.png', 'VinDr_RibCXR_val_013.png']
def segment(img_arr):
if np.ndim(img_arr) != 2:
img_arr = img_arr[:, :, 1]
image = img_arr[np.newaxis, :, :, np.newaxis]
threshold = 0.5
logits = model(image)
prob = tf.sigmoid(logits)
pred = tf.cast(prob > threshold, dtype=tf.float32)
pred = np.array(pred.numpy())[0,:,:,0]
return pred
iface = gr.Interface(fn=segment, inputs=gr.inputs.Image(shape=(512, 512)), outputs="image").launch()
|