Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,45 +2,32 @@ import gradio as gr
|
|
2 |
import tensorflow as tf
|
3 |
import numpy as np
|
4 |
|
5 |
-
# Define a custom layer for FixedDropout
|
6 |
-
class FixedDropout(tf.keras.layers.Dropout):
|
7 |
-
def _get_noise_shape(self, inputs):
|
8 |
-
if self.noise_shape is None:
|
9 |
-
return self.noise_shape
|
10 |
-
symbolic_shape = tf.shape(inputs)
|
11 |
-
noise_shape = [symbolic_shape[axis] if shape is None else shape
|
12 |
-
for axis, shape in enumerate(self.noise_shape)]
|
13 |
-
return tuple(noise_shape)
|
14 |
-
|
15 |
-
# Register the custom layer
|
16 |
-
tf.keras.utils.get_custom_objects()['FixedDropout'] = FixedDropout
|
17 |
-
|
18 |
# Load your trained TensorFlow model
|
19 |
model = tf.keras.models.load_model('modelo_treinado.h5') # Load your saved model
|
20 |
|
21 |
# Define a function to make predictions
|
22 |
def classify_image(input_image):
|
23 |
-
#
|
24 |
-
input_image = tf.image.resize(input_image, (
|
25 |
-
input_image = (input_image / 255.0) # Normalize
|
26 |
-
input_image = np.expand_dims(input_image, axis=0) #
|
27 |
|
28 |
-
#
|
29 |
prediction = model.predict(input_image)
|
30 |
|
31 |
-
#
|
32 |
class_index = np.argmax(prediction)
|
33 |
-
class_labels = ["Normal", "Cataract"] #
|
34 |
predicted_class = class_labels[class_index]
|
35 |
|
36 |
return predicted_class
|
37 |
|
38 |
-
#
|
39 |
input_interface = gr.Interface(
|
40 |
fn=classify_image,
|
41 |
-
inputs="image", #
|
42 |
-
outputs="text" #
|
43 |
)
|
44 |
|
45 |
-
#
|
46 |
input_interface.launch()
|
|
|
2 |
import tensorflow as tf
|
3 |
import numpy as np
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
# Load your trained TensorFlow model
|
6 |
model = tf.keras.models.load_model('modelo_treinado.h5') # Load your saved model
|
7 |
|
8 |
# Define a function to make predictions
|
9 |
def classify_image(input_image):
|
10 |
+
# Redimensione a imagem para as dimensões corretas (192x256)
|
11 |
+
input_image = tf.image.resize(input_image, (192, 256)) # Redimensione para as dimensões esperadas
|
12 |
+
input_image = (input_image / 255.0) # Normalize para [0, 1]
|
13 |
+
input_image = np.expand_dims(input_image, axis=0) # Adicione a dimensão de lote
|
14 |
|
15 |
+
# Faça a previsão usando o modelo
|
16 |
prediction = model.predict(input_image)
|
17 |
|
18 |
+
# Assumindo que o modelo retorna probabilidades para duas classes, você pode retornar a classe com a maior probabilidade
|
19 |
class_index = np.argmax(prediction)
|
20 |
+
class_labels = ["Normal", "Cataract"] # Substitua pelas suas etiquetas de classe reais
|
21 |
predicted_class = class_labels[class_index]
|
22 |
|
23 |
return predicted_class
|
24 |
|
25 |
+
# Crie uma interface Gradio
|
26 |
input_interface = gr.Interface(
|
27 |
fn=classify_image,
|
28 |
+
inputs="image", # Especifique o tipo de entrada como "image"
|
29 |
+
outputs="text" # Especifique o tipo de saída como "text"
|
30 |
)
|
31 |
|
32 |
+
# Inicie o aplicativo Gradio
|
33 |
input_interface.launch()
|