当前位置: 首页 > news >正文

python配合yolo分类模型开发分类软件

  1. 上一篇文章写了yolo的分类模型的训练,写篇文章基于yolo分类模型开发分类软件。
  2. 开发环境:pycharm,PySide6 6.6.1 ,PySide6-Addons 6.6.1,PySide6-Essentials 6.6.1,torch 2.3.1+cu121,torchaudio 2.3.1+cu121,torchvision 0.18.1+cu121,onnx 1.16.1,onnxruntime 1.17.3,opencv-contrib-python 4.10.0.82,opencv-python 4.10.0.82,opencv-python-headless 4.7.0.72
  3. 分类使用的数据集,halcon的pill分类demo的数据集
    请添加图片描述
  4. 软件界面
    请添加图片描述
    请添加图片描述
    请添加图片描述
  5. 核心代码
    yolo推理代码
  results = self.Model.predict(image_mat_)if(len(results)>0):###获取分类名names_=results[0].namesprobs_=results[0].probsclass_id_=probs_.top1class_socre_=probs_.top1conf.item()self.Classification=names_[class_id_]self.Sorce=str(class_socre_)

onnx推理核心代码

 			target_image_height_ = input_onnx_.shape[2]###获取输入的目标维度target_image_width_ = input_onnx_.shape[3]# image_mat_=image_mat_.resize(target_image_width_,target_image_height_)###缩放图片scale_image_mat_=cv2.resize(image_mat_,(target_image_width_,target_image_height_))print("ImageMatShape:", scale_image_mat_.shape)image_np_ = np.array(scale_image_mat_)  ###图片转成np数组print("ImageNpShape:", image_np_.shape)image_np_ = image_np_.transpose(2, 0, 1)  ##转成通道在前面的维度print("ImageNpShape:", image_np_.shape)resized_width = image_np_.shape[2]  ##获取图片输入输出resized_height = image_np_.shape[1]image_np_ = image_np_.reshape(1, 3, target_image_height_, target_image_width_)  ##添加一个新维度print(image_np_[0, 0, 0, 0])print("ImageNpShape:", image_np_.shape)image_np_ = image_np_.astype(np.float32)image_np_ = image_np_ / 255.0  ##数据归一化print(image_np_[0, 0, 0, 0])###获取输出点outputs = self.OnnxModel.get_outputs()output_onnx_ = outputs[0]print("Name:", output_onnx_.name)print("Type:", output_onnx_.type)print("Shape:", output_onnx_.shape)###运行推理outputs = self.OnnxModel.run(["output0"], {"images": image_np_})if(len(outputs)>0):ng_sorce_=outputs[0][0][0]ok_sorce_=outputs[0][0][1]if(ng_sorce_>ok_sorce_):self.Classification="ng"self.Sorce=str(ng_sorce_)else:self.Classification="ok"self.Sorce = str(ok_sorce_)
  1. 推理的效果显示
    请添加图片描述
    请添加图片描述

http://www.mrgr.cn/news/50527.html

相关文章:

  • 影刀RPA实战:CSDN博文点赞收藏评论自动化工具
  • 5分钟了解软件开发的20项基本原则
  • PLM产品生命周期管理系统有哪家比较好?三品PLM系统:卓越的产品生命管理解决方案
  • 经纬恒润半主动悬架控制器成功量产
  • Vant 日期时间组件拓展
  • 网络IP地址冲突:含义、影响及应对策略‌
  • yarn error nopt@7.2.1: The engine “node“ is....Expected version “^14.17.0....
  • 【MySQL】VARCHAR和CHAR的区别?
  • PythonAI 学习大纲
  • 云原生介绍
  • 本地部署ComfyUI并添加强大的Flux.1开源文生图模型远程制作AI图片
  • 滑动窗口经典例题
  • <<迷雾>> 第11章 全自动加法计算机(8)--一只开关取数并相加 示例电路
  • 知道ip地址怎么看网络地址
  • Vue3+TypeScript+AntVX6实现Web组态(从技术层面与实现层面进行分析)内含实际案例教学
  • 加盟模式如何运营?有哪些好的技巧和方法!
  • 开放式耳机哪个品牌好?盘点开放式蓝牙耳机排行榜前五名
  • 基于YOLOv9的空中飞鸟识别检测系统(附项目源码和数据集下载)
  • 2024双11买什么东西比较好?双11必买好物清单推荐
  • 创建Python GUI的方法