A few-shot bearing fault diagnosis method based on simplified transformer and learnable fusion mechanism
By simplifying the Transformer structure and using learnable similarity metrics, and combining multi-scale feature extraction and global feature modeling, the problem of balancing local details and global contextual information in bearing fault diagnosis is solved, improving classification accuracy and robustness in low-sample environments, making it suitable for practical industrial applications.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHENYANG GOLDING NC & INTELLIGENCE TECH CO LTD
- Filing Date
- 2025-09-08
- Publication Date
- 2026-07-21
AI Technical Summary
Existing technologies struggle to simultaneously consider both local details and global contextual information in bearing fault diagnosis, and their generalization ability is insufficient in environments with few samples, resulting in poor classification accuracy and robustness.
A simplified Transformer structure is adopted, which combines multi-scale feature extraction, learnable similarity measurement and encoder-decoder attention mechanism. Through multi-scale feature extraction module, learnable local similarity module and global feature modeling module, bearing fault classification is realized.
It improves the accuracy of bearing fault classification under few sample conditions, reduces computational complexity and the number of parameters, supports fast forward inference and online deployment, and is suitable for practical industrial applications.
Smart Images

Figure CN122432950A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent fault diagnosis and pattern recognition technology, specifically a few-sample bearing fault diagnosis method that simplifies the Transformer and learnable fusion mechanism. Background Technology
[0002] As a critical rotating component in mechanical equipment, the health condition of rolling bearings has a decisive impact on the safety and reliability of equipment operation. Traditional bearing fault diagnosis often relies on time-frequency analysis of signals and statistical feature extraction, combined with shallow classifiers for fault identification. However, these methods depend on expert experience and perform poorly in complex operating conditions or environments with scarce samples.
[0003] With the development of deep learning, Convolutional Neural Networks (CNNs) and Transformers have been gradually introduced into the field of bearing fault diagnosis due to their powerful feature extraction and global dependency modeling capabilities. In particular, Transformers can capture global information using self-attention mechanisms, but their computational complexity is high and they are difficult to effectively mine local detailed features.
[0004] Furthermore, the importance of few-shot learning in industrial fault diagnosis is becoming increasingly prominent, and how to improve the accuracy and robustness of fault identification under limited sample conditions has become a research hotspot.
[0005] Therefore, designing a bearing fault classification method that integrates multi-scale local features and global contextual information, combines learnable similarity metrics, and is adapted to few-sample learning has become a key technical path to solve the above problems. Summary of the Invention
[0006] To address the problems in existing bearing fault diagnosis technologies, such as difficulty in simultaneously considering local details and global contextual information, and insufficient generalization ability in low-sample environments, this invention proposes a low-sample bearing fault classification method that integrates multi-scale feature extraction, learnable similarity measurement, and encoder-decoder attention mechanism.
[0007] The technical solution adopted by the present invention to achieve the above objectives is as follows:
[0008] A simplified method for few-sample bearing fault diagnosis using Transformer and learnable fusion mechanisms includes the following steps:
[0009] 1) Collect bearing vibration signals from query samples and support samples, and convert them into two-dimensional spectrograms using short-time Fourier transform;
[0010] 2) Use the multi-scale feature extraction module to extract multi-scale spatial features from the query sample spectrogram and the support sample spectrogram;
[0011] 3) Calculate the local feature similarity score between spatial features using a learnable local similarity module;
[0012] 4) Calculate the global semantic similarity score between spatial features using the encoder-decoder global feature modeling module;
[0013] 5) Use learnable fusion weights to perform weighted fusion of local feature similarity scores and global semantic similarity scores to obtain the final classification result.
[0014] Step 2) includes the following steps:
[0015] 2.1) Downsampling is performed on the spectrogram;
[0016] 2.2) Feature extraction is performed on the downsampled spectrogram using several multi-scale feature extraction units stacked sequentially;
[0017] 2.3) The extracted features are added to the spectrogram to form a residual structure, and then GroupNorm normalization and GELU activation are performed sequentially;
[0018] 2.4) Use 3×3 depth convolution to extract spatial features within each channel, then integrate the channel information through 1×1 pointwise convolution, and perform GELU activation on the convolution results to generate multi-scale spatial features.
[0019] Step 2.1) includes the following steps:
[0020] 2.1.1) The number of channels in the spectrogram is mapped from 1 channel to a higher channel number using a first-layer 3×3 convolution. dim represents the feature channel number parameter, the kernel size is 3×3, and the padding method is same padding;
[0021] 2.1.2) Spatial downsampling is performed on the processed spectrogram after 2×2 max pooling, and GroupNorm is used to normalize the convolution channels of the downsampled feature map;
[0022] 2.1.3) Perform nonlinear processing on the spectrum after downsampling using the GELU activation function;
[0023] 2.1.4) The number of channels in the spectrogram is reduced from [previous level] using a second 3×3 convolution layer. Expand to dim;
[0024] 2.1.5) Perform max pooling, GroupNorm normalization and GELU activation again to achieve a second spatial downsampling, and finally output the spectrum x.
[0025] Step 2.2) includes the following steps:
[0026] 2.2.1) Local neighborhood features are independently modeled within each channel of the spectrogram x using k×k depth convolutions;
[0027] 2.2.2) Use a 7×7 depthwise convolution with an inflation rate of 2 to obtain cross-scale contextual information features of local neighborhood features;
[0028] 2.2.3) Multiply and fuse cross-scale contextual information features with the spectrogram x to achieve attention-weighted local feature enhancement, i.e.:
[0029] LKA(x)=x⊙Conv dilated (Conv depthwise (x))
[0030] Where LKA(x) is the enhanced feature, Conv depthwise For depthwise convolution, Conv dilated This is dilated convolution.
[0031] Step 3) includes the following steps:
[0032] 3.1) Use the query sample feature map as Support sample feature maps as They are then flattened into two-dimensional matrices, and the flattened feature maps are normalized using the L2 norm in the channel dimension, i.e.
[0033]
[0034] Where B is the batch size, N is the number of supporting samples, C is the number of channels, and H and W are the feature map space dimensions. and These are the normalized query sample features and supporting sample features;
[0035] 3.2) On the normalized features, calculate the cosine similarity position by position to construct the similarity matrix S. b,n,h :
[0036]
[0037] Where h represents the spatial location index, s b,n,h This represents the cosine similarity score between sample b and sample n at spatial location h, where C is the number of channels. Let represent the normalized feature vector of sample b at channel c and position h. This represents the normalized feature vector of sample n at channel c and position h;
[0038] 3.3) The similarity matrix is mapped using a lightweight multilayer perceptron (MLP) with a dropout layer to obtain learnable local feature similarity scores:
[0039] m l =f MLP (S b,n,h )
[0040] Where, m l This represents the local feature similarity score, where the subscript l indicates locality, and f MLP This indicates lightweight multilayer perceptron processing.
[0041] 3.4) Aggregate the local feature similarity scores by category to obtain a vector of dimension [B, num_classes], where B represents the batch size and num_classes represents the number of categories.
[0042] Step 4) includes the following steps:
[0043] 4.1) Perform global average pooling on the input query sample feature map x1 to obtain a global vector representation. Self-attention modeling of query features is performed by scaling click attention, where:
[0044] Q = qW Q K = qW K V=qW V
[0045] Among them, W Q W K W V The parameter matrix is represented as follows: The attention weights are calculated as follows:
[0046]
[0047] The residuals of the self-attention output and the global vector representation q are added together and normalized using LayerNorm to obtain the enhanced query vector representation q. * ;
[0048] 4.2) Perform global average pooling on the feature maps x2 of all support samples for each category to obtain... B represents the number of samples in the current category s, and dim represents the number of channels per sample. Self-attention enhancement is applied to s using scaled dot product attention. The enhanced result is added to the residual of s and then normalized using LayerNorm. A two-layer feedforward fully connected network (FFN) is used to further model the non-linear relationship of the normalized result, and the FFN result is input into the residual sum and then subjected to LayerNorm. Finally, the batch dimension of the current category s is averaged to obtain the global encoding vector for each category. The value of the batch dimension is equal to the number of samples in the current category s;
[0049] 4.3) For the query vector q* With each category vector c k Normalize and calculate the cosine similarity cos_sim k :
[0050]
[0051] in, and Represents the normalized query vector q * and each category vector c k ;
[0052] 4.4) The cosine similarity is nonlinearly transformed using MLP to obtain the category matching score. k And construct a list m of matching scores between the query sample and all categories. u =[score1,...,score K ]:
[0053] score k =MLP(cos_sim k ).
[0054] Step 5) includes the following steps:
[0055] 5.1) Treat α1 and α2 as trainable scalar parameters and update them during training;
[0056] 5.2) Transform the weights into positive values using the softplus function:
[0057]
[0058] in, The weights are the weights after the function transformation;
[0059] 5.3) Normalize the positive value weights proportionally:
[0060]
[0061] Where, β i These are the normalized weights, where ∈ is a constant;
[0062] 5.4) The local similarity score m l With global similarity score m u Blending by normalized weights:
[0063] y = β1·m l +β2·m u
[0064] Where y is the fused vector;
[0065] 5.5) The fused vectors are classified using a classifier to generate a prediction score for each category as the final classification prediction result.
[0066] A simplified few-sample bearing fault diagnosis system based on Transformer and learnable fusion mechanisms includes the following steps:
[0067] The bearing signal processing module is used to acquire bearing vibration signals from query samples and support samples, and convert them into a two-dimensional spectrum using short-time Fourier transform.
[0068] The feature extraction module is used to extract multi-scale spatial features of the query sample spectrogram and the support sample spectrogram using the multi-scale feature extraction module;
[0069] The local feature similarity score calculation module is used to calculate the local feature similarity score between spatial features through the learnable local similarity module;
[0070] The global semantic similarity score calculation module is used to calculate the global semantic similarity score between spatial features through the encoder-decoder global feature modeling module;
[0071] The classification prediction module is used to perform weighted fusion of local feature similarity scores and global semantic similarity scores using learnable fusion weights to obtain the final classification result.
[0072] The present invention has the following beneficial effects and advantages:
[0073] 1. The efficient feature extraction module of this invention achieves spectrogram channel mapping, spatial downsampling, and local feature enhancement through convolution, pooling, and multi-scale feature extraction structures.
[0074] 2. The global feature modeling module of this invention utilizes a simplified Transformer encoder to complete global context modeling of supporting samples, thereby improving category discrimination capabilities.
[0075] 3. The learnable fusion module of the present invention combines similarity with encoder-decoder structure, and significantly improves the accuracy of few-shot classification by adaptively fusing local and global feature similarity through trainable weights.
[0076] 4. The end-to-end lightweight design of this invention adopts a modular structure with a moderate number of parameters, supports rapid forward inference and online deployment, and is suitable for practical industrial applications.
[0077] 5. The few-shot optimization mechanism of this invention generates a global encoding vector by aggregating the batch mean within each category, which effectively alleviates the model performance degradation problem in few-shot scenarios. Attached Figure Description
[0078] Figure 1 This is a schematic diagram of the overall system architecture;
[0079] Figure 2 Here is a structural diagram of the multi-scale feature extraction module;
[0080] Figure 3 This is a schematic diagram of the local similarity measurement module;
[0081] Figure 4 Simplify the Transformer architecture diagram for encoder-decoder;
[0082] Figure 5 This is a schematic diagram of the fusion output module;
[0083] Figure 6 This is a schematic diagram of the process of the present invention. Detailed Implementation
[0084] The present invention will now be described in further detail with reference to the accompanying drawings and embodiments.
[0085] like Figure 1 and Figure 6 As shown, a simplified Transformer and learnable fusion mechanism method for few-sample bearing fault diagnosis includes...
[0086] 1. Obtain the spectrograms of the query sample and supporting samples to be diagnosed: Convert the vibration signal into a two-dimensional spectrogram using short-time Fourier transform;
[0087] 2. Extract the query sample and the supported feature maps using a lightweight multi-scale feature extraction module, wherein the lightweight multi-scale feature extraction module includes:
[0088] A convolutional backbone network is used to spatially downsample and channel-fuse the input spectrogram.
[0089] At least one multi-scale feature extraction unit based on convolutional attention (LKA), wherein the LKA is composed of pointwise convolution and depthwise separable dilated convolution in sequence.
[0090] 3. Input the query sample feature map and the support sample feature map into the learnable local similarity module to calculate the local feature similarity score;
[0091] 4. Input the query sample feature map and the support sample feature map into the encoder-decoder global feature modeling module to calculate the global semantic similarity score. The encoder-decoder global feature modeling module includes:
[0092] It supports a global encoder for generating class prototype vectors through global average pooling, self-attention mechanisms, and feedforward neural networks;
[0093] A query set self-attention decoder is used to obtain a global semantic feature representation of the query sample;
[0094] A matching submodule based on cosine similarity and lightweight multilayer perceptron (MLP) is used to query the global similarity between a sample and the prototype vectors of each category.
[0095] 5. The local feature similarity score and the global semantic similarity score are weighted and fused according to the learnable fusion weights to obtain the final classification result.
[0096] The lightweight multi-scale feature extraction module (Feature_Extractor) is used to capture bearing fault features at different scales with low computational overhead, and specifically includes the following steps:
[0097] A) Initial convolution and downsampling: First, map the number of channels in the input spectrogram from 1 channel to... The convolutional kernel size is 3×3 with same padding; spatial downsampling is performed using 2×2 max pooling, and Group Normalization (normalizing the number of groups to 1) is used to adapt to mini-batch training under conditions of few samples; non-linearity is introduced through the GELU activation function; and then a second 3×3 convolution layer is used to divide the channels from... Extending to dim, the process of max pooling, GroupNorm, and GELU activation is repeated to achieve a second spatial downsampling.
[0098] B) MultiScaleExtractor: Several MultiScaleExtractor units are stacked sequentially on the downsampled feature map (the number is controlled by the depth parameter); each MultiScaleExtractor unit contains a Local Kernel Attention (LKA) module to extract local spatial dependencies.
[0099] a) First step: Depth convolution: Use k×k (5×5 in this implementation) depth convolution to independently model local neighborhood features in each channel;
[0100] b) Second step dilated convolution: Use a 7×7 depthwise convolution with a dilation rate of 2 to expand the receptive field, capture cross-scale contextual information, and keep the computational cost low;
[0101] c) Feature fusion: Multiply the results of depthwise convolution and dilated convolution by the original input tensor to achieve attention-weighted local feature enhancement.
[0102] LKA(x)=x⊙Conv dilated (Convdepthwise (x))
[0103] C) Residual connection and normalization: The LKA output is added to the input features to form a residual structure, which is then normalized using GroupNorm and enhanced with GELU activation to improve nonlinear expressive power;
[0104] D) Depthwise separable convolution enhancement: Use 3×3 depthwise convolution to extract spatial features within each channel, and then integrate the channel information through 1×1 pointwise convolution; perform GELU activation on the convolution result to generate the output features of the current MultiScaleExtractor.
[0105] E) Output Features: The feature map output by Feature_Extractor has a spatial resolution equal to that of the original input. The number of channels is dim, which has cross-scale context awareness capabilities and serves as the input for subsequent local similarity calculation modules and global feature modeling modules.
[0106] The learnable local similarity module is used to characterize the fine-grained similarity between the query sample and the support samples in local spatial location, specifically including the following steps:
[0107] A) Feature flattening and normalization: This involves flattening and normalizing the feature map of the query sample. and supporting sample feature maps Each matrix is flattened into a two-dimensional matrix and then normalized using the L2 norm in the channel dimension to eliminate the influence of amplitude differences.
[0108]
[0109] Where B is the batch size, N is the number of supporting samples, C is the number of channels, and H and W are the feature map space dimensions.
[0110] B) Cosine similarity calculation: On the normalized features, cosine similarity is calculated position by position to measure the directional consistency of different samples in corresponding local regions.
[0111]
[0112] Where h represents the spatial location index, s b,n,h This represents the cosine similarity score between sample b and sample n at spatial location h, where C is the number of channels. Let represent the normalized feature vector of sample b at channel c and position h. This represents the normalized feature vector of sample n at channel c and position h.
[0113] C) Nonlinear Mapping and Score Generation: The obtained similarity matrix is input into a lightweight multilayer perceptron (MLP) containing a Dropout layer. The first layer of the MLP uses the GELU activation function, and the second layer is a linear mapping, thereby mapping the similarity values into learnable local matching scores.
[0114] m l =f MLP (S b,n,h )
[0115] Where m l This represents the local matching score of the output, with the subscript 'l' indicating locality.
[0116] D) Output: The generated local similarity scores are aggregated by category to obtain a vector of dimension [B, num_classes], which serves as the output of the local branch. Here, B represents the batch size, and num_classes represents the number of categories.
[0117] The encoder-decoder-simplified architecture is used to construct global semantic associations across samples based on features from the support set and query set, and outputs a category similarity score, specifically including:
[0118] A) Query Feature Processing: Perform global average pooling on the feature map q of the input query set (to obtain a global vector representation). Self-attention modeling of query features is achieved by scaling click attention, where:
[0119] Q = qW Q K = qW K V=qW V
[0120] Among them W Q W K W V The parameter matrix is represented as follows: The attention weights are calculated as follows:
[0121]
[0122] The self-attention output is added to the original feature residuals and then normalized using LayerNorm to obtain the enhanced query vector representation.
[0123] B) Support set feature encoding: Global average pooling is performed on each support set feature map s to obtain... Self-attention enhancement is performed on the support set using scaled dot product attention, along with residuals and LayerNorm. A two-layer feedforward fully connected network (FFN) is used to further model the nonlinear relationship, and LayerNorm is applied after summing the input residuals. Finally, the batch dimension is averaged to obtain the global encoding vector for each class.
[0124] C) Cross-sample similarity calculation: For the query vector q and each category vector c k Normalize:
[0125]
[0126] Calculate cosine similarity:
[0127]
[0128] The cosine similarity is input into a multilayer perceptron (MLP), and a category matching score is obtained through nonlinear transformation:
[0129] score k =MLP(cos_sim k )
[0130] D) Output: The module output is a list m of matching scores between the query sample and all categories. u =[score1,...,score K This information is used by the subsequent branch fusion module for weighting and final classification decisions.
[0131] The learnable weights of the weighted fusion are used to dynamically balance the contribution ratios of local branches and global branches, specifically including the following steps:
[0132] A) Weight initialization: α1 and α2 are used as trainable scalar parameters and updated during training;
[0133] B) Positive Value Constraint: The weights are transformed into positive values using the softplus function.
[0134]
[0135] C) Normalization: The weights of positive values are normalized proportionally to prevent numerical instability.
[0136]
[0137] Where ∈ is a constant used to avoid the denominator being zero.
[0138] D) Weighted fusion: The local similarity score m is weighted... l With global similarity score m u Blending by normalized weights:
[0139] y = β1·m l +β2·m u
[0140] The fused vector is used as input to the final classifier, which generates a predicted score for each category as output.
[0141] Example
[0142] 1. Data Preprocessing and Spectrum Construction: The bearing vibration signal x(t) is acquired and converted into a spectrum using Short Time Fourier Transform (STFT):
[0143]
[0144] Where t represents a time point, f represents the frequency, and N represents the number of sampling points. The output frequency domain plot features are represented by C, where C represents the number of channels, H represents the frequency axis, and W represents the number of time frames.
[0145] 2. Multi-scale feature extraction module: such as Figure 2 The module shown consists of a shallow convolutional backbone network and a multi-layered, stacked simplified convolutional attention module (MultiScaleExtractor). The convolutional backbone network contains two consecutive 3×3 convolutional operations, followed by 2×2 max pooling, Group Normalization, and GELU activation functions in sequence to extract basic features and perform spatial downsampling. This process is repeated twice, resulting in a final spatial size reduction from the original input to [value missing], while the number of channels increases from C to 64. This layer-by-layer reduction in spatial size provides a more compact and discriminative feature representation for the subsequent attention module.
[0146] F bone =Backbone(X)
[0147]
[0148] Here, Backbone(·) represents the convolutional backbone network, and the continuously stacked MultiScaleExtractor modules realize the progressive feature extraction of single-scale LKA, with depth controlling its depth.
[0149] 3. Local similarity measurement module: such as Figure 3 As shown, this module first calculates the support samples S based on the extracted features. i The cosine similarity between the sample Q and the query sample Q is then used to obtain the final similarity score through MLP nonlinear mapping.
[0150] Sim local (Q,S i ) = MLP(cos(Q,S) i ))
[0151] In this module, standard cosine similarity is combined with a trainable MLP to adaptively model the relationships between features, and Dropout is used to improve generalization ability. Its output serves as a representation of the local branch, which is used together with the global features for subsequent fusion decisions.
[0152] 4. Global attention modeling module: such as Figure 4 The module shown consists of three parts: (1) a global encoder supporting the set; (2) a query sample self-attention decoder; and (3) a learnable metric based on cosine similarity.
[0153] (1) Support set global encoder: To extract the global representation of each class of support samples, firstly, its feature map is... Perform global average pooling (GAP) to obtain the channel-compressed feature vector:
[0154]
[0155] Subsequently, to enhance the consistency and discriminative power of intra-class features, a simplified encoder module is introduced. The overall transformation process is as follows:
[0156]
[0157] Where q, k, v = W q x, W k x, W v x represents the query, key, and value vectors obtained from the linear mapping, each with dimension 1. Shared parameter matrix The attention output is added to the input residual and normalized by a layer before being fed into a lightweight feedforward network. The output is then concatenated with the residual and normalized again. Finally, the encoding results f of each class of support samples are averaged along the batch dimension to obtain the class prototype vector.
[0158]
[0159] Among them, B k The number of supporting samples for class I, This represents the global semantic vector for this category, used for global matching.
[0160] (2) Query sample self-attention decoder: query sample feature map Extract its global representation:
[0161]
[0162] Where B represents the batch size, C is the number of channels, and H×W is the feature map size. The semantic structure within the query sample is then modeled using the same self-attention mechanism described above.
[0163]
[0164] (3) Learnable matching module based on cosine similarity: The above query features F Q With each class of support set encoding vector Similarity measurement is performed. First, normalization is applied:
[0165]
[0166] Then calculate the cosine similarity for each class:
[0167]
[0168] To improve the separability and non-linear expressiveness of the matching results, a lightweight MLP mapping function is further introduced:
[0169]
[0170] The MLP consists of two fully connected layers, activating ReLU and a linear function respectively, and a Drouput layer to enhance the metric function's responsiveness to similarity differences. The final output is a score for each class. Used for subsequent fusion and classification.
[0171] 5. Fusion output module: such as Figure 5 As shown, the local feature representation output by the local similarity module is finally weighted and fused with the global semantic representation of the global encoder-decoder module to achieve comprehensive utilization of multi-path information. The fusion process is formalized as follows:
[0172] O=α·Loc_Sim(Q,S)+(1-α)·F
[0173] Where α∈[0,1] are trainable fusion weight parameters, Loc_Sim(·) represents the output of the local similarity module, Q represents the query set, S represents the support set, and F is the output of the global module. The fused O represents the input to the final classifier, completing the task of discriminating bearing fault categories with few samples.
[0174] Example verification
[0175] Experiments using the publicly available bearing dataset, Paderborn University, demonstrate that this implementation maintains a diagnostic accuracy of 97.33% (99.2% accuracy retention) while reducing the number of model parameters by 24.7%, computational complexity by 46.7%, and inference time by 54.5% (inference latency reduced from approximately 40ms to 20ms), showcasing good efficiency and real-time application potential.
[0176] Experimental results show that by reasonably trimming the structure and replacing the modules, not only is the accuracy basically intact, but the model efficiency is also effectively improved, providing a feasible and efficient solution for real-time industrial fault diagnosis.
Claims
1. A simplified few-sample bearing fault diagnosis method using Transformer and learnable fusion mechanisms, characterized in that, Includes the following steps: 1) Collect bearing vibration signals from query samples and support samples, and convert them into two-dimensional spectrograms using short-time Fourier transform; 2) Use the multi-scale feature extraction module to extract multi-scale spatial features from the query sample spectrogram and the support sample spectrogram; 3) Calculate the local feature similarity score between spatial features using a learnable local similarity module; 4) Calculate the global semantic similarity score between spatial features using the encoder-decoder global feature modeling module; 5) Use learnable fusion weights to perform weighted fusion of local feature similarity scores and global semantic similarity scores to obtain the final classification result.
2. The method for few-sample bearing fault diagnosis based on a simplified Transformer and learnable fusion mechanism according to claim 1, characterized in that, Step 2) includes the following steps: 2.1) Downsampling is performed on the spectrogram; 2.2) Feature extraction is performed on the downsampled spectrogram using several multi-scale feature extraction units stacked sequentially; 2.3) The extracted features are added to the spectrogram to form a residual structure, and then GroupNorm normalization and GELU activation are performed sequentially; 2.4) Use 3×3 depth convolution to extract spatial features within each channel, then integrate the channel information through 1×1 pointwise convolution, and perform GELU activation on the convolution results to generate multi-scale spatial features.
3. The simplified Transformer and learnable fusion mechanism-based few-sample bearing fault diagnosis method according to claim 2, characterized in that, Step 2.1) Includes the following steps: 2.1.1) The number of channels in the spectrogram is mapped from 1 channel to a higher channel number using a first-layer 3×3 convolution. dim represents the feature channel number parameter, the kernel size is 3×3, and the padding method is same padding; 2.1.2) Spatial downsampling is performed on the processed spectrogram after 2×2 max pooling, and GroupNorm is used to normalize the convolution channels of the downsampled feature map; 2.1.3) Perform nonlinear processing on the spectrum after downsampling using the GELU activation function; 2.1.4) The number of channels in the spectrogram is reduced from [previous level] using a second 3×3 convolution layer. Expand to dim; 2.1.5) Perform max pooling, GroupNorm normalization and GELU activation again to achieve a second spatial downsampling, and finally output the spectrum x.
4. The method for few-sample bearing fault diagnosis based on a simplified Transformer and learnable fusion mechanism according to claim 2, characterized in that, Step 2.2) includes the following steps: 2.2.1) Local neighborhood features are independently modeled within each channel of the spectrogram x using k×k depth convolutions; 2.2.2) Use a 7×7 depthwise convolution with an inflation rate of 2 to obtain cross-scale contextual information features of local neighborhood features; 2.2.3) Multiply and fuse cross-scale contextual information features with the spectrogram x to achieve attention-weighted local feature enhancement, i.e.: LKA(x)=x⊙Conv dilated (Conv depthwise (x)) Where LKA(x) is the enhanced feature, Conv depthwise For depthwise convolution, Conv dilated This is dilated convolution.
5. The method for few-sample bearing fault diagnosis based on a simplified Transformer and learnable fusion mechanism according to claim 1, characterized in that, Step 3) includes the following steps: 3.1) Use the query sample feature map as Support sample feature maps as They are then flattened into two-dimensional matrices, and the flattened feature maps are normalized using the L2 norm in the channel dimension, i.e. Where B is the batch size, N is the number of supporting samples, C is the number of channels, and H and W are the feature map space dimensions. and These are the normalized query sample features and supporting sample features; 3.2) On the normalized features, calculate the cosine similarity position by position to construct the similarity matrix S. b,n,h : Where h represents the spatial location index, s b,n,h This represents the cosine similarity score between sample b and sample n at spatial location h, where C is the number of channels. Let represent the normalized feature vector of sample b at channel c and position h. This represents the normalized feature vector of sample n at channel c and position h; 3.3) The similarity matrix is mapped using a lightweight multilayer perceptron (MLP) with a dropout layer to obtain learnable local feature similarity scores: m l =f MLP (S b,n,h ) Where, m l This represents the local feature similarity score, where the subscript l indicates locality, and f MLP This indicates lightweight multilayer perceptron processing. 3.4) Aggregate the local feature similarity scores by category to obtain a vector of dimension [B, num_classes], where B represents the batch size and num_classes represents the number of categories.
6. The method for few-sample bearing fault diagnosis based on a simplified Transformer and learnable fusion mechanism according to claim 1, characterized in that, Step 4) includes the following steps: 4.1) Perform global average pooling on the input query sample feature map x1 to obtain a global vector representation. Self-attention modeling of query features is performed by scaling click attention, where: Q=qW Q ,K=qW K ,V=qW V Among them, W Q W K W V The parameter matrix is represented as follows: The attention weights are calculated as follows: The residuals of the self-attention output and the global vector representation q are added together and normalized using LayerNorm to obtain the enhanced query vector representation q. * ; 4.2) Perform global average pooling on the feature maps x2 of all support samples for each category to obtain... B represents the number of samples in the current category s, and dim represents the number of channels per sample. Self-attention enhancement is applied to s using scaled dot product attention. The enhanced result is added to the residual of s and then normalized using LayerNorm. A two-layer feedforward fully connected network (FFN) is used to further model the non-linear relationship of the normalized result, and the FFN result is input into the residual sum and then subjected to LayerNorm. Finally, the batch dimension of the current category s is averaged to obtain the global encoding vector for each category. The value of the batch dimension is equal to the number of samples in the current category s; 4.3) For the query vector q * With each category vector c k Normalize and calculate the cosine similarity cos_sim k : in, and Represents the normalized query vector q * and each category vector c k ; 4.4) The cosine similarity is nonlinearly transformed using MLP to obtain the category matching score. k And construct a list m of matching scores between the query sample and all categories. u =[score1,...,score K ]: score k =MLP(cos_sim k )。 7. The method for few-sample bearing fault diagnosis based on a simplified Transformer and learnable fusion mechanism according to claim 1, characterized in that, Step 5) includes the following steps: 5.1) Treat α1 and α2 as trainable scalar parameters and update them during training; 5.2) Transform the weights into positive values using the softplus function: in, The weights are the weights after the function transformation; 5.3) Normalize the positive value weights proportionally: Where, β i The weights are normalized, and ∈ is a constant; 5.4) The local similarity score m l With global similarity score m u Blending by normalized weights: y=β1·m l +β2·m u Where y is the fused vector; 5.5) The fused vectors are classified using a classifier to generate a prediction score for each category as the final classification prediction result.
8. A simplified Transformer and learnable fusion mechanism for few-sample bearing fault diagnosis, characterized in that, Includes the following steps: The bearing signal processing module is used to acquire bearing vibration signals from query samples and support samples, and convert them into a two-dimensional spectrum using short-time Fourier transform. The feature extraction module is used to extract multi-scale spatial features of the query sample spectrogram and the support sample spectrogram using the multi-scale feature extraction module; The local feature similarity score calculation module is used to calculate the local feature similarity score between spatial features through the learnable local similarity module; The global semantic similarity score calculation module is used to calculate the global semantic similarity score between spatial features through the encoder-decoder global feature modeling module; The classification prediction module is used to perform weighted fusion of local feature similarity scores and global semantic similarity scores using learnable fusion weights to obtain the final classification result.