inigo99 commited on
Commit
36808c9
1 Parent(s): 6512986

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -1,22 +1,21 @@
1
  from huggingface_hub import from_pretrained_fastai
2
  import gradio as gr
3
- from fastai.vision.all import *
4
  from icevision.all import *
5
 
6
  # repo_id = "YOUR_USERNAME/YOUR_LEARNER_NAME"
7
  repo_id = "inigo99/kangaroo-detector"
8
 
9
  class_map = ClassMap(['kangaroo'])
10
- model = models.efficientdet.model(backbone=models.efficientdet.backbones.d1(pretrained=True),
11
- num_classes=len(class_map), img_size=(384, 384))
12
- state_dict = torch.load('efficientdetD1kangaroo.pth')
13
  model.load_state_dict(state_dict)
14
 
15
  # Definimos una función que se encarga de llevar a cabo las predicciones
16
  def predict(img):
17
  #img = PILImage.create(img)
18
  infer_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(384),tfms.A.Normalize()])
19
- pred_dict = models.efficientdet.end2end_detect(img, infer_tfms, model.to("cpu"), class_map=class_map, detection_threshold=0.5)
20
  return pred_dict['img']
21
 
22
  # Creamos la interfaz y la lanzamos.
 
1
  from huggingface_hub import from_pretrained_fastai
2
  import gradio as gr
 
3
  from icevision.all import *
4
 
5
  # repo_id = "YOUR_USERNAME/YOUR_LEARNER_NAME"
6
  repo_id = "inigo99/kangaroo-detector"
7
 
8
  class_map = ClassMap(['kangaroo'])
9
+ model = models.torchvision.faster_rcnn.model(backbone=models.torchvision.faster_rcnn.backbones.resnet18_fpn(pretrained=True),
10
+ num_classes=len(class_map))
11
+ state_dict = torch.load("fasterRCNNkangaroo.pth")
12
  model.load_state_dict(state_dict)
13
 
14
  # Definimos una función que se encarga de llevar a cabo las predicciones
15
  def predict(img):
16
  #img = PILImage.create(img)
17
  infer_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(384),tfms.A.Normalize()])
18
+ pred_dict = models.torchvision.faster_rcnn.end2end_detect(img, infer_tfms, model.to("cpu"), class_map=class_map, detection_threshold=0.5)
19
  return pred_dict['img']
20
 
21
  # Creamos la interfaz y la lanzamos.