File size: 2,057 Bytes
e237bf5
cc6e84a
 
9a307c6
cc6e84a
9a307c6
 
 
cc6e84a
6b1ec43
cc6e84a
1fe5a70
cc6e84a
 
 
 
 
 
6b1ec43
cc6e84a
 
 
 
d697aa2
cc6e84a
 
 
 
 
 
 
297e309
cc6e84a
 
 
 
 
 
ba63bbf
cc6e84a
ba63bbf
 
cc6e84a
 
ba63bbf
 
cc6e84a
 
 
 
ba63bbf
cc6e84a
297e309
cc6e84a
297e309
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
52
53
54
55
56

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
from tensorflow.keras.optimizers import Adam
import numpy as np
from huggingface_hub import hf_hub_url, hf_hub_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=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 = hf_hub_download(repo_id=repo_id, filename=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]) * 100  # Convert to percentage
        st.write(f"Healthy with {probability:.2f}%")  # Display with 2 decimal places

    else:
        probability = result[0][0] * 100  # Convert to percentage
        st.write(f"Glaucoma with {probability:.2f}%")  # Display with 2 decimal places
            
    image1 = load_img(input_image)
    image1 = img_to_array(image1)
    image1 = np.array(image1)
    image1 = image1 / 255
    
    

    st.image(image1, caption='Uploaded Image', use_column_width=True, clamp=True)