File size: 1,155 Bytes
674c93a
ee7346e
 
c58ca64
ee7346e
c58ca64
acffed1
674c93a
6548833
674c93a
 
 
6548833
acffed1
674c93a
acffed1
674c93a
 
 
 
 
 
6548833
674c93a
 
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
from huggingface_hub import from_pretrained_fastai
import gradio as gr
from fastai.vision.all import *
from icevision.all import *
from icevision.models.checkpoint import *
import PIL

checkpoint_path = "fasterRCNNKangaroo.pth"
model = models.torchvision.faster_rcnn.model(backbone=models.torchvision.faster_rcnn.backbones.resnet50_fpn,
                                             num_classes=2)

state_dict = torch.load(checkpoint_path, map_location=torch.device('cpu'))
model.load_state_dict(state_dict)

infer_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(384),tfms.A.Normalize()])

# Definimos una función que se encarga de llevar a cabo las predicciones
def predict(img):
    img = PIL.Image.fromarray(img, "RGB")
    pred_dict =  models.ross.efficientdet.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(type="pil", label="VFNet Inference")],
             examples=['00004.jpg','00083.jpg', '00119.jpg']).launch(share=False)