A dynamic weight selection method for gastric pathological section gland multi-classification segmentation
The gastric pathological slide gland multi-class segmentation method with dynamic weight selection solves the problems of accuracy and efficiency in multi-class classification of gastric pathological slide glands by using a multi-class image segmentation network and a dynamic weight selection module, and achieves higher classification and segmentation accuracy.
Patent Information
- Application Number
- CN202311315526.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-12
- Publication Date
- 2026-01-23
- Estimated Expiration
- 2043-10-12
AI Technical Summary
Traditional image processing methods cannot meet the requirements of accurate and efficient multi-classification of glands in gastric pathological sections, especially in handling subtle differences between different types of glands, class imbalance, and improving model accuracy.
A multi-class segmentation method for gastric pathological slice glands using dynamic weight selection is proposed. By establishing a multi-class image segmentation network and combining k-flod cross-validation, attention mechanism, and dynamic weight selection module, the model training process is optimized to improve the accuracy of classification and segmentation.
This study effectively improved the accuracy of multi-class segmentation of glands in gastric pathological sections. By introducing an attention mechanism and a dynamic weight selection module, the classification and segmentation performance of the model was enhanced.
Smart Images

Figure QLYQS_5 
Figure QLYQS_17 
Figure QLYQS_18
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image processing, and particularly relates to a gastric pathological section gland multi-classification segmentation method based on dynamic weight selection. BACKGROUND
[0002] Gastric pathological section gland multi-classification is an important medical image processing task, which is of great significance for disease diagnosis and treatment. However, due to the complexity and diversity of gastric pathological section images, traditional image processing methods often cannot meet the needs of accuracy and efficiency. In recent years, deep learning models, especially various variants based on Unet network models, have shown superior performance in medical image processing tasks. These models can automatically learn and extract image features, thereby avoiding the need for manual selection of features and parameters. However, despite the significant progress made by deep learning technology in many fields, there are still some challenges in the task of gastric pathological section gland multi-classification. For example, how to effectively handle the subtle differences between different types of glands, how to handle the class imbalance problem, and how to improve the accuracy of the model, etc. Therefore, it is necessary to develop a deep learning model that can effectively classify gastric pathological section glands. SUMMARY
[0003] In order to overcome the above technical deficiencies, the present application provides a gastric pathological section gland multi-classification segmentation method based on dynamic weight selection to improve the accuracy of classification and segmentation.
[0004] The technical solution adopted by the present application to overcome the technical problems is:
[0005] A gastric pathological section gland multi-classification segmentation method based on dynamic weight selection, characterized in that it comprises the following steps:
[0006] a) obtaining a plurality of gastric pathological images and their corresponding json annotation files;
[0007] b) establishing a data set according to the gastric pathological images and their corresponding json annotation files;
[0008] c) dividing the data set into a training set and a test set;
[0009] d) establishing a multi-classification image segmentation network, inputting the images in the training set into the multi-classification image segmentation network, and outputting a gastric pathological section gland multi-classification segmentation result image;
[0010] e) training the multi-classification image segmentation network to obtain an optimized multi-classification image segmentation network;
[0011] f) inputting the images in the test set into the optimized multi-classification image segmentation network, and outputting a gastric medical record slice gland multi-classification segmentation result image shuchu_final.
[0012] Further, the gastric pathology image is obtained from the gastric slice summary classification in the pathological digital slice cloud annotation platform in step a).
[0013] Further, step b) comprises the following steps:
[0014] b-1) establishing a makedatasets module, the makedatasets module comprising an openslide module, a json module, a numpy module and an os module in Python;
[0015] b-2) inputting the gastric pathology image into the makedatasets module, and using the openslide module in Python to cut each gastric medical record image into an image with a size of 224*224, and saving the cut image in a tuxiang folder in the current path of the project;
[0016] b-3) inputting the gastric pathology image corresponding json annotation file into the makedatasets module, and using the json module in Python to cut each json annotation file into 224*224, and saving the cut json annotation file in a biaozhu folder in the current path of the project;
[0017] b-4) inputting the cut image in the tuxiang folder and the cut json annotation file in the biaozhu folder into the makedatasets module, using the numpy module and the json module in Python to read the pixel coordinate information in the cut json annotation file, and using the os module in Python to screen out the corresponding image according to the pixel coordinate information and store it in a select_image folder in the current directory of the project;
[0018] b-5) inputting the image in the select_image folder into the makedatasets module, using the numpy module and the os module in Python to combine the image and the corresponding json annotation file to generate an npz file used for training the multi-classification image segmentation network, using the cv2 module in Python to name the first array of the npz file as image and the second array of the npz file as label, and saving all the npz files to a shujuji folder in the current directory of the project to form a data set.
[0019] Preferably, in step c), the npz files in the shujuji folder are divided into training and testing sets in a 9:1 ratio. The npz files of the testing set are stored in the train folder under the current path of the project, and the npz files of the test set are stored in the test folder under the current path of the project.
[0020] Furthermore, step d) includes the following steps:
[0021] d-1) The multi-class image segmentation network consists of a k-flod validation module, an image downsampling module, an attention connection module, a vector generation module, a Transformer module, a Decoder module, and a dynamic weight selection module;
[0022] d-2) Input the training set into the k-flod validation module of the multi-class image segmentation network. The training set is split into k parts by the k-flod cross-validation strategy, of which k-1 parts are used for training and are denoted as train_new, and 1 part is used for validation and is denoted as validation.
[0023] d-3) The image downsampling module of the multi-class image segmentation network consists of an npz file reading function, a first downsampling unit, a second downsampling unit, and a third downsampling unit. It reads the i-th npz file from train_new. i The input is fed into the npz file reading function, where i∈{1,2,...,k-1}, and i npz files are read by calling the os and numpy modules in Python. iThe first array `image` is input into the first downsampling unit. By calling the `os` and `cv2` modules in Python, the first array `image` is reduced to H / 2*W / 2*C, forming image `downsamplel`, where H is the image height, W is the image width, and C is the dimension. The attention connection module of the multi-class image segmentation network consists of a multi-head attention mechanism. Image `downsamplel` is input into the attention connection module, and through the calculation of the multi-head attention mechanism, image `downsample_1` is output. Image `downsample_1` is then input into the second downsampling unit. By calling the `os` and `cv2` modules in Python, the image is further reduced to H / 2*W / 2*C, forming image `downsamplel`. Image downsample1 is reduced to H / 4*W / 4*4C to form image downsample2. Image downsample2 is input into the attention connection module. Through the multi-head attention mechanism, image downsample_2 is output. Image downsample2 is input into the third downsampling unit. By calling the os and cv2 modules in Python, image downsample2 is reduced to H / 8*W / 8*8C to form image downsample3. Image downsample3 is input into the attention connection module. Through the multi-head attention mechanism, image downsample_3 is output.
[0024] d-4) The vector generation module of the multi-class image segmentation network consists of the Patch Embedding function. The image downsample3 is input into the vector generation module. The image downsample3 is divided into N patches and flattened by calling the torch.Tensor module in the pytorch library of Python. The predefined position encoding layer in the torch.nn module in the pytorch library of Python is called to generate a position encoding vector of length N. The elements in the position encoding vector are added to the corresponding patch, and a one-dimensional vector vector1 with position information is output.
[0025] d-5) The Transformer module of the multi-class image segmentation network consists of 12 identical transformer blocks. The one-dimensional vector vector1 is input into the 12 transformer blocks in sequence, and the output is the encoded feature map encoded_feature.
[0026] d-6) The Decoder module of the multi-class image segmentation network consists of a Reshape function, a first upsampling function, a second upsampling function, a third upsampling function, an image restoration function, and a Linear Projection function. The feature map `encoded_feature` is input into the Reshape function of the Decoder module. By calling the `reshape` module in the PyTorch library of Python, the size of the feature map `encoded_feature` is transformed into a feature map `reshape_feature` of size H / 16*W / 16*N. The feature map `reshape_feature` is then input into the first upsampling function of the Decoder module. By calling the `os` and `cv2` modules in Python, the feature map `reshape_feature` is expanded to H / 8*W / 8*8C, forming image `upsample1`. Image `upsample1` is added to image `downsample_3` to obtain image `upsample_1`. Image `upsample_1` is then input into the second upsampling function of the Decoder module. By calling the `os` module in Python... The `cv2` module expands image `upsample_1` to H / 4 * W / 4 * 4 C, forming image `upsample2`. Image `upsample2` is then added to image `downsample_2` to obtain image `upsample_3`. Image `upsample_3` is input into the third upsampling function of the `Decoder` module. By calling the `os` and `cv2` modules in Python, image `upsample_2` is expanded to H / 2 * W / 2 * C, forming image `upsample3`. Image `upsample3` is then added to image `downsample_1` to obtain image `upsample_3`. Image `upsample_3` is input into the image restoration function of the `Decoder` module. By calling the `cv2` module in Python, image `upsample_3` is expanded to H * W * C, forming image `upsample4`. Image `upsample4` is then input into the Linear array of the `Decoder` module. In the Projection function, the image upsample4 is processed into the i-th npz file of size H*W*CLASS, which is the gastric medical record slice gland multi-class segmentation result image output1, by calling the os module in the pytorch library of Python. Here, CLASS is the number of categories. After the corresponding gastric medical record slice gland multi-class segmentation result images are obtained for k-1 npz files in train_new, the training parameters of the multi-class image segmentation network are saved and the training parameters are denoted as path.
[0027] d-7) For an npz file with classification category x, repeat steps d-3) to d-6) x times, saving the training parameters of the multi-class image segmentation network each time, denoted as path1, path2, ..., path x ;d-8) The dynamic weight selection module of the multi-class image segmentation network consists of a label reading function, a weight selection function, and a weight import function. The npz file from the validation module is input into the label reading function of the dynamic weight selection module. The values of the second array `label` in the npz file are read by calling the `os` and `numpy` modules in Python, and stored in the file `label.txt`. The `label.txt` file is then input into the weight selection function of the dynamic weight selection module. The values in the `label.txt` file are evaluated by calling the `os` module in Python, and training parameters corresponding to 1, 2, ..., x in step d-7) are selected based on the values in `label.txt`. The storage address of the selected training parameters is obtained and input into the weight import function of the dynamic weight selection module. The selected training parameters are imported into the multi-class image segmentation network by calling the `torch.load` function from the PyTorch library in Python. Preferably, k is 4 in step d-2), C is 64 in step d-3), and x is 3 in step d-7).
[0028] Furthermore, step e) includes the following steps:
[0029] e-1) The loss of the model is calculated using the cross-entropy loss method in Python;
[0030] e-2) Use the SGD optimizer to train the multi-class image segmentation network through loss to obtain the optimized multi-class image segmentation network.
[0031] Preferably, in step e-2), the momentum factor of the SGD optimizer is set to 0.9, the weight decay is set to 0.0001, and the learning rate is set to the base learning rate of 0.01. When training the multi-class image segmentation network, the iterator DataLoader in Python is used to iterate the data. The parameters of DataLoader are set to batch_size as 16, shuffle as True, num_workers as 1, and training for 150 epochs.
[0032] The beneficial effects of this invention are: it improves the accuracy of multi-class segmentation of the model, adds an attention mechanism to the connection module, and introduces a k-flod cross-validation strategy and a dynamic weight selection module when optimizing the multi-class image segmentation network, so that the model can effectively perform multi-class segmentation of glands in gastric pathological slices. Detailed Implementation
[0033] The present invention will be further described below.
[0034] A method for multi-class segmentation of glands in gastric pathological sections with dynamic weight selection, characterized by comprising the following steps:
[0035] a) Obtain several gastric pathological images and their corresponding JSON annotation files.
[0036] b) Create a dataset based on gastric pathological images and their corresponding JSON annotation files.
[0037] c) Divide the dataset into training and test sets.
[0038] d) Establish a multi-class image segmentation network, input the images in the training set into the multi-class image segmentation network, and output the multi-class segmentation result image of the glands in the gastric medical record slice.
[0039] e) Train the multi-class image segmentation network to obtain the optimized multi-class image segmentation network.
[0040] f) Input the images in the test set into the optimized multi-class image segmentation network, and output the multi-class segmentation result image of the glands in the gastric medical record slices, shuchu_final.
[0041] An attention mechanism was added to the connection module, and a k-flod cross-validation strategy and a dynamic weight selection module were introduced when optimizing the multi-class image segmentation network, so that the model can effectively perform multi-class segmentation of glands in gastric pathological slices. In one embodiment of the present invention, gastric pathological images are obtained from the gastric slice summary classification in the pathological digital slice cloud annotation platform in step a).
[0042] In one embodiment of the present invention, step b) includes the following steps:
[0043] b-1) Create the makedatasets module, which includes the openslide, json, numpy, and os modules in Python.
[0044] b-2) Input the gastric pathology images into the makedatasets module, and use the openslide module in Python to segment each gastric medical record image into a 224*224 image. Save the segmented images in the tuxiang folder in the current path of the project.
[0045] b-3) Input the JSON annotation files corresponding to the gastric pathology images into the makedatasets module, use the json module in Python to split each JSON annotation file into 224*224, and save the split JSON annotation files in the biaozhu folder in the current path of the project.
[0046] b-4) Input the segmented images in the tuxiang folder and the segmented JSON annotation files in the biaozhu folder into the makedatasets module. Use the numpy and json modules in Python to read the pixel coordinate information in the segmented JSON annotation files. Based on the pixel coordinate information, use the os module in Python to filter out the corresponding images and store them in the select_image folder in the current directory of the project.
[0047] b-5) Input the images in the select_image folder into the makedatasets module. Use the numpy and os modules in Python to merge the images and their corresponding JSON annotation files to generate npz files for training a multi-class image segmentation network. Call the cv2 module in Python to name the first array of the npz file as image and the second array as label. Save all the npz files to the shujuji folder in the current directory of the project to form a dataset.
[0048] In this embodiment, preferably, in step c), the npz files in the shujuji folder are divided into training and testing sets in a 9:1 ratio. The npz files for the testing set are stored in the train folder under the current path of the project, and the npz files for the test set are stored in the test folder under the current path of the project. In one embodiment of the present invention, step d) includes the following steps:
[0049] d-1) The multi-class image segmentation network consists of a k-flod validation module, an image downsampling module, an attention connection module, a vector generation module, a Transformer module, a Decoder module, and a dynamic weight selection module.
[0050] d-2) Input the training set into the k-flod validation module of the multi-class image segmentation network. The training set is split into k parts by the k-flod cross-validation strategy, where k-1 parts are used for training and are denoted as train_new, and 1 part is used for validation and is denoted as validation.
[0051] d-3) The image downsampling module of the multi-class image segmentation network consists of an npz file reading function, a first downsampling unit, a second downsampling unit, and a third downsampling unit. It reads the i-th npz file from train_new. i The input is fed into the npz file reading function, where i∈{1,2,...,k-1}, and i npz files are read by calling the os and numpy modules in Python. i The first array `image` is input into the first downsampling unit. By calling the `os` and `cv2` modules in Python, the first array `image` is reduced to H / 2*W / 2*C, forming image `downsamplel`, where H is the image height, W is the image width, and C is the dimension. The attention connection module of the multi-class image segmentation network consists of a multi-head attention mechanism, which replaces simple skip connections. Image `downsamplel` is input into the attention connection module, and through the multi-head attention mechanism, image `downsample_1` is output. Image `downsample_1` is then input into the second downsampling unit, and by calling the `os` module in Python... The `os` and `cv2` modules reduce image `downsample1` to H / 4*W / 4*4C to form image `downsample2`. Image `downsample2` is then input into the attention connection module. Through multi-head attention mechanism calculation, image `downsample_2` is output. Image `downsample2` is then input into the third downsampling unit. By calling the `os` and `cv2` modules in Python, image `downsample2` is reduced to H / 8*W / 8*8C to form image `downsample3`. Image `downsample3` is then input into the attention connection module. Through multi-head attention mechanism calculation, image `downsample_3` is output.
[0052] d-4) The vector generation module of the multi-class image segmentation network consists of the Patch Embedding function. The image downsample3 is input into the vector generation module. The image downsample3 is divided into N patches and flattened by calling the torch.Tensor module in the pytorch library of Python. The predefined position encoding layer in the torch.nn module in the pytorch library of Python is called to generate a position encoding vector of length N. The elements in the position encoding vector are added to the corresponding patch, and a one-dimensional vector vector1 with position information is output so that the multi-class image segmentation network can distinguish elements at different positions. At the same time, it is convenient for the subsequent Transformer module to extract the global context dependency.
[0053] d-5) The Transformer module of the multi-class image segmentation network consists of 12 identical transformer blocks. The one-dimensional vector vector1 is sequentially input into the 12 transformer blocks, making full use of the attention mechanism's ability to capture global contextual dependencies, and outputting the encoded feature map encoded_feature.
[0054] d-6) The Decoder module of the multi-class image segmentation network consists of a Reshape function, a first upsampling function, a second upsampling function, a third upsampling function, an image restoration function, and a Linear Projection function. The feature map `encoded_feature` is input into the Reshape function of the Decoder module. By calling the `reshape` module in the PyTorch library of Python, the size of the feature map `encoded_feature` is transformed into a feature map `reshape_feature` of size H / 16*W / 16*N. The feature map `reshape_feature` is then input into the first upsampling function of the Decoder module. By calling the `os` and `cv2` modules in Python, the feature map `reshape_feature` is expanded to H / 8*W / 8*8C, forming image `upsample1`. Image `upsample1` is added to image `downsample_3` to obtain image `upsample_1`. Image `upsample_1` is then input into the second upsampling function of the Decoder module. By calling the `os` module in Python... The `cv2` module expands image `upsample_1` to H / 4 * W / 4 * 4 C, forming image `upsample2`. Image `upsample2` is then added to image `downsample_2` to obtain image `upsample_3`. Image `upsample_3` is input into the third upsampling function of the `Decoder` module. By calling the `os` and `cv2` modules in Python, image `upsample_2` is expanded to H / 2 * W / 2 * C, forming image `upsample3`. Image `upsample3` is then added to image `downsample_1` to obtain image `upsample_3`. Image `upsample_3` is input into the image restoration function of the `Decoder` module. By calling the `cv2` module in Python, image `upsample_3` is expanded to H * W * C, forming image `upsample4`. Image `upsample4` is then input into the Linear array of the `Decoder` module. In the Projection function, the upsample4 image is processed into the i-th npz file of size H*W*CLASS, which is the gastric medical record slice gland multi-class segmentation result image output1, by calling the os module in the pytorch library of Python. Here, CLASS is the number of categories. After the corresponding gastric medical record slice gland multi-class segmentation result images are obtained for k-1 npz files in train_new, the training parameters of the multi-class image segmentation network are saved and the training parameters are denoted as path.
[0055] d-7) For an npz file with classification category x, repeat steps d-3) to d-6) x times, saving the training parameters of the multi-class image segmentation network each time, denoted as path1, path2, ..., path x .
[0056] d-8) The dynamic weight selection module of the multi-class image segmentation network consists of a label reading function, a weight selection function, and a weight import function. The npz file from validation is input into the label reading function of the dynamic weight selection module. The values of the second array `label` in the npz file are read by calling the `os` and `numpy` modules in Python, and stored in the file `label.txt`. The `label.txt` file is then input into the weight selection function of the dynamic weight selection module. The values in `label.txt` are evaluated by calling the `os` module in Python, and training parameters corresponding to 1, 2, ..., x in step d-7) are selected based on the values in `label.txt`. The storage address of the selected training parameters is obtained and input into the weight import function of the dynamic weight selection module. The `torch.load` function from the PyTorch library in Python is called to import the selected training parameters into the multi-class image segmentation network, enabling the multi-class image segmentation network to perform image segmentation tasks on validation.
[0057] In this embodiment, preferably, k is 4 in step d-2), C is 64 in step d-3), and x is 3 in step d-7).
[0058] In one embodiment of the present invention, step e) includes the following steps:
[0059] e-1) The loss of the model is calculated using the cross-entropy loss method in Python.
[0060] e-2) Use the SGD optimizer to train the multi-class image segmentation network through loss to obtain the optimized multi-class image segmentation network.
[0061] In this embodiment, preferably, in step e-2), the momentum factor of the SGD optimizer is set to 0.9, the weight decay is set to 0.0001, and the learning rate lr is set to the base learning rate of 0.01. When training the multi-class image segmentation network, the iterator DataLoader in Python is used to iterate the data. The parameters of DataLoader are set to batch_size as 16, shuffle as True, num_workers as 1, and training for 150 epochs.
[0062] Finally, it should be noted that the above descriptions are merely preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for multi-class segmentation of glands in gastric pathological sections using dynamic weight selection, characterized in that, Includes the following steps: a) Obtain several gastric pathological images and their corresponding JSON annotation files; b) Create a dataset based on gastric pathological images and their corresponding JSON annotation files; c) Divide the dataset into a training set and a test set; d) Establish a multi-class image segmentation network, input the images in the training set into the multi-class image segmentation network, and output the multi-class segmentation result image of the glands in the gastric medical record slice; e) Train the multi-class image segmentation network to obtain the optimized multi-class image segmentation network; f) Input the images in the test set into the optimized multi-class image segmentation network, and output the multi-class segmentation result image of the glands in the gastric medical record slices, shuchu_final; Step d) includes the following steps: d-1) The multi-class image segmentation network consists of a k-flod validation module, an image downsampling module, an attention connection module, a vector generation module, a Transformer module, a Decoder module, and a dynamic weight selection module; d-2) Input the training set into the k-flod validation module of the multi-class image segmentation network. The training set is split into k parts by the k-flod cross-validation strategy, of which k-1 parts are used for training and are denoted as train_new, and 1 part is used for validation and is denoted as validation. d-3) The image downsampling module of the multi-class image segmentation network consists of an npz file reading function, a first downsampling unit, a second downsampling unit, and a third downsampling unit. It reads the i-th npz file from train_new. The input is given to the npz file reading function. This involves reading *i* npz files by calling the `os` and `numpy` modules in Python. The first array `image` is input into the first downsampling unit. The first array `image` is then scaled down to a smaller size using the `os` and `cv2` modules in Python. This forms the image downsamplel. Image height, Image width, In a multi-class image segmentation network, the attention connection module is composed of a multi-head attention mechanism. The image `downsample_1` is input into the attention connection module, and through the calculation of the multi-head attention mechanism, the output image `downsample_1` is obtained. Image `downsample_1` is then input into the second downsampling unit, where the `os` and `cv2` modules in Python are used to downsample image `downsample_1` to a smaller size. Image downsample2 is generated and input into the attention connection module. Through multi-head attention mechanism calculation, image downsample_2 is output. Image downsample2 is then input into the third downsampling unit, where the os and cv2 modules in Python are used to downsample image down to a smaller size. The image downsample3 is generated and input into the attention connection module. Through the calculation of the multi-head attention mechanism, the image downsample_3 is output. d-4) The vector generation module of the multi-class image segmentation network consists of the Patch Embedding function. The image downsample3 is input into the vector generation module. The image downsample3 is divided into N patches and flattened by calling the torch.Tensor module in the pytorch library of Python. The predefined position encoding layer in the torch.nn module in the pytorch library of Python is called to generate a position encoding vector of length N. The elements in the position encoding vector are added to the corresponding patch, and a one-dimensional vector vector1 with position information is output. d-5) The Transformer module of the multi-class image segmentation network consists of 12 identical transformer blocks. The one-dimensional vector vector1 is input into the 12 transformer blocks in sequence, and the output is the encoded feature map encoded_feature. d-6) The Decoder module of the multi-class image segmentation network consists of a Reshape function, a first upsampling function, a second upsampling function, a third upsampling function, an image restoration function, and a Linear Projection function. The feature map encoded_feature is input into the Reshape function of the Decoder module, which uses the reshape module from the PyTorch library in Python to transform the size of the encoded_feature. The feature map `reshape_feature` is input into the first upsampling function of the `Decoder` module. The `os` and `cv2` modules in Python are then used to expand the feature map `reshape_feature` to... Image upsample1 is generated. Image upsample1 is added to image downsample_3 to obtain image upsample_1. Image upsample_1 is then input into the second upsampling function of the Decoder module. The upsample_1 image is expanded by calling the os and cv2 modules in Python. This generates an image upsample2. Upsample2 is then added to downsample_2 to obtain image upsample_2. Image upsample_2 is then input into the third upsampling function of the Decoder module. The upsample_2 image is then expanded using the os and cv2 modules in Python. Image upsample_3 is generated. Image upsample_3 is added to image downsample_1 to obtain image upsample_3. Image upsample_3 is then input into the image restoration function of the Decoder module, which uses the cv2 module in Python to expand image upsample_3 into... This generates an image upsample4, which is then input into the Linear Projection function of the Decoder module. The os module in the PyTorch library of Python is then used to process the upsample4 image to a size of [size missing]. Multi-class segmentation result of gastric lesions in the i-th npz file ,in The number of categories is denoted as 'path'. After obtaining the corresponding gastric medical record slice gland multi-class segmentation result images for k-1 npz files in train_new, the training parameters of the multi-class image segmentation network are saved and denoted as 'path'. d-7) For an npz file with classification category x, repeat steps d-3) to d-6) x times, saving the training parameters of the multi-class image segmentation network each time, denoted as . ; d-8) The dynamic weight selection module of the multi-class image segmentation network consists of a label reading function, a weight selection function, and a weight import function. The npz file from the validation module is input into the label reading function of the dynamic weight selection module. The values of the second array `label` in the npz file are read by calling the `os` and `numpy` modules in Python, and stored in the file `label.txt`. The `label.txt` file is then input into the weight selection function of the dynamic weight selection module. The values in the `label.txt` file are evaluated by calling the `os` module in Python, and the weights selected based on the values in `label.txt` correspond to those in step d-7). The training parameters are obtained, the storage address of the selected training parameters is obtained, and the storage address is input into the weight import function of the dynamic weight selection module. The selected training parameters are then imported into the multi-class image segmentation network by calling the torch.load function in the pytorch library of Python.
2. The method for multi-class segmentation of gastric pathological sections with glands using dynamic weight selection according to claim 1, characterized in that: In step a), gastric pathological images are obtained from the gastric slide summary classification in the pathological digital slide cloud annotation platform.
3. The method for multi-class segmentation of gastric pathological sections with glands using dynamic weight selection according to claim 1, characterized in that, Step b) includes the following steps: b-1) Create the makedatasets module, which includes the openslide, json, numpy, and os modules in Python; b-2) Input the gastric pathology images into the makedatasets module, and use the openslide module in Python to segment each gastric medical record image into 224-bit segments. The image is 224 pixels long. The resulting image will be saved in the tuxiang folder in the current path of the project. b-3) Input the JSON annotation files corresponding to the gastric pathology images into the makedatasets module, and use the json module in Python to split each JSON annotation file into 224.
224. Save the split JSON annotation file in the biaozhu folder in the current path of the project; b-4) Input the segmented images in the tuxiang folder and the segmented JSON annotation files in the biaozhu folder into the makedatasets module. Use the numpy and json modules in Python to read the pixel coordinate information in the segmented JSON annotation files. Use the os module in Python to filter out the corresponding images based on the pixel coordinate information and store them in the select_image folder in the current directory of the project. b-5) Input the images in the select_image folder into the makedatasets module. Use the numpy and os modules in Python to merge the images and their corresponding JSON annotation files to generate npz files for training a multi-class image segmentation network. Call the cv2 module in Python to name the first array of the npz file as image and the second array as label. Save all the npz files to the shujuji folder in the current directory of the project to form a dataset.
4. The method for multi-class segmentation of gastric pathological sections with glands using dynamic weight selection according to claim 3, characterized in that: In step c), the npz files in the shujuji folder are divided into training and testing sets in a 9:1 ratio. The npz files of the testing set are stored in the train folder under the current path of the project, and the npz files of the test set are stored in the test folder under the current path of the project.
5. The method for multi-class segmentation of gastric pathological sections with glands using dynamic weight selection according to claim 1, characterized in that: In step d-2), k takes the value of 4; in step d-3), The value is 64, and in step d-7), x takes the value 3.
6. The method for multi-class segmentation of gastric pathological sections with glands using dynamic weight selection according to claim 1, characterized in that, Step e) includes the following steps: e-1) The loss of the model is calculated using the cross-entropy loss method in Python; e-2) Use the SGD optimizer to train the multi-class image segmentation network through loss to obtain the optimized multi-class image segmentation network.
7. The method for multi-class segmentation of gastric pathological sections with glands using dynamic weight selection according to claim 6, characterized in that: In step e-2), the momentum factor of the SGD optimizer is set to 0.9, the weight decay is set to 0.0001, and the learning rate (lr) is set to the base learning rate of 0.
01. When training the multi-class image segmentation network, the iterator DataLoader in Python is used to iterate the data. The parameters of DataLoader are set to batch_size as 16, shuffle as True, and num_workers as 1, and the training is performed for 150 epochs.
Citation Information
Patent Citations
Stomach pathological section gland segmentation method based on Swinin-Unet model
CN116485811A
Network architecture for crack image segmentation and training method and segmentation method thereof
CN116542991A