赞
踩
- # 安装pyqt5
- pip install PySide6
-
使用PySide6中自带的工具设计UI界面,并通过插件将.ui文件转换为.py文件(这样才可以进行顺利展示)。
编写交互文件,绑定检测事件,通过使用YOLOv8模型权重进行预测,得到结果并渲染到UI界面。
pip install gradio
- # 1.案例
- import gradio as gr
-
- def greet(name):
- return "Hello" + name + "!"
-
- iface = gr.Interface(dn=greet, inputs="text", outputs="text")
- iface.launch()
-
- # 2. import gradio as gr
- from PIL import Image
- from ultralytics import YOLO
-
- def predict_image(img):
- # 转换PIL图像为RGB
- if img.mode != "RGB":
- img = img.convert('RGB')
-
- # 使用YOLOv8模型进行预测
- model = YOLO('runs/detect/train853/weights/best.pt')
- 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界面
- iface = gr.Interface(
- fn=predict_image,
- inputs=gr.Image(type='pil'),
- outputs='image',
- examples=["./image/T0001_XM_20110807100242_01.jpg"],
- title="Real-Time Object Detection with YOLOv8",
- description="Upload an image to detect objects using Yolov8"
- )
-
- # 启动界面
- iface.launch()
- # 原来
- Name: MarkupSafe
- Version: 2.1.3
-
- # 降低MarkupSafe版本
- python -m pip install markupsafe==2.0.1
-
- # 升级pandas版本
- 原有版本:2.0.3
- 升级版本:2.1.4
-
- # 升级jinjia2版本
- 原有版本:2.11.2
- 升级最新版本:3.1.2
-
- python -m pip install jinja2==3.1.2
- pip install onnxruntime-gpu
-
- # 验证安装成功
- import onnxruntime
-
- print(onnxruntime.get_device())
- yolo export model=./yolov8n.pt format=onnx
-
- # 或者
- from ultralytics import YOLO
- # 载入模型
- model = YOLO("./yolov8n.pt")
- # 导出模型
- model.export(format='onnx')
- import onnx
-
- # 读取onnx模型
- onnx_model = onnx.load('./yolov8n.onnx')
-
- # 检查模型格式是否正确
- onnx.checker.check_model(onnx_model)
- print("无报错,转换成功")
- # 单张图像
- yolo predict pose model=./yolov8n.onnx source=image/train01.jpg
-
- # 视频
- yolo predict pose model=./yolov8n.onnx source=videos/train02.mp4
-
- # 摄像头
- yolo predict pose model=./yolov8n.onnx source=0 show verbose=False
-
-
- # 或者使用Python API
- from ultralytics import YOLO
- model = YOLO('./yolov8n.onnx', task='pose')
-
- # 预测图像
- results = model.predict('images/train01.jpg', task='pose', save=True)
- import cv2
- import numpy as np
- from PTL import Image
-
- import onnxruntime
-
- import torch
-
- # 有GPU
- device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
-
- # 创建onnx runtime的InferenceSession
- session = onnxruntime.InferenceSession("./yolov8n.onnx", None)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。