Spaces:
Build error
Build error
File size: 1,187 Bytes
6fa74f8 63fca82 8c508e1 6fa74f8 44e148e 6fa74f8 9a1ed21 8c508e1 6fa74f8 63fca82 6fa74f8 44e148e 6fa74f8 9a1ed21 6fa74f8 3638ef4 6fa74f8 63fca82 |
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import math
import gradio as gr
import tensorflow as tf
configs = [
{
"model": "my_model_2.h5", "size": 512
},
{
"model": "my_model.h5", "size": 224
},
]
config = configs[0]
new_model = tf.keras.models.load_model(config["model"])
def classify_image(inp):
inp = inp.reshape((-1, config["size"], config["size"], 3))
prediction = new_model.predict(inp).flatten()
print(prediction)
if len(prediction) > 1:
probability = 100 * math.exp(prediction[0]) / (math.exp(prediction[0]) + math.exp(prediction[1]))
else:
probability = round(100. / (1 + math.exp(-prediction[0])), 2)
if probability > 45:
return "Glaucoma", probability
if probability > 25:
return "Unclear", probability
return "Not glaucoma", probability
gr.Interface(
fn=classify_image,
inputs=gr.inputs.Image(shape=(config["size"], config["size"])),
outputs=[
gr.outputs.Textbox(label="Label"),
gr.outputs.Textbox(label="Glaucoma probability (0 - 100)"),
],
examples=["001.jpg", "002.jpg", "225.jpg"],
flagging_options=["Correct label", "Incorrect label"],
allow_flagging="manual",
).launch()
|