Traditional Chinese medicine production line space-time fault prediction method based on multi-channel Swin Transform

By constructing a multi-scale spatial and temporal feature extraction module using a multi-channel Swin Transformer, the complex spatiotemporal fault prediction problem in traditional Chinese medicine manufacturing production lines was solved, achieving high-precision and real-time fault prediction, thereby improving production stability and drug quality.

CN121350754APending Publication Date: 2026-01-16KUNMING UNIV OF SCI & TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511465888.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-10-14
Publication Date
2026-01-16

AI Technical Summary

Technical Problem

Existing technologies struggle to effectively integrate the multi-scale spatial characteristics and long-term/short-term time dependencies of traditional Chinese medicine manufacturing lines, resulting in low fault prediction accuracy and difficulty in meeting the requirements for real-time performance and accuracy.

Method used

A multi-channel Swing Transformer-based approach is adopted to predict spatiotemporal faults in traditional Chinese medicine manufacturing production lines by constructing multi-scale spatial feature extraction and temporal feature extraction modules, combined with gating mechanisms and relative position coding.

Benefits of technology

It significantly improves the accuracy and stability of fault prediction, accurately captures long-term trends and short-term fluctuations, is suitable for real-time industrial scenarios, and improves the continuity of production and the stability of drug quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121350754A_ABST
    Figure CN121350754A_ABST
Patent Text Reader

Abstract

The invention discloses a traditional Chinese medicine production line space-time fault prediction method based on multi-channel Swin Transform, and the method comprises the steps: data obtaining and preprocessing: collecting multi-device data of a traditional Chinese medicine production line, and constructing space-time diagram data after preprocessing; wherein the space-time diagram data is composed of a node feature matrix and a diagram structure; constructing a fusion spatial feature extraction model; taking the time-space diagram data as fusion spatial feature extraction model input to obtain fusion spatial feature features; constructing a time feature extraction module based on a three-level architecture of Swin Transform, and processing and fusing spatial features to obtain feature representation in a time dimension; and fault prediction: inputting the space-time fusion feature into a prediction module, and outputting an equipment state prediction value of a future preset time step. According to the invention, the multi-scale spatial-temporal characteristic-based equipment state complex fault prediction is realized by acquiring the multi-equipment data in the traditional Chinese medicine preparation process.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application relates to a traditional Chinese medicine pharmaceutical production line space-time fault prediction method based on a multi-channel Swin Transformer, and belongs to the technical field of industrial process monitoring and fault prediction. BACKGROUND

[0002] The traditional Chinese medicine pharmaceutical process involves multiple processing units, multiple production line equipment, and multiple link production (such as crushing, granulation, total mixing, and packaging), and the equipment types are various (such as a wet method mixing granulator, a swing granulator, a filling machine, a boxing machine, and a secondary counting machine). The production process equipment faults (such as servo motor faults, transmission mechanism faults, communication faults, negative pressure abnormalities, filling errors, and temperature abnormalities) have multi-scale space-time characteristics. In the time scale, there are not only instantaneous sudden faults but also slowly accumulated process deviations. In the spatial scale, there are not only single-equipment local abnormalities but also whole-line systematic disorders. The equipment faults not only cause production plan delays and produce unqualified products (such as granule moisture fluctuations, uneven particle sizes, and wrong or missing packages), but also seriously affect the production continuity and the drug quality stability.

[0003] The existing fault prediction methods mainly have the following limitations:

[0004] (1) Mechanism model-based method: dependent on accurate physical models, the traditional Chinese medicine production process is complex and changeable, the conditions are difficult to accurately describe, the model solving is difficult and the calculation amount is large, and it is difficult to meet the real-time prediction demand.

[0005] (2) Knowledge-based method: dependent on expert experience to build a knowledge base, long cycle and difficult to update, difficult to adapt to complex and changeable fault modes.

[0006] (3) Traditional machine learning method (supervised / unsupervised learning, etc.): limited in processing complex nonlinear relationships and high-dimensional data, and difficult to effectively extract the space-time dependence between data.

[0007] (4) RNN / LSTM / GRU-based method: good at capturing short-term time dependence, but poor in modeling long-term dependence of long sequence data, and the model complexity is high and easy to overfit.

[0008] (5) CNN-based method: good at extracting local spatial features, but weak in modeling global space-time dependence.

[0009] (6) The method based on Transformer / TCN: Transformer can handle long-range dependencies but has high computational complexity and is not fine enough in capturing local spatial information; TCN is suitable for time series but has limited spatial feature modeling capability. Existing methods are difficult to efficiently and accurately capture complex global temporal dependencies and multi-scale spatial feature (whole line, process, and region) dependencies in traditional Chinese medicine pharmaceutical production line data.

[0010] Therefore, there is an urgent need for a method that can effectively fuse multi-scale spatial features and long-short term temporal dependencies to achieve high-precision and real-time fault prediction for traditional Chinese medicine pharmaceutical production lines. SUMMARY

[0011] The present application provides a traditional Chinese medicine pharmaceutical production line spatio-temporal fault prediction method based on a multi-channel Swin Transformer to process multi-device data in traditional Chinese medicine pharmaceutical processes to achieve complex fault prediction based on multi-scale spatio-temporal features.

[0012] The technical solution of the present application is:

[0013] According to the first aspect of the present application, a traditional Chinese medicine pharmaceutical production line spatio-temporal fault prediction method based on a multi-channel Swin Transformer is provided, comprising:

[0014] S1, data acquisition and preprocessing: multi-device data of a traditional Chinese medicine pharmaceutical production line is collected, and after preprocessing, spatio-temporal graph data is constructed; wherein the spatio-temporal graph data is composed of a node feature matrix and a graph structure;

[0015] S2, constructing a fusion spatial feature extraction model; the spatio-temporal graph data is input into the fusion spatial feature extraction model to obtain the fusion spatial feature;

[0016] S3, constructing a time feature extraction module based on a three-level architecture of Swin Transformer to process the fusion spatial feature to obtain a feature representation in the time dimension;

[0017] S4, fault prediction: input the spatio-temporal fusion feature into the prediction module to output the device state prediction value at the future preset time step.

[0018] Further, the S2 comprises:

[0019] S21, input the node feature matrix into a 1x1 convolution layer for preliminary feature extraction to obtain preliminary features;

[0020] S22, constructing a multi-scale spatial feature module based on a three-level architecture of the Swin Transformer; inputting the extracted preliminary features into three parallel extraction layers of the multi-scale spatial feature module for multi-scale spatial feature extraction to obtain spatial features at a region level, spatial features at a process level, and spatial features at a whole production line level;

[0021] S23, gate fusion: dynamically fusing the spatial features at the region level, the spatial features at the process level, and the spatial features at the whole production line level by using a gating mechanism to generate fused spatial features.

[0022] Further, the multi-scale spatial feature extraction module comprises a region feature extraction layer, a single-process feature extraction layer, and a whole-line feature extraction layer; the region feature extraction layer, the single-process feature extraction layer, and the whole-line feature extraction layer are of the same structure, and the inputs of the respective layers are as follows: the input of the whole-line feature extraction layer is the preliminary feature; according to the multi-device attribute, the devices are divided into M categories, and the feature corresponding to the m-th category of device in the preliminary feature is the m-th region feature; the input of the region feature extraction layer is each region feature input in turn; wherein m = 1, 2, … M; according to the number of devices, the feature of the n-th device in the preliminary feature is taken as the n-th process feature; the input of the single-process feature extraction layer is each process feature input in turn; wherein n = 1, 2, … B, and B is the total number of devices of the traditional Chinese medicine pharmaceutical production line collected.

[0023] Further, the region feature extraction layer, the single-process feature extraction layer, and the whole-line feature extraction layer are of the same structure, which is described with the region feature extraction layer: the region feature extraction layer comprises a plurality of sub-modules stacked in turn, and the spatial features at the region level are obtained through the plurality of sub-modules; each sub-module comprises linear mapping, scaled dot attention, weighted summation, residual connection and layer normalization, feedforward network, and cross-region interaction mechanism; for each sub-module: the input feature is divided into three local regions by linear mapping, a query vector Q, a key vector K, and a value vector V are constructed in each local region, and the weighted summation based on the scaled dot attention is calculated for the first and second local regions to obtain the preliminary representation of the local region; after the residual connection and normalization are performed on the third local region feature and the input feature of the region feature extraction layer, the enhanced region feature representation is obtained by inputting the preliminary representation of the local region into the feedforward network for nonlinear feature transformation and performing residual connection and normalization again; for the enhanced region feature representation, the cross-region interaction mechanism is introduced to combine the adjacency matrix information of the graph structure G, realize information transmission and fusion between different regions, and obtain the output feature of the sub-module.

[0024] Further, the gating mechanism converts each spatial feature into a one-dimensional vector by a linear function and calculates a gating weight, and the fusion is weighted according to the weight.

[0025] Further, the time feature extraction module comprises a plurality of time feature sub-modules stacked in sequence, and the feature representation in the time dimension is obtained after layer-by-layer processing by the plurality of time feature sub-modules; each time feature sub-module comprises linear mapping, scaled dot attention, weighted summation, residual connection and layer normalization, feedforward network, and relative position representation mechanism; for each time feature sub-module: firstly, the input fusion space feature is projected into a query vector, a key vector and a value vector through linear mapping, and the relative position information of the time step is introduced in combination with the relative position representation mechanism; on this basis, the scaled dot attention score between the query and the key is calculated, and the attention weight is obtained after normalization by the softmax function, so that the features of different time steps are weighted and summed and aggregated to obtain the preliminary representation in the time dimension; then, the preliminary representation after weighted aggregation is subjected to residual connection and layer normalization operation with the input fusion space feature of the current time feature sub-module; then, the result is input into the feedforward network for nonlinear feature transformation, and residual connection and normalization are performed again to obtain the output feature of the current time feature sub-module.

[0026] Further, the prediction module comprises two convolution layers, the first convolution layer takes the spatio-temporal fusion feature as input, performs dimension reduction in the feature dimension, and the output result is denoted as A, and the second convolution layer takes A as input and further reduces the dimension in the time step dimension, and outputs the device state prediction value of the future preset time step.

[0027] According to the second aspect of the present application, a traditional Chinese medicine pharmaceutical production line spatio-temporal fault prediction system based on a multi-channel Swin Transformer is provided, which comprises the modules of any one of the traditional Chinese medicine pharmaceutical production line spatio-temporal fault prediction methods based on a multi-channel Swin Transformer.

[0028] According to the third aspect of the present application, a computer device is provided, which comprises a memory, a processor and a computer program stored on the memory, and the processor executes the computer program to realize the steps of the method described above.

[0029] The beneficial effects of the present application are:

[0030] 1. Effective fusion of multi-scale space features: by designing multi-scale space feature extraction modules (whole line layer, process layer, and region layer) and a gating fusion mechanism, the macroscopic whole line correlation, fine-grained process characteristics, and local region device features of the traditional Chinese medicine pharmaceutical production line can be captured simultaneously, overcoming the limitations of single spatial scale modeling, significantly improving the model's representation ability for complex spatial structures, ensuring the accuracy of key feature capture while improving the model efficiency, and making it more suitable for real-time industrial scenarios.

[0031] 2. Long and short-term time-dependent precise modeling: In the time feature extraction module, a trainable relative position encoding is introduced to explicitly model the differences in time sequence and the influence of different time periods, effectively solving the information decay problem in long sequence modeling, and accurately capturing long-term trends and short-term fluctuations.

[0032] 3. Significant improvement in fault prediction accuracy: Experimental verification shows that the method (STFusionCNN) of the present application significantly outperforms existing mainstream models such as Swin Transformer, Transformer, LSTM, TCN, CNN-LSTM in terms of fault prediction accuracy on real data sets of traditional Chinese medicine production lines. For example, under certain batch number and embedding dimension configurations, the prediction accuracy can reach 0.9795, and the precision and F1 score also perform excellently.

[0033] 4. Strong robustness and generalization: The model maintains high prediction accuracy and stability under different prediction steps (short, medium, and long), especially excels in handling long sequence prediction tasks, and has strong anti-performance decay ability.

[0034] 5. High practical value: The method has been successfully applied to actual traditional Chinese medicine granule production lines, achieving fault early warning for key equipment such as filling machines, box filling machines, and secondary counting machines, and providing effective technical support for improving the intelligent level of traditional Chinese medicine production and the stability of drug quality. BRIEF DESCRIPTION OF DRAWINGS

[0035] Figure 1 The model architecture diagram of the present application.

[0036] Figure 2 The regional feature extraction layer structure diagram.

[0037] Figure 3 The time feature extraction module structure diagram.

[0038] Figure 4 The model performance (Accuracy, Precision, F1) comparison diagram under different embedding dimensions.

[0039] Figure 5 The performance comparison diagram of STFusionCNN model ablation experiment.

[0040] Figure 6 The overall performance (Accuracy) comparison diagram of STFusionCNN and other benchmark models on the data set.

[0041] Figure 7 The accuracy (Accuracy) comparison diagram of STFusionCNN and other benchmark models under different prediction steps (5, 10, 20, 30). DETAILED DESCRIPTION

[0042] In order to make the purposes, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work under the premise that the embodiments in the present application fall within the scope of protection of the present application. It should be noted that the embodiments in the present application and the features in the embodiments can be combined with each other in any manner without conflict.

[0043] Embodiment 1: As shown in the following table, a traditional Chinese medicine pharmaceutical production line space-time fault prediction method based on a multi-channel Swin Transformer includes the following steps: Figures 1-7

[0044] S1, data acquisition and preprocessing: multi-device data of the traditional Chinese medicine pharmaceutical production line is collected, and a space-time graph data is constructed after preprocessing; wherein the space-time graph data is composed of a node feature matrix and a graph structure G.

[0045] Specifically: Specifically, multi-device data is collected in real time from a programmable logic controller (PLC) of the traditional Chinese medicine pharmaceutical production line. The multi-device data includes process parameters, device running state signals and environmental monitoring data from different devices. For the multi-device data, preprocessing operations such as cleaning, denoising and normalization are performed in sequence to obtain multi-device data with higher quality and unified format. On this basis, the preprocessed multi-device data is organized into a three-dimensional tensor , wherein represents the historical time step, represents the device number, represents the feature dimension corresponding to each device. Thus, describes the dynamic evolution process of multi-source devices in the time dimension. Further, to depict the dependence relationship and interaction mode between devices, a graph structure G=(V, E, W) is constructed, wherein V is a node set represented by the device, |V|= ; E is an edge set, representing the logical or physical connection relationship between devices; W is an adjacency matrix for measuring the association strength between nodes, which can be constructed based on prior knowledge or obtained through a data-driven method (such as similarity calculation based on a Gaussian kernel function).

[0046] Therefore, the space-time graph data is composed of a node feature matrix and a graph structure G: the former depicts the time sequence evolution characteristics of the device, and the latter models the spatial dependence relationship between devices, and the combination of the two can provide a unified data representation framework for subsequent space-time modeling and analysis.

[0047] ​S2, construct a fusion spatial feature extraction model; input the spatio-temporal graph data into the fusion spatial feature extraction model to obtain fusion spatial features.

[0048] S21, input the node feature matrix into a 1*1 convolutional layer for preliminary feature extraction to obtain preliminary features , the number of convolutional output channels (new feature dimension).

[0049] S22, construct a multi-scale spatial feature module based on a three-level architecture of Swin Transformer; input the extracted preliminary features into three parallel extraction layers of the multi-scale spatial feature module for multi-scale spatial feature extraction to obtain spatial features P area at the region level, spatial features P rule at the process level, and spatial features P node at the whole production line level; the specific architecture of the multi-scale spatial feature extraction module is shown in Figure 1 .

[0050] Further, the multi-scale spatial feature extraction module comprises a region feature extraction layer, a single process feature extraction layer, and a whole line feature extraction layer; the region feature extraction layer, the single process feature extraction layer, and the whole line feature extraction layer have the same structure, and the inputs of the layers are as follows:

[0051] the input of the whole line feature extraction layer is the preliminary feature ;

[0052] According to the multi-device attribute, the devices are divided into M categories, so the feature of the m-th category of device in the preliminary feature is the m-th region feature; the input of the region feature extraction layer is each region feature input in turn; wherein m = 1, 2,..., M;

[0053] According to the number of devices, the feature of the n-th device in the preliminary feature is taken as the n-th process feature; the input of the single process feature extraction layer is each process feature input in turn; wherein n = 1, 2,..., B, and B is the total number of devices in the pharmaceutical production line in the sampling.

[0054] Exemplarily: in the embodiment of the application, the numbers of the filling machine, the boxing machine, and the secondary counting machine are 1, 2, and 3, respectively; according to the device function attribute, N = 1 and 2, i.e., the filling machine and the boxing machine are taken as filling devices, so the feature corresponding to the filling device in the preliminary feature is the filling region feature, i.e., the first region feature; N = 3 corresponds to the secondary counting machine, which is taken as a counting device, so the feature corresponding to the counting device in the preliminary feature The features of the corresponding computing device are counted as region features, i.e., the second region features; the input of the region feature extraction layer is the first region features and the second region features input in sequence; in the sampling process, the total number of devices in the pharmaceutical production line is 3, so the input of the single-process feature extraction layer is the first process feature, the second process feature and the third process feature input in sequence.

[0055] Further, the region feature extraction layer, the single-process feature extraction layer and the whole-line feature extraction layer have the same structure, which is described as follows:

[0056] As shown in Figure 2 , the region feature extraction layer includes a plurality of sub-modules stacked in sequence, and the spatial features P area at the region level are obtained through the plurality of sub-modules. Each sub-module includes a linear mapping (Linear, used for Q, K, V projection), a scaled dot-product attention (Scaled Dot-Product Attention, used for self-attention calculation), a weighted sum (weighted sum & Filter), a residual connection and layer normalization (Add & Norm, used for attention output stabilization), a feedforward network (FeedForward Network, used for nonlinear feature transformation) and a cross-region interaction mechanism (such as the shifted window mechanism in Swin Transformer). For each sub-module: the input features are divided into three local regions (i.e., windows or patches) through linear mapping, query vectors Q, key vectors K and value vectors V are constructed in each local region, and the weighted sum based on the scaled dot-product attention is calculated for the first and second local regions to obtain the preliminary representation of the local region; after the residual connection and normalization are performed between the third local region feature and the input features of the region feature extraction layer, the nonlinear feature transformation is performed on the preliminary representation of the local region by inputting it into the feedforward network, and the residual connection and normalization are performed again to obtain the enhanced region feature representation; for the enhanced region feature representation, the cross-region interaction mechanism is introduced to combine the adjacency matrix information of the graph structure G, realize the information transmission and fusion between different regions, and obtain the output features of the sub-module (i.e., the output of the first sub-module is used as the input of the second sub-module, and so on).

[0057] According to the above technical solution, the above structure repeatedly performs through stacking multiple layers (L layers), thereby realizing multi-scale spatial feature extraction from shallow local to deep global, and finally outputting the spatial features P area at the region level, which are used to describe the correlation and interaction intensity of the device in the local space.

[0058] Therefore, although the three extraction layers are consistent in structural form, due to the difference in input levels, the learned feature expressions correspond to the region, process and whole line three levels respectively, realizing the layer-by-layer feature modeling from local to global.

[0059] S23, Gated Fusion: dynamically fusing the spatial features P area at the region level rule , the spatial features P node at the process level P and the spatial features P at the whole line level to generate fused spatial features X . The gating mechanism converts each spatial feature into a one-dimensional vector through a linear function and calculates the gating weight, and then fuses by weighting.

[0060] The fused features X ; wherein, , , is the gating weight of each spatial feature calculated by the Softmax function, g line , g rule , g area ∈ [ 0 , 1 ] and .

[0061] S3, constructing a time feature extraction module based on a three-level architecture of Swin Transformer, processing the fused spatial features X P to obtain the feature representation in the time dimension.

[0062] Further, the time feature extraction module includes a plurality of time feature sub-modules stacked in sequence, and after being processed by the plurality of time feature sub-modules layer by layer, the feature representation in the time dimension X PT is obtained; each time feature sub-module includes linear mapping (Linear, used for Q, K, V projection), scaled dot-product attention (Scaled Dot-Product Attention, used for self-attention calculation in the time dimension), weighted sum (Weighted Sum, used for time feature aggregation), residual connection and layer normalization (Add & Norm, used for feature stabilization), feedforward network (Feed Forward Network, used for nonlinear feature transformation) and relative position representation mechanism (Relative Position Representation, RPR, used for modeling relative position information between time steps).

[0063] For each time feature sub-module: first, the input fused spatial features X P are projected into query vector Q t , key vector K t and value vector V t through linear mapping.and the relative position representation mechanism to introduce the relative position information of the time step; on this basis, the scaled dot-product attention score between the query and the key is calculated, and the attention weight is obtained after normalization by the softmax function, so as to weight and sum the features of different time steps and aggregate them to obtain the preliminary representation in the time dimension; then, the preliminary representation after weighted aggregation is fused with the input of the current time feature sub-module to obtain the feature X P Residual connection and layer normalization are performed to enhance the stability and gradient flow of the features; then, the result is input into the feedforward network for nonlinear feature transformation to improve the time feature expression ability of the model, and residual connection and normalization are performed again to obtain the output feature of the current time feature sub-module. Through the stacking of multiple time feature sub-modules, the model can gradually capture the multi-scale dynamic change relationship between short-term fluctuations and long-term dependencies in the time sequence, and finally obtain the feature representation X in the time dimension. PT .

[0064] S4, fault prediction: the spatio-temporal fusion feature X PT is input into the prediction module, which includes two convolutional layers, the first convolutional layer takes the spatio-temporal fusion feature X PT as input, performs dimension reduction in the feature dimension S, and the output result is denoted as A, and the second convolutional layer takes A as input and further reduces the dimension in the time step dimension to output the device state prediction value (such as binary classification normal / fault state) of the future τ time steps.

[0065] The above S2, S3 and S4 construct the STFusionCNN model of the application, and the training of the STFusionCNN model is as follows: the model is trained using historical spatio-temporal graph data, and the precision, accuracy and F1 Score of the predicted value and the true value are used to measure the performance of the model, the model is trained using historical spatio-temporal graph data, and the Adam optimizer is used for optimization, and the loss function is binary cross entropy (BCE).

[0066] Further, the first convolutional layer and the second convolutional layer of the prediction module are both 1x1 convolutional layers.

[0067] The application is further described as follows in combination with simulation:

[0068] I. Model training and parameter setting:

[0069] The multi-device data of the application adopts production data collected on a PLC under normal production of a traditional Chinese medicine production line, and all the controller data is composed of 0 and 1. The multi-device data includes process parameters, device running state signals and environmental monitoring data (a total of 891 dimensions) from different devices. The data collected from September 5, 2024 to October 6, 2024, a total of 82310 data, after preprocessing, a total of 56884 valid data were combed, and there were 163 dimensions. The data of 163 dimensions came from the filling machine, the boxing machine and the secondary counting machine. The filling machine involved 76 characteristic dimensions, the boxing machine involved 46 characteristic dimensions, and the secondary counting machine involved 41 characteristic dimensions. The above 56884 valid data were divided into training set, validation set and test set (such as 7:1.5:1.5), and the optimizer Adam participated in the data: learning rate lr=0.0001, =0.9, =0.999), hardware platform: for example, NVIDIA GeForce RTX 4080 SUPER GPU, PyTorch framework. The faults of the filling machine are divided into weighing faults, visual detection and sealing faults, and temperature and air pressure communication faults. The faults of the boxing machine are divided into mechanical transmission faults and raw material conveying faults. The fault of the secondary counting machine is the mechanical transmission servo motor fault.

[0070] II. Model parameter simulation experiment

[0071] The trained STFusionCNN model is deployed to a computer. The computer continuously receives real-time data streams uploaded by the PLC (the sampling frequency is set according to the process), and after the same preprocessing as in the training stage, the model is input for rolling prediction. The model outputs the state prediction value of each key point (such as the filling machine pressure, the boxing machine photoelectric signal, and the secondary counting machine counting pulse) at future τ time steps. The monitoring system sets a fault feature threshold value, and when the prediction value exceeds the threshold value, a warning signal is triggered to notify the operator or the control system to intervene (such as checking the equipment, adjusting the parameters, and preparing for shutdown maintenance), thereby avoiding or reducing the production loss and quality problems caused by faults. Experiments show that the system can effectively predict faults such as filling errors and counting abnormalities, and significantly reduce the unplanned downtime rate.

[0072] Table 1. Batch size experimental results of fault prediction process

[0073]

[0074] The model has two key parameters, namely, a model batch size and an embedding dimension. Experimental results obtained by adjusting the two parameters in the model design process are shown in Tables 1 and 2. When the batch size is too small, the gradient is unstable, forward propagation, back propagation and optimization are performed for each small batch, the overall time consumption is longer, the loss curve is unstable, and the training process fluctuates greatly. When the batch size is too large, the more data loaded in each batch, the higher the GPU memory occupation, the larger the batch trend, the better the fitting of the training set, but the generalization ability is poor. The final batch size train_batch / val_batch is 64 / 128.

[0075] Table 2 Experimental results of embedding dimension in the fault prediction process

[0076]

[0077] On the basis of Table 2, further combined Figure 4 It can be seen that the performance of the model in the accuracy Accuracy is less different under different embedding dimension settings. When the embedding dimension increases from 64 to 512, the accuracy is maintained at 0.96-0.98, which shows that even a lower dimension setting can ensure that the model has high classification accuracy. However, in the precision Precision, different embedding dimensions have a significant impact on the performance of the model. The model with an embedding dimension of 256 performs most stably and has the highest precision, reaching about 0.98, which shows that this dimension has achieved a good balance between feature expression and model complexity. When the dimension is 128 and 64, although the precision is slightly lower, it is still at an acceptable level, especially the performance of 128 is more stable. When the embedding dimension is 32, the precision is significantly lower and fluctuates greatly, which shows that the model's information expression ability is limited when dealing with complex patterns, and it is not recommended to use in tasks with high prediction accuracy requirements. The final embedding dimension is set to 256. When the embedding dimension is lower than 256, the low-dimensional space may not be able to fully represent the complex structure and relationship of the data, resulting in the loss of key features and insufficient model expression ability. When the embedding dimension is higher than 256, the high-dimensional space may learn noise or specific patterns in the training data, resulting in decreased generalization ability. Increasing the dimension will significantly increase the memory occupation and computing time.

[0078] III. Ablation experiment:

[0079] To evaluate the impact of each component of the STFusionCNN model on prediction performance, the present application designs a series of ablation experiments, constructs various model versions for comparative analysis. The evaluation is mainly from the following four aspects: BaseCNN: only contains a convolution feature extraction module, does not contain a time series modeling and multi-scale structure, and is used as a control benchmark; STFusionCNN-Swin: introduces the S22 of the present application to the base model for multi-scale spatial feature extraction, to evaluate its role in improving spatial dependence modeling; STFusionCNN-GRU: adds the GRU mechanism proposed in S23 to the STFusionCNN to capture dynamic dependencies in the time dimension; STFusionCNN: the model of the present application built by S2, S3 and S4. The experimental results are shown in Table 3 and Figure 5 Figure 5 Table 3 STFusionCNN ablation experiments on the dataset

[0080] Table 3 STFusionCNN ablation experiments on the dataset

[0081]

[0082] According to the experimental results in Table 3 and Figure 5 It can be seen from the experimental results that: after introducing the Swin Transformer module, the model's expression ability for complex spatial structures is significantly enhanced; adding the fusion GRU mechanism can effectively improve the dependence capturing ability in the time dimension; the CNN spatial refinement module (i.e. the prediction module) helps to enhance local features and improve the overall precision of the model; the experimental results also show that time series data has a strict sequential relationship, and the introduction of trainable relative time position parameters can help the model focus on key time steps, thereby further improving the prediction accuracy and stability.

[0083] Four, comparative experiment:

[0084] ​In order to verify the practicability of the model, the application selects five models of Swin Transformer, Transformer, LSTM, TCN and CNN-LSTM for comparative experiments, mainly for comprehensive evaluation of the performance of different deep learning paradigms in spatiotemporal prediction tasks. These models respectively represent attention mechanisms (Swin Transformer, Transformer), recurrent networks (LSTM), convolutional networks (TCN) and hybrid architectures (CNN-LSTM), which can cover the core methods of spatiotemporal modeling. Through comparison, the necessity of explicit spatial modeling, the best strategy for long sequence prediction, the trade-off between computational efficiency and accuracy, as well as the differences in robustness, generalization and interpretability of the model can be verified. The experimental design not only has theoretical significance (such as verifying the transferability of Swin Transformer in spatiotemporal tasks), but also provides a basis for practical application, ensuring that the selected model achieves an optimal balance in performance, efficiency and applicability. The specific experimental results are shown in Table 4 and Figure 6

[0085] Table 4 Comparison results of STFusionCNN and other models on the data set

[0086]

[0087] From Table 4 and Figure 6 it can be seen that if the prediction effect of the algorithm model is poor under normal working conditions, the prediction result fluctuation range is large, which is easy to cause false alarm, thereby affecting the reliability of the model. Therefore, when evaluating the effectiveness of the model, firstly, the prediction effect under normal conditions should be focused on. When the prediction result tends to be stable under normal conditions, the model has learned various responses in the production process, and when a fault occurs, it can better perform fault prediction. The accurate normal prediction of the model plays an important role in fault prediction. Table 4 and Figure 6 ​The graph shows the accuracy of Swin Transformer, Transformer, LSTM, TCN, and CNN-LSTM in predicting faults under normal production conditions. As can be seen from the graph, the accuracy trends of each model during training differ significantly with each epoch. Overall, the fusion model and the Transformer-based model perform particularly well. The Swin Transformer model shows stable performance, maintaining an accuracy of around 0.975 with minimal fluctuations, demonstrating good stability and generalization ability. Although the Transformer model's accuracy fluctuates significantly in the early stages of training, it eventually stabilizes at a level close to 0.975, demonstrating strong learning ability. In contrast, the CNN-LSTM model has a slightly lower accuracy, maintaining around 0.965, but with smaller overall fluctuations and a relatively stable training process, representing moderate performance. The LSTM model's accuracy is slightly lower than CNN-LSTM, and it shows a certain degree of decline in later stages, indicating its limited ability to recognize complex temporal patterns. The TCN model performed the weakest, with the lowest accuracy (fluctuating between 0.94 and 0.955) and poor stability during training. The STFusionCNN model consistently maintained the highest accuracy, eventually approaching 0.98, and stabilized within the first 10 epochs, indicating that this model not only has high accuracy but also fast convergence speed, making it the best overall performer.

[0088] V. Multi-step prediction and comparison; specific experimental results are shown in Tables 5-1 and 5-2. Figure 7 As shown:

[0089] Figure 7 The performance of six deep learning models was compared under different prediction step sizes (5, 10, 20, 30). Figure 7The three graphs from the first row to the fourth row correspond to the prediction step lengths 5, 10, 20 and 30 respectively. For each graph, the line type from top to bottom corresponds to STFusionCNN, Swin Transformer, Transformer, CNNLSTM, LSTM and TCN respectively. The indicators include accuracy, precision and F1 score, and are visualized with the training epoch number. The models involved in the comparison include STFusionCNN, Swin Transformer, Transformer, CNNLSTM, LSTM and TCN. From the overall trend, STFusionCNN performs best in all indicators. It not only has the highest accuracy, but also maintains stable precision and F1 score at different prediction step lengths, with fast convergence speed and smooth training curve without obvious fluctuations, showing strong generalization ability and model robustness. Swin Transformer follows closely, especially in short-step prediction, showing good precision and consistency. Transformer performs moderately, although not as good as the STFusion series, but still better than traditional structures. In comparison, LSTM and CNNLSTM perform significantly weaker. With the increase of prediction step length, the accuracy and F1 score decrease rapidly, and the model effect is unstable, especially LSTM, which shows obvious precision fluctuations at 30 steps, indicating that it has a significant disadvantage in processing long sequence prediction tasks. TCN performs moderately, with acceptable stability but lower precision than the STFusion series.

[0090] Specifically, when the prediction step length is 5, almost all models can achieve good performance. At this time, the accuracy of STFusionCNN is close to 1.0, and the F1 score also remains at a high level, making it the best choice among all models. When the prediction step length is 10, some models start to differentiate in performance. The STFusion series remains stable, followed by the Transformer model, and LSTM and CNN1D start to show a downward trend in accuracy. When the prediction step length is 20 and 30, the model performance decreases significantly, especially for LSTM, which almost loses its prediction ability. However, STFusionCNN still maintains the lead, showing excellent resistance to performance degradation and long sequence modeling ability. From the training process analysis, the learning speed of different models differs significantly in the first 10 epochs. STFusionCNN reaches high precision in a very short training period, while LSTM and CNNLSTM converge slowly and have problems with unstable training. In addition, from the perspective of precision and F1 score, STFusionCNN not only has high classification accuracy, but also has good classification balance ability, making relatively accurate judgments even with few class samples.

[0091] Table 5-1 Comparison of STFusionCNN with other models in predicting different time lengths

[0092]

[0093] Table 5-2 Comparison of STFusionCNN with other models in predicting different time lengths

[0094]

[0095] The following comparison only considers accuracy, such as Figure 7 Overall, short step sizes (Acc-5, Acc-10) generally show higher accuracy, with STFusionCNN, CNNLSTM, and Transformer exhibiting the most stable performance, consistently maintaining above 95%. However, as the prediction step size increases (Acc-20, Acc-30), the model accuracy generally decreases, with LSTM and TCN showing particularly significant drops and poor performance, indicating limited long-term prediction capabilities. STFusionCNN performs consistently across all prediction step sizes, maintaining near 95% accuracy with short step sizes and exhibiting a smaller decrease in accuracy with long step sizes, making it one of the most generalizable models. CNNLSTM also demonstrates strong long-term prediction capabilities, maintaining high levels even with Acc-20 and Acc-30. In contrast, Swin Transformer performs well with short step sizes but fluctuates more significantly with long step sizes, making it less stable than STFusionCNN and CNNLSTM. Transformer performs excellently with short step sizes, showing some decline with long step sizes but remaining relatively reliable. LSTM and TCN show a significant drop in accuracy for long-term predictions, especially LSTM, which performs poorly in the later stages of training with Acc-20 and Acc-30, making it unsuitable for tasks that rely on long-term predictions. Overall, STFusionCNN is the best choice.

[0096] The specific embodiments of the present invention have been described in detail above with reference to the accompanying drawings. However, the present invention is not limited to the above embodiments. Within the scope of knowledge possessed by those skilled in the art, various changes can be made without departing from the spirit of the present invention.

Claims

1. A multi-channel Swin Transformer-based traditional Chinese medicine pharmaceutical production line space-time fault prediction method, characterized in that, The method comprises the following steps: S1, data acquisition and preprocessing: collecting multi-device data of a traditional Chinese medicine pharmaceutical production line, and constructing spatio-temporal graph data after preprocessing; wherein the spatio-temporal graph data is composed of node feature matrix and graph structure; S2, constructing a fusion spatial feature extraction model; inputting the spatio-temporal graph data into the fusion spatial feature extraction model to obtain fusion spatial features; S3, constructing a time feature extraction module based on a three-level architecture of Swin Transformer, processing the fusion spatial features to obtain feature representation in the time dimension; S4, fault prediction: inputting the spatio-temporal fusion features into a prediction module to output device state prediction values at a future preset time step.

2. The multi-channel Swin Transformer-based traditional Chinese medicine pharmaceutical production line space-time fault prediction method according to claim 1, characterized in that, The S2 comprises: S21, inputting the node feature matrix into a 1*1 convolution layer for preliminary feature extraction to obtain preliminary features; S22, constructing a multi-scale spatial feature module based on a three-level architecture of Swin Transformer; inputting the extracted preliminary features into three parallel extraction layers of the multi-scale spatial feature module for multi-scale spatial feature extraction to obtain spatial features at the regional level, spatial features at the process level, and spatial features at the whole production line level; S23, gate fusion: dynamically fusing the spatial features at the regional level, the spatial features at the process level, and the spatial features at the whole production line level by using a gate mechanism to generate fusion spatial features.

3. The multi-channel Swin Transformer-based traditional Chinese medicine pharmaceutical production line space-time fault prediction method according to claim 2, characterized in that, The multi-scale spatial feature extraction module comprises a regional feature extraction layer, a single process feature extraction layer, and a whole line feature extraction layer; the regional feature extraction layer, the single process feature extraction layer, and the whole line feature extraction layer have the same structure, and the inputs of the layers are as follows: The input of the whole line feature extraction layer is the preliminary features; According to the attributes of the devices, the devices are divided into M categories, so the features of the m-th category of devices in the preliminary features are the m-th regional features; the input of the regional feature extraction layer is each regional feature input in turn; wherein m=1, 2,...M; According to the number of devices, the features of the n-th device in the preliminary features are the n-th process features; the input of the single process feature extraction layer is each process feature input in turn; wherein n=1, 2,...B, and B is the total number of devices of the traditional Chinese medicine pharmaceutical production line collected.

4. The multi-channel Swin Transformer-based traditional Chinese medicine pharmaceutical production line space-time fault prediction method according to claim 3, characterized in that, The regional feature extraction layer, the single process feature extraction layer, and the whole line feature extraction layer have the same structure, and are described by taking the regional feature extraction layer as an example: The regional feature extraction layer comprises a plurality of sub-modules stacked in turn, and the regional feature extraction layer obtains spatial features at the regional level through the plurality of sub-modules; Each sub-module includes linear mapping, scaled dot-product attention, weighted summation, residual connection and layer normalization, feed-forward network, and cross-region interaction mechanism; for each sub-module: the input features are divided into three local regions through linear mapping, query vector Q, key vector K, and value vector V are constructed in each local region, and the weighted summation based on scaled dot-product attention is calculated for the first and second local regions to obtain the preliminary representation of the local region; after performing residual connection and normalization on the third local region feature and the input feature of the region feature extraction layer, the preliminary representation of the local region is input into the feed-forward network for nonlinear feature transformation, and residual connection and normalization are performed again to obtain the enhanced region feature representation; A cross-region interaction mechanism is introduced for the enhanced region feature representation to combine the adjacency matrix information of the graph structure G, realize information transmission and fusion between different regions, and obtain the output feature of the sub-module.

5. The multi-channel Swin Transformer-based traditional Chinese medicine pharmaceutical production line space-time fault prediction method according to claim 2, characterized in that, The gating mechanism converts each spatial feature into a one-dimensional vector through a linear function and calculates a gating weight, and fuses according to the weight.

6. The multi-channel Swin Transformer-based traditional Chinese medicine pharmaceutical production line space-time fault prediction method according to claim 1, characterized in that, The time feature extraction module includes a plurality of time feature sub-modules stacked in sequence, and the feature representation in the time dimension is obtained after the plurality of time feature sub-modules are processed layer by layer; each time feature sub-module includes linear mapping, scaled dot-product attention, weighted summation, residual connection and layer normalization, feed-forward network, and relative position representation mechanism; for each time feature sub-module: first, the input fused spatial feature is projected into query vector, key vector and value vector through linear mapping, and the relative position information of the time step is introduced in combination with the relative position representation mechanism; on this basis, the scaled dot-product attention score between the query and the key is calculated, and the attention weight is obtained after normalization by the softmax function, so that the features of different time steps are weighted and aggregated to obtain the preliminary representation in the time dimension; then, the preliminary representation after weighted aggregation is connected with the input fused spatial feature of the current time feature sub-module through residual connection and layer normalization operation; then, the result is input into the feed-forward network for nonlinear feature transformation, and residual connection and normalization are performed again to obtain the output feature of the current time feature sub-module.

7. The multi-channel Swin Transformer-based traditional Chinese medicine pharmaceutical production line space-time fault prediction method according to claim 1, characterized in that, The prediction module includes two convolution layers, the first convolution layer takes the spatio-temporal fusion feature as input, performs dimension reduction in the feature dimension, and the output result is denoted as A, the second convolution layer takes A as input, further reduces the dimension in the time step dimension, and outputs the device state prediction value at the future preset time step.

8. A traditional Chinese medicine pharmaceutical production line space-time fault prediction system based on a multi-channel Swin Transformer, characterized by, The module of the traditional Chinese medicine pharmaceutical production line spatio-temporal fault prediction method based on the multi-channel Swin Transformer according to any one of claims 1-7.

9. A computer apparatus comprising a memory, a processor, and a computer program stored on the memory, wherein the computer program, when executed by the processor, causes the processor to perform the method of any one of claims 1 to 8. The processor executes the computer program to implement the steps of the method of claim 1.