paascorb commited on
Commit
0cc18a8
1 Parent(s): a6042dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -1,23 +1,25 @@
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
  from icevision.models.checkpoint import *
6
  import PIL
7
 
8
  checkpoint_path = "efficientdetMapaches.pth"
9
- checkpoint_and_model = model_from_checkpoint(checkpoint_path, map_location=torch.device('cpu'))
10
- model = checkpoint_and_model["model"]
11
- model_type = checkpoint_and_model["model_type"]
12
- class_map = checkpoint_and_model["class_map"]
13
 
14
- img_size = checkpoint_and_model["img_size"]
15
- valid_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(img_size), tfms.A.Normalize()])
 
 
16
 
17
  # Definimos una función que se encarga de llevar a cabo las predicciones
18
  def predict(img):
19
  img = PIL.Image.open(img)
20
- pred_dict = model_type(img, valid_tfms, model.to("cpu"), class_map=class_map, detection_threshold=0.5)
21
  return pred_dict["img"]
22
 
23
  # Creamos la interfaz y la lanzamos.
 
1
  from huggingface_hub import from_pretrained_fastai
2
  import gradio as gr
3
  from fastai.vision.all import *
4
+ from icevision import models
5
  from icevision.all import *
6
  from icevision.models.checkpoint import *
7
  import PIL
8
 
9
  checkpoint_path = "efficientdetMapaches.pth"
10
+ model = models.ross.efficientdet.model(backbone=models.ross.efficientdet.backbones.tf_lite0(pretrained=True),
11
+ num_classes=2,
12
+ img_size=384)
 
13
 
14
+ state_dict = torch.load('fasterRCNNkangaroo.pth')
15
+ model.load_state_dict(state_dict)
16
+
17
+ infer_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(384),tfms.A.Normalize()])
18
 
19
  # Definimos una función que se encarga de llevar a cabo las predicciones
20
  def predict(img):
21
  img = PIL.Image.open(img)
22
+ pred_dict = model_type(img, infer_tfms, model.to("cpu"), class_map=ClassMap(['raccoon']), detection_threshold=0.5)
23
  return pred_dict["img"]
24
 
25
  # Creamos la interfaz y la lanzamos.