Spaces:
Runtime error
Runtime error
File size: 1,130 Bytes
27611db f1425c5 27611db e270e63 8b3839f 8466eb7 8b3839f 8466eb7 e3b2b2b f1425c5 8b3839f 18aa4f1 f1425c5 e270e63 f1425c5 8b3839f 9f37413 70e172b 8b3839f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
from fastai.vision.all import *
from icevision.all import *
from fastai.basics import *
from fastai.callback import *
from icevision import models
import PIL
import gradio as gr
class_map=ClassMap(['kangaroo'])
# Cargamos el learner
model = models.torchvision.faster_rcnn.model(backbone=models.torchvision.faster_rcnn.backbones.resnet18_fpn(pretrained=True),
num_classes=len(class_map))
state_dict = torch.load('fasterRCNNkangaroo.pth', map_location = torch.device('cpu'))
model.load_state_dict(state_dict)
# Definimos una función que se encarga de llevar a cabo las predicciones
infer_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(384),tfms.A.Normalize()])
def predict(img):
img = PILImage.create(img)
pred_dict = models.torchvision.faster_rcnn.end2end_detect(img, infer_tfms, model.to("cpu"), class_map=ClassMap(['kangaroo']), detection_threshold=0.5)
return pred_dict['img']
# Creamos la interfaz y la lanzamos.
gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(128, 128)), outputs=gr.outputs.Image(),examples=['00014.jpg','00167.jpg']).launch(share=False)
|