Spaces:
Runtime error
Runtime error
File size: 1,738 Bytes
0f07c40 1398914 59f67e0 1398914 59f67e0 1398914 59f67e0 0f07c40 59f67e0 1398914 59f67e0 1398914 12adead 1398914 8c1932f 0f07c40 8c1932f 92faf40 8c1932f 0f07c40 1398914 0f07c40 bb7cb7c 0f07c40 bb7cb7c 0f07c40 667d2da 0f07c40 8569023 |
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 |
from gradio.outputs import Label
from icevision.all import *
from icevision.models.checkpoint import *
import PIL
import gradio as gr
import os
# Load model
checkpoint_path = "models/model_checkpoint.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"]
# Transforms
img_size = checkpoint_and_model["img_size"]
valid_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(img_size), tfms.A.Normalize()])
examples = [['sample_images/IMG_20191212_151351.jpg'],['sample_images/IMG_20191212_153420.jpg'],['sample_images/IMG_20191212_154100.jpg']]
def show_preds(input_image):
img = PIL.Image.fromarray(input_image, "RGB")
pred_dict = model_type.end2end_detect(img, valid_tfms, model, class_map=class_map, detection_threshold=0.5,
display_label=False, display_bbox=True, return_img=True,
font_size=16, label_color="#FF59D6")
return pred_dict["img"], len(pred_dict["detection"]["bboxes"])
gr_interface = gr.Interface(
fn=show_preds,
inputs=["image"],
outputs=[gr.outputs.Image(type="pil", label="RetinaNet Inference"), gr.outputs.Textbox(type="number", label="Microalgae Count")],
title="Microalgae Detector with RetinaNet",
description="This RetinaNet model counts microalgaes on a given image. Upload an image or click an example image below to use.",
article="<p style='text-align: center'><a href='https://dicksonneoh.com/' target='_blank'>Blog post</a></p>",
examples=examples,
theme="dark-grass",
)
gr_interface.launch() |