Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,16 @@
|
|
| 1 |
import tensorflow as tf
|
| 2 |
import efficientnet.tfkeras as efn
|
| 3 |
import gradio as gr
|
| 4 |
-
import numpy as np
|
| 5 |
|
| 6 |
# Dimensões da imagem
|
| 7 |
-
IMG_HEIGHT =
|
| 8 |
-
IMG_WIDTH =
|
| 9 |
|
| 10 |
# Função para construir o modelo
|
| 11 |
def build_model(img_height, img_width, n):
|
| 12 |
inp = tf.keras.layers.Input(shape=(img_height, img_width, n))
|
| 13 |
-
efnet = efn.
|
| 14 |
input_shape=(img_height, img_width, n),
|
| 15 |
weights='imagenet',
|
| 16 |
include_top=False
|
|
@@ -47,22 +47,33 @@ def predict(input_image):
|
|
| 47 |
input_image = tf.expand_dims(input_image, axis=0)
|
| 48 |
prediction = loaded_model.predict(input_image)
|
| 49 |
|
| 50 |
-
# A saída será uma matriz de previsões
|
| 51 |
class_names = ["Normal", "Cataract"]
|
|
|
|
| 52 |
|
| 53 |
# Determine a classe mais provável
|
| 54 |
-
predicted_class = class_names[np.argmax(
|
| 55 |
|
| 56 |
# Adicione informações adicionais à saída
|
| 57 |
-
confidence =
|
| 58 |
|
| 59 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
# Crie uma interface Gradio para fazer previsões
|
| 62 |
iface = gr.Interface(
|
| 63 |
predict,
|
| 64 |
inputs=gr.inputs.Image(label="Carregue uma imagem da região ocular", type="pil"),
|
| 65 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
theme="auto", # Usar o tema padrão do Gradio
|
| 67 |
)
|
| 68 |
|
|
|
|
| 1 |
import tensorflow as tf
|
| 2 |
import efficientnet.tfkeras as efn
|
| 3 |
import gradio as gr
|
| 4 |
+
import numpy as np
|
| 5 |
|
| 6 |
# Dimensões da imagem
|
| 7 |
+
IMG_HEIGHT = 512
|
| 8 |
+
IMG_WIDTH = 512
|
| 9 |
|
| 10 |
# Função para construir o modelo
|
| 11 |
def build_model(img_height, img_width, n):
|
| 12 |
inp = tf.keras.layers.Input(shape=(img_height, img_width, n))
|
| 13 |
+
efnet = efn.EfficientNetB3( # Usando EfficientNetB3
|
| 14 |
input_shape=(img_height, img_width, n),
|
| 15 |
weights='imagenet',
|
| 16 |
include_top=False
|
|
|
|
| 47 |
input_image = tf.expand_dims(input_image, axis=0)
|
| 48 |
prediction = loaded_model.predict(input_image)
|
| 49 |
|
| 50 |
+
# A saída será uma matriz de previsões
|
| 51 |
class_names = ["Normal", "Cataract"]
|
| 52 |
+
probabilities = prediction[0]
|
| 53 |
|
| 54 |
# Determine a classe mais provável
|
| 55 |
+
predicted_class = class_names[np.argmax(probabilities)]
|
| 56 |
|
| 57 |
# Adicione informações adicionais à saída
|
| 58 |
+
confidence = probabilities[np.argmax(probabilities)]
|
| 59 |
|
| 60 |
+
return {
|
| 61 |
+
"Imagem de Entrada": input_image[0].numpy(),
|
| 62 |
+
"Classificação": predicted_class,
|
| 63 |
+
"Confiança": confidence,
|
| 64 |
+
"Probabilidades": {class_names[i]: probabilities[i] for i in range(len(class_names))}
|
| 65 |
+
}
|
| 66 |
|
| 67 |
# Crie uma interface Gradio para fazer previsões
|
| 68 |
iface = gr.Interface(
|
| 69 |
predict,
|
| 70 |
inputs=gr.inputs.Image(label="Carregue uma imagem da região ocular", type="pil"),
|
| 71 |
+
outputs=[
|
| 72 |
+
gr.outputs.Image(label="Imagem de Entrada"),
|
| 73 |
+
gr.outputs.Textbox(label="Classificação"),
|
| 74 |
+
gr.outputs.Textbox(label="Confiança"),
|
| 75 |
+
gr.outputs.Table(label="Probabilidades")
|
| 76 |
+
],
|
| 77 |
theme="auto", # Usar o tema padrão do Gradio
|
| 78 |
)
|
| 79 |
|