Small sample medical image classification method, system, device and storage medium
Through the combination of semantic sequence construction and distribution-aware prototype calculation, the problem of insufficient representation complexity and spatial continuity in medical image processing is solved, and efficient small sample medical image classification is achieved.
Patent Information
- Application Number
- CN202510546352.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-28
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2045-04-28
AI Technical Summary
Traditional prototype networks are difficult to effectively characterize the complexity of intra-class distribution in medical imaging processing, and it is difficult to capture key local structures. Simple Euclidean distance measurements are difficult to cope with the problems of large internal differences and blurred boundaries in medical imaging categories. The existing improved methods have high computational complexity or ignore spatial continuity.
The semantic sequence construction module is used to segment medical images into overlapping slice sequences with spatial context information, and the feature sequence is processed through the Mamba state space model, combined with the distribution-aware prototype calculation module to use Mahayana distance for classification decisions, and introduce learnable position coding and attention mechanisms to capture long-distance dependencies.
It realizes efficient modeling of medical image features, improves the computing efficiency and model expression capabilities in small sample learning scenarios, and provides more accurate medical image classification decision boundaries.
Smart Images

Figure CN120088580B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a small sample medical image classification method, system, device and storage medium, and belongs to the field of medical image processing and artificial intelligence. Background Art
[0002] In recent years, deep learning technology has made significant progress in medical image processing, demonstrating tremendous potential in tasks such as tumor detection, organ segmentation, and disease diagnosis. Compared to traditional manual diagnosis, deep learning-based medical image analysis offers advantages such as high efficiency, stability, and strong consistency. However, deep learning models typically require large amounts of labeled data for training. The medical imaging field faces challenges such as high professional labeling costs, strict data privacy protections, and a scarcity of rare disease samples. These factors constitute major bottlenecks in the application of deep learning in medical imaging.
[0003] Few-shot learning, a technique that enables effective classification using limited labeled samples, offers a potential solution to the scarcity of medical imaging data. Prototypical networks, due to their simple structure and ease of implementation, have become a key approach for small-shot medical image classification. However, traditional prototypical networks have significant shortcomings when processing medical images: using only mean features cannot represent the complexity of intra-class distributions; global features struggle to capture key local structures; and simple Euclidean distance metrics struggle to account for the large intra-class variations and blurred boundaries characteristic of medical image classes.
[0004] Existing improvement methods focus on two main directions: First, enhancing feature representation capabilities by introducing sequence processing architectures such as Transformers. However, these methods are computationally complex, have a large number of parameters, and are prone to overfitting in small sample scenarios. Second, designing multiple prototypes or prototype representation methods that consider covariance often overlook the spatial continuity of medical images and the integration of local-global features. Therefore, a solution is urgently needed that can efficiently model medical image features, adapt to small sample learning scenarios, and balance computational efficiency and model expressiveness. Summary of the Invention
[0005] In order to improve the efficiency of medical image feature modeling and enhance classification efficiency and accuracy, the present invention provides a small sample medical image classification method, system, device, and storage medium. The technical solution is as follows:
[0006] The first object of the present invention is to provide a small sample medical image classification method, comprising the following steps:
[0007] Step 1: Segment the input medical image into a sequence of overlapping slices with spatial context information through a semantic sequence building module;
[0008] The processing of the semantic sequence building module includes:
[0009] Given an input image , using a size of Window and overlap ratio To slice:
[0010]
[0011] in, and are the steps in height and width respectively, i and j Represents the height and width position index respectively;
[0012] Step 2: Use the encoder to extract the feature representation of each slice and add position encoding;
[0013] Step 3: Process the feature sequence through a sequence enhancement module to capture long-range dependencies. The sequence enhancement module uses the Mamba state space model to process the feature sequence.
[0014] Step 4: construct a category prototype that takes feature distribution into consideration using a distribution-aware prototype calculation module, wherein the distribution-aware prototype calculation module constructs a prototype representation for each category that includes a mean vector and a covariance matrix;
[0015] Step 5: Use Mahalanobis distance to calculate the distance between the query sample and the prototype of each category and make a classification decision.
[0016] Optionally, step 2 further includes:
[0017] Introducing learnable positional encodings ,in L Indicates the total number of slices, D Represents the dimension of the slice features (i.e., the length of the feature vector of each slice after passing through the encoder);
[0018] The position code is added to the features of each slice, which is expressed as:
[0019]
[0020] in, represents the enhanced features containing spatial information, Represents the characteristics of the slice, Indicates the first i , j ) slices of learnable positional encoding vector;
[0021] Assign each slice a score reflecting its importance to the classification decision:
[0022]
[0023] in, represents the importance evaluation network, Indicates the i Spatial enhancement features of each slice;
[0024] Calculate attention weights:
[0025]
[0026] in, Indicates that the spatial relationship matrix is constructed based on the distance between the center points of the slices. Used to control the influence of importance, and Respectively represent i Slice enhancement features and j Slice enhancement features, represents the semantic similarity of slice features, Represents a slice i With slices k The spatial relationship matrix elements of;
[0027] Finally, the enhanced feature sequence is obtained through weighted aggregation:
[0028]
[0029] in, represents the enhanced feature sequence after weighted aggregation, express, B Indicates the batch size.
[0030] Optionally, step 3 includes:
[0031] Step 31: normalize the aggregated feature sequence input layer;
[0032] Step 32: Separate the main path features and the residual path features through linear projection;
[0033] Step 33: Use one-dimensional convolution to extract local feature patterns;
[0034] Step 34: Apply SSM parameters to generate and selectively scan sequence data;
[0035] Step 35: Integrate the two features through a gating mechanism to obtain an enhanced sequence representation.
[0036] Optionally, the Mahalanobis distance is calculated as follows:
[0037]
[0038] in, represents a query sample, Represents the category prototype, Representation category c The mean of all sample features, Representation category c The covariance matrix of all sample features.
[0039] Optionally, a regularization term is added to the covariance matrix: ,in, is the regularization coefficient, and I represents the identity matrix.
[0040] Optionally, the method uses a cross entropy loss function with a temperature parameter to train the model under a meta-learning framework. The cross entropy loss function is expressed as:
[0041]
[0042] in, is a learnable temperature parameter that controls the smoothness of the category probability distribution; represents the support set, which is the set of labeled samples used for prototype calculation. Representation support set The samples and their labels in N Representation support set The number of samples in .
[0043] Optionally, an L2 regularization term is added to the cross entropy loss function:
[0044]
[0045] in, Represents the L2 regularization coefficient, which is used to control the weight of the parameter norm penalty term. Represents the set of all trainable parameters of the model;
[0046] The final total loss is:
[0047] .
[0048] A second object of the present invention is to provide a small sample medical image classification system, wherein the system is used to implement any of the above medical image classification methods, comprising:
[0049] An image acquisition module, used for acquiring medical images to be classified;
[0050] A semantic sequence building module for segmenting medical images into overlapping slice sequences with spatial context information;
[0051] The processing of the semantic sequence building module includes:
[0052] Given an input image , using a size of Window and overlap ratio To slice:
[0053]
[0054] in, and are the steps in height and width respectively, i and j Represents the height and width position index respectively;
[0055] A feature extraction module that uses an encoder to extract feature representations for each slice and adds positional encoding;
[0056] A sequence enhancement module is used to process feature sequences and capture long-range dependencies. The sequence enhancement module uses a Mamba state space model to process the feature sequences.
[0057] A distribution-aware prototype calculation module is used to construct a category prototype that takes feature distribution into consideration. The distribution-aware prototype calculation module constructs a prototype representation for each category that includes a mean vector and a covariance matrix.
[0058] The classification decision module uses Mahalanobis distance to calculate the distance between the query sample and the prototype of each category and make classification decisions.
[0059] A third object of the present invention is to provide a small sample medical image classification device, comprising a memory and a processor;
[0060] The memory is used to store computer programs;
[0061] The processor is configured to implement any one of the above methods for classifying small sample medical images when executing the computer program.
[0062] A fourth object of the present invention is to provide a computer-readable storage medium, characterized in that a computer program is stored on the storage medium, and when the computer program is executed by a processor, the small sample medical image classification method as described in any one of the above items is implemented.
[0063] The beneficial effects of the present invention are:
[0064] Through an innovative overlapping slicing strategy and learnable position encoding, the present invention converts medical images into long sequence representations that preserve spatial continuity, perfectly adapting to the sequence processing characteristics of the Mamba model and solving the problem that traditional methods have difficulty in constructing effective sequence inputs. Based on Mamba's selective state space model, it achieves modeling of long-distance dependencies with linear computational complexity, effectively capturing the associations of pathological features scattered across various image regions, significantly improving computational efficiency compared to existing technologies.
[0065] The Distribution-Aware Prototype Computation (DAPC) module introduces a prototype representation method based on the Mahalanobis distance, taking into account both the mean vector and the covariance matrix. This fully captures the distribution information of Mamba's output features, enabling the model to more accurately distinguish complex categories in medical images. This distribution-aware prototype representation method perfectly matches the rich feature sequences generated by Mamba, providing a more precise decision boundary for few-shot medical image classification.
[0066] The end-to-end architecture designed specifically for Mamba's characteristics has fundamentally solved the fundamental problem of insufficient adaptability of traditional few-sample learning methods in the field of medical imaging, providing an efficient, robust and practical technical path for medical diagnosis assistance systems. BRIEF DESCRIPTION OF THE DRAWINGS
[0067] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0068] Figure 1 It is the overall structural diagram of the MSMPN model of the present invention.
[0069] Figure 2 It is a processing flow chart of the semantic sequence construction module (SSCM) of the present invention.
[0070] Figure 3 It is a partial code screenshot of the sequence enhancement module (MSEM) of the present invention.
[0071] Figure 4 It is a flowchart of the construction and experiment of the MSMPN model of the present invention.
[0072] Figure 5 This is the architecture diagram of the ResNet-12 model. DETAILED DESCRIPTION
[0073] To make the objectives, technical solutions and advantages of the present invention more clear, the embodiments of the present invention will be described in further detail below with reference to the accompanying drawings.
[0074] Example 1:
[0075] This embodiment provides a small sample medical image classification method, including the following steps:
[0076] Step 1: Segment the input medical image into a sequence of overlapping slices with spatial context information through a semantic sequence building module;
[0077] The processing of the semantic sequence building module includes:
[0078] Given an input image , using a size of Window and overlap ratio To slice:
[0079]
[0080] in, and are the steps in height and width respectively, i and j Represents the height and width position index respectively;
[0081] Step 2: Use the encoder to extract the feature representation of each slice and add position encoding;
[0082] Step 3: Process the feature sequence through the sequence enhancement module to capture long-range dependencies. The sequence enhancement module uses the Mamba state space model to process the feature sequence;
[0083] Step 4: Use the distribution-aware prototype calculation module to construct a category prototype that takes into account the feature distribution. The distribution-aware prototype calculation module constructs a prototype representation for each category that includes a mean vector and a covariance matrix.
[0084] Step 5: Use Mahalanobis distance to calculate the distance between the query sample and the prototype of each category and make a classification decision.
[0085] Example 2:
[0086] This embodiment provides the construction, training and verification process of the MSMPN framework.
[0087] like Figure 1As shown in the figure, the MSMPN framework consists of three main functional modules, namely the semantic sequence construction module (SSCM), the Mamba-based sequence enhancement module (MSEM) and the distribution-aware prototype computing (DAPC). Among them, the SSCM module generates long sequence inputs suitable for Mamba processing, the MSEM module efficiently processes these sequences and extracts complex feature representations, and the DAPC module accurately characterizes the distribution characteristics of these complex features for classification decisions.
[0088] The following is a detailed introduction to these three modules.
[0089] 1. Semantic Sequence Building Module (SSCM).
[0090] Medical image pathological features usually span multiple regions, and traditional grid segmentation methods may destroy key anatomical structures. To address this limitation, this embodiment proposes an SSCM module, the structure of which is as follows: Figure 2 shown.
[0091] This module uses an overlapping slice strategy that preserves spatial context information to segment medical images into local regions and uses an encoder to extract feature representations for each slice. The specific processing process is as follows:
[0092] Given an input image , using a size of Window and overlap ratio To slice:
[0093]
[0094] in, and are the steps in height and width respectively, i and j Represents the height and width position index respectively;
[0095] In order to preserve the spatial position information of the slices in the original image, this embodiment introduces a learnable position encoding ,in L is the total number of slices, is the slice feature dimension.
[0096]
[0097] in, H and W Represent the height and width of the input image respectively, w h and w w Represents the height and width of the slice window respectively, sh and s w Respectively represent the step lengths in height and width during the slicing process, Indicates rounding up.
[0098] Each slice feature is added with its corresponding position encoding to obtain an enhanced feature containing spatial information:
[0099]
[0100] in, represents the enhanced features containing spatial information, Represents the characteristics of the slice, Indicates the first i , j ) slices.
[0101] Considering that the contribution of different regions to diagnosis varies significantly, this implementation refers to the self-attention mechanism of the Transformer architecture and designs an importance evaluation network, which uses a fully connected layer + nonlinear activation structure to enhance the features of each space. Output importance score , assigning each slice a score reflecting its importance to the classification decision:
[0102]
[0103] in, represents the importance evaluation network, Indicates the i Spatial enhancement features of each slice;
[0104] We then designed a spatial perception attention aggregation mechanism, taking into account three key factors:
[0105] (1) Semantic similarity of slice features;
[0106] (2) The spatial distance relationship of the slices in the original image;
[0107] (3) Importance score of the slice.
[0108] The attention weight calculation formula is:
[0109]
[0110] in, represents the spatial relationship matrix constructed based on the distance between slice centers, Used to control the influence of importance, and Respectively represent iSlice enhancement features and j Slice enhancement features, represents the semantic similarity of slice features, Represents a slice i With slices k The spatial relationship matrix elements of;
[0111] Finally, the enhanced feature sequence is obtained through weighted aggregation:
[0112]
[0113] in, represents the enhanced feature sequence after weighted aggregation, B Indicates the batch size.
[0114] 2. Mamba-based sequence enhancement module (MSEM).
[0115] This module combines positional encoding and spatially aware attention mechanisms to capture the spatial relationships between slices, and uses the Mamba state-space model to process sequence features to effectively model long-range dependencies.
[0116] In the MSMPN framework, MSEM uses the Mamba state space model to efficiently process sequence data. The core of Mamba is its selective SSM mechanism, which defines four input-dependent parameters ( , , , ) and convert them to:
[0117]
[0118] Sequence transformation can be expressed as:
[0119]
[0120] in represents the time step, is the input, is the hidden state, is the output. The hidden state serves as a fixed-size storage unit to store historical information.
[0121] This embodiment designs a special processing architecture for medical image features. The pseudo code of the core processing flow of the MSEM module is as follows: Figure 3 The MambaSSM function encapsulates the core processing logic of the Mamba state space model, including dynamic parameter calculation and sequence conversion.
[0122] The calculation process of the MSEM module is as follows:
[0123] In this embodiment, the input is a batch spatial enhancement feature sequence First, the layer is normalized to improve the stability of feature distribution, and then the features are divided into main path features through linear transformation and residual path characteristics . Main path features After one-dimensional convolution and SiLU activation, it is input to the Mamba selective state space module to recursively model the long-range dependency of the sequence. Generate gate weights after nonlinear transformation , used to control the fusion ratio of the main path information and the original input. The final output sequence is:
[0124]
[0125] in, is a learnable scaling parameter, , is the Sigmoid function, represents element-wise multiplication, Represents the output of the Mamba state space module for the main path features. The Mamba state space module uses the following recursive evolution:
[0126]
[0127] in For the moment The hidden state of and The state transition parameters and input mapping parameters are dynamically generated according to the input. The main path feature Finally, the output of the main path is mapped back to the original feature dimension through linear transformation and fused with the gating weight to obtain the enhanced sequence output for subsequent prototype calculation or classification.
[0128] The meaning of each variable is as follows: is the input spatial enhancement feature sequence, For the main path branch feature, is the residual branch feature, represents the Mamba selective state space processing module, is the gating weight, is the learnable scaling factor, is the Sigmoid function, is the Hadamard product (element-wise multiplication), is hidden state, are dynamically generated state space parameters.
[0129] 3. Distributed Perception Prototype Computing Module (DAPC)
[0130] In order to more accurately represent the distribution of category features, this embodiment proposes a distribution-aware prototype calculation method based on Mahalanobis distance, which not only considers the category center but also captures the distribution characteristics within the category. Each category in , construct a prototype representation consisting of a mean vector and a covariance matrix:
[0131]
[0132] The mean vector For category The average of all sample features:
[0133]
[0134] Covariance matrix Then captures the shape of the feature distribution:
[0135]
[0136] For the single-sample case, the identity matrix is used as the default covariance.
[0137] Query Sample With category c The distance is calculated by the Mahalanobis distance, which takes into account the heterogeneity of the feature space:
[0138]
[0139] At the same time, to improve numerical stability, we add a regularization term to the covariance matrix: ,in is the regularization coefficient.
[0140] MSMPN uses a cross-entropy loss function with a temperature parameter to train the model under a meta-learning framework:
[0141]
[0142] in, Is a learnable temperature parameter that controls the smoothness of the category probability distribution. A smaller Produces a steeper distribution and enhances the discriminative ability of the model; larger This produces a smoother distribution and improves model generalization; represents the support set, which is the set of labeled samples used for prototype calculation. represents the samples and their labels in the support set, and N represents the support set The number of samples in .
[0143] To prevent overfitting, this example adds an L2 regularization term:
[0144]
[0145] The final total loss is:
[0146] .
[0147] The specific implementation process of the construction, training and verification of the MSMPN framework is as follows Figure 4 As shown, the specific steps include:
[0148] Step 1: Experimental data preparation and preprocessing.
[0149] This example uses the latest version of MedMNIST+ to construct a dataset for few-shot medical image classification. MedMNIST+ contains 18 sub-datasets, each covering images of different categories and modalities, and all images are uniformly resized to 128 × 128 pixels. This example selects six representative sub-datasets: PathMNIST (histopathology), DermaMNIST (skin lesions), BreastMNIST (breast ultrasound), OCTMNIST (retinal optical coherence tomography), PneumoniaMNIST (chest X-rays), and OrganCMNIST (organ CT). These sub-datasets feature a highly diverse range of modalities, comprehensively covering the characteristics of medical imaging tasks and providing a foundation for reliable model evaluation in real-world clinical scenarios.
[0150] To evaluate the model's generalization ability on unseen categories, this example designed a cross-dataset meta-learning strategy with non-overlapping category partitioning. This strategy aims to test the model's knowledge transfer capabilities across different medical image processing domains, addressing the practical needs for generalization in clinical practice. Specifically, the meta-learning framework of this experiment is divided into the following three phases:
[0151] (1) Meta-training stage:
[0152] This phase selected nine categories from PathMNIST, including adipose tissue, background, and debris. In addition, two categories, basal cell carcinoma and benign keratosis, were selected from DermaMNIST. Training on these categories provided the model with a rich foundation for learning medical image features.
[0153] (2) Meta-validation: In this phase, two classes, melanoma and melanocytic nevus, were selected from DermaMNIST; the normal class was selected from BreastMNIST; four classes, including choroidal neovascularization and diabetic macular edema, were selected from OCTMNIST; two classes, normal and pneumonia, were selected from PneumoniaMNIST; and the bladder class was selected from OrganCMNIST. Through this validation step, the performance of the model was further evaluated and adjusted.
[0154] (3) Meta-testing phase: This phase focuses on evaluation in a completely new domain, using only 10 categories from OrganCMNIST, including left / right femur, heart, left / right kidney, liver, left / right lung, pancreas, and spleen. These categories do not overlap with those in the training and validation phases and are intended to test the model’s ability to transfer knowledge in a completely new domain.
[0155] This example uses only categories from OrganCMNIST in the test set, focusing on evaluating the model's ability to transfer knowledge learned from multiple medical imaging modalities to a completely unfamiliar domain. This cross-domain evaluation simulates real-world clinical scenarios, validates the model's generalization capabilities to unseen categories, and further demonstrates its practical application value in medical image analysis.
[0156] Step 2: Model initialization and configuration.
[0157] This experiment uses ResNet-12 as the basic feature encoder. The ResNet-12 network structure is as follows Figure 5 This embodiment first conducts extensive training on public datasets to obtain good pre-training weights, which facilitates providing high-dimensional feature input for MSMPN.
[0158] To build a complete MSMPN model, this embodiment implements the following module configuration:
[0159] SSCM: It uses a four-window slicing strategy to segment the input image with a 25% overlap between slices, and designs a learnable position encoding to incorporate spatial position information into the feature representation;
[0160] MSEM: A Mamba model with a state dimension of 16 and an internal feature dimension of 128 for efficient feature sequence processing.
[0161] DAPC: Implemented a prototype calculation method based on Mahalanobis distance, and added a regularization coefficient of 0.1 to ensure numerical stability.
[0162] Step 3: Implement the training process.
[0163] Training was performed using the Adam optimizer, with an initial learning rate of 3e-4 and a cosine annealing strategy for learning rate scheduling. To enhance model generalization, data augmentation techniques such as random rotation (±30°), scaling (0.85-1.15), and brightness and contrast adjustment (±30%) were applied to the support set samples.
[0164] The training batch size was set to 4, and a cumulative gradient update strategy was used to stabilize the training process. Weight decay (1e-4) and label smoothing (0.1) were applied to prevent overfitting. Training was performed on a high-performance computing platform equipped with NVIDIA GPUs, utilizing mixed-precision training techniques to improve computational efficiency.
[0165] The training adopts a meta-learning paradigm, randomly constructing multiple 5-way tasks in each training cycle and training them alternately under 1-shot and 5-shot settings to enhance the model's adaptability under conditions of different sample numbers.
[0166] Step 4: Sequence construction and feature enhancement.
[0167] During the experiment, detailed implementation steps were carried out for the overlapping slicing strategy of the SSCM module:
[0168] (1) Each input image is sliced using a sliding window technique with a window size of 32 × 32 pixels and an overlap rate of 25%.
[0169] (2) Extract feature representation for each slice using a pre-trained feature encoder;
[0170] (3) Add learnable position encoding to integrate spatial position information;
[0171] (4) Use the importance evaluation network to assign a weight score to each slice;
[0172] (5) Applying a spatially aware attention mechanism to comprehensively consider semantic similarity, spatial distance, and importance scores;
[0173] (6) Obtain enhanced feature sequence through weighted aggregation.
[0174] For the MSEM module, a sequence processing flow based on Mamba is implemented:
[0175] (1) Normalize the input layer of the aggregated feature sequence;
[0176] (2) Separate the main path features and residual path features through linear projection;
[0177] (3) Use one-dimensional convolution to extract local feature patterns;
[0178] (4) Apply SSM parameter generation and selective scanning to process sequence data;
[0179] (5) The two-way features are integrated through a gating mechanism to obtain enhanced sequence representation.
[0180] Step 5: Prototype representation and classification decision.
[0181] In the DAPC module, the following steps are implemented to construct a distribution-aware prototype representation:
[0182] (1) For each category of support set samples, calculate the feature mean vector;
[0183] (2) Calculate the covariance matrix of intra-class features to capture the distribution shape;
[0184] (3) Add a regularization term to the covariance matrix to ensure numerical stability;
[0185] (4) For the query sample, calculate the Mahalanobis distance with the prototype of each category;
[0186] (5) Apply the Softmax function with a temperature parameter to obtain the category probability distribution;
[0187] (6) Select the category with the highest probability as the final classification result.
[0188] Step 6: Performance evaluation and ablation experiments.
[0189] In the evaluation phase, 5-way tasks are used to test model performance in both 1-shot and 5-shot settings, with 8 query samples per category. To ensure the reliability of the evaluation results, 600 tasks are randomly generated in each test setting, and the average classification accuracy and its 95% confidence interval are reported.
[0190] To deeply analyze the contribution of each component, this example designed two sets of key ablation experiments:
[0191] 1. Feature dimension impact analysis: Test the model performance under 128-, 256-, and 512-dimensional feature representations respectively;
[0192] 2. Component contribution analysis: Evaluate the importance of each component by removing or replacing the SSCM, MSEM, and DAPC modules.
[0193] In addition, this embodiment comprehensively compares MSMPN with traditional small-sample learning methods (such as prototype networks, relational networks, matching networks, MetaOpt, etc.) to verify its advantages in small-sample classification tasks of medical images.
[0194] The Multi-Slice Mamba Prototype Network (MSMPN) proposed in this paper has achieved multiple technological innovations in the field of few-shot medical image classification, mainly reflected in the following key aspects:
[0195] First, the Semantic Sequence Construction Module (SSCM) is an innovative module specifically designed to address the key characteristics of the Mamba state-space model. To fully leverage its strengths, the Mamba model requires long, semantically rich sequence inputs, which traditional medical image processing methods struggle to provide. The SSCM addresses this core issue through an innovative overlapping slicing strategy, dividing medical images into local regions that maintain spatial continuity and generating long sequence representations suitable for Mamba processing. This module uses a 25% overlap rate to ensure feature continuity in boundary regions, while introducing a learnable positional encoding to preserve spatial information. A spatially aware attention aggregation mechanism is also designed, simultaneously considering semantic similarity between slices, spatial distance relationships, and region importance scores, effectively converting two-dimensional medical images into one-dimensional, long sequence features that can be efficiently processed by Mamba.
[0196] Second, the Mamba-based Sequence Enhancement Module (MSEM) leverages Mamba's selective state-space modeling capabilities to process the long sequences generated by SSCM. Mamba's core strengths lie in its linear computational complexity and data-dependent selection mechanism, enabling it to efficiently process long sequences of features generated by SSCM. This module fuses features from the main and residual paths through a selective scanning process and gating mechanism, effectively capturing long-range dependencies in medical images while maintaining computational efficiency. This is crucial for understanding relevant pathological features scattered across different image regions.
[0197] Third, the Distribution-Aware Prototypical Computation (DAPC) module addresses the problem of representing the complex feature sequences output by Mamba. Because the feature sequences generated by Mamba have complex distributional characteristics, traditional prototypical networks, using only mean representation, cannot fully capture this complexity. DAPC introduces a prototype representation method based on the Mahalanobis distance, taking into account both the mean vector and the covariance matrix. This fully captures the distribution information of Mamba's output features, enabling the model to more accurately distinguish complex categories in medical images. This distribution-aware prototype representation method perfectly matches the rich feature sequences generated by Mamba, providing a more precise decision boundary for few-shot medical image classification.
[0198] By organically combining these innovative technologies, the present invention forms a complete technical chain: SSCM generates long sequence inputs suitable for Mamba processing, MSEM efficiently processes these sequences and extracts complex feature representations, and DAPC accurately characterizes the distribution characteristics of these complex features for classification decisions. This end-to-end architecture, specifically designed for Mamba's characteristics, fundamentally addresses the lack of adaptability of traditional few-shot learning methods in the medical imaging field, providing an efficient, robust, and practical technical path for medical diagnostic assistance systems.
[0199] In order to further illustrate the technical effects of the present invention, the following experimental results are provided.
[0200] First, the experimental environment is shown in Table 1:
[0201] Table 1 Network model training detailed parameters
[0202]
[0203] Table 2 shows the 5-way classification results of the proposed method and baseline methods such as prototype network and relational network on mini-MedMNIST.
[0204] Table 2 Experimental comparison of the present invention and the baseline method
[0205]
[0206] As can be seen from Table 2, the proposed method achieves an accuracy of 53.92% in the 1-shot test, which is slightly lower than MetaOpt, but achieves an accuracy of 68.73% in the 5-shot test, significantly surpassing all compared methods.
[0207] In terms of performance improvement from 1-shot to 5-shot, the accuracy of our method increased by 14.81%, significantly exceeding other methods such as Prototype Networks and MetaOpt. This phenomenon demonstrates that the Mamba architecture design of our invention exhibits greater advantages as the number of samples increases. The MSEM module of our invention, through its efficient linear complexity sequence processing capabilities, can more comprehensively capture the relationship patterns between samples in the multi-sample scenario, resulting in a more significant performance improvement as the number of samples increases.
[0208] While our model performed comparable to other methods in the 1-shot test, its significant advantage in the 5-shot results demonstrates the practical value of our architecture in real-world medical applications. In most real-world medical applications, multiple samples per class are typically available, rather than strictly single samples. The outstanding performance of our model under these practical conditions demonstrates the effectiveness of MSMPN in capturing complex relationships between samples and integrating information from multiple sources.
[0209] The ablation experiment results are shown in Table 3:
[0210] Table 3 Comparison of MSMPN input feature dimensions
[0211]
[0212] The ablation experiment results show that the model achieves the best performance (53.19%) when the feature dimension is 256, rather than the higher dimension of 512 (50.85%) or the lower dimension of 128 (49.55%). This shows that model performance does not always improve with the increase of representation dimension, but there is an optimal point. In the small sample learning scenario, a feature dimension of 256 provides a balance between representation ability and generalization. When the dimension is too low (128), the model lacks sufficient representation ability to capture complex feature relationships; when the dimension is too high (512), the model is prone to overfitting in the case of very few samples, resulting in performance degradation.
[0213] The comparison results of MSMPN component ablation are shown in Table 4:
[0214] Table 4 Comparison of MSMPN component ablation
[0215]
[0216] Ablation experiments on different component combinations further revealed the contribution of each module. When all three core modules, SSCM, MSEM, and DAPC, were used, the proposed model performed best in the 5-shot task. It is particularly noteworthy that when Mamba was replaced by Transformer, the model achieved the highest accuracy (55.49%) in the 1-shot task, indicating that the global self-attention mechanism of Transformer can provide certain advantages in the case of very few samples. However, as the support set samples increase from 1 to 5, the model needs to handle more complex intra-class distribution and variability. At this time, Mamba's efficient sequence processing capability gives it an advantage in integrating multi-sample information.
[0217] Comprehensive analysis shows that the proposed MSMPN framework not only outperforms existing methods but, more importantly, exhibits significant performance improvements with increasing sample size, which has significant practical value in the field of medical image analysis. This advantage stems from the collaborative work of three key components in the MSMPN architecture: SSCM preserves spatial continuity through an overlapping slicing strategy, MSEM leverages Mamba's efficient sequence processing capabilities to capture long-range dependencies, and DAPC improves classification accuracy by considering intra-class distribution characteristics.
[0218] Some steps in the embodiments of the present invention may be implemented using software, and the corresponding software program may be stored in a readable storage medium, such as a CD or a hard disk.
[0219] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A small sample medical image classification method, characterized in that: The following steps are involved: Step 1: Segment the input medical image into a sequence of overlapping slices with spatial context information through a semantic sequence building module; The processing of the semantic sequence building module includes: Given an input image , using a size of Window and overlap ratio To slice: in, and are the steps in height and width respectively, i and j Represents the height and width position index respectively; Step 2: Use the encoder to extract the feature representation of each slice and add position encoding; Step 3: Process the feature sequence through a sequence enhancement module to capture long-range dependencies. The sequence enhancement module uses the Mamba state space model to process the feature sequence. Step 4: construct a category prototype that takes feature distribution into consideration using a distribution-aware prototype calculation module, wherein the distribution-aware prototype calculation module constructs a prototype representation for each category that includes a mean vector and a covariance matrix; Step 5: Use Mahalanobis distance to calculate the distance between the query sample and each category prototype and make a classification decision; The step 2 further comprises: Introducing learnable positional encodings ,in L Indicates the total number of slices, is the slice feature dimension; The position code is added to the features of each slice, which is expressed as: in, represents the enhanced features containing spatial information, Represents the characteristics of the slice, Indicates the first i , j ) slice position codes; Assign each slice a score reflecting its importance to the classification decision: in, represents the importance evaluation network, Indicates the i Spatial enhancement features of each slice; Calculate attention weights: in, Indicates that the spatial relationship matrix is constructed based on the distance between the center points of the slices. Used to control the influence of importance, Respectively represent i Slice enhancement features and j Slice enhancement features, represents the semantic similarity of slice features, Represents a slice i With slices k The spatial relationship matrix elements of; Finally, the enhanced feature sequence is obtained through weighted aggregation: in, represents the enhanced feature sequence after weighted aggregation, B Indicates the batch size.
2. The small sample medical image classification method according to claim 1, characterized in that: The step 3 comprises: Step 31: normalize the aggregated feature sequence input layer; Step 32: Separate the main path features and the residual path features through linear projection; Step 33: Use one-dimensional convolution to extract local feature patterns; Step 34: Apply SSM parameters to generate and selectively scan sequence data; Step 35: Integrate the two features through a gating mechanism to obtain an enhanced sequence representation.
3. The small sample medical image classification method according to claim 1, characterized in that: The calculation method of the Mahalanobis distance is: in, represents a query sample, Represents the category prototype, Representation category c The mean of all sample features, Representation category c The covariance matrix of all sample features.
4. The small sample medical image classification method according to claim 3, characterized in that: It also includes adding a regularization term to the covariance matrix: ,in, is the regularization coefficient, and I represents the identity matrix.
5. The small sample medical image classification method according to claim 1, characterized in that: The method adopts a cross entropy loss function with a temperature parameter to train the model under the meta-learning framework. The cross entropy loss function is expressed as: in, is a learnable temperature parameter that controls the smoothness of the category probability distribution; represents the support set, i.e. the set of labeled samples used for prototype calculation, Representation support set The samples and their labels in N Representation support set The number of samples in .
6. The small sample medical image classification method according to claim 5, characterized in that: Add an L2 regularization term to the cross entropy loss function: in, Represents the L2 regularization coefficient, which is used to control the weight of the parameter norm penalty term. Represents the set of all trainable parameters of the model; The final total loss is: 。 7. A small sample medical image classification system, characterized by: The system is used to implement the small sample medical image classification method according to any one of claims 1 to 6, comprising: An image acquisition module, used for acquiring medical images to be classified; A semantic sequence building module for segmenting medical images into overlapping slice sequences with spatial context information; The processing of the semantic sequence building module includes: Given an input image , using a size of Window and overlap ratio To slice: in, and are the steps in height and width respectively, i and j Represents the height and width position index respectively; A feature extraction module that uses an encoder to extract feature representations for each slice and adds positional encoding; A sequence enhancement module is used to process feature sequences and capture long-range dependencies. The sequence enhancement module uses a Mamba state space model to process the feature sequences. A distribution-aware prototype calculation module is used to construct a category prototype that takes feature distribution into consideration. The distribution-aware prototype calculation module constructs a prototype representation for each category that includes a mean vector and a covariance matrix. The classification decision module uses Mahalanobis distance to calculate the distance between the query sample and the prototype of each category and make classification decisions.
8. A small sample medical image classification device, characterized in that: including memory and processor; The memory is used to store computer programs; The processor is configured to implement the small sample medical image classification method according to any one of claims 1 to 6 when executing the computer program.
9. A computer-readable storage medium, characterized in that The storage medium stores a computer program, and when the computer program is executed by the processor, the small sample medical image classification method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Small sample medical image classification method and system and storage medium
CN118429724A
Multi-class welding spot defect classification method, system and equipment based on Transform and channel interaction and medium
CN119851043A