Add classifier
Browse files- app.py +39 -4
- modelo.pkl +3 -0
- requirements.txt +7 -0
app.py
CHANGED
@@ -1,7 +1,42 @@
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastai.vision.all import *
|
2 |
+
from fastai.vision.core import PILImage
|
3 |
+
import torch
|
4 |
import gradio as gr
|
5 |
|
6 |
+
import warnings
|
7 |
+
warnings.filterwarnings("ignore")
|
8 |
|
9 |
+
|
10 |
+
learn = load_learner('modelo.pkl')
|
11 |
+
|
12 |
+
# Funci贸n de predicci贸n
|
13 |
+
def classify_image(image):
|
14 |
+
classes = ['abdomen', 'tobillo', 'col. cervical', 'torax', 'clavicula', 'codo', 'pies', 'dedos', 'antebrazo', 'mano', 'cadera',
|
15 |
+
'rodilla', 'pierna', 'col. lumbar', 'otros', 'pelvis', 'hombro', 'senos nasales', 'craneo', 'muslo', 'col. toracica', 'mu帽eca']
|
16 |
+
|
17 |
+
# Cargar imagen y realizar predicci贸n
|
18 |
+
img = PILImage.create(image)
|
19 |
+
pred, pred_idx, probs = model.predict(img)
|
20 |
+
|
21 |
+
# Filtrar probabilidades
|
22 |
+
probs = torch.where(probs > 1e-2, probs, torch.tensor(0).to(probs.device))
|
23 |
+
|
24 |
+
# Obtener top 5 resultados
|
25 |
+
top5_probs, top5_idxs = torch.topk(probs, 5)
|
26 |
+
top5_classes = [classes[idx] for idx in top5_idxs]
|
27 |
+
|
28 |
+
# Crear lista de predicciones
|
29 |
+
predictions = []
|
30 |
+
for i in range(5):
|
31 |
+
if top5_probs[i] > 1e-2:
|
32 |
+
prob = round(float(top5_probs[i].numpy()), 3)
|
33 |
+
predictions.append(f"{top5_classes[i]}: {prob}")
|
34 |
+
|
35 |
+
return predictions
|
36 |
+
|
37 |
+
|
38 |
+
inputs = gr.inputs.Image()
|
39 |
+
outputs = gr.outputs.Textbox()
|
40 |
+
|
41 |
+
gr.Interface(fn=classify_image, inputs=inputs, outputs=outputs, title='Clasificaci贸n de Im谩genes M茅dicas',
|
42 |
+
description='Cargue una radiograf铆a').launch()
|
modelo.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6b07890782ac08210b5a6849a6bc73a4c3b4061e11c8885168f92e8a43184949
|
3 |
+
size 114980453
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==3.34.0
|
2 |
+
gradio_client==0.2.6
|
3 |
+
torch==2.0.1
|
4 |
+
torchvision==0.15.2
|
5 |
+
timm==0.9.2
|
6 |
+
fastai==2.7.12
|
7 |
+
|