Glaucoma_RIM / app.py
ferferefer's picture
Add application file
cc6e84a
raw
history blame
1.8 kB
import streamlit as st
import tensorflow as tf
from tf.keras.applications import EfficientNetV2B0
from keras.layers import Flatten,Dense,Dropout,GlobalAveragePooling2D
from tf.keras.models import load_model
from tf.keras.preprocessing.image import load_img
from tf.keras.preprocessing.image import img_to_array
from keras.models import Model
from transformers import pipeline
import numpy as np
from huggingface_hub import hf_hub_url, cached_download
img_shape = (224,224,3)
model = EfficientNetV2B0(include_top = False,input_shape=img_shape)
flat_1=GlobalAveragePooling2D()(model.output)
capa_3 = Dense(1,activation='sigmoid')(flat_1)
model = Model(inputs=model.inputs,outputs = capa_3)
model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=1e-4),loss="BinaryCrossentropy", metrics=["accuracy"])
#Subir los pesos del modelo
repo_id = "ferferefer/RIM_ONE_Glaucoma"
filename = "vgg_rim_checkpoint.h5" # o el path a tu SavedModel
# Obtener la URL y descargar el archivo (temporalmente)
model_file = cached_download(hf_hub_url(repo_id, filename))
# Cargar el modelo
model.load_weights(model_file)
st.title('RIM_ONE Glaucoma Image Classifier')
input_image = st.file_uploader('Upload image')
if st.button('PREDICT'):
predict = load_img(input_image, target_size=img_shape)
predict_modified = img_to_array(predict)
predict_modified = np.expand_dims(predict_modified, axis=0)
result = model.predict(predict_modified)
if result < 0.5:
probability = 1 - result[0][0]
print(f"Healthy with {probability}%")
else:
probability = result[0][0]
print(f"Glaucoma with {probability}%")
image1 = load_img(input_image)
image1 = img_to_array(image1)
image1 = np.array(image1)
st.image(image1, width=500)