Spaces:
Sleeping
Sleeping
File size: 1,720 Bytes
adf2111 0ad24c5 73036df 5f0bbf5 7a80d19 73036df adf2111 73036df adf2111 73036df e0ee69d 73036df 907b41c 73036df e0ee69d 73036df adf2111 73036df 907b41c adf2111 907b41c adf2111 907b41c |
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 |
import gradio as gr
import tensorflow as tf
import numpy as np
# Define a custom layer for FixedDropout
class FixedDropout(tf.keras.layers.Dropout):
def _get_noise_shape(self, inputs):
if self.noise_shape is None:
return self.noise_shape
symbolic_shape = tf.shape(inputs)
noise_shape = [symbolic_shape[axis] if shape is None else shape
for axis, shape in enumerate(self.noise_shape)]
return tuple(noise_shape)
# Register the custom layer
tf.keras.utils.get_custom_objects()['FixedDropout'] = FixedDropout
# Load your trained TensorFlow model
model = tf.keras.models.load_model('modelo_treinado.h5') # Load your saved model
# Define a function to make predictions
def classify_image(input_image):
# Preprocess the input image (resize and normalize)
input_image = tf.image.resize(input_image, (224, 224)) # Make sure to match your model's input size
input_image = (input_image / 255.0) # Normalize to [0, 1]
input_image = np.expand_dims(input_image, axis=0) # Add batch dimension
# Make a prediction using your model
prediction = model.predict(input_image)
# Assuming your model outputs probabilities for two classes, you can return the class with the highest probability
class_index = np.argmax(prediction)
class_labels = ["Normal", "Cataract"] # Replace with your actual class labels
predicted_class = class_labels[class_index]
return predicted_class
# Create a Gradio interface
input_interface = gr.Interface(
fn=classify_image,
inputs="image", # Specify input type as "image"
outputs="text" # Specify output type as "text"
)
# Launch the Gradio app
input_interface.launch()
|