DHEIVER commited on
Commit
2283b5b
·
1 Parent(s): 0ad24c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -24
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
- # Preprocess the input image (resize and normalize)
24
- input_image = tf.image.resize(input_image, (224, 224)) # Make sure to match your model's input size
25
- input_image = (input_image / 255.0) # Normalize to [0, 1]
26
- input_image = np.expand_dims(input_image, axis=0) # Add batch dimension
27
 
28
- # Make a prediction using your model
29
  prediction = model.predict(input_image)
30
 
31
- # Assuming your model outputs probabilities for two classes, you can return the class with the highest probability
32
  class_index = np.argmax(prediction)
33
- class_labels = ["Normal", "Cataract"] # Replace with your actual class labels
34
  predicted_class = class_labels[class_index]
35
 
36
  return predicted_class
37
 
38
- # Create a Gradio interface
39
  input_interface = gr.Interface(
40
  fn=classify_image,
41
- inputs="image", # Specify input type as "image"
42
- outputs="text" # Specify output type as "text"
43
  )
44
 
45
- # Launch the Gradio app
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()