Practica2 / app.py
Jacampo's picture
Update app.py
8451cff
raw
history blame contribute delete
879 Bytes
import icevision
from icevision.all import *
import torch
import gradio as gr
import PIL
from PIL import Image
# Cargamos el learner
learner = torch.load('fasterRCNNKangaroo_obligatorio.pth',map_location='cpu')
# Definimos una función que se encarga de llevar a cabo las predicciones
def predict(img):
#return img
size = 384
class_map = ClassMap(['kangaroo'])
infer_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(size),tfms.A.Normalize()])
pred_dict = models.torchvision.faster_rcnn.end2end_detect(img, infer_tfms, learner.to("cpu"), class_map=class_map, detection_threshold=0.5)
#return pred_dict['img']
return img
# Creamos la interfaz y la lanzamos.
gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(128, 128)), outputs=gr.outputs.Image(type="pil",label='Imagen resultado'),examples=['00001.jpg','00002.jpg']).launch(share=False)