File size: 1,338 Bytes
ab9e38d a82dcb6 9605967 1f38e8d 0d067fc 4129c4b 865fc80 70fc88e 4129c4b a82dcb6 e3c5df3 45d2fe3 a82dcb6 45d2fe3 a82dcb6 1f38e8d a82dcb6 1f38e8d 9f1ce46 1f38e8d 59a07ff 1f38e8d a82dcb6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
from huggingface_hub import from_pretrained_fastai
import gradio as gr
from fastai.vision.all import *
from icevision.all import *
from icevision.models.checkpoint import *
import PIL
# class map > y con esto done;
class_map = ClassMap(['raccoon','banana'])
size = 384
model_type = models.ross.efficientdet
model_2 = model_type.model(
backbone= model_type.backbones.tf_d0 (pretrained=True),
num_classes=len(class_map),
img_size = size
)
# load from model_repo:
from huggingface_hub import hf_hub_download
hf_hub_download(repo_id="Alesteba/deep_model_02", filename="ross_racoon.pth")
state_dict = torch.load('./ross_racoon.pth', map_location=torch.device('cpu'))
model_2.load_state_dict(state_dict)
# use test img:
infer_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(size),tfms.A.Normalize()])
def predict(img):
img = PIL.Image.fromarray(img, "RGB")
pred_dict_2 = model_type.end2end_detect(
img,
infer_tfms,
model_2.to("cpu"),
class_map=class_map,
detection_threshold=0.5
)
return pred_dict_2["img"]
gr.Interface(
fn=predict,
inputs=gr.inputs.Image(shape=(128, 128)),
outputs=[gr.outputs.Image(type="pil", label="VFNet Inference")],
examples=['raccoon-test_1.jpg','raccoon-test_2.jpg']
).launch(share=False)
|