Active tuberculosis prediction method and system based on multilevel knowledge distillation
Through multi-level knowledge distillation technology, the teacher-student model is built using the random cross attention group and the intermediate feature layer module, and the problem of low detection efficiency and accuracy caused by model complexity in the existing technology is solved, and the efficiency of tuberculosis detection is achieved. and improve accuracy, suitable for clinical applications.
Patent Information
- Application Number
- CN202411158111.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-22
- Publication Date
- 2024-11-29
AI Technical Summary
In the prior art, in tuberculosis detection, deep learning models have better generalization performance only when structure is complex, but the model is too complex, resulting in low training and detection efficiency and low accuracy, and fail to effectively utilize the feature information of negative labels. , it is difficult to adapt to the fusion of lesions of multiple scales.
Using a multi-level knowledge distillation method, by introducing a random cross attention group and an intermediate feature layer distillation module, the teacher-student model is constructed, and multi-scale feature extraction and knowledge transmission is carried out to ensure that the student model integrates knowledge at different resolutions and scales. , improve detection efficiency and accuracy.
It improves the efficiency and accuracy of tuberculosis image detection, simplifies the model structure, makes it more suitable for clinical applications, and enhances the generalization ability and robustness of the model.
Smart Images

Figure CN119048468A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of medical image detection, and in particular to a method and system for predicting active pulmonary tuberculosis based on multi-level knowledge distillation. Background Art
[0002] One of the most widely used medical imaging technologies for detecting and diagnosing diseases through medical images, it has shown great advantages with its diverse methods and non-invasive characteristics. Faced with a large amount of image data, manual detection is not only limited in efficiency, but more importantly, it cannot ensure stable and high accuracy standards for detection. Using advanced computer algorithms and artificial intelligence technologies, computers can automatically identify and analyze tuberculosis lesions in medical images, reduce the interference of human factors, and play a huge role in large-scale detection of tuberculosis screening tasks. In related technologies, for artificial intelligence technologies for clinical screening of tuberculosis, traditional deep learning model training only uses positive images and labels, but negative labels also have rich information. Related technologies fail to utilize the feature information of negative labels, and the models trained by the deep learning methods of related technologies have good generalization performance only when the structure is complex. However, complex models are difficult to deploy to clinical applications and do not have good real-time performance. Tuberculosis lesions have diverse characteristics and different sizes. Single-scale feature extraction models cannot meet the requirements. The model needs to adapt to feature fusion of multiple scales. Therefore, related technologies have problems in tuberculosis detection due to overly complex model structures, resulting in low training detection efficiency and low detection accuracy. Summary of the invention
[0003] In order to solve the above technical problems, the purpose of the present invention is to provide an active pulmonary tuberculosis prediction method and system based on multi-level knowledge distillation, which can extract multi-level knowledge distillation from different resolutions and scales, thereby improving the detection efficiency and accuracy of pulmonary tuberculosis images.
[0004] The first technical solution adopted by the present invention is: a method for predicting active pulmonary tuberculosis based on multi-level knowledge distillation, comprising the following steps:
[0005] Acquiring pulmonary tuberculosis image data and performing data preprocessing to obtain preprocessed pulmonary tuberculosis image data;
[0006] The random cross attention group is introduced to construct the teacher model and perform feature extraction and loss calculation on the preprocessed tuberculosis image data to obtain the multi-scale teacher prediction feature map and teacher model loss;
[0007] The intermediate feature layer distillation module is introduced and combined with the teacher model to build a teacher-student model to obtain multi-scale prediction feature maps, student model loss and distillation loss;
[0008] The teacher model loss, student model loss and distillation loss are added together and combined with the multi-scale prediction feature map to obtain the prediction output result of tuberculosis.
[0009] Furthermore, the step of acquiring the pulmonary tuberculosis image data and performing data preprocessing to obtain the preprocessed pulmonary tuberculosis image data specifically includes:
[0010] Acquire pulmonary tuberculosis image data and perform format conversion processing to obtain pulmonary tuberculosis image data in PNG format;
[0011] Normalizing the pulmonary tuberculosis image data in PNG format to obtain normalized pulmonary tuberculosis image data;
[0012] Performing data enhancement processing on the normalized pulmonary tuberculosis image data to obtain enhanced pulmonary tuberculosis image data;
[0013] The enhanced pulmonary tuberculosis image data is divided into a pulmonary tuberculosis image training data set and a pulmonary tuberculosis image test data set, and the preprocessed pulmonary tuberculosis image data is output.
[0014] Furthermore, the step of introducing a random cross attention group, constructing a teacher model, and performing feature extraction and loss calculation on the preprocessed tuberculosis image data to obtain a multi-scale teacher prediction feature map and a teacher model loss specifically includes:
[0015] Introduce random cross attention groups to build a teacher model;
[0016] Based on the teacher model, feature extraction is performed on the preprocessed tuberculosis image data to obtain a multi-scale teacher prediction feature map;
[0017] A softmax function with a temperature coefficient is introduced to smooth the output of the teacher model and obtain the teacher model loss.
[0018] Further, the teacher model includes a first convolutional layer, a first random cross attention group, a second random cross attention group, a third random cross attention group, a fourth random cross attention group and a second convolutional layer, wherein:
[0019] The front end of the first random cross attention group, the front end of the second random cross attention group, the front end of the third random cross attention group, and the front end of the fourth random cross attention group are all connected to a patch embedding layer;
[0020] The first random cross attention group, the second random cross attention group, the third random cross attention group and the fourth random cross attention group all have the same structure, and all include a first normalization layer, a first random cross attention layer, a second normalization layer, a third convolutional layer, a second random cross attention layer and a fourth convolutional layer;
[0021] The first random cross attention layer and the second random cross attention layer have the same structure, both including a self-attention layer and a cross attention layer.
[0022] Furthermore, the step of extracting features from the preprocessed tuberculosis image data based on the teacher model to obtain a multi-scale teacher prediction feature map specifically includes:
[0023] The preprocessed tuberculosis image data was input into the teacher model;
[0024] Based on the first convolutional layer of the teacher model, feature extraction is performed on the preprocessed pulmonary tuberculosis image data to obtain shallow feature image data of pulmonary tuberculosis;
[0025] Based on the patch embedding layer of the teacher model, the shallow feature image data of pulmonary tuberculosis is encoded to obtain the encoded shallow feature image data of pulmonary tuberculosis;
[0026] Based on the first random cross attention group of the teacher model, deep feature extraction processing is performed on the encoded shallow feature image data of pulmonary tuberculosis to obtain the first teacher prediction feature map;
[0027] Based on the second random cross attention group of the teacher model, the first teacher prediction feature map is subjected to deep feature extraction processing to obtain the second teacher prediction feature map;
[0028] Based on the third random cross attention group of the teacher model, deep feature extraction processing is performed on the second teacher prediction feature map to obtain the third teacher prediction feature map;
[0029] Based on the fourth random cross attention group and the second convolutional layer of the teacher model, deep feature extraction processing is performed on the third teacher prediction feature map to obtain the fourth teacher prediction feature map;
[0030] The first teacher prediction feature map, the second teacher prediction feature map, the third teacher prediction feature map and the fourth teacher prediction feature map are integrated to obtain a multi-scale teacher prediction feature map.
[0031] Furthermore, the first random cross attention group based on the teacher model performs deep feature extraction processing on the encoded shallow feature image data of pulmonary tuberculosis to obtain the first teacher prediction feature map, which specifically includes:
[0032] Input the encoded pulmonary tuberculosis shallow feature image data into the first random cross attention group of the teacher model;
[0033] Based on the first normalization layer of the first random cross attention group, the encoded pulmonary tuberculosis shallow layer feature image data is normalized to obtain the first normalized pulmonary tuberculosis shallow layer feature image data;
[0034] Based on the first random cross attention layer of the first random cross attention group, feature extraction processing is performed on the first normalized pulmonary tuberculosis shallow feature image data to obtain preliminary pulmonary tuberculosis deep feature image data;
[0035] Combining the encoded pulmonary tuberculosis shallow layer characteristic image data with the preliminary pulmonary tuberculosis shallow layer characteristic image data to obtain combined pulmonary tuberculosis shallow layer characteristic image data;
[0036] Based on the second normalization layer of the first random cross attention group, normalizing the combined pulmonary tuberculosis shallow layer feature image data to obtain second normalized pulmonary tuberculosis shallow layer feature image data;
[0037] Based on the third convolutional layer of the first random cross attention group and the second random cross attention layer, feature extraction processing is performed on the second normalized shallow feature image data of pulmonary tuberculosis to obtain deep feature image data of pulmonary tuberculosis;
[0038] Based on the fourth convolutional layer of the first random cross attention group, the deep feature image data of tuberculosis is convolved to obtain the first teacher prediction feature map.
[0039] Furthermore, it also includes: in the first random cross-attention layer and the second random cross-attention layer, according to the learnable parameters of the input data, selecting the corresponding self-attention layer or cross-attention layer for feature extraction processing.
[0040] Furthermore, the step of introducing the intermediate feature layer distillation module and combining the teacher model to construct a teacher-student model to obtain a multi-scale prediction feature map, a student model loss, and a distillation loss specifically includes:
[0041] Constructing a student model, the student model includes a first intermediate feature layer, a second intermediate feature layer, a third intermediate feature layer, and a fourth intermediate feature layer, obtaining output results of the first intermediate feature layer, the second intermediate feature layer, the third intermediate feature layer, and the fourth intermediate feature layer in the student model, and obtaining a multi-scale student prediction feature map, the multi-scale student prediction feature map includes a first student prediction feature map, a second student prediction feature map, a third student prediction feature map, and a fourth student prediction feature map;
[0042] The multi-scale student prediction feature map is concatenated with the multi-scale teacher prediction feature map to obtain a multi-scale prediction feature map;
[0043] A softmax function with a temperature coefficient is introduced to smooth the output of the student model and obtain the student model loss;
[0044] An intermediate feature layer distillation module is introduced to connect the teacher model and the student model, build a teacher-student model and obtain the distillation loss.
[0045] Furthermore, the data processing process of the intermediate feature layer distillation module is as follows:
[0046] Performing interpolation processing on the first teacher prediction feature map to obtain an interpolated first teacher prediction feature map;
[0047] The interpolated first teacher prediction feature map is concatenated with the second teacher prediction feature map to obtain a first intermediate feature map;
[0048] Embedding global information into the first intermediate feature map through global average pooling to obtain a first intermediate feature map with global information;
[0049] The first intermediate feature map with global information is sequentially subjected to convolution, batch normalization and activation processing to obtain an activated first intermediate feature map;
[0050] A first learnable matrix and a second learnable matrix are introduced to respectively perform attention information extraction processing on the activated first intermediate feature map to obtain first attention feature information and second attention feature information;
[0051] The first attention feature information is multiplied by the second teacher prediction feature map, the second attention feature information is spliced with the first teacher prediction feature map, and the multiplication result and the splicing result are added to obtain a second intermediate feature map.
[0052] The second technical solution adopted by the present invention is: an active pulmonary tuberculosis prediction system based on multi-level knowledge distillation, comprising:
[0053] A preprocessing module is used to obtain pulmonary tuberculosis image data and perform data preprocessing to obtain preprocessed pulmonary tuberculosis image data;
[0054] The first building module is used to introduce random cross attention groups, build a teacher model, and perform feature extraction and loss calculation on the preprocessed tuberculosis image data to obtain the multi-scale teacher prediction feature map and teacher model loss;
[0055] The second building module is used to introduce the intermediate feature layer distillation module and combine it with the teacher model to build a teacher-student model to obtain multi-scale prediction feature maps, student model loss and distillation loss;
[0056] The prediction module is used to add the teacher model loss, the student model loss and the distillation loss and combine them with the multi-scale prediction feature map to obtain the prediction output result of tuberculosis.
[0057] The beneficial effects of the method and system of the present invention are as follows: the present invention acquires tuberculosis image data and performs data preprocessing, introduces random cross-attention groups, constructs a teacher model, adopts a multi-scale learning method, fuses features captured by the teacher model from different resolutions and scales, ensures that the student model fully grasps the important information in the image, further introduces an intermediate feature layer distillation module and combines it with the teacher model to construct a teacher-student model. The complex teacher model guides the concise student model at multiple levels through multi-level distillation, so that it can better imitate the teacher model in feature extraction and expression, thereby improving the detection efficiency and accuracy of tuberculosis images. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] Figure 1 It is a flowchart of the steps of a method for predicting active pulmonary tuberculosis based on multi-level knowledge distillation of the present invention;
[0059] Figure 2 It is a structural block diagram of an active pulmonary tuberculosis prediction system based on multi-level knowledge distillation of the present invention;
[0060] Figure 3 It is a structural schematic diagram of a teacher model provided by a specific embodiment of the present invention;
[0061] Figure 4 is a schematic diagram of the structure of a random cross-attention group provided by a specific embodiment of the present invention;
[0062] Figure 5 is a schematic diagram of the structure of a random cross attention layer provided in a specific embodiment of the present invention;
[0063] Figure 6 It is a schematic diagram of the structure of the self-attention layer and the cross-attention layer provided in a specific embodiment of the present invention;
[0064] Figure 7 is a schematic structural diagram of an intermediate characteristic layer distillation module provided in a specific embodiment of the present invention;
[0065] Figure 8 It is a structural diagram of a teacher-student model provided by a specific embodiment of the present invention. DETAILED DESCRIPTION
[0066] The present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. The step numbers in the following embodiments are only provided for the convenience of explanation and description, and the order between the steps is not limited in any way. The execution order of each step in the embodiment can be adaptively adjusted according to the understanding of those skilled in the art.
[0067] Reference Figure 1 The present invention provides a method for predicting active pulmonary tuberculosis based on multi-level knowledge distillation, the method comprising the following steps:
[0068] S1, acquiring pulmonary tuberculosis image data and performing data preprocessing to obtain preprocessed pulmonary tuberculosis image data;
[0069] Specifically, pulmonary tuberculosis image data is acquired and format converted to obtain pulmonary tuberculosis image data in PNG format; the pulmonary tuberculosis image data in PNG format is normalized to obtain normalized pulmonary tuberculosis image data; data enhancement is performed on the normalized pulmonary tuberculosis image data to obtain enhanced pulmonary tuberculosis image data; the enhanced pulmonary tuberculosis image data is divided into a pulmonary tuberculosis image training data set and a pulmonary tuberculosis image test data set, and the preprocessed pulmonary tuberculosis image data is output.
[0070] In this embodiment, the original CXR image data is obtained, and the data in DICOM format is converted into PNG format, the image data is adjusted to a size of 2048x2048, and the collected data is randomly divided into a training set and a test set in a ratio of 8:2. Then, the pixel values of all images are normalized to [0,1], and the diversity of the data is increased by random horizontal flipping, random vertical flipping, histogram equalization, grayscale change and other operations.
[0071] S2, introduce random cross attention groups, build a teacher model and perform feature extraction and loss calculation on the preprocessed tuberculosis image data to obtain the multi-scale teacher prediction feature map and teacher model loss;
[0072] S21, introduce random cross attention groups and build a teacher model;
[0073] Among them, the teacher model includes a first convolutional layer, a first random cross attention group, a second random cross attention group, a third random cross attention group, a fourth random cross attention group and a second convolutional layer, and the front end of the first random cross attention group, the front end of the second random cross attention group, the front end of the third random cross attention group and the front end of the fourth random cross attention group are all connected with a patch embedding layer; the first random cross attention group, the second random cross attention group, the third random cross attention group and the fourth random cross attention group have the same structure, and all include a first normalization layer, a first random cross attention layer, a second normalization layer, a third convolutional layer, a second random cross attention layer and a fourth convolutional layer; the first random cross attention layer and the second random cross attention layer have the same structure, and both include a self-attention layer and a cross attention layer.
[0074] In this embodiment, reference Figure 3 The teacher model consists of two 3x3 convolutional blocks and four residual structured random cross attention groups (RCCA). After each RCCA model, the feature map is reduced by half to capture deep semantic features of different scales.
[0075] S22, extracting features from the preprocessed tuberculosis image data based on the teacher model to obtain a multi-scale teacher prediction feature map;
[0076] Specifically, the preprocessed tuberculosis image data is input into the teacher model; based on the first convolutional layer of the teacher model, the preprocessed tuberculosis image data is subjected to feature extraction processing to obtain shallow feature image data of tuberculosis; based on the patch embedding layer of the teacher model, the shallow feature image data of tuberculosis is encoded to obtain encoded shallow feature image data of tuberculosis; based on the first random cross attention group of the teacher model, the encoded shallow feature image data of tuberculosis is subjected to deep feature extraction processing to obtain a first teacher prediction feature map; based on the second random cross attention group of the teacher model, the first teacher prediction feature map is subjected to deep feature extraction processing to obtain a second teacher prediction feature map; based on the third random cross attention group of the teacher model, the second teacher prediction feature map is subjected to deep feature extraction processing to obtain a third teacher prediction feature map; based on the fourth random cross attention group and the second convolutional layer of the teacher model, the third teacher prediction feature map is subjected to deep feature extraction processing to obtain a fourth teacher prediction feature map; the first teacher prediction feature map, the second teacher prediction feature map, the third teacher prediction feature map and the fourth teacher prediction feature map are integrated to obtain a multi-scale teacher prediction feature map.
[0077] Among them, it should be noted that the data processing processes of the first random cross-attention group, the second random cross-attention group, the third random cross-attention group, and the fourth random cross-attention group in the embodiments of the present invention are all the same. Only the first random cross-attention group is used for explanation here. Specifically, the encoded shallow feature image data of tuberculosis is input into the first random cross-attention group of the teacher model; based on the first normalization layer of the first random cross-attention group, the encoded shallow feature image data of tuberculosis is normalized to obtain the first normalized shallow feature image data of tuberculosis; based on the first random cross-attention layer of the first random cross-attention group, the first normalized shallow feature image data of tuberculosis is feature extracted to obtain preliminary deep feature image data of tuberculosis; combining the encoded shallow feature image data of tuberculosis with the preliminary shallow feature image data of tuberculosis to obtain combined shallow feature image data of tuberculosis; based on the second normalization layer of the first random cross attention group, normalizing the combined shallow feature image data of tuberculosis to obtain second normalized shallow feature image data of tuberculosis; based on the third convolution layer of the first random cross attention group and the second random cross attention layer, performing feature extraction processing on the second normalized shallow feature image data of tuberculosis to obtain deep feature image data of tuberculosis; based on the fourth convolution layer of the first random cross attention group, convolution processing is performed on the deep feature image data of tuberculosis to obtain a first teacher prediction feature map.
[0078] In this embodiment, given an input image X∈R H x W x 3 , first use the 3×3 convolutional layer in shallow feature extraction to generate shallow features Fs∈R H x W x C , Fs is encoded into multiple patches through patch embedding, and then the patches are extracted through the deep feature extraction of the RCCA module to obtain the deep feature maps Tn, n∈{1, 2, 3, 4} in sequence. An additional convolutional layer is introduced at the end of the minimum feature map T4 to refine the features extracted from RCCA. The above process is expressed as follows:
[0079] Tn=RCCA(Embedding(Conv(X))), n∈{1, 2, 3, 4}
[0080] refer to Figure 4 ,Each RCCA module consists of 2 groups of random cross attention and convolution blocks.
[0081] First, use Layer Norm (normalization layer) to process patches, then use random cross attention (RCA) to capture spatial long-term dependencies, and retain the original input information through residual connections. Since some spatially close pixels in the two-dimensional feature map are far away from each other in the one-dimensional label sequence, this excessive distance will cause local pixels to be forgotten, so the convolution layer is used to compensate for local features, and then a random cross is used for feature extraction. At the end, an additional convolution layer is introduced to refine the extracted features and enhance the overall expression ability of the model. The expression is as follows:
[0082] A=RCA(LN(Tn))+Tn, n∈{1, 2, 3, 4}
[0083] Ri=RCA(Conv(LN(Ai)))+A
[0084] like Figure 5 and Figure 6 As shown, the RCA structure consists of self-attention and cross-attention.
[0085] The Q, K, and V of the self-attention module come from the same input sequence f, while the K and V of the cross-attention module come from an input sequence f0 that is different from Q. The cross-attention module uses the information of f0 to help f perform attention weighting to generate the final output.
[0086] Each time passing through the RCA module, the learnable parameter P obtained in the training phase determines whether to randomly perform cross attention or self-attention. Specifically, the output of the i-th attention layer is calculated as follows:
[0087]
[0088] h l =(1-β)·SA(Q f , K f , V f )+β·CA(Q f , K f0 , V f0 )
[0089] where β is a Bernoulli distributed random variable with probability P.
[0090] S23. Introduce a softmax function with a temperature coefficient to smooth the output of the teacher model and obtain the teacher model loss.
[0091] Specifically, the teacher model is trained on the ChestXray14 dataset through transfer learning, the AdamW optimizer is selected for training, and the initial learning rate is set to 1×10 -4, weight decay is set to 0.01, batch_size is set to 32, and cross entropy loss is used to optimize the training process of the teacher model.
[0092] Since the network's Logits contain more advanced and clearer semantic information, it is more effective for the transfer of dark knowledge. Therefore, while saving the pre-trained weights of the teacher model, the output logits of the teacher model on the training data and validation data are also saved. In order to better transfer the knowledge of the teacher model, the softmax function with the temperature coefficient T is used to process the logits of the teacher model to adjust its smoothness, and used as a soft label to supervise the training of the student model. The expression is:
[0093] soft_target=Softmax(Z t / T)
[0094] Where Z t is the logits output of the teacher model.
[0095] S3, introduce the intermediate feature layer distillation module and combine it with the teacher model to build a teacher-student model to obtain multi-scale prediction feature maps, student model loss and distillation loss;
[0096] S31, constructing a student model, the student model includes a first intermediate feature layer, a second intermediate feature layer, a third intermediate feature layer and a fourth intermediate feature layer, obtaining output results of the first intermediate feature layer, the second intermediate feature layer, the third intermediate feature layer and the fourth intermediate feature layer in the student model, and obtaining a multi-scale student prediction feature map, the multi-scale student prediction feature map includes a first student prediction feature map, a second student prediction feature map, a third student prediction feature map and a fourth student prediction feature map;
[0097] It should be noted that according to the structural characteristics of the teacher model, a smaller-scale deep learning model of the same system or a different system is selected as the student model to match the teacher network, and a teacher-student network model is built, including but not limited to the following 4-stage feature extraction structure network can be used as the student model, 4-stage Resnet 50, ConvNeXt, SwimTransformer, Swim Transformer V2.
[0098] S32, concatenating the multi-scale student prediction feature map with the multi-scale teacher prediction feature map to obtain a multi-scale prediction feature map;
[0099] S33, introduce a softmax function with a temperature coefficient, smooth the output result of the student model, and obtain the student model loss;
[0100] Specifically, the same data as the teacher network is input, the output logits are obtained through the student model, and the Kullback-Leibler divergence (KL divergence) is used to calculate the loss between the output logits of the student model and the soft labels of the teacher model. Similarly, the temperature coefficient T is also applied to the logits of the student model. Specifically, the output logits of the student model are calculated, and the expression is:
[0101] soft_target s =Softmax(Z s / T)
[0102] In the above formula, T represents the temperature coefficient.
[0103] S34. Introduce the intermediate feature layer distillation module, connect the teacher model and the student model, build the teacher-student model and obtain the distillation loss.
[0104] Specifically, the first teacher prediction feature map is interpolated to obtain the interpolated first teacher prediction feature map; the interpolated first teacher prediction feature map is spliced with the second teacher prediction feature map to obtain the first intermediate feature map; the global information is embedded in the first intermediate feature map through global average pooling to obtain the first intermediate feature map with global information; the first intermediate feature map with global information is sequentially convolved, batch normalized and activated to obtain the activated first intermediate feature map; the first learnable matrix and the second learnable matrix are introduced to extract attention information from the activated first intermediate feature map to obtain the first attention feature information and the second attention feature information; the first attention feature information is multiplied with the second teacher prediction feature map, the second attention feature information is spliced with the first teacher prediction feature map, and the multiplication result is added to the splicing result to obtain the second intermediate feature map.
[0105] In this embodiment, first of all, it should be noted that the teacher model training set is used as the training set of the student model, and the student model is initialized using the teacher model weight parameters. Since the ultimate goal is to make the generalization performance of the student network close to that of the teacher network, when training the teacher-student model, the teacher model is frozen, and knowledge distillation is performed on the multi-scale intermediate feature layer and the Logit response stage to optimize the student network so that its generalization performance is close to that of the teacher network.
[0106] like Figure 8As shown in the figure, both the teacher model and the student model have four intermediate feature layers of different scales, which are denoted as Tn, n∈{1, 2, 3, 4}. In the first coding layer, only the loss of the feature map extracted by the teacher network and the student network at the same coding layer is calculated; in the second, third and fourth coding layers, after the feature information of the previous coding layer and the current layer is fused, the loss of the fused feature map and the feature map of the student model is calculated. Both the teacher model and the student model have four intermediate feature layers of different scales, which are denoted as Tn, n∈{1, 2, 3, 4}. In the first coding layer, only the loss of the feature map extracted by the teacher network and the student network at the same coding layer is calculated; in the second, third and fourth coding layers, after the feature information of the previous coding layer and the current layer is fused, the loss of the fused feature map and the feature map of the student model is calculated.
[0107] Specifically, the feature map T1 is fused with the feature map T2 through the ICF module to generate a feature map M2 with richer semantics, and the loss is then calculated with S2.
[0108] like Figure 7 As shown, the input feature map T1 is first interpolated to achieve spatial transformation and reduce the size of the feature map. Then, the interpolated T1 is concatenated with the feature map T2 from the next stage to obtain the intermediate feature map m1. Then, global information is embedded through global average pooling to obtain C. Then, 1x1 convolution, batch normalization BN, and ReLU function activation are performed to obtain F. The learnable matrices A and B are introduced, and F is used to obtain a and b through Soft attention. Finally, the product of a and T2 + b is concatenated with T1 to obtain M1. M1 calculates the L2 loss with the feature map of the student network at the same layer, and back propagates to optimize the learning content of the student network. The above process is expressed by the following formula:
[0109] m=I(T1)+T2
[0110]
[0111] z = ReLU(BN(Conv(C)))
[0112]
[0113] Where I(·) represents the interpolation operation, A and B are two learnable matrices, and a and b represent the soft attention vectors of T1 and T2, respectively.
[0114] S4. Add the teacher model loss, student model loss and distillation loss and combine them with the multi-scale prediction feature map to obtain the prediction output result of tuberculosis.
[0115] Specifically, the total Logit loss of the teacher-student model is calculated, and its expression is:
[0116]
[0117] Where KL(-) represents KL divergence calculation.
[0118] In addition to the Logit distillation loss and the multi-scale intermediate feature layer distillation loss, the student model is also trained in combination with the classification loss of the original task. The total loss is the weighted sum of the classification loss, the Logit distillation loss, and the multi-scale intermediate feature layer distillation loss, and its expression is:
[0119]
[0120] Among them, γ1, γ2 and γ3 are weight coefficients used to balance the contribution of the two losses, yi and They represent the true category and the predicted category respectively, and c represents the number of samples.
[0121] Finally, the generalization performance of the student model is optimized based on the total loss backpropagation. After the trained and optimized student model is obtained, the model now has the ability to analyze and classify image data. The student model can be applied to the test set to verify its classification ability for active pulmonary tuberculosis, and the robustness of the model can be analyzed using an external test set.
[0122] In summary, the embodiment of the present invention includes constructing a new teacher model, proposing a new feature fusion structure and training a student model based on two knowledge distillation modes. A teacher model with multi-scale feature extraction and random cross attention is used to extract deeper semantic features, and a smaller student model is trained under the supervision of the feature knowledge of the intermediate feature layer of the teacher model and the response knowledge at the end, thereby obtaining a comprehensive judgment result of active tuberculosis detection.
[0123] The multi-scale feature extraction model with cross attention and multi-head self-attention was redesigned. The type of attention was randomly selected according to the learnable parameters, and the spatial arrangement of the sequence was disrupted by convolution. The attention was repeated twice, which can capture richer semantic features without causing too much computational redundancy. The feature map is gradually reduced in a four-stage feature advance mode to capture multi-scale features, which is suitable for the characteristics of active tuberculosis lesions.
[0124] At the same time, the knowledge distillation method is applied to the task of tuberculosis detection, and the student model is guided through two distillation paths to enrich its learning content. First, by using both soft labels and image hard labels, the student model can obtain similarity and uncertainty information between categories from the probability distribution of the teacher model, thereby improving generalization and robustness. Secondly, a multi-scale learning method is adopted to fuse the features captured by the teacher model from different resolutions and scales to ensure that the student model fully grasps the important information in the image. The complex teacher model guides the concise student model at multiple levels through multi-level distillation, so that it can better imitate the teacher model in feature extraction and expression. Not only does it significantly improve the performance of the student model, but it also simplifies the deployment of the model, which is closer to the requirements of clinical applications.
[0125] Reference Figure 2 , an active tuberculosis prediction system based on multi-level knowledge distillation, including:
[0126] A preprocessing module is used to obtain pulmonary tuberculosis image data and perform data preprocessing to obtain preprocessed pulmonary tuberculosis image data;
[0127] The first building module is used to introduce random cross attention groups, build a teacher model, and perform feature extraction and loss calculation on the preprocessed tuberculosis image data to obtain the multi-scale teacher prediction feature map and teacher model loss;
[0128] The second building module is used to introduce the intermediate feature layer distillation module and combine it with the teacher model to build a teacher-student model to obtain multi-scale prediction feature maps, student model loss and distillation loss;
[0129] The prediction module is used to add the teacher model loss, the student model loss and the distillation loss and combine them with the multi-scale prediction feature map to obtain the prediction output result of tuberculosis.
[0130] The contents of the above method embodiments are all applicable to the present system embodiments. The functions specifically implemented by the present system embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0131] The above is a specific description of the preferred implementation of the present invention, but the invention is not limited to the embodiments. Those skilled in the art may make various equivalent modifications or substitutions without violating the spirit of the present invention. These equivalent modifications or substitutions are all included in the scope defined by the claims of this application.
Claims
1. A method for predicting active pulmonary tuberculosis based on multi-level knowledge distillation, characterized in that: The following steps are involved: Acquiring pulmonary tuberculosis image data and performing data preprocessing to obtain preprocessed pulmonary tuberculosis image data; The random cross attention group is introduced to construct the teacher model and perform feature extraction and loss calculation on the preprocessed tuberculosis image data to obtain the multi-scale teacher prediction feature map and teacher model loss; The intermediate feature layer distillation module is introduced and combined with the teacher model to build a teacher-student model to obtain multi-scale prediction feature maps, student model loss and distillation loss; The teacher model loss, student model loss and distillation loss are added together and combined with the multi-scale prediction feature map to obtain the prediction output result of tuberculosis.
2. The method for predicting active pulmonary tuberculosis based on multi-level knowledge distillation according to claim 1, characterized in that: The step of acquiring pulmonary tuberculosis image data and performing data preprocessing to obtain preprocessed pulmonary tuberculosis image data specifically includes: Acquire pulmonary tuberculosis image data and perform format conversion processing to obtain pulmonary tuberculosis image data in PNG format; Normalizing the pulmonary tuberculosis image data in PNG format to obtain normalized pulmonary tuberculosis image data; Performing data enhancement processing on the normalized pulmonary tuberculosis image data to obtain enhanced pulmonary tuberculosis image data; The enhanced pulmonary tuberculosis image data is divided into a pulmonary tuberculosis image training data set and a pulmonary tuberculosis image test data set, and the preprocessed pulmonary tuberculosis image data is output.
3. The method for predicting active pulmonary tuberculosis based on multi-level knowledge distillation according to claim 2, characterized in that: The step of introducing a random cross attention group, constructing a teacher model, performing feature extraction and loss calculation on the preprocessed tuberculosis image data, and obtaining a multi-scale teacher prediction feature map and a teacher model loss specifically includes: Introduce random cross attention groups to build a teacher model; Based on the teacher model, feature extraction is performed on the preprocessed tuberculosis image data to obtain a multi-scale teacher prediction feature map; A softmax function with a temperature coefficient is introduced to smooth the output of the teacher model and obtain the teacher model loss.
4. The method for predicting active pulmonary tuberculosis based on multi-level knowledge distillation according to claim 3, characterized in that: The teacher model includes a first convolutional layer, a first random cross attention group, a second random cross attention group, a third random cross attention group, a fourth random cross attention group and a second convolutional layer, wherein: The front end of the first random cross attention group, the front end of the second random cross attention group, the front end of the third random cross attention group, and the front end of the fourth random cross attention group are all connected to a patch embedding layer; The first random cross attention group, the second random cross attention group, the third random cross attention group and the fourth random cross attention group all have the same structure, and all include a first normalization layer, a first random cross attention layer, a second normalization layer, a third convolutional layer, a second random cross attention layer and a fourth convolutional layer; The first random cross attention layer and the second random cross attention layer have the same structure, both including a self-attention layer and a cross attention layer.
5. The method for predicting active pulmonary tuberculosis based on multi-level knowledge distillation according to claim 4, characterized in that: The step of extracting features from the preprocessed tuberculosis image data based on the teacher model to obtain a multi-scale teacher prediction feature map specifically includes: The preprocessed tuberculosis image data was input into the teacher model; Based on the first convolutional layer of the teacher model, feature extraction is performed on the preprocessed pulmonary tuberculosis image data to obtain shallow feature image data of pulmonary tuberculosis; Based on the patch embedding layer of the teacher model, the shallow feature image data of pulmonary tuberculosis is encoded to obtain the encoded shallow feature image data of pulmonary tuberculosis; Based on the first random cross attention group of the teacher model, deep feature extraction processing is performed on the encoded shallow feature image data of pulmonary tuberculosis to obtain the first teacher prediction feature map; Based on the second random cross attention group of the teacher model, the first teacher prediction feature map is subjected to deep feature extraction processing to obtain the second teacher prediction feature map; Based on the third random cross attention group of the teacher model, deep feature extraction processing is performed on the second teacher prediction feature map to obtain the third teacher prediction feature map; Based on the fourth random cross attention group and the second convolutional layer of the teacher model, deep feature extraction processing is performed on the third teacher prediction feature map to obtain the fourth teacher prediction feature map; The first teacher prediction feature map, the second teacher prediction feature map, the third teacher prediction feature map and the fourth teacher prediction feature map are integrated to obtain a multi-scale teacher prediction feature map.
6. The method for predicting active pulmonary tuberculosis based on multi-level knowledge distillation according to claim 5, characterized in that: The first random cross attention group based on the teacher model performs deep feature extraction processing on the encoded shallow feature image data of pulmonary tuberculosis to obtain the first teacher prediction feature map. The step specifically includes: Input the encoded pulmonary tuberculosis shallow feature image data into the first random cross attention group of the teacher model; Based on the first normalization layer of the first random cross attention group, the encoded pulmonary tuberculosis shallow layer feature image data is normalized to obtain the first normalized pulmonary tuberculosis shallow layer feature image data; Based on the first random cross attention layer of the first random cross attention group, feature extraction processing is performed on the first normalized pulmonary tuberculosis shallow feature image data to obtain preliminary pulmonary tuberculosis deep feature image data; Combining the encoded pulmonary tuberculosis shallow layer characteristic image data with the preliminary pulmonary tuberculosis shallow layer characteristic image data to obtain combined pulmonary tuberculosis shallow layer characteristic image data; Based on the second normalization layer of the first random cross attention group, normalizing the combined pulmonary tuberculosis shallow layer feature image data to obtain second normalized pulmonary tuberculosis shallow layer feature image data; Based on the third convolutional layer of the first random cross attention group and the second random cross attention layer, feature extraction processing is performed on the second normalized shallow feature image data of pulmonary tuberculosis to obtain deep feature image data of pulmonary tuberculosis; Based on the fourth convolutional layer of the first random cross attention group, the deep feature image data of tuberculosis is convolved to obtain the first teacher prediction feature map.
7. The method for predicting active pulmonary tuberculosis based on multi-level knowledge distillation according to claim 6, characterized in that: It also includes, in the first random cross-attention layer and the second random cross-attention layer, selecting the corresponding self-attention layer or cross-attention layer for feature extraction processing according to the learnable parameters of the input data.
8. The method for predicting active pulmonary tuberculosis based on multi-level knowledge distillation according to claim 7, characterized in that: The step of introducing the intermediate feature layer distillation module and combining it with the teacher model to construct a teacher-student model and obtain multi-scale prediction feature maps, student model loss and distillation loss specifically includes: Constructing a student model, the student model includes a first intermediate feature layer, a second intermediate feature layer, a third intermediate feature layer, and a fourth intermediate feature layer, obtaining output results of the first intermediate feature layer, the second intermediate feature layer, the third intermediate feature layer, and the fourth intermediate feature layer in the student model, and obtaining a multi-scale student prediction feature map, the multi-scale student prediction feature map includes a first student prediction feature map, a second student prediction feature map, a third student prediction feature map, and a fourth student prediction feature map; The multi-scale student prediction feature map is concatenated with the multi-scale teacher prediction feature map to obtain a multi-scale prediction feature map; A softmax function with a temperature coefficient is introduced to smooth the output of the student model and obtain the student model loss; An intermediate feature layer distillation module is introduced to connect the teacher model and the student model, build a teacher-student model and obtain the distillation loss.
9. The method for predicting active pulmonary tuberculosis based on multi-level knowledge distillation according to claim 8, characterized in that: The data processing process of the intermediate feature layer distillation module is as follows: Performing interpolation processing on the first teacher prediction feature map to obtain an interpolated first teacher prediction feature map; The interpolated first teacher prediction feature map is concatenated with the second teacher prediction feature map to obtain a first intermediate feature map; Embedding global information into the first intermediate feature map through global average pooling to obtain a first intermediate feature map with global information; The first intermediate feature map with global information is sequentially subjected to convolution, batch normalization and activation processing to obtain an activated first intermediate feature map; A first learnable matrix and a second learnable matrix are introduced to respectively perform attention information extraction processing on the activated first intermediate feature map to obtain first attention feature information and second attention feature information; The first attention feature information is multiplied by the second teacher prediction feature map, the second attention feature information is spliced with the first teacher prediction feature map, and the multiplication result and the splicing result are added to obtain a second intermediate feature map.
10. An active pulmonary tuberculosis prediction system based on multi-level knowledge distillation, characterized in that: Includes the following modules: A preprocessing module is used to obtain pulmonary tuberculosis image data and perform data preprocessing to obtain preprocessed pulmonary tuberculosis image data; The first building module is used to introduce random cross attention groups, build a teacher model, and perform feature extraction and loss calculation on the preprocessed tuberculosis image data to obtain the multi-scale teacher prediction feature map and teacher model loss; The second building module is used to introduce the intermediate feature layer distillation module and combine it with the teacher model to build a teacher-student model to obtain multi-scale prediction feature maps, student model loss and distillation loss; The prediction module is used to add the teacher model loss, the student model loss and the distillation loss and combine them with the multi-scale prediction feature map to obtain the prediction output result of tuberculosis.
Citation Information
Cited By
Cross-modal knowledge migration unmanned aerial vehicle motor fault diagnosis method based on knowledge distillation
CN120470418A
Tunnel apparent disease detection method and system based on deep learning and knowledge distillation
CN121235997A
