|
from huggingface_hub import from_pretrained_fastai |
|
import gradio as gr |
|
from icevision.all import * |
|
|
|
|
|
repo_id = "inigo99/kangaroo-detector" |
|
|
|
class_map = ClassMap(['kangaroo']) |
|
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") |
|
model.load_state_dict(state_dict) |
|
|
|
|
|
def predict(img): |
|
|
|
infer_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(384),tfms.A.Normalize()]) |
|
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'] |
|
|
|
|
|
gr.Interface(fn=predict, inputs=gr.inputs.Image(type='filepath'), outputs=gr.outputs.Image(type='pil'), examples=['00001.jpg','00002.jpg']).launch(share=False) |
|
|