|
from fastai.vision.all import * |
|
from fastai.vision.core import PILImage |
|
import torch |
|
import gradio as gr |
|
|
|
import warnings |
|
warnings.filterwarnings("ignore") |
|
|
|
|
|
learn = load_learner('modelo.pkl') |
|
|
|
classes = ['abdomen', 'antebrazo', 'cadera', 'cervical', 'clavicula', 'codo', 'col. torax', 'craneo', 'dedos', 'hombro', |
|
'lumbar', 'mano', 'muslo', 'mu帽eca', 'otros', 'pelvis', 'pierna', 'pies', 'rodilla', 'senos nasales', 'tobillo', 'torax'] |
|
|
|
|
|
def classify_image(image, model=learn, classes=classes): |
|
|
|
|
|
img = PILImage.create(image) |
|
pred, pred_idx, probs = model.predict(img) |
|
|
|
|
|
probs = torch.where(probs > 1e-2, probs, torch.tensor(0).to(probs.device)) |
|
|
|
|
|
top5_probs, top5_idxs = torch.topk(probs, 5) |
|
top5_classes = [classes[idx] for idx in top5_idxs] |
|
|
|
|
|
predictions = [] |
|
for i in range(5): |
|
if top5_probs[i] > 1e-2: |
|
prob = round(float(top5_probs[i].numpy()), 3) |
|
predictions.append(f"{top5_classes[i]}: {prob}") |
|
|
|
return predictions |
|
|
|
|
|
inputs = gr.inputs.Image() |
|
outputs = gr.outputs.Textbox() |
|
|
|
gr.Interface(fn=classify_image, inputs=inputs, outputs=outputs, title='Clasificaci贸n de Im谩genes M茅dicas', |
|
description='Cargue una radiograf铆a').launch() |
|
|