Spaces:
Runtime error
Runtime error
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() | |