专业做物业网站的公司吗,高端网站设计公司排名,牟平网站制作公司,电子商务网站建设有什么意义上一篇圆形表盘指针式仪表的项目受到很多人的关注#xff0c;咱们一鼓作气#xff0c;把数字式工业仪表的智能读数也研究一下。本篇主要讲如何用YOLOV8实现数字式工业仪表的自动读数#xff0c;并将读数结果进行输出#xff0c;若需要完整数据集和源代码可以私信。 目录
咱们一鼓作气把数字式工业仪表的智能读数也研究一下。本篇主要讲如何用YOLOV8实现数字式工业仪表的自动读数并将读数结果进行输出若需要完整数据集和源代码可以私信。 目录
1.yolov8实现数字型仪表智能读数
2.数字仪表表盘目标检测
2.1准备数据
2.2模型选择
2.3加载预训练模型
2.4数据组织
3.目标检测训练代码
4.目标检测推理代码
整理不易欢迎一键三连
送你们一条美丽的--分割线-- 1.yolov8实现数字型仪表智能读数 首先介绍下数字型仪表的数据集如下所示包含了各种数字型仪表 最后实现的效果如下 从原始数据输入至最后输出仪表读数共需要3步
从原始影像中通过目标检测识别出表盘的位置基于第一步的结果将表盘的位置切分出来再进一步通过目标检测识别表盘中的数字基于第二步的结果对表盘中的数字进行智能读数。 此篇主要介绍第一步【从原始影像中通过目标检测识别出表盘的位置】
2.数字仪表表盘目标检测 通过目标检测方法对数字仪表表盘进行目标识别的方法不限本文仍以YOLOv8为例进行说明。
2.1准备数据 训练数据集共包含390张验证集140张测试集139张。部分训练数据如下图所示。 label部分采用YOLO格式的txt文件格式如下所示 2.2模型选择 以YOLOv8n为例模型选择代码如下
model YOLO(yolov8n.yaml) # build a new model from YAML
model YOLO(yolov8n.pt) # load a pretrained model (recommended for training)
model YOLO(yolov8n.yaml).load(yolov8n.pt) # build from YAML and transfer weights 其中yolov8n.yaml为./ultralytics/cfg/models/v8/yolov8n.yaml可根据自己的数据进行模型调整打开yolov8n.yaml显示内容如下
# Ultralytics YOLO , AGPL-3.0 license
# YOLOv8 object detection model with P3-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect# Parameters
nc: 1 # number of classes
scales: # model compound scaling constants, i.e. modelyolov8n.yaml will call yolov8.yaml with scale n# [depth, width, max_channels]n: [0.33, 0.25, 1024] # YOLOv8n summary: 225 layers, 3157200 parameters, 3157184 gradients, 8.9 GFLOPss: [0.33, 0.50, 1024] # YOLOv8s summary: 225 layers, 11166560 parameters, 11166544 gradients, 28.8 GFLOPsm: [0.67, 0.75, 768] # YOLOv8m summary: 295 layers, 25902640 parameters, 25902624 gradients, 79.3 GFLOPsl: [1.00, 1.00, 512] # YOLOv8l summary: 365 layers, 43691520 parameters, 43691504 gradients, 165.7 GFLOPsx: [1.00, 1.25, 512] # YOLOv8x summary: 365 layers, 68229648 parameters, 68229632 gradients, 258.5 GFLOPs# YOLOv8.0n backbone
backbone:# [from, repeats, module, args]- [-1, 1, Conv, [64, 3, 2]] # 0-P1/2- [-1, 1, Conv, [128, 3, 2]] # 1-P2/4- [-1, 3, C2f, [128, True]]- [-1, 1, Conv, [256, 3, 2]] # 3-P3/8- [-1, 6, C2f, [256, True]]- [-1, 1, Conv, [512, 3, 2]] # 5-P4/16- [-1, 6, C2f, [512, True]]- [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32- [-1, 3, C2f, [1024, True]]- [-1, 1, SPPF, [1024, 5]] # 9# YOLOv8.0n head
head:- [-1, 1, nn.Upsample, [None, 2, nearest]]- [[-1, 6], 1, Concat, [1]] # cat backbone P4- [-1, 3, C2f, [512]] # 12- [-1, 1, nn.Upsample, [None, 2, nearest]]- [[-1, 4], 1, Concat, [1]] # cat backbone P3- [-1, 3, C2f, [256]] # 15 (P3/8-small)- [-1, 1, Conv, [256, 3, 2]]- [[-1, 12], 1, Concat, [1]] # cat head P4- [-1, 3, C2f, [512]] # 18 (P4/16-medium)- [-1, 1, Conv, [512, 3, 2]]- [[-1, 9], 1, Concat, [1]] # cat head P5- [-1, 3, C2f, [1024]] # 21 (P5/32-large)- [[15, 18, 21], 1, Detect, [nc]] # Detect(P3, P4, P5) 主要需要修改的地方为nc也就是num_class此处如果是自己的表盘识别数据那就要换成自己的表盘类别此处我的输入影像中只有表盘这一个类别所以nc1。 如果其他的模型参数不变的话就默认保持原版yolov8需要改造模型结构的大佬请绕行。
2.3加载预训练模型 加载预训练模型yolov8n.pt可以在第一次运行时自动下载如果受到下载速度限制也可以自行下载好下载链接放在对应目录下即可。 2.4数据组织 yolov8还是以yolo格式的数据为例./ultralytics/cfg/datasets/data.yaml的内容示例如下
# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ../datasets/coco8 # dataset root dir
train: images/train # train images (relative to path) 4 images
val: images/val # val images (relative to path) 4 images
test: # test images (optional)# Classes (80 COCO classes)
names:0: person1: bicycle2: car# ...77: teddy bear78: hair drier79: toothbrush 此处建议根据自己的数据集设置新建一个shuziyibiao_data.yaml文件放在./ultralytics/cfg/datasets/目录下最后数据集设置就可以直接用自己的shuziyibiao_data.yaml文件了。以我的shuziyibiao_data.yaml文件为例 path: /home/datasets/shuziyibiao_dataset # dataset root dir
train: images/train # train images (relative to path) 4 images
val: images/val # val images (relative to path) 4 images
test: images/test # test images (optional)names:0: biao3.目标检测训练代码 准备好数据和模型之后就可以开始训练了train.py的内容显示为
from ultralytics import YOLO# Load a model
model YOLO(yolov8n.yaml) # build a new model from YAML
model YOLO(yolov8n.pt) # load a pretrained model (recommended for training)
model YOLO(yolov8n.yaml).load(yolov8n.pt) # build from YAML and transfer weights# Train the model
results model.train(datashuziyibiao_data.yaml, epochs50, imgsz640)
训练完成后的结果如下 其中weights文件夹内hi包含2个模型一个best.pth一个last.pth。 至此就可以使用best.pth进行推理预测表盘位置了。 在此贴上我的训练结果 4.目标检测推理代码
批量推理python代码如下
from ultralytics import YOLO
from PIL import Image
import cv2
import osmodel YOLO(/yolov8/runs/detect/train4/weights/best.pt) # load a custom model
path /home/数字仪表/dataset/images/test/ #test_image_path_dir
img_list os.listdir(path)
for img_path in img_list:
### detectim1 Image.open(os.path.join(path,img_path))results model.predict(sourceim1, saveTrue,save_txtTrue) 推理得到的可视化结果如下 为了方便下一步的表盘中的数字识别任务可以将框内的表盘提取并裁剪出来方便后续使用。裁剪后的表盘如下所示。 【YOLOv8】 用YOLOv8实现数字式工业仪表智能读数(二)
【YOLOv8】 用YOLOv8实现数字式工业仪表智能读数(三)-CSDN博客
整理不易欢迎一键三连
送你们一条美丽的--分割线-- ⛵⛵⭐⭐ 文章转载自: http://www.morning.bpmft.cn.gov.cn.bpmft.cn http://www.morning.lsxabc.com.gov.cn.lsxabc.com http://www.morning.nwtmy.cn.gov.cn.nwtmy.cn http://www.morning.mnwb.cn.gov.cn.mnwb.cn http://www.morning.rbknf.cn.gov.cn.rbknf.cn http://www.morning.wrtpk.cn.gov.cn.wrtpk.cn http://www.morning.yfcyh.cn.gov.cn.yfcyh.cn http://www.morning.bttph.cn.gov.cn.bttph.cn http://www.morning.ctqlq.cn.gov.cn.ctqlq.cn http://www.morning.mdwlg.cn.gov.cn.mdwlg.cn http://www.morning.kdnbf.cn.gov.cn.kdnbf.cn http://www.morning.ffgbq.cn.gov.cn.ffgbq.cn http://www.morning.fkgcd.cn.gov.cn.fkgcd.cn http://www.morning.jbtzx.cn.gov.cn.jbtzx.cn http://www.morning.rgkd.cn.gov.cn.rgkd.cn http://www.morning.fplwz.cn.gov.cn.fplwz.cn http://www.morning.hqwcd.cn.gov.cn.hqwcd.cn http://www.morning.dcmnl.cn.gov.cn.dcmnl.cn http://www.morning.rqkck.cn.gov.cn.rqkck.cn http://www.morning.wsyq.cn.gov.cn.wsyq.cn http://www.morning.pgjyc.cn.gov.cn.pgjyc.cn http://www.morning.mkfr.cn.gov.cn.mkfr.cn http://www.morning.yzsdp.cn.gov.cn.yzsdp.cn http://www.morning.hwlk.cn.gov.cn.hwlk.cn http://www.morning.bpmnq.cn.gov.cn.bpmnq.cn http://www.morning.elbae.cn.gov.cn.elbae.cn http://www.morning.zdxinxi.com.gov.cn.zdxinxi.com http://www.morning.wmpw.cn.gov.cn.wmpw.cn http://www.morning.dnconr.cn.gov.cn.dnconr.cn http://www.morning.oumong.com.gov.cn.oumong.com http://www.morning.lfxcj.cn.gov.cn.lfxcj.cn http://www.morning.nqcts.cn.gov.cn.nqcts.cn http://www.morning.ljzqb.cn.gov.cn.ljzqb.cn http://www.morning.xyrw.cn.gov.cn.xyrw.cn http://www.morning.mkrjf.cn.gov.cn.mkrjf.cn http://www.morning.njpny.cn.gov.cn.njpny.cn http://www.morning.wblpn.cn.gov.cn.wblpn.cn http://www.morning.jlrym.cn.gov.cn.jlrym.cn http://www.morning.krrjb.cn.gov.cn.krrjb.cn http://www.morning.ywpcs.cn.gov.cn.ywpcs.cn http://www.morning.ghgck.cn.gov.cn.ghgck.cn http://www.morning.xxrgt.cn.gov.cn.xxrgt.cn http://www.morning.pxbky.cn.gov.cn.pxbky.cn http://www.morning.mm27.cn.gov.cn.mm27.cn http://www.morning.shnqh.cn.gov.cn.shnqh.cn http://www.morning.3ox8hs.cn.gov.cn.3ox8hs.cn http://www.morning.ljngm.cn.gov.cn.ljngm.cn http://www.morning.nkjpl.cn.gov.cn.nkjpl.cn http://www.morning.lnbcx.cn.gov.cn.lnbcx.cn http://www.morning.bgqqr.cn.gov.cn.bgqqr.cn http://www.morning.ljsxg.cn.gov.cn.ljsxg.cn http://www.morning.jhfkr.cn.gov.cn.jhfkr.cn http://www.morning.smtrp.cn.gov.cn.smtrp.cn http://www.morning.hxmqb.cn.gov.cn.hxmqb.cn http://www.morning.gryzk.cn.gov.cn.gryzk.cn http://www.morning.frllr.cn.gov.cn.frllr.cn http://www.morning.yltyr.cn.gov.cn.yltyr.cn http://www.morning.stsnf.cn.gov.cn.stsnf.cn http://www.morning.clndl.cn.gov.cn.clndl.cn http://www.morning.bcngs.cn.gov.cn.bcngs.cn http://www.morning.nrftd.cn.gov.cn.nrftd.cn http://www.morning.ndltr.cn.gov.cn.ndltr.cn http://www.morning.bktzr.cn.gov.cn.bktzr.cn http://www.morning.okiner.com.gov.cn.okiner.com http://www.morning.fmtfj.cn.gov.cn.fmtfj.cn http://www.morning.sxfnf.cn.gov.cn.sxfnf.cn http://www.morning.rbbgh.cn.gov.cn.rbbgh.cn http://www.morning.bpwz.cn.gov.cn.bpwz.cn http://www.morning.cwjxg.cn.gov.cn.cwjxg.cn http://www.morning.jcyyh.cn.gov.cn.jcyyh.cn http://www.morning.lbggk.cn.gov.cn.lbggk.cn http://www.morning.dydqh.cn.gov.cn.dydqh.cn http://www.morning.hxxzp.cn.gov.cn.hxxzp.cn http://www.morning.hjjhjhj.com.gov.cn.hjjhjhj.com http://www.morning.rgwrl.cn.gov.cn.rgwrl.cn http://www.morning.ykmtz.cn.gov.cn.ykmtz.cn http://www.morning.tslxr.cn.gov.cn.tslxr.cn http://www.morning.ygmw.cn.gov.cn.ygmw.cn http://www.morning.hdrsr.cn.gov.cn.hdrsr.cn http://www.morning.hwsgk.cn.gov.cn.hwsgk.cn