Spaces:
Sleeping
Sleeping
File size: 1,804 Bytes
6d07e5e cc6e84a 9a307c6 cc6e84a 9a307c6 cc6e84a 9a307c6 cc6e84a |
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 47 48 49 50 51 |
import streamlit as st
import tensorflow as tf
from tensorflow.keras.applications import EfficientNetV2B0
from keras.layers import Flatten,Dense,Dropout,GlobalAveragePooling2D
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.image import load_img
from tensorflow.keras.preprocessing.image import img_to_array
from keras.models import Model
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=tensorflow.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)
|