Alesteba commited on
Commit
a82dcb6
·
1 Parent(s): 5f36bc3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # imports
2
+
3
+ from icevision.all import *
4
+
5
+ model_2 = models.torchvision.retinanet.model(
6
+ backbone=models.torchvision.retinanet.backbones.resnext50_32x4d_fpn (pretrained=True),
7
+ num_classes=len(class_map)
8
+ )
9
+
10
+ # load from model_repo:
11
+
12
+ from huggingface_hub import hf_hub_download
13
+ hf_hub_download(repo_id="Alesteba/deep_model_02", filename="retinanet_racoon.pth")
14
+
15
+ state_dict = torch.load('retinanet_racoon.pth')
16
+
17
+ model_2.load_state_dict(state_dict)
18
+
19
+ # use test img:
20
+
21
+ img = PIL.Image.open('test.jpg')
22
+
23
+ infer_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(size),tfms.A.Normalize()])
24
+
25
+ pred_dict_2 = models.torchvision.retinanet.fastai.end2end_detect(
26
+
27
+ img,
28
+ infer_tfms,
29
+ model_2.to("cpu"),
30
+ class_map=class_map,
31
+ detection_threshold=0.5
32
+ )
33
+
34
+ # modelo 2 -> construido:
35
+
36
+ res_img = pred_dict_2['img']
37
+