File size: 873 Bytes
ee7346e
c58ca64
 
acffed1
5ecb28b
6548833
5ecb28b
 
6548833
acffed1
5ecb28b
 
674c93a
5ecb28b
 
 
 
6548833
5ecb28b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import gradio as gr
from icevision.all import *
import PIL

class_map = ClassMap(['kangaroo'])
model = models.torchvision.faster_rcnn.model(backbone=models.torchvision.faster_rcnn.backbones.resnet50_fpn,
                                             num_classes=len(class_map))
state_dict = torch.load('fasterRCNNKangaroo.pth')
model.load_state_dict(state_dict)

infer_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(size),tfms.A.Normalize()])
size = 384
def predict(img):
    img = PILImage.create(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=gr.inputs.Image(shape=(128, 128)), outputs=gr.outputs.Image(),examples=['00004.jpg','00083.jpg', '00119.jpg']).launch(share=False)