Spaces:
Runtime error
Runtime error
File size: 838 Bytes
0b9fc54 7576a67 e01b5b1 7576a67 0b9fc54 159fe1d 0b9fc54 7a27f0d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import gradio as gr
from fastai.vision.all import *
from icevision.all import *
class_map = ClassMap(['disk'])
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('fasterRCNNDisc.pth',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()])
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']
gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(128, 128)), outputs=gr.outputs.Image(),examples=['image.jpg','image1.jpg','image2.jpg']).launch(share=False)
|