Full-view digital slice image classification method based on spatial context perception

By introducing the Segment Anything Model (SAM) into the full-field digital slice image classification method to extract spatial context information, and combining the group mask strategy and pseudo-packet consistency loss constraints of the multi-instance learning model, the existing technology solves the problem of ignoring spatial context. problem, significantly improving the performance of image classification and the ability to identify tissue structures.

CN118570534APending Publication Date: 2024-08-30CHONGQING UNIV
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202410675507.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-29
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

Existing full-field digital slice image classification methods ignore the spatial context between image blocks when dealing with high-resolution backgrounds, resulting in insufficient recognition of tissue structure and pathological changes.

Method used

A full-field digital slice image classification method based on spatial context awareness is adopted to extract spatial context information through Segment Anything Model (SAM). Combined with the multi-instance learning (MIL) model, the group mask strategy and pseudo-packet consistency loss constraints are introduced to enhance Model utilization of spatial context.

Benefits of technology

Significantly improves the performance of image classification, enhances the ability to understand and identify spatial relationships in pathological slices, reduces the model's dependence on local features, and improves the ability to analyze tissue structure.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118570534A
    Figure CN118570534A
Patent Text Reader

Abstract

The invention discloses a full-view digital slice image classification method based on spatial context awareness, which comprises the following steps: data preprocessing: segmenting each WSI through SAM to obtain segmentation prior information, and carrying out blocking post-processing on the WSI to obtain image block features and combined features, splicing all the block features and the combined features to obtain a feature file corresponding to the WSI; performing instance level and packet level processing on the feature file, and inputting the processed instance into a model to train an SAM-MIL model; and finally, a feature file corresponding to a new full-view digital slice image WSI is obtained firstly, image block features and combined features in the feature file corresponding to the WSI are all input into the trained SAM-MIL model, a classification result # imgabs0 # of the WSI is obtained through reasoning, and it can be known through experiments that the method is high in image classification accuracy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a full-view digital slice classification method, and in particular to a full-view digital slice multi-instance learning classification method based on spatial context perception. Background Art

[0002] In modern medicine, especially in the field of cancer treatment, the analysis of histopathological images is considered the gold standard for diagnosis, which is crucial for the diagnosis of cancer. The digitization of pathological images into whole slide images (WSIs) by digital pathology slide scanners has opened up a new way for computer-assisted analysis. Given the huge dimensionality of WSIs and the lack of detailed pixel annotations, multiple instance learning (MIL) methods are usually used to analyze histopathological images, where MIL is used as a weakly supervised learning paradigm. MIL divides each WSI (called a bag) into many image patches or instances, and only bag-level labels are required for training. MIL-based WSI classification methods mainly follow three steps: 1) instance feature extraction, 2) instance feature aggregation, and 3) bag prediction.

[0003] Although the MIL model simplifies the problem by segmenting the image into small patches for independent feature extraction, this approach essentially ignores the global spatial context between patches. Since each patch is processed independently and features are extracted in isolation, the MIL model tends to focus only on local features. This lack of spatial context is detrimental to understanding tissue structure, identifying pathological changes, and classifying diseases in the ultra-high resolution context of WSIs. For example, some pathological features may span multiple patches and can only be correctly identified and interpreted when the spatial relationship between these patches is considered. Pathologists consider the spatial layout of tissues and the relationship between adjacent patches when analyzing WSIs to identify tumor markers and understand pathological processes. However, the MIL models described previously did not focus on how to recover and utilize the spatial context lost during the patch segmentation process, but were directly trained using patch features. Some studies are attempting to reconstruct spatial context. For example, Chen et al. conceptualized full-field digital slide images as 2D point clouds, and a patch-based graph convolutional network learned implicit context-aware embeddings by leveraging the spatial relationship between patches to facilitate context-aware survival prediction. Bai et al. introduced a novel framework to use Transformer for object localization, implicitly capturing spatial context via the diffusion activation technique. But in current MIL models, the reconstruction of spatial context is mainly done implicitly. However, these methods often fail to fully exploit the richness of spatial context information. This implicit use of spatial context may underestimate the critical role of spatial relations in tissue structure analysis and tumor diagnosis.

[0004] Therefore, it is crucial to effectively integrate spatial context information into MIL and use raw image-level features to guide model training. Due to the rapid development of large models in recent years, large models have greatly revolutionized the application of traditional artificial intelligence in various fields including medicine, thanks to their excellent zero-shot and few-shot generalization capabilities in downstream tasks. Among them, as a pioneering visual segmentation large model, Segment Anything Model (SAM) can be directly applied to the analysis of WSIs, providing additional, semantically irrelevant visual segmentation prior features without further training or fine-tuning. The high-quality segmentation features provided by SAM make it an excellent tool for extracting spatial context from raw WSIs. However, due to the unique difficulties of medical images (traditional visual large models are mainly trained on non-medical datasets), the effectiveness of SAM in medical imaging still needs to be explored. Although a large number of works have introduced SAM into the field of medical images, they mainly focus on low-resolution image segmentation tasks. Many of these works are still behind the current mainstream methods, proving that we still need to fine-tune the SAM model or provide appropriate prompts. The direct application of SAM to medical imaging tasks is often limited by the generalization ability, which varies significantly across different datasets and tasks. Summary of the invention

[0005] In view of the above problems existing in the prior art, the technical problem to be solved by the present invention is: how to skillfully use the segmentation prior information provided by SAM to improve the classification performance of WSIs.

[0006] In order to solve the above technical problems, the present invention adopts the following technical solution: a full-view digital slice image classification method based on spatial context perception, comprising the following steps:

[0007] S1: Data preprocessing: Obtain N publicly available labeled full-view digital slice images WSIs to form dataset B;

[0008] S1-1: For each full-view digital slice image WSI, the foreground and background are segmented and the coordinates of the foreground and background are retained.

[0009] S1-2: Segment the tissue in each foreground image to obtain several tissues, and save each tissue and its corresponding coordinates. Each tissue is first divided into several blocks, and each block is put into the pre-trained feature extractor for feature extraction to obtain block features.

[0010] Each foreground is compressed and input into SAM for segmentation. The visual segmentation results of several regions are obtained and saved. The visual segmentation results include the coordinate information of the region and the area of ​​the segmented region. Each region represents a class. The feature extraction of the region corresponding to each class is performed to obtain the combined features of the class.

[0011] The tile features and combined features obtained in the previous operation are called instances, and the instances extracted from the same WSI will be integrated into the same package, that is, when there are one or more disease instances in a package, the entire package will be marked as a disease.

[0012] All the tile features and combined features are spliced ​​together to obtain the feature file corresponding to WSI.

[0013] S2: SAM-MIL model training stage;

[0014] S2-1: Instance level processing of feature files:

[0015] Read in all tile features and combined features in the i-th feature file, trace back the original coordinates of each tile feature in WSI, and group the tile features according to the segmentation class of SAM. If the original coordinates of the four corners of the tile feature are all located in a type of area segmented by SAM, the tile features are divided into the same group.

[0016] A dynamic mask ratio is determined for each group, and a mask operation is performed on the tile features in the group according to the dynamic mask ratio. All tile features after the mask operation are concatenated and then added to all tile features that have not been masked to obtain the combined features corresponding to the WSI. The combined features corresponding to the WSI are defined as the training feature data.

[0017] Input the training feature data corresponding to WSI into the SAM-MIL model to obtain the classification loss

[0018] S2-2: Package-level processing of feature files: read all tile features in the i-th feature file, and all tile features first pass through the forward propagation of the SAM-MIL model to obtain a global attention weight attn i .

[0019] All the tile features in the i-th feature file are randomly divided into m pseudo packages. The label of each pseudo package inherits the label of the corresponding WSI. Each pseudo package is input into the SAM-MIL model in turn to obtain the classification loss of m pseudo packages. The average of these losses is the pseudo package classification loss of the i-th feature file.

[0020] According to the classes defined for tile features in S2-1, the consistency loss is calculated for the attention weights corresponding to the tile features in each class. The consistency loss of each class is summed to obtain the consistency loss constraint of the global spatial context of the i-th feature file.

[0021] S2-3: The optimization loss of the SAM-MIL model is This optimized loss is back-propagated in the model to optimize the parameters of the SAM-MIL model. When the loss no longer decreases, the trained SAM-MIL model is obtained. α and β are scaling factors.

[0022] S3: Inference stage: For a new full-view digital slice image WSI, the method in S1 is used to obtain its corresponding feature file. All the block features and combined features in the feature file corresponding to WSI are input into the trained SAM-MIL model, and the classification result of WSI is obtained by inference.

[0023] Furthermore, in S1-2, the method for extracting the combined features is:

[0024] Let S = {s1,s2,…,s l} represents the output of SAM, where l represents the segmentation area of ​​SAM. For each segmentation area s r , combined feature g r The extraction is as follows:

[0025]

[0026] in is an average aggregation function, represents the jth instance in the i-th package, s r Represents the rth segmentation region in a WSI.

[0027] Furthermore, in S2-1, the mask operation method is: using a group masking strategy under the guidance of SAM based on spatial context to mask the instance features, such as formula (5):

[0028]

[0029] Among them, M p is the patch mask determined by the SAM information, ⊙ represents the Hadamard product, e p is the masked patch feature embedding, They refer to feature extraction functions that add spatial context information. k is the instance in the kth bag that is retained after masking, B kFor the kth package, the definition is the same as before, k and i are just for traversal definition subscripts; represents the jth instance of the kth package;

[0030] Instances are classified into groups {G1, G2, …, G z}. Each instance p i Assigned to group G according to the class to which it belongs k In the distribution p i →G k Indicates p i The category index is k. k ,definition is the area of ​​the group category k. Processed by adjusting the sigmoid function To calculate the normalized ratio for each group

[0031]

[0032] where σ adj is the adjusted sigmoid function with slope a and center point offset b, which control the slope and horizontal displacement of the sigmoid curve respectively. Then the normalized ratio Multiply by the target mask ratio MR provided as input target , to calculate the dynamic mask ratio for each segment group

[0033]

[0034] The mask for each group is then calculated and aggregated to create a combined mask M for all instances comp :

[0035]

[0036] Finally, the combined mask M comp Applies to all instances

[0037] I k =Mask(B k ,M comp ) (14)

[0038] Among them, Mask(·,·) is a masking operation on the instance.

[0039] Furthermore, in S2-1, the mask operation method is: in S2-1, the classification loss The calculation method is:

[0040]

[0041] in represents the loss function of the SAM-MIL model, and Y is the label inherited from WSI (Ground Truth). Represents the prediction results output by the SAM-MIL model at the instance level.

[0042] Furthermore, in S2-1, the mask operation method is: in S2-2, the pseudo packet classification loss The calculation method is:

[0043]

[0044] in represents the loss function of the SAM-MIL model, P i represents the instance features in the ith pseudo-bag, and Y is the label inherited from WSI, and They refer to the classification function and feature aggregation function with added spatial context information, respectively. n means there are n WSIs in total, and represents the total number of WSIs.

[0045] Furthermore, in S2-1, the mask operation method is: in S2-2, the consistency loss constraint The calculation method is:

[0046]

[0047] Where sim represents the attention weight attn i and attn j The similarity function between them, and δ is a Kronecker function. If the segmentation category s i and j If they are the same, then it is equal to 1, otherwise it is 0. The attention weight comes from the attention mechanism of the SAM-MIL model, and s i and j is the segmentation category from SAM, N means there are N instances in the package corresponding to each WSI. represents the total number of features in a feature file.

[0048] Compared with the prior art, the present invention has at least the following advantages:

[0049] In this paper, we propose a spatial context-aware full-view digital slide image classification method named SAM-MIL, which aims to mine and utilize spatial context information from pathological slides to enhance the MIL model. As a large segmentation model, SAM can obtain and encode prior visual context knowledge in space and appearance. The original pathological slides are segmented with this knowledge obtained by the SAM model, so as to explicitly model the instance relationship based on proximity and visual similarity, which is called "spatial context". Using this spatial context knowledge, a SAM-guided grouping mask scheme is given. The grouping mask scheme groups according to their visual segmentation categories, thereby filtering out redundant instances to alleviate the extreme distribution imbalance of instances. At the same time, in order to reduce the risk of typical feature loss caused by instance masking, the instances in the categories segmented by SAM are aggregated as a category feature and added to the retained instances to compensate for the information loss caused by the mask. In addition, SAM-MIL divides the instances to create additional pseudo-packets to increase the training set, and introduces spatial context consistency between pseudo-packets to further improve the model. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] Figure 1 It is the overall framework diagram of the method of the present invention.

[0051] Figure 2 FIG. 4 is a schematic diagram of an example-level mask operation of the present invention.

[0052] Figure 3 This is the pseudo-package and consistency constraints at the package level of the present invention.

[0053] Figure 4 This is a flow chart of WSIs preprocessing of the present invention.

[0054] Figure 5 The performance improvement diagram of the combined features.

[0055] Figure 6 Visualize the segmentation effect of SAM as a segmentation model in the original slice.

[0056] Figure 7 This is the visualization result of the model in the dataset (based on the predicted disease probability). DETAILED DESCRIPTION

[0057] This paper demonstrates that explicit spatial context information is beneficial for MIL classification, and that independent local features may cause the model to ignore the connections between patches and higher-level organizational structural relationships. To address this issue, a visual segmentation base model (SAM) is adopted to introduce spatial context by extracting spatial context information from the image hierarchy in WSI. Meanwhile, multiple components are designed to explicitly introduce the extracted spatial context into the MIL model to guide the classification of WSI. Specifically, we develop a SAM-guided group masking strategy to mask instances with spatial context information and extract representative group features from each category, thereby compensating for the information loss caused by the masking operation and providing macro-feature information. In addition, we introduce a spatial context-based consistency loss constraint to enhance the spatial context information during pseudo-bag training. Experimental results show the superiority and versatility of the SAM-MIL framework relative to other methods, and further demonstrate the positive impact of the explicitly introduced spatial context on the MIL model.

[0058] See also Figure 1 , a full-view digital slide image classification method based on spatial context perception, comprising the following steps:

[0059] S1: Data preprocessing: Obtain N publicly available labeled full-view digital slice images WSIs to form dataset B;

[0060] S1-1: Segment the foreground and background of each full-field digital slice image WSI, and retain the coordinates of the foreground and background;

[0061] S1-2: Segment the tissue in each foreground image to obtain several tissues, and save each tissue and its corresponding coordinates. Each tissue is first divided into several 512*512 pixel tiles, and each tile is put into the pre-trained feature extractor for feature extraction [using the existing network] to obtain the tile features;

[0062] Each foreground is compressed and input into SAM for segmentation. The visual segmentation results of several regions are obtained and saved. The visual segmentation results include the coordinate information of the region and the area of ​​the segmented region. Each region represents a class. The feature extraction of the region corresponding to each class is performed to obtain the combined features of the class.

[0063] The tile features and combined features obtained in the previous operation are called instances, and the instances extracted from the same WSI will be integrated into the same package, that is, when there are one or more disease instances in a package, the entire package will be marked as a disease. The purpose is actually to avoid pixel-level annotation, and only retain package-level annotations without worrying about whether each pixel is a disease. The pixel-level labeling process in ultra-high-resolution WSI is time-consuming and labor-intensive, which poses a challenge to traditional deep learning methods that rely on pixel-level labeling in computational pathology. In order to meet such challenges, multiple instance learning (MIL) has been widely introduced into WSI analysis. Multiple instance learning can regard this problem as a weakly supervised learning problem. MIL divides each WSI (called a package) into many tiles or instances, and only package-level labels are required for training.

[0064] All the tile features and combined features are spliced ​​together to obtain the feature file corresponding to WSI.

[0065] S2: SAM-MIL model training phase.

[0066] S2-1: Instance level processing of feature files.

[0067] Read in all the tile features and combined features in the i-th feature file, trace back the original coordinates of each tile feature in WSI, and group the tile features according to the segmentation class of SAM (that is, the tiles in one category in the original WSI image will now be grouped in one group). If the original coordinates of the four corners of the tile feature are all located in a category of area segmented by SAM, the tile features will be divided into the same group.

[0068] A dynamic mask ratio is determined for each group, and a mask operation is performed on the tile features in the group according to the dynamic mask ratio. All tile features after the mask operation are concatenated and then added to all tile features that have not been masked to obtain the combined features corresponding to the WSI. The combined features corresponding to the WSI are defined as the training feature data.

[0069] The tile features of each group can be calculated according to the segmented area of ​​the SAM of this type through an adjusted sigmoid function to obtain a dynamic mask ratio (that is, groups with larger areas or more tile features will be assigned higher mask ratios), and then each category in this feature file is traversed to obtain a dynamic group mask ratio. The dynamic mask ratio is applied to each tile feature combination for masking. The masked tile feature groups are reassembled and combined with the unmasked combined features to merge into complete training feature data.

[0070] Input the training feature data corresponding to WSI into the SAM-MIL model to obtain the classification loss

[0071] S2-2: Packet-level processing of signature files

[0072] Read all the tile features in the i-th feature file. All tile features first pass through the forward propagation of the SAM-MIL model to obtain a global attention weight attn i .

[0073] All the tile features in the i-th feature file are randomly divided into m pseudo packages. The label of each pseudo package inherits the label of the corresponding WSI. Each pseudo package is input into the SAM-MIL model in turn to obtain the classification loss of m pseudo packages. The average of these losses is the pseudo package classification loss of the i-th feature file.

[0074] According to the classes defined for tile features in S2-1, the consistency loss is calculated for the attention weights corresponding to the tile features in each class. The consistency loss of each class is summed to obtain the consistency loss constraint of the global spatial context of the i-th feature file.

[0075] S2-3: The optimization loss of the SAM-MIL model is This optimized loss is back-propagated in the model to optimize the parameters of the SAM-MIL model. When the loss no longer decreases, the trained SAM-MIL model is obtained. α and β are scaling factors.

[0076] S3: Inference stage: For a new full-view digital slice image WSI, the method in S1 is used to obtain its corresponding feature file. All the block features and combined features in the feature file corresponding to WSI are input into the trained SAM-MIL model, and the classification result of WSI is obtained by inference.

[0077] 2. The method of the present invention is described in detail below.

[0078] In the multi-instance learning (MIL) paradigm, a dataset B is a scene consisting of multiple bags, represented as B = {B1, B2, ..., B N}, each package consists of N instances In a D-dimensional feature space, i = 1, 2...N. In the classification task, each bag is associated with a predetermined label Y, and each instance B in the bag i With unspecified label y i If a bag contains at least one positive example, the bag is classified as positive; otherwise, it is considered negative.

[0079] Multi-instance learning model The learning goal is to infer the label of a bag by considering the information embedded in its instances, as shown in Formula (1):

[0080]

[0081] in It is a feature extraction function that converts each instance into a low-dimensional feature representation; It is a feature aggregation function that synthesizes the extracted features into a package representation; is a classification function that predicts the label of a package from the aggregated feature representation, It represents the jth instance in the i-th package, which can also be understood as the j-th feature in the feature file corresponding to the i-th WSI image. Indicates B i The predicted label of .

[0082] However, the traditional multi-instance learning paradigm mainly focuses on the extraction of local features, resulting in a large neglect of spatial context. In this paper, we will explicitly introduce spatial context through the spatial attention model SAM in the feature extraction stage and feature aggregation stage to guide model training:

[0083]

[0084] Where SAM represents the method guided by the spatial context information extracted by SAM. The multi-instance learning model, namely the MIL model, represents SAM to extract spatial context information. and They refer to the classification function, feature aggregation function and feature extraction function that add spatial context information respectively.

[0085] As attached Figure 2 As shown in Figure 3, we introduce a new multi-instance learning model approach to enhance classification performance by integrating spatial context. Previous works mainly exploited local patch features of WSIs, ignoring the potential of global visual contextual content. To address this issue, we integrate the spatial context from SAM into our MIL framework. Specifically, we design a combined feature extractor that not only includes the traditional feature extraction stage, but also utilizes the segmentation results from SAM to extract representative combined features from each segmented region. Let S = {s1,s2,…,s l} represents the output of SAM, where l represents the segmentation area of ​​SAM. For each segmentation area s r , combined feature g r The extraction is as follows:

[0086]

[0087] in is an average aggregation function used to extract combined features from each segmented region. represents the jth instance in the i-th package, s r represents the rth segmentation region in a WSI, which can also be understood as the jth feature in the feature file corresponding to the i-th WSI image. These combined features are then integrated into the training process of the MIL model as special tags.

[0088]

[0089] This enables our MIL model to capture the complex spatial context of the image, thus improving the classification performance. By leveraging the patch features extracted in the instance feature extraction stage and the SAM segmentation, we can incorporate the spatial context of SAM in two levels in the instance feature aggregation stage.

[0090] At the instance level, similar and redundant patches in WSIs compromise the richness in the original slices, which may cause the MIL model to over-focus on trivial details. This focus on non-essential information may have an adverse impact on the generalization ability and overall efficiency of the model. Therefore, we adopt a group masking strategy guided by SAM based on spatial context to mask instance features and alleviate the class imbalance problem in WSIs, as shown in Formula (5):

[0091]

[0092] Among them, M p is the patch mask determined by the SAM information, ⊙ represents the Hadamard product, e p is the masked patch feature embedding, and I represents the instance feature. k is the instance in the kth bag that is retained after masking, B k For the kth package, the definition is the same as before, k and i are just for traversal definition subscripts; represents the jth instance of the kth package.

[0093] At the bag level, SAM-MIL pseudo-bags all tile features in the feature file and constrains the model training through the spatial context consistency between these bags. Considering the scarcity of labels, we introduce a method to create synthetic diversity in training data. Instance features are randomly assigned to m pseudo-bags as shown in the following equation:

[0094]

[0095] Among them is the feature set of each pseudo-package.

[0096] Based on the above, we can leverage the corresponding SAM segmentation information to enhance model optimization at two levels, and describe the implementation of each component of this approach in detail below.

[0097] At the instance level, we introduce a large-scale instance masking strategy, called the group masking strategy guided by SAM, which aims to filter out instances that have a significant impact on the final classification task. Given that there are a large number of similar and redundant instances in WSIs, these repeated information may cause the MIL model to over-focus on unimportant details, thereby damaging the generalization ability and efficiency of the model. Therefore, the goal of the masking strategy is to reduce the impact of these unimportant instances and ensure that the model focuses on key areas. The specific scheme diagram can be seen in Figure 2 Specifically, we have the following three strategies:

[0098] Random mask strategy: Figure 2 As shown in (a) and (b), we introduce two parallel random masking methods. The first is "random masking of all features", which randomly masks the entire feature set to reduce the influence of certain instances, thereby reducing redundant information. The second strategy is "random masking of non-combinatorial features", which selectively masks only the features of common instances that are not included in the combined features. This method strives to preserve the important structural information identified by SAM.

[0099] Grouped masking strategy guided by SAM: Since the redundancy of different types of patches in a slide varies, adopting direct fair masking without considering these factors may aggravate the scarcity of already scarce patches.

[0100] Therefore, we group all patches based on the spatial context provided by SAM, assigning each group a dynamic mask ratio according to the area information evaluated by SAM. Figure 2 A more sophisticated masking method is shown in (c). First, instances are classified into groups {G1, G2, …, G z}. Each instance p i According to the segmentation category to which it belongs, it is assigned to group G k In the distribution p i →G k Indicates p i The category index is k. For each segment group G k , we define is the area of ​​the group category k. We process it by adjusting the sigmoid function To calculate the normalized ratio for each group

[0101]

[0102] where σ adj is the adjusted sigmoid function with slope a and center point offset b, which control the slope and horizontal displacement of the sigmoid curve respectively. Then the normalized ratio Multiply by the target mask ratio (MR) provided as input target ) to calculate the dynamic mask ratio for each segment group

[0103]

[0104] This ratio defines the extent to which features in each segment group will be masked.

[0105] The mask for each segment group is then calculated and aggregated to create a combined mask M for all instances comp :

[0106]

[0107] Finally, the combined mask M comp Applied to all instances, all instances that need to be masked are filtered out, and then a mask operation is performed on all instances at one time, that is, the feature instances that need to be masked in the group of features are filtered out according to the dynamic mask ratio, and the masks filtered out from all groups are merged, and then these masks are applied to all tile features.

[0108] I k =Mask(B k ,M comp ), (26)

[0109] Among them, Mask(·,·) is a masking operation on the instance.

[0110] At the package level, we effectively enlarge the training dataset by splitting the instance features of WSIs into multiple pseudo packages. Each pseudo package inherits the label of its source slide, thereby preserving the ground truth in the expanded dataset. This splitting into pseudo packages maximizes the use of available data, reduces model overfitting, and enhances the learning potential of the model. These pseudo packages are then passed through the MIL model individually for optimization. Figure 3 As shown, the average training loss of all pseudo bags is calculated and used as the aggregate loss for model training, which is expressed by the following equation:

[0111]

[0112] in Represents the loss function of the MIL model, P i represents the instance features in the ith pseudo bag, and Y is the label inherited from WSI. and They refer to the classification function and feature aggregation function with added spatial context information, respectively. n means there are n WSIs in total, and represents the total number of WSIs.

[0113] In addition to the classification loss, we also add a consistency constraint based on the segmentation category information obtained from SAM, see Figure 3 This constraint is based on the premise that the global attention weights assigned by the model to patches within the same segmentation category should be more similar, thereby enhancing the model's interpretability and robustness to potential pathologies. The consistency loss is calculated as follows:

[0114]

[0115] Where sim represents the attention weight attn i and attn j The similarity function between them, and δ is a Kronecker function. If the segmentation category s i and j If they are the same, then it is equal to 1, otherwise it is 0. The attention weight comes from the attention mechanism of the MIL model, and s i and j is the segmentation category from SAM, N means there are N instances in the package corresponding to each WSI. represents the total number of features in a feature file.

[0116] Classification Loss The calculation method is:

[0117]

[0118] in represents the loss function of the SAM-MIL model, and Y is the label inherited from WSI (GroudTruth), Represents the prediction results output by the SAM-MIL model at the instance level.

[0119] In summary, the instance-level and bag-level losses, as well as the consistency loss, are aggregated to achieve overall model optimization, thereby ensuring that the attention mechanism is guided not only by the classification objective of MIL but also by the spatial context information extracted by SAM.

[0120]

[0121] where α and β are scaling factors.

[0122] The MIL framework implemented in this work is built on the widely recognized and used AB-MIL. This architecture allows the model to effectively focus on the image regions that are most critical to the final classification judgment through the attention mechanism, while further enhancing the model's understanding and processing capabilities of tissue structure by introducing spatial context information obtained from SAM.

[0123] The WSI data used in the present invention requires certain preprocessing. In order to integrate the segmentation of SAM into the preprocessing workflow of WSIs, it is necessary to adjust the traditional preprocessing process, as shown in the attached Figure 4 We modified the data preprocessing process of CLAM and divided the preprocessing workflow of WSIs into three stages: foreground segmentation, block & SAM segmentation, and feature and SAM information extraction.

[0124] Foreground segmentation: This stage is strictly performed according to the CLAM procedure to achieve automatic segmentation of tissue areas, fill small gaps and holes, store contours, and create analysis files.

[0125] Blocking and SAM Segmentation: After completing the foreground segmentation, for each slice, our algorithm finely crops a 512×512 image patch within the segmented foreground contour. It uses the hierarchical structure of HDF5 to store image patches and their coordinates and slice metadata in a stacked data format. In addition, each slice is segmented using SAM within the segmented foreground, and the segmentation information is saved in the HDF5 format.

[0126] Feature and SAM information extraction: For each slice, we use a deep convolutional neural network (ResNet50 model pre-trained on ImageNet or other feature extractors) to calculate the local feature representation of each image block, converting each 512×512 block into a 1024-dimensional feature vector. In addition to the original feature extraction, the SAM segmentation information saved in the previous stage is used to extract global features representing each segmentation category for each region within the classification area, called group features, and explicitly annotated and saved in the feature file. In addition, the area information of each block in the SAM segmentation is also recorded to provide guidance for subsequent training.

[0127] To ensure high-quality segmentation and extraction of relevant tissue blocks, as well as ease of use, we have integrated the foreground segmentation and patching with the SAM segmentation stage into a single process. Under user-defined parameters, we will segment and create image patches for the original WSI slices, and then use SAM to segment the foreground area of ​​each slice. This integrated process will produce five different types of output files: image masks in H5 format, patch coordinate information Patches in H5 format, SAM segmentation information Segments stored in PKL format, image patch stitches in H5 format, and slice comprehensive information Process List in CSV format.

[0128] After the output of the first step, the second stage will use the pre-trained model to perform feature extraction on each segmented block independently and extract the group features of SAM. This stage will produce three different types of files: h5_files in H5 format, storing coordinates and extracted features; pt_files in PT format, containing only the features of the tiles; and seg_files in H5 format to save the segmentation information of SAM.

[0129] In subsequent training, our MIL framework will require the feature files of each block and the segmentation results of SAM, as well as their respective segmented regions.

[0130] In addition to the standard process, we also provide options to generate the required pt and seg files from h5_files, Segments, and Process List, as well as options to generate these files from the original pt_files, Segments, and Process List. This design makes our preprocessing workflow applicable to already extracted tile features, reducing the time for repeated feature extraction.

[0131] 4. Experiment and Analysis

[0132] 4.1 The test dataset of the present invention selects two datasets CAMELYON-16 and TCGA-NSCLC that are widely used in the field of WSIs classification.

[0133] The CAMELYON-16 dataset is proposed for breast cancer metastasis detection research. The dataset contains a total of 400 whole slice images (WSIs), which are officially divided into 270 training samples and 130 test samples, with the test samples accounting for about one-third of the total. In accordance with the widely used practice before, we adopted a three-fold cross-validation method to reduce the impact of data segmentation and random seeds on model evaluation, ensuring that each slice is used in the training and testing stages. Under this arrangement, each fold contains approximately 133 slices. Based on the results of three iterations, we report the mean and standard deviation of the performance indicators.

[0134] The TCGA-NSCLC dataset covers two specific lung cancer subtypes: lung adenocarcinoma (LUAD) and squamous cell lung cancer (LUSC). It includes 541 diagnostic whole-slide images of LUAD from 478 different cases, and 512 slides of LUSC, also from 478 cases. We applied a 5-fold cross-validation strategy to this dataset to ensure a comprehensive evaluation. The results are summarized by the mean and standard deviation of the performance metrics of the five test folds.

[0135] Following previous work, we crop each WSI into a series of non-overlapping patches of 512 × 512. Background regions, including holes, are discarded following the preprocessing method of CLAM.

[0136] 4.2 The performance of our model is evaluated using accuracy, area under the curve (AUC), and F1 score. AUC is the main performance indicator in the binary classification task, so we only report AUC and F1 scores in the ablation experiments. We use the ResNet50 model pre-trained on ImageNet-1k as the backbone network and extract an initial feature vector from each block with a dimension of 1024. The last convolution module of ResNet50 is removed, and global average pooling is applied to the final feature map to generate the initial feature vector. The initial feature vector is then reduced to 512 dimensions through a fully connected layer. In order to verify the reliability of the extracted combined features, we experimented with the features extracted by ResNet50 and PLIP respectively. The feature extraction process of PLIP follows the specifications outlined in the official repository. All models are trained for 200 cycles and an early stopping strategy is adopted. All experiments are performed using NVIDIA GPU. The main performance experiment comparisons are shown in Table 1:

[0137] Table 1: Performance of different MIL methods on CAMELYON-16 (C16) and TCGA lung cancer (TCGA). Accuracy and F1 score are determined by the optimal threshold. *MHIM-MIL and IBMIL are two-stage methods and require additional pre-training or clustering operations.

[0138]

[0139] We mainly compare with the following models: AB-MIL, DSMIL, CLAM-SB, CLAM-MB, TransMIL, DTFD-MIL, IBMIL, and MHIM-MIL. In addition, we also compare two traditional MIL pooling operations, namely Max-pooling and Mean-pooling. Due to the difference in datasets, the results of all other methods are reproduced using the provided official code under the same settings.

[0140] As shown in Table 1, most MIL models in WSI classification tasks focus on how to better utilize local patch features for learning, and many effective models have been designed to improve performance. For example, MHIM enhances the training of student models by mining hard examples during training and masking examples based on attention scores. However, previous works did not explicitly introduce spatial context; instead, all modeling relied solely on local patch features. The models only focus on the visual features within each patch obtained by slicing, which may lead to performance degradation. Our proposed SAM-MIL explicitly incorporates spatial context and achieves significant performance improvements on both datasets (96.08% AUC on CAMELYON-16 and 96.01% AUC on TCGA) by leveraging the segmentation prior information of SAM to guide training. Its performance exceeds that of MHIM and IBMIL, which require two-stage training, highlighting the importance of spatial context information for model training. This not only shows that directly introducing spatial context has a positive effect on model training, but also reflects that our designed model can effectively utilize additional spatial context to help model training.

[0141] 4.3 In the ablation experiment, we first tested the effectiveness of each component. The experimental results are shown in Table 2:

[0142] Table 2: Functions of various components in the SAM-MIL model

[0143]

[0144] Table 2 shows the effects of different components in SAM-MIL on two datasets. The baseline of the experiment adopts AB-MIL, which is widely used in WSI tasks. First, an instance-level SAM-guided grouping mask strategy is introduced to group instance features using the spatial context extracted by SAM. This strategy brings an AUC improvement of 2.01% and 1.45% on CAMELYON-16 and TCGA, respectively, which proves the effectiveness of the instance grouping mask strategy. The performance of different mask strategies in this part will be discussed in detail later. In addition, the discussion will also explore the various area calculation functions used in the grouping mask strategy. After introducing packet-level pseudo-packet partitioning and consistency loss based on spatial context, these methods bring an AUC improvement of 1.69% and 1.39% on CAMELYON-16 and TCGA, respectively, confirming the effectiveness of utilizing spatial context at the packet level. After incorporating both instance-level and bag-level enhancements, our full SAM-MIL achieves state-of-the-art performance (96.08% AUC on CAMELYON-16 and 96.01% AUC on TCGA). Overall, the individual components of our design effectively exploit the spatial context explicitly introduced at two levels, and experimental results show that this explicit spatial context can play a positive guiding role in model training.

[0145] 4.4 The impact of different masking strategies. The results are shown in Table 3 below:

[0146] Table 3: Impact of different masking strategies

[0147]

[0148] In the instance grouping masking stage, one of our key designs is the instance masking strategy. We introduce three different instance-level masking strategies (random masking, non-combination feature masking, and group masking guided by SAM) for instance masking. The table shows the performance comparison of different masking strategies on two datasets. First, the experimental results show that our random masking strategy has achieved significant improvements. This can be attributed to the fact that the combined features we extracted can well represent the category information and the effectiveness of our masking strategy. In addition, our proposed SAM-guided group masking strategy achieves the best results on both datasets (AUC of 96.01% on CAMELYON-16 and 95.84% on TCGA). This effect highlights the value of incorporating spatial context information and the importance of applying different mask ratios in different categories to significantly reduce redundant information. Overall, our proposed instance-level masking strategies achieve excellent results, confirming their effectiveness on different datasets.

[0149] 4.5 The impact of different mask functions on model performance. The experimental results are shown in Table 4:

[0150] Table 4: Effects of different mask functions

[0151]

[0152] In the SAM-guided group mask strategy, masks are applied at different scales according to the areas of individual category groups. A specified function is used to calculate the corresponding scales from the category areas. In our experiments, three different functions are evaluated: constant function, linear function, and adjusted sigmoid function. The experimental results of these functions are shown in Table 4. First, due to the imbalanced data, the fixed scale shows limited improvement. The linear function is negatively affected by extreme values, resulting in poor performance. The adjusted sigmoid function is adopted to address the shortcomings of the first two methods by adjusting its center point and slope, and the results are superior in various datasets.

[0153] 4.6 To verify the effectiveness of the combined features, we conducted experiments on the CAMELYON-16 dataset. The experimental results are shown in Tables 5 and Figure 5 :

[0154] Table 5: Impact of combined features

[0155]

[0156] The group features of our proposed SAM-guided feature extractor are not only applicable to the MIL framework we designed, but can also be applied to various mainstream MIL models, achieving immediate performance improvement. In our experiments, the features extracted by ResNet50 and PLIP are processed under the guidance of SAM and verified on the CAMELYON-16 dataset. In addition to the baseline AB-MIL mentioned earlier, we also selected several advanced MIL models to evaluate the effectiveness of our group features. The corresponding experimental results are shown in the table. The results show that combining the features extracted by SAM leads to performance improvements for both methods. In addition, it is observed that due to the lack of pre-training on medical images, the features extracted using ResNet50 are slightly inferior to those extracted using PLIP in performance. However, after supplementing with the group features extracted based on spatial context, the features extracted by ResNet50 show a greater performance improvement. This may indicate that our proposed group features provide important guidance for models that lack prior knowledge. Overall, our SAM-guided feature extractor can be used as a plug-and-play module for various mainstream MIL models.

[0157] In addition, in order to prove that SAM has sufficient sensitivity for the segmentation of pathological images, we visualized some of the segmentation results in the original image. Figure 6 At the same time, in order to better understand the model decision-making process, we visualized the specific output of the model and drew a visualization of the disease probability calculated in the model decision. The results are shown in Figure 7 .

Claims

1. A full-view digital slide image classification method based on spatial context perception, characterized in that: The steps include: S1: Data preprocessing: Obtain N publicly available labeled full-view digital slice images WSIs to form dataset B; S1-1: Segment the foreground and background of each full-field digital slice image WSI, and retain the coordinates of the foreground and background; S1-2: Segment the tissue in each foreground image to obtain several tissues, and save each tissue and its corresponding coordinates; each tissue is first divided into several blocks, and each block is put into the pre-trained feature extractor for feature extraction to obtain block features; After each foreground is compressed, it is input into SAM for segmentation, and the visual segmentation results of several regions are obtained and saved. The visual segmentation results include the coordinate information of the region and the area of ​​the segmented region. Each region represents a class, and the feature extraction of the region corresponding to each class is performed to obtain the combined features of the class; The tile features and combined features obtained in the previous operation are called instances, and the instances extracted from the same WSI will be integrated into the same package, that is, when there is one or more disease instances in a package, the entire package will be marked as a disease; All the block features and combined features are spliced ​​together to obtain the feature file corresponding to WSI; S2: SAM-MIL model training stage; S2-1: Instance level processing of feature files: Read in all tile features and combined features in the i-th feature file, trace back the original coordinates of each tile feature in WSI, and group the tile features according to the segmentation class of SAM. If the original coordinates of the four corners of the tile feature are all located in a class of area segmented by SAM, the tile features are divided into the same group; A dynamic mask ratio is determined for each group, and a mask operation is performed on the tile features in the group according to the dynamic mask ratio. All tile features after the mask operation are concatenated, and then all tile features without the mask operation are added to obtain the combined features corresponding to the WSI. The combined features corresponding to the WSI are defined as the training feature data; Input the training feature data corresponding to WSI into the SAM-MIL model to obtain the classification loss S2-2: Package level processing of feature files: Read all the tile features in the i-th feature file. All tile features first pass through the forward propagation of the SAM-MIL model to obtain a global attention weight attn i ; All the tile features in the i-th feature file are randomly divided into m pseudo packages. The label of each pseudo package inherits the label of the corresponding WSI. Each pseudo package is input into the SAM-MIL model in turn to obtain the classification loss of m pseudo packages. The average of these losses is the pseudo package classification loss of the i-th feature file. According to the classes defined for tile features in S2-1, the consistency loss is calculated for the attention weights corresponding to the tile features in each class. The consistency loss of each class is summed up to obtain the consistency loss constraint of the global spatial context of the i-th feature file. S2-3: The optimization loss of the SAM-MIL model is Back-propagate this optimization loss in the model to optimize the parameters of the SAM-MIL model. When the loss no longer decreases, the trained SAM-MIL model is obtained. α and β are scaling factors. S3: Inference stage: For a new full-view digital slice image WSI, the method in S1 is used to obtain its corresponding feature file. All the block features and combined features in the feature file corresponding to WSI are input into the trained SAM-MIL model, and the classification result of WSI is obtained by inference.

2. The full-view digital slide image classification method based on spatial context perception according to claim 1, characterized in that: In S1-2, the method for extracting the combined features is: Let S = {s1,s2,…,s l } represents the output of SAM, where l represents the segmentation area of ​​SAM. For each segmentation area s r , combined feature g r The extraction is as follows: in is an average aggregation function, represents the jth instance in the i-th package, s r Represents the rth segmentation region in a WSI.

3. The full-view digital slide image classification method based on spatial context perception according to claim 1, characterized in that: In S2-1, the mask operation method is: using a group masking strategy under the guidance of SAM based on spatial context to mask the instance features, such as formula (5): Among them, M p is the patch mask determined by the SAM information, ⊙ represents the Hadamard product, e p is the masked patch feature embedding, They refer to feature extraction functions that add spatial context information respectively; I k is the instance in the kth bag that is retained after masking, B k For the kth package, the definition is the same as before, k and i are just for traversal definition subscripts; represents the jth instance of the kth package; Instances are classified into groups {G1, G2, …, G z }; each instance p i Assigned to group G according to the class to which it belongs k In the distribution p i →G k Indicates p i The category index is k; for G k ,definition is the area of ​​the group category k; processed by the adjusted sigmoid function To calculate the normalized ratio for each group where σ adj is an adjusted sigmoid function with slope a and center point offset b, which control the slope and horizontal displacement of the sigmoid curve respectively; then the normalized ratio Multiply by the target mask ratio MR provided as input target , to calculate the dynamic mask ratio for each segment group The mask for each group is then calculated and aggregated to create a combined mask M for all instances comp : Finally, the combined mask M comp Applies to all instances I k =Mask(B k ,M comp ) (6) Among them, Mask(·,·) is a masking operation on the instance.

4. The method for classifying full-view digital slide images based on spatial context perception according to claim 1, characterized in that: In S2-1, the mask operation method is: In S2-1, the classification loss The calculation method is: in represents the loss function of the SAM-MIL model, and Y is the label inherited from WSI, Represents the prediction results output by the SAM-MIL model at the instance level.

5. The full-view digital slide image classification method based on spatial context perception according to claim 1, characterized in that: In S2-1, the mask operation method is: In S2-2, the pseudo packet classification loss The calculation method is: in represents the loss function of the SAM-MIL model, P i represents the instance features in the ith pseudo-bag, and Y is the label inherited from WSI, and They refer to the classification function and feature aggregation function with added spatial context information, respectively. n means there are n WSIs in total, and represents the total number of WSIs.

6. The method for classifying full-view digital slide images based on spatial context perception according to claim 1, characterized in that: In S2-1, the mask operation method is: In S2-2, the consistency loss constraint The calculation method is: Where sim represents the attention weight attn i and attn j The similarity function between them, and δ is a Kronecker function. If the segmentation category s i and j If they are the same, then it is equal to 1, otherwise it is 0; the attention weight comes from the attention mechanism of the SAM-MIL model, and s i and j It is the segmentation category from SAM, N means there are N instances in the package corresponding to each WSI; it represents the total number of features in a feature file.

Citation Information

Cited By

  • High-resolution medical pathology WSI image analysis method based on scanning invariance Mama

    CN120070283A

  • High-resolution medical pathology WSI image analysis method based on scan-invariant Mamba

    CN120070283B

  • Defect detection method and device, electronic equipment and storage medium

    CN120598935A