简单的基于Transformer的滚动轴承故障诊断(CWRU轴承数据集)

360影视 2025-01-25 10:44 2

摘要:from sklearn.metrics import accuracy_score, precision_score, f1_score, confusion_matriximport matplotlib.pyplot as pltimport scipy

from sklearn.metrics import accuracy_score, precision_score, f1_score, confusion_matriximport matplotlib.pyplot as pltimport scipy.ioimport numpy as npimport osimport tensorflow as tffrom tensorflow import kerasfrom tensorflow.keras import layers , modelsfrom sklearn.model_selection import train_test_splitfrom tensorflow.keras.optimizers import Adamfrom sklearn.preprocessing import LabelEncoderfrom tensorflow.keras.utils import to_categoricalimport seaborn as snsfrom tensorflow.keras.callbacks import ReduceLROnPlateau# File path for spectrogram .mat files.file_path = r"data/spectrogram_CWRU_48k"# Swish activation functiondef swish(x):return x * tf.nn.sigmoid(x)# Function to downsample the y-axis (frequency axis) of a spectrogramdef downsample_spectrogram_y_axis(spectrogram, downsample_factor):return spectrogram[::downsample_factor, :]def load_data(file_numbers, file_path, labels_mapping, slice_width, std_num, downsample_factor):data = labels = # Loop through each file number to process its corresponding file.for file_number in file_numbers:label = labels_mapping[file_number] # Retrieve the label for the current file.file_name = f"spectrogram_{file_number}.mat" # Construct the file name.full_path = os.path.join(file_path, file_name) # Construct the full file path.mat_contents = scipy.io.loadmat(full_path) # Load the .mat file.# Extract the spectrogram data from the loaded .mat content.sxx = mat_contents['spectrogram']# If the spectrogram's frequency axis is less than 250, pad it to reach 250.if sxx.shape[0] plt.figure(figsize=(10, 6))sns.lineplot(data=history.history['loss'], label='Training Loss', color='blue')sns.lineplot(data=history.history['val_loss'], label='Validation Loss', color='red')plt.title('Training and Validation Loss')plt.xlabel('Epochs')plt.ylabel('Loss')plt.legendplt.grid(True)#plt.savefig("CWRU_traning_loss_9959.pdf")plt.showplt.figure(figsize=(10, 6))sns.lineplot(data=history.history['accuracy'], label='Accuracy', color='green')plt.title('Model Accuracy')plt.xlabel('Epochs')plt.ylabel('Accuracy')plt.legendplt.grid(True)#plt.savefig("CWRU_model_accuracy_9959.pdf")plt.show知乎学术咨询:https://www.zhihu.com/consult/people/792359672131756032?isMe=1担任《Mechanical System and Signal Processing》《中国电机工程学报》等期刊审稿专家,擅长领域:信号滤波/降噪,机器学习/深度学习,时间序列预分析/预测,设备故障诊断/缺陷检测/异常检测。分割线分割线分割线

采用8种方法对一维信号进行降噪(Python)

NS: noisy signalS: original siganlmean filter: ws = window sizemedian filter:average filter: ns = number of noisy signal(different)bandpass filter: l = low cut-off frequency, h = high ...threshold filter: r = ratio(max abs(fft) / min ...)wavelet filter: a = thresholdstd filter:NN: neural network

完整代码:

MATLAB环境下一种改进的瞬时频率(IF)估计方法

一维时间序列信号的稀疏度度量方法(MATLAB R2018A)

算法运行环境为MATLAB R2018A,执行一维信号的稀疏度量方法,包括峰度(Kurt)、负熵(NE)、d -范数(DN)、2-范数与1-范数之比(L2/L1)、基尼指数(GI)、修正平滑指数(MSI)、基尼指数2 (GI2)、基尼指数3 (GI3)、广义基尼指数(GGI)、完全广义基尼指数等。

算法可迁移至金融时间序列,地震信号,机械振动信号,语音信号,声信号,生理信号(EEG,EMG)等一维时间序列信号。

完整代码可通过知乎付费咨询获得:

使用条件生成对抗网络CGAN生成三缸泵流量信号(MATLAB R2021B)

来源:丫亚的乐园

相关推荐