DHEIVER commited on
Commit
78b24ae
·
1 Parent(s): 32e9f67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -18
app.py CHANGED
@@ -1,34 +1,39 @@
1
  import gradio as gr
2
  import tensorflow as tf
3
  from tensorflow.keras.models import load_model
4
- from PIL import Image
5
- import numpy as np
6
 
7
- # Load the TensorFlow model
8
- tf_model_path = 'modelo_treinado.h5' # Update with the path to your TensorFlow model
9
- tf_model = load_model(tf_model_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  # Class labels for the model
12
  class_labels = ["Normal", "Cataract"]
13
 
14
  # Define a function for prediction
15
  def predict(image):
16
- # Preprocess the input image (resize and normalize)
17
- image = image.resize((224, 224)) # Adjust the size as needed
18
- image = np.array(image) / 255.0 # Normalize pixel values
19
- image = np.expand_dims(image, axis=0) # Add batch dimension
20
-
21
- # Make a prediction using the loaded TensorFlow model
22
- predictions = tf_model.predict(image)
23
-
24
- # Get the predicted class label
25
- predicted_label = class_labels[np.argmax(predictions)]
26
-
27
- return predicted_label
28
 
29
  # Create the Gradio interface
30
  gr.Interface(
31
  fn=predict,
32
  inputs=gr.Image(type="pil"),
33
- outputs=gr.Label(num_top_classes=2),
34
  ).launch()
 
1
  import gradio as gr
2
  import tensorflow as tf
3
  from tensorflow.keras.models import load_model
4
+ from tensorflow.keras.layers import Layer
 
5
 
6
+ # Define the custom 'FixedDropout' layer
7
+ class FixedDropout(Layer):
8
+ def __init__(self, rate, **kwargs):
9
+ super(FixedDropout, self).__init__(**kwargs)
10
+ self.rate = rate
11
+
12
+ def call(self, inputs, training=None):
13
+ if training is None:
14
+ training = K.learning_phase()
15
+
16
+ if training == 1:
17
+ return K.dropout(inputs, self.rate)
18
+ return inputs
19
+
20
+ # Register the custom layer in a custom object scope
21
+ custom_objects = {"FixedDropout": FixedDropout}
22
+
23
+ # Load the TensorFlow model with the custom object scope
24
+ tf_model_path = 'modelo_treinado.h5' # Update with the path to your model
25
+ tf_model = load_model(tf_model_path, custom_objects=custom_objects)
26
 
27
  # Class labels for the model
28
  class_labels = ["Normal", "Cataract"]
29
 
30
  # Define a function for prediction
31
  def predict(image):
32
+ # Your prediction code here...
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  # Create the Gradio interface
35
  gr.Interface(
36
  fn=predict,
37
  inputs=gr.Image(type="pil"),
38
+ outputs=gr.Label(num_top_classes=2)
39
  ).launch()