prova5
Browse files
app.py
CHANGED
|
@@ -1,29 +1,19 @@
|
|
| 1 |
from fastai.vision.all import *
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
learn = load_learner('model.pkl')
|
| 5 |
|
| 6 |
categories = ('Normal', 'Cancer')
|
| 7 |
|
| 8 |
def classify_image(img):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
# Obtener las zonas de enfoque del modelo
|
| 12 |
-
interp = ClassificationInterpretation.from_learner(learn)
|
| 13 |
-
losses_idx = interp.top_losses(3) # Limitar a las 3 principales p茅rdidas
|
| 14 |
-
# Mostrar la interpretaci贸n visual en la imagen
|
| 15 |
-
interp.show_xyz(img, losses_idx=losses_idx, label_idxs=idx)
|
| 16 |
-
# Obtener la imagen con la interpretaci贸n visual
|
| 17 |
-
interp_img = interp.get_preds()[0]
|
| 18 |
-
return dict(zip(categories, map(float, probs))), interp_img
|
| 19 |
|
| 20 |
-
image = gr.inputs.Image(
|
| 21 |
label = gr.outputs.Label()
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
]
|
| 27 |
-
|
| 28 |
-
intf = gr.Interface(fn=classify_image, inputs=image, outputs=[label, interpretation], examples=examples)
|
| 29 |
-
intf.launch(inline=False)
|
|
|
|
| 1 |
from fastai.vision.all import *
|
| 2 |
import gradio as gr
|
| 3 |
+
import skimage
|
| 4 |
|
| 5 |
learn = load_learner('model.pkl')
|
| 6 |
|
| 7 |
categories = ('Normal', 'Cancer')
|
| 8 |
|
| 9 |
def classify_image(img):
|
| 10 |
+
pred,idx,probs = learn.predict(img)
|
| 11 |
+
return dict(zip(categories, map(float,probs)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
image = gr.inputs.Image()
|
| 14 |
label = gr.outputs.Label()
|
| 15 |
+
examples = ['Cancer.png', 'Normal.png', 'NormalDif.png']
|
| 16 |
+
interpretation='default'
|
| 17 |
|
| 18 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples, interpretation=interpretation)
|
| 19 |
+
intf.launch()
|
|
|
|
|
|
|
|
|
|
|
|