paascorb commited on
Commit
df08274
1 Parent(s): f85b30d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -2,17 +2,22 @@ from huggingface_hub import from_pretrained_fastai
2
  import gradio as gr
3
  from fastai.vision.all import *
4
  from icevision.all import *
 
5
  import PIL
6
 
7
- repo_id = "paascorb/image-detection-efficientdet"
 
 
 
 
8
 
9
- learner = from_pretrained_fastai(repo_id)
 
10
 
11
  # Definimos una función que se encarga de llevar a cabo las predicciones
12
  def predict(img):
13
  img = PIL.Image.open(img)
14
- infer_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(size),tfms.A.Normalize()])
15
- pred_dict = models.ross.efficientdet.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.
 
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)
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.