from icevision.all import * from icevision import models from fastai.basics import * from fastai.vision.all import * from fastai.callback import * import PIL import gradio as gr # Cargamos el learner model = models.torchvision.faster_rcnn.model(backbone=models.torchvision.faster_rcnn.backbones.resnet18_fpn, num_classes=2) state_dict = torch.load('fasterRCNNkangaroo.pth') 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(shape=(128, 128)),examples=['00004.jpg','00014.jpg']).launch(share=False)