首页 > 编程语言 >Python环境下基于注意力机制的小样本轴承故障诊断

Python环境下基于注意力机制的小样本轴承故障诊断

时间:2024-03-19 14:30:14浏览次数:25  
标签:Acc 轴承 Loss Python 1.0000 故障诊断 epoch Train Test

传统的基于特征提取与分类相结合的轴承智能诊断算法,对信号处理要求很高的专家经验,既费时又缺乏通用性。基于深度学习的智能轴承故障诊断方由于具有强大的特征提取能力,避免了繁琐复杂的特征提取工作,但是大多数研究都是在标准数据集下进行的,这意味着模型能够使用足量的数据进行训练,因此不会出现由于缺乏训练数据而导致深度模型诊断错误或过拟合问题。但是,在某些实际情况下,很难收集到足够的数据,例如当突然的故障发生时,在系统关闭前只能获取少量样本,来自这些故障的数据是稀缺的。出现这种情况的原因有几个:

(1)由于严重的后果不允许行轴承陷入故障状态;(2)大多数轴承故障发生缓慢,并遵循退化路径,使得轴承的故障退化可能需要数月甚至数年,这使得收集相关数据集变得困难;(3)机械设备的工况非常复杂,收集和标记足够各种工况下的训练样本是不现实的;(4)在实际应用中,故障类别和工作条件通常是不平衡的。以上数据不足或数据不平衡问题,故障样本都比较少,即为小样本问题。

为了解决小样本轴承故障诊断问题,现有的方法主要分为两个方面:

(1)数据增强;(2)选择特定算法。对于传统的数据增强方法而言,这些方法能增加数据量,但数据多样性没有发生质的改变,因此诊断效果有待提升;同时,这些方法可能引入噪声样本,也可能剔除重要的样本信息。生成对抗网络的出现弥补了上述方法的不足,用于轴承故障诊断获得了良好的结果,但目前它们都是基于一维信号的故障诊断方法,不能充分学习GAN及其变种图像生成的能力,生成样本质量不高和多样性差;同时,没有充分利用振动信号的时域和频域信息。对于现有的特定小样本轴承故障诊断算法而言,这些方法过分依赖丰富的人工经验,以及出现新的故障类型时,不能直接进行诊断,而需要收集足够的新的故障类型样本,输入模型重新训练再进行诊断。

鉴于此,提出一种基于注意力机制的小样本轴承故障诊断方法,运行环境为Python,采用Pytorch深度学习模块,采用模块如下:

import torch
import torch.nn as nn
import numpy as np
from datasave import train_loader, test_loader
from early_stopping import EarlyStopping
from label_smoothing import LSR
from oneD_Meta_ACON import MetaAconC
import time
from torchsummary import summary
from adabn import reset_bn, fix_bn

运行结果如下:

epoch: 70, Train Loss: 0.5524, Train Acc: 1.0000, Test Loss: 0.5565, Test Acc: 1.0000
EarlyStopping counter: 2 out of 10
epoch: 71, Train Loss: 0.5525, Train Acc: 1.0000, Test Loss: 0.5552, Test Acc: 1.0000
Validation loss decreased (0.555630 --> 0.555175). Saving model ...
epoch: 72, Train Loss: 0.5519, Train Acc: 1.0000, Test Loss: 0.5584, Test Acc: 1.0000
EarlyStopping counter: 1 out of 10
epoch: 73, Train Loss: 0.5517, Train Acc: 1.0000, Test Loss: 0.5550, Test Acc: 1.0000
Validation loss decreased (0.555175 --> 0.555048). Saving model ...
epoch: 74, Train Loss: 0.5514, Train Acc: 1.0000, Test Loss: 0.5544, Test Acc: 1.0000
Validation loss decreased (0.555048 --> 0.554380). Saving model ...
epoch: 75, Train Loss: 0.5516, Train Acc: 1.0000, Test Loss: 0.5560, Test Acc: 1.0000
EarlyStopping counter: 1 out of 10
epoch: 76, Train Loss: 0.5508, Train Acc: 1.0000, Test Loss: 0.5542, Test Acc: 1.0000
Validation loss decreased (0.554380 --> 0.554152). Saving model ...
epoch: 77, Train Loss: 0.5507, Train Acc: 1.0000, Test Loss: 0.5546, Test Acc: 1.0000
EarlyStopping counter: 1 out of 10
epoch: 78, Train Loss: 0.5506, Train Acc: 1.0000, Test Loss: 0.5546, Test Acc: 1.0000
EarlyStopping counter: 2 out of 10
epoch: 79, Train Loss: 0.5505, Train Acc: 1.0000, Test Loss: 0.5541, Test Acc: 1.0000
Validation loss decreased (0.554152 --> 0.554113). Saving model ...
epoch: 80, Train Loss: 0.5503, Train Acc: 1.0000, Test Loss: 0.5536, Test Acc: 1.0000
Validation loss decreased (0.554113 --> 0.553636). Saving model ...
epoch: 81, Train Loss: 0.5501, Train Acc: 1.0000, Test Loss: 0.5534, Test Acc: 1.0000
Validation loss decreased (0.553636 --> 0.553374). Saving model ...
epoch: 82, Train Loss: 0.5501, Train Acc: 1.0000, Test Loss: 0.5536, Test Acc: 1.0000
EarlyStopping counter: 1 out of 10
epoch: 83, Train Loss: 0.5500, Train Acc: 1.0000, Test Loss: 0.5542, Test Acc: 1.0000
EarlyStopping counter: 2 out of 10
epoch: 84, Train Loss: 0.5507, Train Acc: 1.0000, Test Loss: 0.5554, Test Acc: 1.0000
EarlyStopping counter: 3 out of 10
epoch: 85, Train Loss: 0.5499, Train Acc: 1.0000, Test Loss: 0.5531, Test Acc: 1.0000
Validation loss decreased (0.553374 --> 0.553104). Saving model ...
epoch: 86, Train Loss: 0.5499, Train Acc: 1.0000, Test Loss: 0.5527, Test Acc: 1.0000
Validation loss decreased (0.553104 --> 0.552698). Saving model ...
epoch: 87, Train Loss: 0.5498, Train Acc: 1.0000, Test Loss: 0.5531, Test Acc: 1.0000
EarlyStopping counter: 1 out of 10
epoch: 88, Train Loss: 0.5493, Train Acc: 1.0000, Test Loss: 0.5532, Test Acc: 1.0000
EarlyStopping counter: 2 out of 10
epoch: 89, Train Loss: 0.5495, Train Acc: 1.0000, Test Loss: 0.5523, Test Acc: 1.0000
Validation loss decreased (0.552698 --> 0.552310). Saving model ...
epoch: 90, Train Loss: 0.5494, Train Acc: 1.0000, Test Loss: 0.5531, Test Acc: 1.0000
EarlyStopping counter: 1 out of 10
epoch: 91, Train Loss: 0.5492, Train Acc: 1.0000, Test Loss: 0.5538, Test Acc: 1.0000
EarlyStopping counter: 2 out of 10
epoch: 92, Train Loss: 0.5492, Train Acc: 1.0000, Test Loss: 0.5529, Test Acc: 1.0000
EarlyStopping counter: 3 out of 10
epoch: 93, Train Loss: 0.5491, Train Acc: 1.0000, Test Loss: 0.5526, Test Acc: 1.0000
EarlyStopping counter: 4 out of 10
epoch: 94, Train Loss: 0.5489, Train Acc: 1.0000, Test Loss: 0.5529, Test Acc: 1.0000
EarlyStopping counter: 5 out of 10
epoch: 95, Train Loss: 0.5487, Train Acc: 1.0000, Test Loss: 0.5528, Test Acc: 1.0000
EarlyStopping counter: 6 out of 10
epoch: 96, Train Loss: 0.5484, Train Acc: 1.0000, Test Loss: 0.5528, Test Acc: 1.0000
EarlyStopping counter: 7 out of 10
epoch: 97, Train Loss: 0.5485, Train Acc: 1.0000, Test Loss: 0.5517, Test Acc: 1.0000
Validation loss decreased (0.552310 --> 0.551687). Saving model ...
epoch: 98, Train Loss: 0.5484, Train Acc: 1.0000, Test Loss: 0.5514, Test Acc: 1.0000
Validation loss decreased (0.551687 --> 0.551363). Saving model ...
epoch: 99, Train Loss: 0.5484, Train Acc: 1.0000, Test Loss: 0.5515, Test Acc: 1.0000
EarlyStopping counter: 1 out of 10
epoch: 100, Train Loss: 0.5483, Train Acc: 1.0000, Test Loss: 0.5524, Test Acc: 1.0000
EarlyStopping counter: 2 out of 10
epoch: 101, Train Loss: 0.5487, Train Acc: 1.0000, Test Loss: 0.5549, Test Acc: 1.0000
EarlyStopping counter: 3 out of 10
epoch: 102, Train Loss: 0.5507, Train Acc: 1.0000, Test Loss: 0.5597, Test Acc: 1.0000
EarlyStopping counter: 4 out of 10
epoch: 103, Train Loss: 0.5495, Train Acc: 1.0000, Test Loss: 0.5540, Test Acc: 1.0000
EarlyStopping counter: 5 out of 10
epoch: 104, Train Loss: 0.5586, Train Acc: 0.9972, Test Loss: 0.5980, Test Acc: 1.0000
EarlyStopping counter: 6 out of 10
epoch: 105, Train Loss: 0.5563, Train Acc: 1.0000, Test Loss: 0.6087, Test Acc: 0.9900
EarlyStopping counter: 7 out of 10
epoch: 106, Train Loss: 0.5541, Train Acc: 1.0000, Test Loss: 0.6079, Test Acc: 1.0000
EarlyStopping counter: 8 out of 10
epoch: 107, Train Loss: 0.5515, Train Acc: 1.0000, Test Loss: 0.5953, Test Acc: 0.9967
EarlyStopping counter: 9 out of 10
epoch: 108, Train Loss: 0.5503, Train Acc: 1.0000, Test Loss: 0.5740, Test Acc: 0.9967
EarlyStopping counter: 10 out of 10
Early stopping
time:1384.973 s

完整代码:
Python环境下基于注意力机制的小样本轴承故障诊断-今日头条 (toutiao.com)

擅长领域:现代信号处理,机器学习,深度学习,数字孪生,时间序列分析,设备缺陷检测、设备异常检测、设备智能故障诊断与健康管理PHM等。

标签:Acc,轴承,Loss,Python,1.0000,故障诊断,epoch,Train,Test
From: https://blog.csdn.net/weixin_39402231/article/details/136805094

相关文章

  • Pytorch环境下基于Transformer模型的滚动轴承故障诊断
    注意力机制是深度学习中的重要技术之一,正日益受到重视关注。注意力机制作为一种信息贡献筛选的方法被提出,它可以帮助神经网络更多地关注与任务相关的特征,从而减少对任务贡献较小信息的影响。因此,利用注意机制可以提高神经网络的学习能力和可解释性。Transformer是一种基于纯注......
  • OpenCV4中的图像滤波函数定义,原理,以及区别(Python)
    图像滤波1.方框滤波方框滤波的滤波器为矩形,滤波器中的所有元素值均相等。定义如下:dst=boxFilter(src,ddepth,ksize,dst=None,anchor=None,normalize=None,borderType=None)src:输入图像。ddepth:处理后的目标图像的深度,若为-1,则深度与原始图像的深度相同。ks......
  • python自动化——自动化框架常用封装代码复习
    日志模块:importloggingimportosdefcreat_log(name="mylog",level="DEBUG",filename="log.log",sh_level="DEBUG",fh_level="DEBUG"):log=logging.getLogger(name)log.setLevel(level)fh=lo......
  • 分月饼【华为OD机试JAVA&Python&C++&JS题解】
    一.题目-分月饼中秋节,公司分月饼,m个员工,买了n个月饼,m<=n,每个员工至少分1个月饼,但可以分多个,单人分到最多月饼的个数是Max1,单人分到第二多月饼个数是Max2,Max1-Max2<=3,单人分到第n-1多月饼个数是Max(n-1),单人分到第n多月饼个数是Max(n),Max(n-1)–Max(n)<=3,问有多少......
  • Python爬虫是什么?核心概念和原理
    一、爬虫的概念和作用1.1概念:        网络爬虫也叫网络蜘蛛,特指一类自动批量下载网络资源的程序,这是一个比较口语化的定义。更加专业和全面对的定义是:网络爬虫是伪装成客户端与服务端进行数据交互的程序.1.2作用1.2.1数据采集        大数据时代来临......
  • Python面向对象——架构设计【2】
     练习1:打电话请使用面向对象思想描述下列情景:  小明使用手机打电话,还有可能使用座机....classPeople:def__init__(self,name):self.name=namedefcall_up(self,tool):print(self.name,end="")tool.call()cla......
  • Python——Regular Expression(正则表达式)RE
    正则表达式是一种强大的文本处理工具,它使用一种特殊的语法来匹配、查找以及替换字符串中的字符组合。在Python中,正则表达式,"re模块"。英文叫做"RegularExpression"。re模块是Python中用于处理正则表达式的标准库。它提供了多个函数来执行正则表达式的匹配、查找、替换和分割操......
  • 自动化测试框架、Python面向对象以及POM设计模型简介
    1 自动化测试框架概述   所谓的框架其实就是一个解决问题的思维,前言中描述的诸多问题如果得到解决,自然而然这种得到良好解决的东西它就可以称之为一个框架,只是这个框架用来解决如何组织开展自动化测试。一个典型的自动化测试框架一般包括测试用例集模块、测试执行控制模块......
  • python 小小入门2
    紧跟上章使用FinalShell1)mkdiraaa创建文件夹mkdir-p/aaa/bbb/ccc创建文件夹以及后续2)touch 例如touch1.txt也可touch1.txt2.txt3.txt以及touchfsd.sdad也可以创建如果已经有了touch1.txt再创建一个touch1.txt那么他不会覆盖以及删除原来的文件只......
  • python中`__call__`让类像函数一样被调用
    在训练一个网络过程中,有下面代码'''4.训练网络'''print('开始训练')forepochinrange(3):runing_loss=0.0fori,datainenumerate(trainloader,0):inputs,label=data#1.数据加载ifdevice=='gpu':......