CoolFace
Apppublic

dnth/icevision_fridge_tutorial

sourceHugging Faceafl-3.0updated 4y agoView on Hugging Face
1likes
app.py46 linesDownload Raw Back to root
1from gradio.outputs import Label2from icevision.all import *3from icevision.models.checkpoint import *4import PIL5import gradio as gr6import os7 8# Load model9checkpoint_path = "model_checkpoint.pth"10checkpoint_and_model = model_from_checkpoint(checkpoint_path)11model = checkpoint_and_model["model"]12model_type = checkpoint_and_model["model_type"]13class_map = checkpoint_and_model["class_map"]14 15# Transforms16img_size = checkpoint_and_model["img_size"]17valid_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(img_size), tfms.A.Normalize()])18 19# Populate examples in Gradio interface20examples = [21    ['./1.jpg'],22    ['./2.jpg'],23    ['./3.jpg']24]25 26def show_preds(input_image):27    img = PIL.Image.fromarray(input_image, "RGB")28    pred_dict = model_type.end2end_detect(img, valid_tfms, model, 29                                          class_map=class_map, 30                                          detection_threshold=0.5,31                                          display_label=True, 32                                          display_bbox=True, 33                                          return_img=True, 34                                          font_size=35,35                                          label_color="#FF59D6")36    return pred_dict["img"]37 38gr_interface = gr.Interface(39    fn=show_preds,40    inputs=["image"],41    outputs=[gr.outputs.Image(type="pil", label="VFNet Inference")],42    title="Fridge Object Detector",43    description="A VFNet model that detects common objects found in fridge. Upload an image or click an example image below to use.",44    examples=examples,45)46gr_interface.launch(inline=False, share=False, debug=True)