|
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 |
|
|
|
checkpoint_path = "efficientdetMapaches.pth" |
|
checkpoint_and_model = model_from_checkpoint(checkpoint_path) |
|
model = checkpoint_and_model["model"] |
|
model_type = checkpoint_and_model["model_type"] |
|
class_map = checkpoint_and_model["class_map"] |
|
|
|
img_size = checkpoint_and_model["img_size"] |
|
valid_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(img_size), tfms.A.Normalize()]) |
|
|
|
|
|
def predict(img): |
|
img = PIL.Image.open(img) |
|
pred_dict = model_type(img, valid_tfms, model.to("cpu"), class_map=class_map, detection_threshold=0.5) |
|
return pred_dict["img"] |
|
|
|
|
|
gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(128, 128)), outputs=gr.outputs.Image(shape(128,128)), |
|
examples=['raccoon-161.jpg','raccoon-162.jpg']).launch(share=False) |