Update app.py
Browse files
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 |
-
|
10 |
-
|
11 |
-
|
12 |
-
class_map = checkpoint_and_model["class_map"]
|
13 |
|
14 |
-
|
15 |
-
|
|
|
|
|
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,
|
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.
|