import gradio as gr from icevision.all import * import PIL class_map = ClassMap(['raccoon']) model = models.torchvision.faster_rcnn.model(backbone=models.torchvision.faster_rcnn.backbones.resnet50_fpn(pretrained=True), num_classes=len(class_map)) state_dict = torch.load('fasterRCNNRaccoonRESNET50.pth') model.load_state_dict(state_dict) size = 384 infer_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(size),tfms.A.Normalize()]) def predict(img): # img = PIL.Image.open(img) np.int = int img = PIL.Image.fromarray(img) pred_dict = models.torchvision.faster_rcnn.end2end_detect(img, infer_tfms, model.to("cpu"), class_map=class_map, detection_threshold=0.5) return pred_dict['img'] # Creamos la interfaz y la lanzamos. gr.Interface(fn=predict, inputs=["image"], outputs=["image"], examples=['raccoon/train/images/raccoon-197.jpg','raccoon/train/images/raccoon-177.jpg']).launch(share=True,debug=True)