yolov5-face / app.py
nakamura196's picture
feat: initial commit
39d67d3
raw
history blame
1.45 kB
import gradio as gr
from PIL import Image, ImageDraw
import yolov5
import json
model = yolov5.load("./best.pt")
def yolo(im):
results = model(im) # inference
df = results.pandas().xyxy[0].to_json(orient="records")
res = json.loads(df)
draw = ImageDraw.Draw(im)
for bb in res:
xmin = bb['xmin']
ymin = bb['ymin']
xmax = bb['xmax']
ymax = bb['ymax']
draw.rectangle([xmin, ymin, xmax, ymax], outline="red", width=3)
return [
res,
im,
]
inputs = gr.Image(type='pil', label="Original Image")
outputs = [
gr.JSON(label="Output JSON"),
gr.Image(type='pil', label="Output Image with Boxes"),
]
title = "YOLOv5 Face"
description = "YOLOv5 Face Gradio demo for object detection. Upload an image or click an example image to use."
article = "<p style='text-align: center'>YOLOv5 Face is an object detection model trained on the <a href=\"https://doi.org/10.20676/00000353\">顔コレデータセット</a>.</p>"
examples = [
['『源氏百人一首』(大阪公立大学中百舌鳥図書館 国文学研究資料館).jpg'],
['『源氏物語』(国文学研究資料館).jpg'],
['『百鬼夜行図』(東京大学).jpg']
]
demo = gr.Interface(yolo, inputs, outputs, title=title, description=description, article=article, examples=examples)
demo.css = """
.json-holder {
height: 300px;
overflow: auto;
}
"""
demo.launch(share=False)