Files
yolov8-position/gradio_demo.py
2023-08-10 12:25:23 +08:00

29 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import torch
import gradio as gr
model = torch.hub.load("./", "custom", path="best_ffc_11663.pt", source="local")
title = "鸟类视频检测Yolov5模型测试"
desc = "这是一个基于Gradio的Yolov5演示项目非常方便!"
base_conf, base_iou = 0.5, 0.7
def det_image(img, conf_thres, iou_thres):
model.conf = conf_thres
model.iou = iou_thres
return model(img).render()[0]
# examples中的参数要和inputs中对应
# 获取摄像头拍照检测修改inputs中的inputs=[gr.Webcam(),...]就可以了动态的更新添加属性live=True
# 如果将launch()更改为launch(share=True)则会将这个代码放在公网进行访问。
gr.Interface(
# inputs=["image", gr.Slider(minimum=0, maximum=1, value=base_conf), gr.Slider(minimum=0, maximum=1, value=base_iou)],
inputs=[gr.Webcam(),...],
outputs=["image"],
fn=det_image,
title=title,
description=desc,
live=True,
examples=[["./mydata/test/image/Black_Footed_Albatross_0001_796111.jpg", base_conf, base_iou],
["./mydata/test/image/Gadwall_0001_31235.jpg", 0.3, base_iou]]
).launch(share=True)