ancebuc commited on
Commit
3c2ed55
1 Parent(s): 8ef26d8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from icevision.all import *
3
+ import PIL
4
+ class_map = ClassMap(['raccoon'])
5
+ model = models.torchvision.faster_rcnn.model(backbone=models.torchvision.faster_rcnn.backbones.resnet50_fpn(pretrained=True), num_classes=len(class_map))
6
+ state_dict = torch.load('modelResnet50raccoon.pth')
7
+ model.load_state_dict(state_dict)
8
+ size = 384
9
+ infer_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(size),tfms.A.Normalize()])
10
+ def predict(img):
11
+ # img = PIL.Image.open(img)
12
+ np.int = int
13
+ img = PIL.Image.fromarray(img)
14
+
15
+ pred_dict = models.torchvision.faster_rcnn.end2end_detect(img, infer_tfms, model.to("cpu"), class_map=class_map, detection_threshold=0.5)
16
+ return pred_dict['img']
17
+
18
+ # Creamos la interfaz y la lanzamos.
19
+ gr.Interface(fn=predict, inputs=["image"], outputs=["image"], examples=['raccoon-106.jpg','raccoon-129.jpg']).launch(share=True,debug=True)