A chest x-ray image pneumonia classification apparatus

Through the multi-scale spatial weighted residual attention mechanism and the efficient scale attention module, combined with the ConvNeXt network and supervised contrastive learning, the pneumonia classification in chest X-ray images is optimized, the lesion feature extraction and classification accuracy are improved, and the dynamic changes of complex lesions are adapted.

CN120635596BActive Publication Date: 2025-10-10TIANJIN THINKING CHAIN ARTIFICIAL INTELLIGENCE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511106089.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-08-08
Publication Date
2025-10-10
Estimated Expiration
2045-08-08

AI Technical Summary

Technical Problem

In the existing technology of pneumonia classification in chest X-ray images, single-scale feature extraction is difficult to capture the spatial information of complex lesions, the high-dimensional feature space is easily interfered by noise, the generalization ability is insufficient, and contrastive learning does not fully utilize multi-scale spatial information and channel dimension features, resulting in limited classification performance.

Method used

The multi-scale spatial weighted residual attention mechanism (SWRA) and the efficient scale attention module (ESAM) are adopted in combination with the ConvNeXt network. Through multi-scale parallel convolution and channel attention, supervised contrastive learning is embedded to optimize feature extraction and classification.

Benefits of technology

The model's ability to extract complex lesion features has been improved, the classification accuracy of viral pneumonia, lung opacity and normal conditions has been enhanced, the dependence on labeled samples has been reduced, and it has adapted to the dynamic changes of complex lesions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120635596B_ABST
    Figure CN120635596B_ABST
Patent Text Reader

Abstract

The application relates to a chest X-ray image pneumonia classification device, which comprises a data acquisition module, a data enhancement module, a feature extraction module, a feature enhancement module, an average pooling module and a loss optimization module.The data acquisition module is used for acquiring chest X-ray images and performing classification labeling to construct an image dataset.The data enhancement module is used for preprocessing the chest X-ray images, adapting a model input format and performing data enhancement.The feature extraction module is used for designing a multi-scale spatial weighted residual attention mechanism, extracting multi-scale spatial features and embedding a ConvNeXt network.The feature enhancement module is used for constructing an efficient scale attention module, embedding a ConvNeXt network to enhance feature extraction.The average pooling module is used for generating feature representation through global average pooling and optimizing by contrast learning.The loss optimization module is used for designing a joint loss function, combining classification loss and contrast loss for optimization.The model training module is used for training and optimizing a network model, evaluating classification performance and outputting results.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image processing and deep learning technology, and in particular to a device for classifying pneumonia in chest X-ray images. Background Art

[0002] Deep learning, a branch of machine learning, uses multi-layered neural networks to simulate the human brain's information processing mechanisms, automatically extracting features and learning patterns from complex data. Its core lies in building deep neural networks that represent and classify high-dimensional data through layer-by-layer feature extraction and abstraction. In recent years, deep learning models such as Convolutional Neural Networks (CNN), Residual Networks (ResNet), and Vision Transformers (ViT) have demonstrated significant advantages in image processing, particularly in chest X-ray image analysis, where they are widely used for pneumonia detection and classification.

[0003] Chest X-ray images have become an important tool for screening pneumonia. Traditional technologies rely on manual interpretation by radiologists, which is highly subjective and inefficient. To improve screening efficiency and accuracy, researchers have developed automated classification technologies based on deep learning, including CNN-based feature extraction and attention-based feature enhancement. These technologies automatically identify viral pneumonia, other lung infections, and normal conditions by extracting and classifying features from chest X-ray images. However, existing technologies face the following challenges: single-scale feature extraction is difficult to capture the spatial information of complex lesions, resulting in limited classification performance; in high-dimensional feature spaces, the model is susceptible to noise interference and lacks generalization ability; the number of labeled samples is limited, the training cost is high, and the model has poor adaptability to new samples.

[0004] Contrastive Learning, as an unsupervised or semi-supervised learning strategy, can effectively improve the generalization performance of the model by constructing positive and negative sample pairs and optimizing the sample representation in the feature space. In the field of image processing, supervised contrastive learning uses annotation information to enhance the feature similarity of samples of the same type and reduce the similarity of samples of different types, thereby improving classification accuracy. However, existing contrastive learning strategies are mostly based on global features, do not fully utilize multi-scale spatial information, and do not sufficiently enhance features in the channel dimension, resulting in limited performance of the model in complex pneumonia lesion problems. In addition, although attention mechanisms (such as channel attention and spatial attention) are widely used for feature enhancement, a single attention module is difficult to simultaneously take into account the interaction of multi-scale spatial features and channel features, which limits the model's ability to accurately locate and classify lesion areas. Summary of the Invention

[0005] This application provides a chest X-ray image pneumonia classification device, comprising:

[0006] The data acquisition module is used to acquire chest X-ray images, classify and annotate them, and construct an image dataset;

[0007] a data enhancement module, configured to preprocess the chest X-ray image, adapt the model input format, and perform data enhancement;

[0008] Feature extraction module, used to design a multi-scale spatial weighted residual attention mechanism to extract multi-scale spatial features and embed them into the ConvNeXt network;

[0009] Feature enhancement module, used to build an efficient scale-attention module and embed it into the ConvNeXt network to enhance feature extraction;

[0010] Average pooling module, which generates feature representations through global average pooling and adopts contrastive learning optimization;

[0011] Loss optimization module, used to design a joint loss function that combines classification loss and contrast loss for optimization;

[0012] Model training module, used to train and optimize network models, evaluate classification performance and output results;

[0013] The feature extraction module is specifically used to:

[0014] The original features of the input chest X-ray image , through global average pooling and global maximum pooling, generate spatial descriptors and , reflecting the overall intensity and salient features of the image respectively;

[0015] Will F avg and F max Splice along the channel axis to generate splicing features , through convolution operations with kernel sizes of 3×3, 5×5, and 7×7, a multi-scale attention map is generated 、 、 And perform nonlinear transformation on each attention map through Sigmoid activation function;

[0016] Define the learnable weight vector , normalized by the Softmax function, satisfying , calculate the fusion attention map , the formula is:

[0017]

[0018] in, 、 、 For learnable weights, they are optimized through gradient updates during training;

[0019] The fused attention map A fused With the original features X Perform element-by-element multiplication to generate weighted features and connected with the original features through residual connection Add to generate spatial enhancement features , the formula is:

[0020]

[0021] Enhance the spatial features Y It is connected after stage 1, stage 2, and stage 3 of the ConvNeXt network to improve the model's ability to extract multi-scale lesion features.

[0022] Furthermore, the data acquisition module is specifically used to:

[0023] Obtain chest X-ray images including viral pneumonia, lung opacities, and normal states;

[0024] Identify each image and assign a classification label, including viral pneumonia, lung opacity, and normal state;

[0025] Organize images and corresponding labels into a dataset, split it into training and validation sets, and store them in a specified directory for model loading.

[0026] Furthermore, the data enhancement module is specifically used to:

[0027] Resize chest X-ray images to the model input resolution, preserving the image aspect ratio;

[0028] Normalize the image pixel values ​​using a predefined mean and standard deviation;

[0029] Data augmentation operations are applied to the training set, including random affine transformation, color jittering, and Gaussian blur, while only pixel value normalization is performed on the validation set.

[0030] Furthermore, the feature enhancement module is specifically used to:

[0031] For input features Perform channel attention operation and generate channel descriptors through global average pooling , generate the channel weight vector through two layers of fully connected layers and Sigmoid activation function ;

[0032] The channel weight vector W c With input features Y Perform channel-by-channel multiplication to generate channel-weighted features ;

[0033] Channel-weighted features Y c Perform spatial attention operation and generate spatial attention map through 3×3 convolution and Sigmoid activation function ,and Y c Perform element-by-element multiplication to generate spatial enhancement features ;

[0034] Enhance the spatial features Y s It is connected to the second two-dimensional convolution kernel of the ConvNeXt Block in stage3 and stage4 of the ConvNeXt network to form an enhanced ConvNeXt Block.

[0035] Furthermore, the average pooling module is specifically used to:

[0036] Perform global average pooling on the stage 4 output feature map of the ConvNeXt network to generate a global feature representation. The formula is:

[0037]

[0038] Where B is the batch size and D is the feature dimension;

[0039] Through the projection head module, a multi-layer perceptron is used to F pooled Mapping to 128-dimensional contrast space to generate projection features ;

[0040] right F proj Perform L2 normalization to generate normalized features , calculate the cosine similarity matrix S , the formula is:

[0041]

[0042] in, It is the temperature parameter, the default value is 0.07, which is used to adjust the smoothness of the similarity distribution;

[0043] Generate positive sample masks based on labelsM wherein M ij =1 represents a sample i and j the label of y i = y j , otherwise M ij =0;

[0044] The supervised contrastive loss function is used, and the formula is:

[0045]

[0046] wherein, S ij represents the cosine similarity of samples i and j , M ij represents a positive sample mask, and T is a temperature parameter.

[0047] Further, the loss optimization module is specifically configured to:

[0048] calculate the cross-entropy classification loss based on the classification probability of the model output and the real label;

[0049] calculate the contrastive loss using the supervised contrastive loss function;

[0050] The joint loss function is designed, and the formula is:

[0051]

[0052] wherein, represents a dynamic weighting coefficient, which gradually increases the weight of the contrastive loss with the increase of the training round epoch.

[0053] Further, the model training module is specifically configured to:

[0054] The network model is iteratively trained using the training set, the AdamW optimizer is adopted, the learning rate is set to 0.0001, the weight decay is set to 0.01, and the batch size is set to 64; at the same time, the cosine annealing learning rate scheduler is used for learning rate decay, and the gradient clipping technology is adopted to prevent gradient explosion, and the maximum gradient norm limit is set to 1.0;

[0055] The channel attention weight is applied to the input feature map to generate a weighted feature map;

[0056] Calculate the classification accuracy, recall rate, precision, F1 score and Kappa coefficient on the validation set to evaluate the model performance.

[0057] Select the best model parameters based on the performance of the validation set, save the model weights and performance indicators to the specified file.

[0058] The above technical solutions of the present application have the following advantages:

[0059] 1. To solve the problem that single-scale feature extraction is difficult to capture complex pneumonia lesion spatial information, a multi-scale spatial weighted residual attention mechanism (SWRA) is proposed, which embeds the ConvNeXt network to extract diversified lesion features through multi-scale parallel convolution operation and residual connection, and improves the classification accuracy of viral pneumonia, lung opacity and normal state. Through ablation experiments and multiple comparison experiments, it is proved that the multi-scale spatial weighted residual attention mechanism (SWRA) in the present application can enhance the feature extraction ability of the model for complex lesion patterns.

[0060] 2. To solve the problem that high-dimensional feature space is easily disturbed by noise, leading to insufficient generalization ability, an efficient scale attention module (ESAM) is proposed, which combines channel attention and multi-scale spatial attention to enhance the robustness of feature extraction, and embeds the ConvNeXt network to form an enhanced feature representation. Through ablation experiments and multiple comparison experiments, it is proved that the efficient scale attention module (ESAM) in the present application can improve the generalization performance of the model in complex image environment.

[0061] 3. To solve the problem that multiple pneumonia lesions in pneumonia X-ray image recognition have similar manifestations, leading to fuzzy classification boundary, an optimization scheme based on supervised contrast learning is proposed, which generates feature representation through global average pooling, combines cosine similarity matrix and joint loss function to optimize feature discrimination, reduces dependence on labeled samples, and realizes efficient classification performance. Through ablation experiments and multiple comparison experiments, it is proved that the optimization scheme based on supervised contrast learning in the present application can improve the performance of the model for pneumonia X-ray image classification problem. BRIEF DESCRIPTION OF DRAWINGS

[0062] In order to more clearly illustrate the technical solutions in the specific embodiments or prior art of the present application, the following will briefly introduce the drawings needed to be used in the description of specific embodiments or prior art. Obviously, the drawings in the following description are some embodiments of the present application, and those skilled in the art can obtain other drawings according to these drawings without creating any inventive labor.

[0063] Figure 1 The structural diagram of the chest X-ray image pneumonia classification device provided by the present application;

[0064] Figure 2The architecture diagram of the multi-scale spatially weighted residual attention mechanism (SWRA) provided for this application;

[0065] Figure 3 Architecture diagram of the Efficient Scale Attention Module (ESAM) provided for this application. DETAILED DESCRIPTION

[0066] In the following description, specific details such as specific system structures and technologies are provided for purposes of illustration rather than limitation to facilitate a thorough understanding of the embodiments of the present application. However, it will be apparent to those skilled in the art that the present application may be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, and circuits are omitted to avoid obscuring the description of the present application with unnecessary detail.

[0067] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, integers, steps, operations, elements and / or components, but does not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or collections thereof.

[0068] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0069] References to "one embodiment" or "some embodiments" in this specification mean that one or more embodiments of the present application include a particular feature, structure, or characteristic described in conjunction with that embodiment. Thus, phrases such as "in one embodiment," "in some embodiments," "in other embodiments," and "in other embodiments" appearing in various places in this specification do not necessarily refer to the same embodiment, but rather mean "one or more but not all embodiments," unless otherwise specifically emphasized. The terms "including," "comprising," "having," and variations thereof all mean "including but not limited to," unless otherwise specifically emphasized. "Multiple" means "two or more."

[0070] In response to the problems in the background technology, this application proposes a pneumonia classification device for chest X-ray images based on a multi-scale spatial attention mechanism and contrastive learning. By designing a multi-scale spatial weighted residual attention mechanism (SWRA) and an efficient scale attention module (ESAM), combined with supervised contrastive learning, the feature extraction and classification process are optimized. This can effectively improve the performance of the model in the classification tasks of viral pneumonia, lung opacity and normal state, while reducing dependence on a large number of labeled samples and adapting to the dynamic changes of complex lesion characteristics.

[0071] The following embodiments are used to illustrate the present invention, but are not intended to limit the scope of the present invention.

[0072] like Figure 1 As shown, the embodiment of the present application provides a chest X-ray image pneumonia classification device, comprising:

[0073] The data acquisition module is used to acquire chest X-ray images, classify and annotate them, and construct an image dataset;

[0074] a data enhancement module, configured to preprocess the chest X-ray image, adapt the model input format, and perform data enhancement;

[0075] Feature extraction module, used to design a multi-scale spatial weighted residual attention mechanism (SWRA), extract multi-scale spatial features and embed them into the ConvNeXt network;

[0076] Feature enhancement module, used to build the Efficient Scale Attention Module (ESAM), embedded in the ConvNeXt network to enhance feature extraction;

[0077] Average pooling module, which generates feature representations through global average pooling and adopts contrastive learning optimization;

[0078] Loss optimization module, used to design a joint loss function that combines classification loss and contrast loss for optimization;

[0079] Model training module, used to train and optimize network models, evaluate classification performance and output results;

[0080] The feature extraction module is specifically used to:

[0081] The original features of the input chest X-ray image , through global average pooling and global maximum pooling, generate spatial descriptors and , reflecting the overall intensity and salient features of the image respectively;

[0082] Will F avg and F max Splice along the channel axis to generate splicing features , through convolution operations with kernel sizes of 3×3, 5×5, and 7×7, a multi-scale attention map is generated 、 、 And perform nonlinear transformation on each attention map through Sigmoid activation function;

[0083] Define the learnable weight vector , normalized by the Softmax function, satisfying , calculate the fusion attention map , the formula is:

[0084]

[0085] in, 、 、 For learnable weights, they are optimized through gradient updates during training;

[0086] The fused attention map A fused With the original features X Perform element-by-element multiplication to generate weighted features and connected with the original features through residual connection Add to generate spatial enhancement features , the formula is:

[0087]

[0088] Enhance the spatial features Y It is connected after stage 1, stage 2, and stage 3 of the ConvNeXt network to improve the model's ability to extract multi-scale lesion features.

[0089] In some embodiments, the data acquisition module is specifically configured to:

[0090] Chest X-ray images containing viral pneumonia, lung opacity, and normal conditions were obtained from a public database;

[0091] Each image is identified and assigned a classification label based on radiology reports or expert annotations, including viral pneumonia, lung opacity, and normal status;

[0092] The images and corresponding labels are organized into a dataset through index files, divided into a training set (80%) and a validation set (20%), and stored in a specified directory for model loading.

[0093] In some embodiments, the data enhancement module is specifically configured to:

[0094] Resize chest X-ray images to the model input resolution (299×299 pixels), maintaining the image aspect ratio;

[0095] Normalize the image pixel values ​​to the range of [-1, 1] using the predefined mean (0.5, 0.5, 0.5) and standard deviation (0.5, 0.5, 0.5);

[0096] Apply data augmentation operations to the training set, including:

[0097] Random affine transformation, set the rotation angle to ±5 degrees, the translation ratio to ±0.02, and the scaling ratio to 0.97-1.03;

[0098] Color dithering, set brightness and contrast adjustment range 0.9-1.1;

[0099] Gaussian blur, set the convolution kernel size to 3, and the standard deviation to 0.1-0.2;

[0100] The validation set only undergoes pixel value normalization.

[0101] In some embodiments, the feature enhancement module is specifically configured to:

[0102] For input features Perform channel attention operation and generate channel descriptors through global average pooling , generate channel weight vectors through two layers of fully connected layers and Sigmoid activation function ;

[0103] The channel weight vector W c With input features Y Perform channel-by-channel multiplication to generate channel-weighted features ;

[0104] Channel-weighted features Y c Perform spatial attention operation and generate spatial attention map through 3×3 convolution and Sigmoid activation function ,and Y c Perform element-by-element multiplication to generate spatial enhancement features ;

[0105] Enhance the spatial features Y s It is connected to the second two-dimensional convolution kernel of the ConvNeXt Block in stage3 and stage4 of the ConvNeXt network to form an enhanced ConvNeXt Block.

[0106] In some embodiments, the average pooling module is specifically configured to:

[0107] Perform global average pooling on the stage 4 output feature map of the ConvNeXt network to generate a global feature representation. The formula is:

[0108]

[0109] Where B is the batch size and D is the feature dimension;

[0110] Through the projection head module, a multi-layer perceptron is used to F pooled Mapping to 128-dimensional contrast space to generate projection features ;

[0111] right F proj Perform L2 normalization to generate normalized features , calculate the cosine similarity matrix S , the formula is:

[0112]

[0113] in, It is the temperature parameter, the default value is 0.07, which is used to adjust the smoothness of the similarity distribution;

[0114] Generate positive sample masks based on labels M ,in M ij =1 indicates sample i and j Tags y i = y j ,otherwise M ij =0;

[0115] Using the supervised contrast loss function, the formula is:

[0116]

[0117] in, S ij Represents a sample i and j The cosine similarity of M ij represents the positive sample mask, is the temperature parameter.

[0118] In some embodiments, the loss optimization module is specifically configured to:

[0119] Calculate cross entropy classification loss , classification probability and true label based on model output;

[0120] Calculating contrastive loss , using the supervised contrast loss function in step S5;

[0121] Design the joint loss function, the formula is:

[0122]

[0123] in, Represents a dynamic weighting coefficient, which gradually increases the weight of the contrast loss as the number of training rounds increases.

[0124] In some embodiments, the model training module is specifically used to:

[0125] The network model was iteratively trained using the training set, using the AdamW optimizer, with a learning rate of 0.0001, a weight decay of 0.01, and a batch size of 64. A cosine annealing learning rate scheduler was used for learning rate decay, and gradient clipping was used to prevent gradient explosion. The maximum gradient norm was limited to 1.0.

[0126] Apply channel attention weights to the input feature map to generate a weighted feature map;

[0127] Calculate classification accuracy, recall, precision, F1 score, and Kappa coefficient on the validation set to evaluate model performance;

[0128] Select the best model parameters based on the validation set performance and save the model weights and performance metrics to the specified file.

[0129] Current deep learning approaches to pneumonia image classification face challenges with subtle lesion features and fuzzy class boundaries. Existing attention mechanisms often use single-dimensional convolutional kernels, making it difficult to effectively capture the characteristics of lesions of varying sizes. Contrastive learning is often used as data preprocessing and is not fully integrated into model training, limiting the ability to distinguish between classes.

[0130] This application uses the scale-weighted residual attention (SWRA) mechanism, combined with multi-scale convolution kernels, to dynamically extract complex lesion features and improve detection accuracy. SWRA and efficient channel attention (ECA) form the efficient scale attention module (ESAM), which is embedded in the deep structure of ConvNeXt to enhance feature extraction capabilities. At the same time, this application innovatively integrates the contrast loss and classification loss to improve inter-class discrimination and intra-class consistency, effectively addressing the problem of blurred class boundaries. Experiments show that the pneumonia classification device for chest X-ray images proposed in this application achieves an accuracy of 96.10% and an F1 score of 96.60%, which is superior to mainstream neural network models. This application provides important value for efficient and accurate automatic pneumonia identification and is suitable for the intelligent needs of complex clinical scenarios.

[0131] The chest X-ray image pneumonia classification device provided in the embodiment of the present application is designed by designing a multi-scale spatial weighted residual attention mechanism (SWRA, such as Figure 2 ) and the Efficient Scale Attention Module (ESAM, as Figure 3The chest X-ray image pneumonia classification device based on the multi-scale spatial attention mechanism and the contrast learning is combined with supervised contrast learning to construct a deep learning model, so as to realize classification detection and analysis of viral pneumonia, lung opacity and normal state in a chest X-ray image.

[0132] The following is described by means of specific embodiments.

[0133] Embodiments

[0134] To verify the performance superiority of the chest X-ray image pneumonia classification device based on the multi-scale spatial attention mechanism and the contrast learning proposed in the present application, the effectiveness of model optimization in the classification task of viral pneumonia, lung opacity and normal state, and the classification strategy based on supervised contrast learning can improve the generalization ability of the model on complex lesion features, the specific steps are as follows:

[0135] (1) Dataset:

[0136] The dataset shown in Table 1 is used as the basic data source for experimental verification. The dataset contains 6012 lung opacity lesion samples, 10192 normal lung state samples and 1345 viral pneumonia samples, a total of 17549 high-quality image data, as shown in Table 1.

[0137]

[0138] Table 1: Dataset distribution

[0139] (2) Comparison system

[0140] The chest X-ray image pneumonia classification model based on the multi-scale spatial attention mechanism and the contrast learning proposed in the present application is used, and the experimental dataset shown in Table 1 is used, of which 80% is used as the training set and 20% is used as the test set. Compared with the ResNet34, ResNeXt101, DenseNet121, SqueezeNet and ConvNeXt five common deep learning models, since these five models have a high influence in the classification field, the effectiveness of the present application is verified.

[0141] ResNet34: 34-layer residual network architecture is adopted, including a 7x7 convolution layer, four residual block groups (including 3, 4, 6, 3 residual units respectively) and a fully connected classification layer, and the gradient disappearance problem of deep network is solved by using a jump connection.

[0142] ResNeXt101: 101-layer grouped convolution network architecture is adopted, including a 7x7 convolution layer, four residual block groups (including 3, 4, 23, 3 grouped convolution units respectively) and a fully connected classification layer, and each grouped convolution unit adopts 32 parallel branches.

[0143] DenseNet121: It uses a 121-layer densely connected network architecture, consisting of a 7×7 convolutional layer, four dense blocks (containing 6, 12, 24, and 16 dense layers respectively), three transition layers, and a fully connected classification layer, achieving feature reuse through dense connections.

[0144] SqueezeNet: It uses a lightweight network architecture consisting of a 7×7 convolutional layer, eight Fire modules (each module contains a squeeze layer and an expand layer), and a fully connected classification layer, and reduces the number of parameters through 1×1 convolution.

[0145] ConvNeXt: It adopts a modern convolutional network architecture, consisting of four stages (containing 3, 3, 9, and 3 ConvNeXt blocks respectively) and a fully connected classification layer. Each ConvNeXt block contains depth convolution, LayerNorm, point convolution, and GELU activation function.

[0146] (3) Experimental results and analysis:

[0147] During the experiment, each model was tested ten times, and the one with the best performance was taken as the experimental result. The specific results of each model are shown in Table 2.

[0148]

[0149] Table 2 Comparison of model performance on the dataset

[0150] Experimental results show that the PneumoNeXt model in this application achieves optimal performance across key performance indicators such as accuracy, recall, F1-Score, precision, and Kappa coefficient. Specifically, compared to the ConvNeXt baseline model, the accuracy increased by 2.22% and the Kappa coefficient increased by 3.45%, fully verifying the effectiveness and advancement of this application's technical solution.

[0151] The pneumonia classification device for chest X-ray images based on multi-scale spatial attention mechanism and contrastive learning proposed in this application designs a multi-scale spatial weighted residual attention mechanism (SWRA) and an efficient scale attention module (ESAM), combines the ConvNeXt network and supervised contrastive learning, and uses multi-scale parallel convolution and channel attention to extract complex lesion features. At the same time, it optimizes feature discrimination by combining classification loss and contrast loss. It not only significantly improves the classification accuracy of viral pneumonia, lung opacity and normal state, but also effectively reduces the dependence on a large number of labeled samples, and adapts to the diversity and dynamic changes of pneumonia lesions.

[0152] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other and are not used to limit the scope of protection of this application.

[0153] The above-described embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present application, and should all be included in the scope of protection of the present application.

Claims

1. A chest X-ray image pneumonia classification device, characterized in that: include: The data acquisition module is used to acquire chest X-ray images, classify and annotate them, and construct an image dataset; a data enhancement module, configured to preprocess the chest X-ray image, adapt the model input format, and perform data enhancement; Feature extraction module, used to design a multi-scale spatial weighted residual attention mechanism to extract multi-scale spatial features and embed them into the ConvNeXt network; Feature enhancement module, used to build an efficient scale-attention module and embed it into the ConvNeXt network to enhance feature extraction; Average pooling module, which generates feature representations through global average pooling and adopts contrastive learning optimization; Loss optimization module, used to design a joint loss function that combines classification loss and contrast loss for optimization; Model training module, used to train and optimize network models, evaluate classification performance and output results; The feature extraction module is specifically used to: The original features of the input chest X-ray image , through global average pooling and global maximum pooling, generate spatial descriptors and , reflecting the overall intensity and salient features of the image respectively; Will F avg and F max Splice along the channel axis to generate splicing features , through convolution operations with kernel sizes of 3×3, 5×5, and 7×7, a multi-scale attention map is generated 、 、 And perform nonlinear transformation on each attention map through Sigmoid activation function; Define the learnable weight vector , normalized by the Softmax function, satisfying , calculate the fusion attention map , the formula is: in, 、 、 For learnable weights, they are optimized through gradient updates during training; The fused attention map A fused With the original features X Perform element-by-element multiplication to generate weighted features and connected with the original features through residual connection Add to generate spatial enhancement features , the formula is: Enhance the spatial features Y It is connected after stage 1, stage 2, and stage 3 of the ConvNeXt network to improve the model's ability to extract multi-scale lesion features.

2. The chest X-ray image pneumonia classification device according to claim 1, characterized in that: The data acquisition module is specifically used to: Obtain chest X-ray images including viral pneumonia, lung opacities, and normal states; Identify each image and assign a classification label, including viral pneumonia, lung opacity, and normal state; Organize images and corresponding labels into a dataset, split it into training and validation sets, and store them in a specified directory for model loading.

3. The chest X-ray image pneumonia classification device according to claim 1, characterized in that: The data enhancement module is specifically used to: Resize chest X-ray images to the model input resolution, preserving the image aspect ratio; Normalize the image pixel values ​​using a predefined mean and standard deviation; Data augmentation operations are applied to the training set, including random affine transformation, color jittering, and Gaussian blur, while only pixel value normalization is performed on the validation set.

4. The chest X-ray image pneumonia classification device according to claim 1, characterized in that: The feature enhancement module is specifically used to: For input features Perform channel attention operation and generate channel descriptors through global average pooling , generate channel weight vectors through two layers of fully connected layers and Sigmoid activation function ; The channel weight vector W c With input features Y Perform channel-by-channel multiplication to generate channel-weighted features ; Channel-weighted features Y c Perform spatial attention operation and generate spatial attention map through 3×3 convolution and Sigmoid activation function ,and Y c Perform element-by-element multiplication to generate spatial enhancement features ; Enhance the spatial features Y s It is connected to the second two-dimensional convolution kernel of the ConvNeXt Block in stage3 and stage4 of the ConvNeXt network to form an enhanced ConvNeXt Block.

5. The chest X-ray image pneumonia classification device according to claim 1, characterized in that: The average pooling module is specifically used to: Perform global average pooling on the stage 4 output feature map of the ConvNeXt network to generate a global feature representation. The formula is: Where B is the batch size and D is the feature dimension; Through the projection head module, a multi-layer perceptron is used to F pooled Mapping to 128-dimensional contrast space to generate projection features ; right F proj Perform L2 normalization to generate normalized features , calculate the cosine similarity matrix S , the formula is: in, It is the temperature parameter, the default value is 0.07, which is used to adjust the smoothness of the similarity distribution; Generate positive sample masks based on labels M ,in M ij =1 indicates sample i and j Tags y i = y j ,otherwise M ij =0; Using the supervised contrast loss function, the formula is: in, S ij Represents a sample i and j The cosine similarity of M ij represents the positive sample mask, is the temperature parameter.

6. The chest X-ray image pneumonia classification device according to claim 1, characterized in that: The loss optimization module is specifically used to: Calculate cross entropy classification loss , classification probability and true label based on model output; Calculating contrastive loss , using a supervised contrastive loss function; Design the joint loss function, the formula is: in, Represents a dynamic weighting coefficient, which gradually increases the weight of the contrast loss as the number of training rounds increases.

7. The chest X-ray image pneumonia classification device according to claim 1, characterized in that: The model training module is specifically used to: The network model was iteratively trained using the training set, using the AdamW optimizer, with a learning rate of 0.0001, a weight decay of 0.01, and a batch size of 64. A cosine annealing learning rate scheduler was used for learning rate decay, and gradient clipping was used to prevent gradient explosion. The maximum gradient norm was limited to 1.

0. Apply channel attention weights to the input feature map to generate a weighted feature map; Calculate classification accuracy, recall, precision, F1 score, and Kappa coefficient on the validation set to evaluate model performance; Select the best model parameters based on the validation set performance and save the model weights and performance metrics to the specified file.

Citation Information

Patent Citations

  • Microscopic hyperspectral image segmentation method based on multi-scale attention fusion

    CN119810116A

  • Multi-scale fused dehazing method based on stacked hourglass network

    WO2024040973A1