Spaces:
Sleeping
Sleeping
import gradio as gr | |
import torch | |
from PIL import Image | |
from ultralytics import YOLO | |
#加载模型 | |
model=YOLO('yolov8s.pt') | |
#部署到gradio | |
def gradio_image(img): | |
# 转换PIL图像为RGB | |
if img.mode != 'RGB': | |
img=img.revert('RGB') | |
#使用模型进行预测 | |
results=model.predict(source=img,conf=0.25) | |
im_array=results[0].plot() | |
#转化结果为PIL图像并返回 | |
pil_img=Image.fromarray(im_array[...,::-1]) | |
return pil_img | |
#创建gradio界面 | |
demo = gr.Interface( | |
fn=gradio_image, | |
inputs=gr.Image(type='pil'), | |
outputs="image", | |
examples=['input_img/detectron.png'], | |
title="DA SpareRCNN算法展示" | |
).launch(share=True) | |