File size: 1,404 Bytes
fa854e0 |
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 |
import streamlit as st
import streamlit.web.cli as stcli
import tensorflow as tf
import numpy as np
from PIL import Image
IMAGE_SIZE = 256
# Load the saved model
model = tf.keras.models.load_model('my_model.h5')
# Define class labels (adjust this according to your specific classes)
class_labels = ['Mild', 'Moderate', 'No_DR', 'Proliferate_DR', 'Severe']
def predict(image):
# Preprocess the image to the required size and scale
image = tf.image.resize(image, (IMAGE_SIZE, IMAGE_SIZE))
image = np.expand_dims(image, axis=0) # Add batch dimension
# Make prediction
predictions = model.predict(image)
confidence = np.max(predictions)
predicted_class = class_labels[np.argmax(predictions)]
return predicted_class, float(confidence)
# Create the Streamlit interface
st.title("Early Diabetic Retinopathy Detection")
st.write("Upload an image and get the predicted class along with confidence score.")
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption='Uploaded Image.', use_column_width=True)
st.write("")
st.write("Classifying...")
predicted_class, confidence = predict(image)
st.write(f"Predicted Class: {predicted_class}")
st.write(f"Confidence: {confidence:.2f}")
|