Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from icevision.all import *
|
3 |
+
|
4 |
+
class_map = ClassMap(['disk'])
|
5 |
+
model = models.torchvision.faster_rcnn.model(backbone=models.torchvision.faster_rcnn.backbones.resnet18_fpn(pretrained=True),num_classes=len(class_map))
|
6 |
+
state_dict = torch.load('fasterRCNNDisc.pth')
|
7 |
+
model.load_state_dict(state_dict)
|
8 |
+
|
9 |
+
infer_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(384),tfms.A.Normalize()])
|
10 |
+
|
11 |
+
def predict(img):
|
12 |
+
img = PILImage.create(img)
|
13 |
+
pred_dict = models.torchvision.faster_rcnn.end2end_detect(img, infer_tfms, model.to("cpu"), class_map=class_map, detection_threshold=0.5)
|
14 |
+
return pred_dict['img']
|
15 |
+
|
16 |
+
gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(128, 128)), outputs=gr.outputs.Image(),examples=['image.jpg']).launch(share=False)
|