1、多尺度卷积神经网络(Muti-CNN-FNN Network)
并行卷积神经网络(Muti-CNN-FNN Network)模型的主体结构前段部分由三个并行训练的CNN组成,后端部分由一系列前馈神经网络(FNN)组成。下面简称为MCFN。
MCFN模型的并向CNN段实现不同传感器在数据层的信号融合,得到CNN提取的特征信息图,通过Concatenate函数指令将多传感器信号的特征图进行融合;MCFN采用前馈神经网络(FNN)记忆预测对象的退化信息,同时采用“Relu”函数进行非线性操作,实现寿命预测。
2、Python代码
from tensorflow.keras.models import Model,Sequential
from tensorflow.keras.layers import Input, Dense, Flatten, Conv2D, MaxPooling2D,concatenate,GRU
import numpy as np
import scipy.io as scio
from sklearn.preprocessing import MinMaxScaler
#加载数据集
import tensorflow as tf
# 设置随机种子数,确保结果尽可能重现
from numpy.random import seed
seed(1)
tf.random.set_seed(1)
# 加载mat数据集吖
dataFile = 'E:\回家资料\丝杠数据集\SG_data.mat'
data = scio.loadmat(dataFile)
#训练集
X_train = data['Data']
Y_train = data['Data_YLabel']
sc = MinMaxScaler(feature_range=(0, 1))
X_train = sc.fit_transform(X_train)
Y_train = sc.fit_transform(Y_train)
x_train = X_train.reshape((X_train.shape[0], X_train.shape[1],1))
print(x_train.shape)
# 定义模型
# 第 1 个传感器数据输入
input1 = Input(shape=(180, 1, 1))
conv11 = Conv2D(32, (3, 1), )(input1)
pool11 = MaxPooling2D(pool_size=(2, 1))(conv11)
conv12 = Conv2D(32, (3, 1), )(pool11)
pool12 = MaxPooling2D(pool_size=(2, 1))(conv12)
flat1 = Flatten()(pool12)
# 第 2 个传感器数据输入
input2 = Input(shape=(180, 1, 1))
conv21 = Conv2D(32, (1, 1),)(input2)
pool21 = MaxPooling2D(pool_size=(2, 1))(conv21)
conv22 = Conv2D(32, (1, 1),)(pool21)
pool22 = MaxPooling2D(pool_size=(2, 1))(conv22)
flat2 = Flatten()(pool22)
# 第 3 个传感器数据输入
input3 = Input(shape=(180, 1, 1))
conv31 = Conv2D(16, (3, 1), )(input3)
pool31 = MaxPooling2D(pool_size=(2, 1))(conv31)
conv32 = Conv2D(16, (3, 1),)(pool31)
pool32 = MaxPooling2D(pool_size=(2, 1))(conv32)
flat3 = Flatten()(pool32)
# 合并
merge = concatenate([flat1,flat2,flat3])
dense1 = Dense(32, activation="relu")(merge)
dense2 = Dense(16, activation="relu")(dense1)
dense3 = Dense(4, activation="relu")(dense2)
output = Dense(1,)(dense3)
model.compile(optimizer='Adam', loss='mse',)
import matplotlib.pyplot as plt
#可视化预测结果
plt.plot(Y_train)
plt.plot(predict)
plt.show()
#读入mat文件
import scipy.io
scipy.io.savemat('matData4.mat',{'predict_data':predict}) # 写入mat文件
3、预测结果
在自主设计的轴承寿命预测实验台进行了实验验证。