Cervical cancer cell image classification method and system

Through the improved DenseNet121 network model and SE attention module, combined with dataset amplification technology, the problem of small and uneven image data of cervical cells is solved, and the accuracy of image classification and model generalization ability of cervical cancer cells is improved, thus achieving the Better prevention effects of cervical cancer.

CN118918583AInactive Publication Date: 2024-11-08CHANGCHUN UNIV OF SCI & TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410979786.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-22
Publication Date
2024-11-08
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The cervical cell image data is small and uneven, and the model is robust and generalized, which affects the speed and accuracy of cervical cancer cell image classification.

Method used

The improved DenseNet121 network model was adopted and amplified by flipping, rotating and other methods of data sets during the preprocessing stage. The cervical cell images were classified in combination with the SE attention module.

Benefits of technology

It improves the accuracy of cervical cancer cell image classification and the generalization ability of the model, and performs better on the Herlev dataset than other methods, effectively preventing the occurrence of cervical cancer.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118918583A_ABST
    Figure CN118918583A_ABST
Patent Text Reader

Abstract

The invention provides a cervical cancer cell image classification method and system, and relates to the field of cervical cancer cell image classification. The problems of few cervical cell image data and unbalanced classification in the prior art are solved; and the robustness and generalization ability of the model are poor. According to the scheme provided by the invention, the image classification method comprises the following steps: step 1, acquiring a cervical cancer cell image of a Herlev data set, and preprocessing the cervical cancer cell image; step 2, an improved DenseNet121 network model is adopted to classify the cervical cell images preprocessed in the step 1; and step 3, fusing the cervical cancer cell images classified in the step 2 into an SE attention module to complete classification of the cervical cancer cell images. The method is also suitable for the cervical cancer image processing field.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of cervical cancer cell image classification. Background Art

[0002] Cervical cell screening is the most common and effective means of early diagnosis and prevention of cervical cancer and its precancerous lesions. It plays an important role in the diagnosis and prevention of cervical cell lesions and is the best tool to improve cervical cancer screening capabilities, reduce cancer incidence and save lives.

[0003] Early cervical cell screening mainly relied on the experience of physicians to judge cervical cell sections, but this method is usually time-consuming and inefficient. In recent years, artificial intelligence has developed rapidly, and a large number of scholars have studied and proposed methods for cervical cell classification, including traditional machine learning methods and deep learning methods. Compared with traditional machine learning methods, deep learning methods do not require complex processes such as artificial feature extraction, and can achieve end-to-end lesion identification, improving the efficiency of doctors' screening and diagnosis. Using deep learning methods to classify cervical cells will greatly reduce the workload of diagnostic doctors, improve diagnostic efficiency and accuracy, and facilitate the early detection and treatment of cervical precancerous lesions. However, there are still some problems in cervical cell classification in cervical cell screening. For example: cervical cell image data is small and unbalanced; model robustness and generalization ability are poor. These problems will affect the speed and accuracy of classification, etc. It is necessary to study better computer-aided diagnosis methods based on deep learning to improve screening efficiency and reduce diagnostic error rates. Summary of the invention

[0004] The present invention aims at the problems in the prior art that the cervical cell image data is small and the classification is unbalanced; the model robustness and generalization ability are poor. To solve the above technical problems, the present invention is implemented through the following technical solutions:

[0005] The present invention proposes a cervical cancer cell image classification method, which comprises the following steps:

[0006] Step 1: obtaining a cervical cancer cell image of the Herlev data set, and preprocessing the cervical cancer cell image;

[0007] Step 2: Use the improved DenseNet121 network model to classify the cervical cell images preprocessed in step 1;

[0008] Step 3: Integrate the SE attention module into the cervical cancer cell image classified in step 2 to complete the classification of the cervical cancer cell image.

[0009] Furthermore, a preferred implementation is provided, wherein step one also includes the steps of flipping, rotating and amplifying the Herlev dataset.

[0010] Furthermore, a preferred implementation manner is provided, wherein the improved DenseNet121 network model includes four steps of constructing, training, verifying, and testing the DenseNet121 network model.

[0011] Further, a preferred implementation is provided, wherein the construction of the DenseNet121 network model comprises the following steps:

[0012] S1.1, input feature image of any size;

[0013] S1.2, define an adaptive average pooling layer, perform adaptive average pooling on the feature image of any size input by S1.1, and finally output a feature image of fixed size;

[0014] S1.3, normalizing the feature image output in S1.2;

[0015] S1.4, compressing the normalized feature image;

[0016] S1.5. Call the defdensenet121 function to complete the construction of the DenseNet121 model.

[0017] Further, a preferred implementation is provided, wherein the DenseNet121 network model training comprises the following steps:

[0018] S2.1. Import the database required by the DenseNet121 model;

[0019] S2.2, use the database to load the cervical cancer cell image;

[0020] S2.3. Use the if statement to select the device to be used, and move the created improved DenseNet12 model to the selected device;

[0021] S2.4. Create a learning rate scheduler to save the correct accuracy; and define two empty lists to store the training loss and validation loss of each epoch;

[0022] S2.5. Use a for loop to loop through each epoch empty list to count the variables of loss value, number of correct predictions and total number of samples during training.

[0023] Calculate the training set accuracy under each epoch empty list, add the training accuracy of the epoch to the list storing the training accuracy, and complete the training.

[0024] Further, a preferred implementation is provided, wherein the DenseNet121 network model verification comprises the following steps:

[0025] S3.1. Obtain a validation data set, use a for loop to traverse the validation set data, move the validation set input data to the selected device; input the validation set input data into the DenseNet121 network model to obtain the output result; calculate the loss value of the model on the validation set; and count the total number of samples in the validation set;

[0026] S3.2. Calculate and obtain the validation set accuracy under the epoch empty list, that is, the ratio of the number of correctly predicted input data to the total number of input data;

[0027] S3.3. Use the if statement to compare whether the verification set accuracy exceeds the correct accuracy; if the verification set accuracy exceeds the correct accuracy, update the correct accuracy value to complete the verification.

[0028] Further, a preferred implementation is provided, wherein the DenseNet121 network model test comprises the following steps:

[0029] S4.1. Get the test data set, use a for loop to traverse the test data set images and labels, and move the images and labels to the device for calculation;

[0030] S4.2. Calculate the accuracy, precision, sensitivity, specificity and F1 score of the test data set, and calculate the weighted average to obtain the final classification result.

[0031] Solution 2: A cervical cancer cell image classification system, the image classification system comprising:

[0032] A preprocessing module, used for acquiring cervical cancer cell images of the Herlev data set and preprocessing the cervical cancer cell images;

[0033] A pre-classification module is used to classify the pre-processed cervical cell images using an improved DenseNet121 network model;

[0034] The classification module is used to integrate the classified cervical cancer cell images into the SE attention module to complete the classification of cervical cancer cell images.

[0035] Solution 3: An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method for classifying cervical cancer cell images as described in any one of Solution 1 is implemented.

[0036] Solution 4: A computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the cervical cancer cell image classification method as described in any one of Solution 1.

[0037] The present invention is beneficial in that:

[0038] The present invention uses flipping, rotation and other methods to expand the data set, unifies the image size to 224×224, normalizes the image, and then uses the improved DenseNet121 network to classify the processed images.

[0039] The present invention verified the model on the Herlev dataset and compared it with advanced methods such as Herlev-CNet and DSRNet50. The results showed that the model described in the present invention is more effective in classifying cervical cancer cell images and can effectively prevent the occurrence of cervical cancer.

[0040] The present invention is also applicable to the field of cervical cancer disease image processing. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] Figure 1 This is the processed image of the example in the eleventh implementation mode.

[0042] Figure 2 This is a flowchart of cervical cancer cell classification images based on the DenseNet121 network described in Implementation Example 11.

[0043] Figure 3 This is a flow chart of the cervical cell image classification system developed based on PyQt5 as described in Implementation Example 11.

[0044] Figure 4 This is a schematic diagram of the classification results on the Herlev dataset described in Implementation Example 11.

[0045] Figure 5 This is a schematic diagram of the classification results of cervical cancer cells in the example described in Implementation Method 11 by the classification software.

[0046] Figure 1 In the figure, (a) is a schematic diagram of the original cervical cancer cell image, (b) is a schematic diagram of the cervical cancer cell image rotated 90°, (c) is a schematic diagram of the cervical cancer cell image rotated 180°, (d) is a schematic diagram of the cervical cancer cell image rotated 270°, (e) is a schematic diagram of the cervical cancer cell image horizontally flipped, and (f) is a schematic diagram of the cervical cancer cell image vertically flipped;

[0047] Figure 4 In the figure, (a) is a schematic diagram of the classification results of the original DenseNet121 network. Figure 4(b) is a schematic diagram of the classification results of the improved DenseNet121 network. DETAILED DESCRIPTION

[0048] In order to make the purpose, technical solutions and advantages of the implementation methods of the present application clearer, the technical solutions in the implementation methods of the present application will be clearly and completely described below in conjunction with the drawings in the implementation methods of the present application. Obviously, the described implementation methods are only part of the implementation methods of the present application, not all of the implementation methods.

[0049] Embodiment 1: This embodiment provides a method for classifying cervical cancer cell images, and the image classification method comprises the following steps:

[0050] Step 1: obtaining a cervical cancer cell image of the Herlev data set, and preprocessing the cervical cancer cell image;

[0051] Step 2: Use the improved DenseNet121 network model to classify the cervical cell images preprocessed in step 1;

[0052] Step 3: Integrate the SE attention module into the cervical cancer cell image classified in step 2 to complete the classification of the cervical cancer cell image.

[0053] Embodiment 2: This embodiment further limits the cervical cancer cell image classification method described in embodiment 1, and step 1 also includes the steps of flipping, rotating and amplifying the Herlev data set.

[0054] Implementation method three: This implementation method further limits the cervical cancer cell image classification method described in implementation method one. The improved DenseNet121 network model includes four steps of constructing, training, verifying, and testing the DenseNet121 network model.

[0055] Embodiment 4: This embodiment further limits the cervical cancer cell image classification method described in Embodiment 1. The construction of the DenseNet121 network model includes the following steps:

[0056] S1.1, input feature image of any size;

[0057] S1.2, define an adaptive average pooling layer, perform adaptive average pooling on the feature image of any size input by S1.1, and finally output a feature image of fixed size;

[0058] S1.3, normalizing the feature image output in S1.2;

[0059] S1.4, compressing the normalized feature image;

[0060] S1.5. Call the defdensenet121 function to complete the construction of the DenseNet121 model.

[0061] Embodiment 5: This embodiment further limits the cervical cancer cell image classification method described in Embodiment 1.

[0062] The DenseNet121 network model training includes the following steps:

[0063] S2.1. Import the database required by the DenseNet121 model;

[0064] S2.2, use the database to load the cervical cancer cell image;

[0065] S2.3. Use the if statement to select the device to be used, and move the created improved DenseNet12 model to the selected device;

[0066] S2.4. Create a learning rate scheduler to save the correct accuracy; and define two empty lists to store the training loss and validation loss of each epoch;

[0067] S2.5. Use a for loop to loop through each epoch empty list to count the variables of loss value, number of correct predictions and total number of samples during training.

[0068] Calculate the training set accuracy under each epoch empty list, add the training accuracy of the epoch to the list storing the training accuracy, and complete the training.

[0069] Embodiment 6: This embodiment further limits the cervical cancer cell image classification method described in Embodiment 1.

[0070] The DenseNet121 network model verification includes the following steps:

[0071] S3.1. Obtain a validation data set, use a for loop to traverse the validation set data, move the validation set input data to the selected device; input the validation set input data into the DenseNet121 network model to obtain the output result; calculate the loss value of the model on the validation set; and count the total number of samples in the validation set;

[0072] S3.2. Calculate and obtain the validation set accuracy under the epoch empty list, that is, the ratio of the number of correctly predicted input data to the total number of input data;

[0073] S3.3. Use the if statement to compare whether the verification set accuracy exceeds the correct accuracy; if the verification set accuracy exceeds the correct accuracy, update the correct accuracy value to complete the verification.

[0074] Embodiment 7: This embodiment further limits the cervical cancer cell image classification method described in Embodiment 1.

[0075] The DenseNet121 network model test includes the following steps:

[0076] S4.1. Get the test data set, use a for loop to traverse the test data set images and labels, and move the images and labels to the device for calculation;

[0077] S4.2. Calculate the accuracy, precision, sensitivity, specificity and F1 score of the test data set, and calculate the weighted average to obtain the final classification result.

[0078] Embodiment 8: This embodiment proposes a cervical cancer cell image classification system, the image classification system comprising:

[0079] A preprocessing module, used for acquiring cervical cancer cell images of the Herlev data set and preprocessing the cervical cancer cell images;

[0080] A pre-classification module is used to classify the pre-processed cervical cell images using an improved DenseNet121 network model;

[0081] The classification module is used to integrate the classified cervical cancer cell images into the SE attention module to complete the classification of cervical cancer cell images.

[0082] Embodiment 9. This embodiment proposes an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the method for classifying cervical cancer cell images as described in any one of embodiments 1 to 4 is implemented.

[0083] Embodiment 10: This embodiment proposes a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the method for classifying cervical cancer cell images as described in any one of Embodiments 1 to 4 is implemented.

[0084] Embodiment 11. This embodiment provides the following examples to explain the above-mentioned embodiments 1 to 10. The specific examples are as follows:

[0085] See also Figure 1 As shown, this embodiment proposes a cervical cancer cell image classification method, which specifically includes the following steps:

[0086] in, Figure 1 (a) is a schematic diagram of the original cervical cancer cell image, (b) is a schematic diagram of the cervical cancer cell image rotated 90°, (c) is a schematic diagram of the cervical cancer cell image rotated 180°, (d) is a schematic diagram of the cervical cancer cell image rotated 270°, (e) is a schematic diagram of the cervical cancer cell image horizontally flipped, and (f) is a schematic diagram of the cervical cancer cell image vertically flipped; cervical cancer cell images of the Herlev dataset are obtained, and the dataset is flipped, rotated, etc. to generate a certain number of sub-images, thereby increasing the number of training samples. The image size is unified to 224×224, and the image is normalized.

[0087] See also Figure 2 As shown, the classification of cervical cells using the improved DenseNet121 network includes the following steps:

[0088] First, the cervical cancer cell images are preprocessed, and then the processed cervical cancer images are sent to the improved classification network to finally obtain the cervical cell classification results.

[0089] The preprocessing specifically includes the following steps:

[0090] Step 1: Import the required libraries, including os, json, and torchvision.transforms.

[0091] Step 2: Define ROOT_TRAIN, ROOT_VAL, and ROOT_TEST to represent the training set, validation set, and test set, respectively. Perform string assignment operations and assign the corresponding dataset paths to ROOT_TRAIN, ROOT_VAL, and ROOT_TEST, respectively.

[0092] Step 3: Create an empty dictionary class_indices to store all class names and their corresponding numeric indices.

[0093] Step 4: Use a for loop to iterate over the list of three elements [ROOT_TRAIN, ROOT_VAL, ROOT_TEST], and assign each element to the variable root. Use the os.listdir() function to get all the file and folder names under the specified path; use the os.path.join() function to combine the path, file, and folder names into a complete path; use the if condition to filter out the folders, and assign the filtered results to the variable cervical_class. Use the sort() method to sort cervical_class to ensure consistent order across platforms. Use a for loop and the enumerata() function to assign a numeric index to each category, with index as the corresponding index value, using the category name as the key and the numeric index as the value.

[0094] Step 5: Use the transforms.Resize() function to resize the image to the specified size of 224 × 224. Use the transforms.ToTensor() function to convert the image to a tensor. Use the transforms.Normalize() function to normalize the image.

[0095] The model construction specifically includes the following steps:

[0096] Step 1.1. Define a class named DenseLayer and specify that it inherits from the nn.Module class. Define the __init__() function, which accepts three parameters: the number of input channels in_channels, the number of output channels out_channels, and the dilation rate dilation. Call the super().__init__() function to ensure that the module is initialized correctly. Define mid_channels to calculate the number of intermediate channels, which is usually 4 times the number of output channels. Use nn.Sequential() to create a sequence self.conv containing multiple layers, which is used to implement the convolution layer, activation function layer, and batch normalization layer in the model. The first convolution is of size 1×1 and stride 1; the second convolution is a dilated convolution with a size of 3×3, stride 1, and padding the same as the dilation rate. Use def forward(self,x) to define the forward propagation function of the model, which accepts the input tensor x as a parameter. Use the return torch.cat([x, self.conv(x)], dim=1) function to concatenate the input tensor x with the tensor processed by self.conv during forward propagation and return the concatenated tensor.

[0097] Step 1.2, define a class named Transition and specify that it inherits from the nn.Module class. Define the __init__() function, which accepts two parameters: the number of input channels in_channels and the number of output channels out_channels. Call the super().__init__() function to ensure that the module is initialized correctly. Use nn.Sequential() to create a sequence self.down_sample containing multiple layers, which is used to implement the convolution layer, activation function layer, batch normalization layer, and pooling layer in the model. The convolution size is 1×1 and the stride is 1; the average pooling window size is 2×2 and the stride is 2. Use defforward(self,x) to define the forward propagation function of the model, which accepts the input tensor x as a parameter. Use the returnself.down_sample(x) function to return the output tensor.

[0098] Step 1.3. Define a class named ChannelAttention and specify that it inherits from the nn.Module class. Define the __init__() function, which accepts two parameters: the number of input channels in_planes and ratio. Call the super().__init__() function to ensure that the module is initialized correctly. Use the nn.AdaptiveAvgPool2d() function to define an adaptive average pooling layer self.avg_pool, which performs adaptive average pooling on the input feature map of any size and finally outputs a fixed-size feature map. Use the nn.Conv2d() function to define a convolution layer self.fc1 with a convolution kernel size of 1×1, an input channel number of in_planes, and an output channel number of in_planes / / ratio. Use the nn.ReLU() function to define an activation function self.relu1. Define a convolutional layer self.fc2, and use the nn.Conv2d() function to define a convolutional layer self.fc2, with a convolution kernel size of 1×1, the number of input channels in_planes / / ratio, and the number of output channels in_planes. Use the nn.Sigmoid() function to create an activation function self.sigmoid. Use def forward(self,x) to define the forward propagation function of the model, accepting the input tensor x as a parameter. Define an avg_x as the result obtained after passing through the above self.avg_pool, self.fc1, self.relu1 and self.fc2 respectively. Define out=x*avg_x to get the final result self.sigmoid(out).

[0099] Step 1.4, define a class named DenseNet and specify that it inherits from the nn.Module class. Define the __init__() function, which accepts 5 parameters: the number of dense blocks contained in each DenseBlock, the number of channels, the dilation rate, the compression rate, and the number of categories, num_classes. Call the super().__init__() function to ensure that the model is initialized correctly. Define a channel number self.channels, making it channels. Define mid_channels to calculate the number of channels, which is usually twice the number of channels. Define a convolutional layer self.in_conv, and use the nn.Conv2d() function to define a convolutional layer self.in_conv, with a convolution kernel size of 3×3, padding of 1, input channels of 3, and output channels of mid_channels. Use the nn.BatchNorm2d() function to define a normalization layer self.bn to normalize the output of the middle layer (mid_channels) of the network, which helps to speed up the training process and improve the generalization ability of the model. Use the nn.ReLU() function to define an activation function self.relu, specifying the inplace parameter as True. Use the nn.MaxPool2d() function to define a maximum pooling layer self.maxpool, with a pooling window of 2×2 and a step size of 2. Use the nn.Sequential() function to create an empty sequence module self.features for adding layers or modules of the network in sequence.

[0100] Step 1.5. Use a for loop to traverse the range of the length of the block_num list minus one, and perform the following operations for each index idex: Use the self.features.add_module function to add a feature layer named 'dense_block_layer_{idex}', which is created by the self.make_layer() function with parameters block_num[idex], mid_channels, and dilation. Update mid_channels and increase mid_channels by channels*block_num[idex] to use for the number of input channels of the next layer of features. Use the self.features.add_module function to add a channel attention layer named 'channelattention_layer_{idex}', which is created by the ChannelAttention class with a parameter of mid_channels. Update the value of out_channels to int(reduction*mid_channels), which is used for the number of output channels of the next layer of features. Use the self.features.add_module function to add a connection layer named 'transition_layer_{idex}'. This layer is created by the Transition class and plays the role of compressing the model. The parameters are mid_channels and out_channels. Update the value of mid_channels to out_channels, which is used for the number of input channels of the next layer of dense blocks.

[0101] Step 1.6, define the idex variable, whose value is the length of the block_num list minus 1. Using the self.features.add_module function, a feature layer named 'dense_block_layer_{idex}' is added to the module sequence. Its definition is created by the make_layer function with parameters block_num[idex], mid_channels, and dilation, indicating a dense block. Update mid_channels and increase mid_channels by channels*block_num[idex]. Using the self.features.add_module function, a channel attention layer named 'channelattention_last_{idex}' is added to the module sequence. This layer is created by the ChannelAttention class with a parameter of mid_channels. Using the self.features.add_module function, a layer named 'bn' is added to the module sequence. This layer is created by the nn.BatchNorm2d() function with a parameter of mid_channels. Using the self.features.add_module function, a layer named 'relu' is added to the module sequence. This layer is created by the nn.ReLU() function and inplace is True. An average pooling layer self.avgpool is defined using the nn.AdaptiveAvgPool2d() function to implement adaptive average pooling. A fully connected layer self.linear is defined using nn.Linear() to transform the current feature map into the probability distribution of the output category.

[0102] Step 1.7, define a make_layer() method, which is used to create a denseblock composed of multiple denselayers. The method accepts four parameters: the number of denselayer layers contained in the denseblock, block_num, the number of input channels, in_channels, and the dilation rate. The function first creates an empty dense_block object. Secondly, through a for loop, each created DenseLayer layer is added to the dense_block. Each DenseLayer layer will use in_channels as the number of input channels, self.channels as the number of output channels, and dilation as the dilation rate. After each loop, in_channels will be updated to the current number of input channels plus self.channels. The value of dilation is defined by the for loop, so that the second convolution layer of the last three DenseLayers in each dense_block is a hollow convolution, and the dilation is 1, 2, and 3 respectively. Similarly, each created DenseLayer layer is added to the dense_block, and the dilation rate will vary depending on the position of the current layer. After each loop, in_channels will also be updated to the current number of input channels plus self.channels. Use def forward(self,x) to define the forward propagation function of the model, accept the input tensor x as a parameter, and get the final output result.

[0103] Step 1.8, use the def densenet121() function to create a DenseNet121 model. It contains four dense blocks, the number of layers in each dense block is 6, 12, 24, 16, and the number of channels in each dense block is 32. This model can be called directly during training.

[0104] Model training consists of the following steps:

[0105] Step 2.1. Import the libraries you need to use, including model, data, torch.optim, torch.utils.data, and torchvision.datasets.

[0106] Step 2.2. Create train_dataset and val_dataset using the ImageFolder class from the torchvision library, which is used to load images from a directory. Then pass train_dataset and val_dataset from the torch.utils.data module to the DataLoader class to create train_dataloader and val_dataloader for batch loading of images during training and validation. The batch_size is set to 8 and the shuffle parameter is set to True, indicating that the order of each batch of images will be randomized during training and validation.

[0107] Step 2.3, using an if statement, select the device to use based on whether PyTorch's cuda is available. If CUDA is available, that is, a GPU is available, the device is set to 'cuda', otherwise the device is set to 'cpu'. An improved DenseNet121 model is created and moved to the previously selected device.

[0108] Step 2.4, define the loss function loss_fn, and use the nn.CrossEntropyLoss() function to calculate the loss function of multi-classification cross entropy loss. Define the optimizer optimizer, and use the torch.optim.SGD() function to create a stochastic gradient descent (SGD) optimizer to update the parameters of the model. The learning rate is set to 0.0001 and the momentum is set to 0.9. Define the learning rate lr_scheduler, and use the lr_scheduler.StepLR() function to create a learning rate scheduler to reduce the learning rate to the original 0.1 every 10 epochs. Define the total number of training rounds num_epochs. Initialize a variable best_accuracy to save the best accuracy, with an initial value of 0.0. Define two empty lists train_losses and val_losses, which are used to store the training loss and validation loss of each epoch respectively. Define two empty lists val_accuracies and train_accuracies, which are empty lists used to store the validation set accuracy and training set accuracy of each epoch respectively.

[0109] Step 2.5. Use a for loop to loop through each epoch. num_epochs specifies the total number of training rounds. Use model.train() to set the model to training mode, which enables specific operations during the training process. Define total_loss, correct_predictions, and total_samples to count the loss value, number of correct predictions, and total number of samples during the training process. Use a for loop and the enumerate() function to traverse the training set data. Move the input data and labels to the previously selected device. Use the optimizer.zero_grad() function to clear the previously accumulated gradients before starting training for each batch. Input the input data into the model to get the output output. Use the previously defined loss function loss_fn(output, target) to calculate the loss value between the model's predicted output and the true label to get the output loss. Use the loss.backward() function to perform backpropagation and calculate the gradient. Use the optimizer.step() function to update the model parameters based on the calculated gradient. Define the total_loss variable and use the loss.item() function to accumulate the loss value of the current batch. Define _, predicted, and use the torch.max() function to get the category predicted by the model. Define the correct_predictions variable, and use (predicted == target).sum().item() to count the number of correct predictions in the current batch. Define the total_samples variable, and use the target.size() function to count the total number of samples in the current batch.

[0110] Step 2.6, define the train_accuracy variable, calculate and get the training set accuracy under the current epoch, that is, the proportion of the number of correctly predicted samples to the total number of samples. Define the train_loss variable, calculate and get the average training loss under the current epoch. Use the train_losses.append() function to add the average training loss value of the current epoch to the list storing the training loss. Use the train_accuracies.append() function to add the training accuracy of the current epoch to the list storing the training accuracy.

[0111] The verification steps are as follows:

[0112] Step 3.1, use model.eval() to set the model to evaluation mode. Define total_loss, correct_predictions, and total_samples, initialized to 0, to count the loss value, number of correct predictions, and total number of samples in the validation process. Use the torch.no_grad() context manager to reduce the need to calculate gradients, which can reduce memory consumption and increase the calculation rate. Use a for loop to traverse the validation set data and move the validation set data and labels to the previously selected device. Input the validation set input data into the model to get the output result val_output. Use loss_fn() to calculate the loss value of the model on the validation set and accumulate it to the val_loss variable. Define _, val_predicted, and use the torch.max(val_output.data,1) function to get the predicted category of the model on the validation set. Define the correct_val_predictions variable, and use the (val_predicted == val_target).sum().item() function to count the number of correct predictions on the validation set. Define the total_val_samples variable, and use the val_target.size() function to count the total number of samples in the validation set.

[0113] Step 3.2, define the val_accuracy variable, calculate and get the validation set accuracy under the current epoch, that is, the proportion of the number of correctly predicted samples to the total number of samples. Define the val_loss variable, calculate and get the average validation loss under the current epoch. Use the val_losses.append() function to add the average validation loss value of the current epoch to the list storing validation losses. Use the val_accuracies.append() function to add the validation accuracy of the current epoch to the list storing validation accuracy.

[0114] Step 3.3, use the if statement to compare whether the validation set accuracy val_accuracy exceeds the best accuracy best_accuracy recorded previously. Define a folder name 'model' to save the model weight file. Use the os.path.exists(folder) function and the os.mkdir('model') function to check whether the specified folder exists, and create the folder if it does not exist. If the current validation set accuracy exceeds the best accuracy recorded previously, update the best accuracy value. Use the torch.save() function to save the current parameters of the model to a file named 'best_model.pth'. Using the if statement, when epoch == num_epochs-1, that is, the last epoch of training, save the model parameters to a file named 'last_model.pth'.

[0115] The model testing specifically includes the following steps:

[0116] Step 4.1. Import the libraries you need to use, including torch.utils.data, torchvision.datasets, numpy, sklearn.metrics, model, and data.

[0117] Step 4.2. Create test_dataset using the ImageFolder class from the torchvision library, which is used to load images from a directory. Then pass the test_dataset from the torch.utils.data module to the DataLoader class to create a test_dataloader for batch loading of images during testing. The batch_size is set to 8 and the shuffle parameter is set to True, indicating that the order of each batch of images will be randomized during testing.

[0118] Step 4.3, use the if statement to select the device to be used based on whether PyTorch's cuda is available. If CUDA is available, that is, a GPU is available, the device is set to 'cuda', otherwise the device is set to 'cpu'. An improved DenseNet121 model is created and moved to the previously selected device. The model is loaded using the model.load_state_dict(torch.load()) function. The confusion matrix conf_matrix is ​​defined using the np.zeros() function, and all elements are initialized to 0.

[0119] Step 4.4, use model.eval() to set the model to evaluation mode. Using the torch.no_grad() context manager does not require the calculation of gradients, which can reduce memory consumption and increase the calculation rate. Initialize the number of correctly classified samples correct and the total number of samples total, and initialize the variables of the accumulated accuracy accuracy_sum, precision precision_sum, recall recall_sum, specificity specificity_sum, and F1 score f1_sum.

[0120] Step 4.5. Use a for loop to iterate over the test set images and labels, and use to(device) to move the images and labels to the device for calculation. Perform forward propagation through the model to get the predicted output outputs. Define _, predicted, and use the torch.max() function to get the category predicted by the model. Define the total variable and use the labels.size() function to count the total number of samples in the current batch. Define the correct variable and use (predicted == target).sum().item() to count the number of correct predictions in the current batch. Use labels.cpu() and predicted.cpu() to move the labels and prediction results to the CPU. Use the confusion_matrix() function to update the confusion matrix conf_matrix.

[0121] Step 4.6, use the accuracy_score() function to calculate the accuracy of the current batch; use the precision_score() function to calculate the precision of the current batch; use the recall_score() function to calculate the recall of the current batch; use the np.diag() function to calculate the specificity of the current batch; use the f1_score() function to calculate the F1 score of the current batch. Accumulate the accuracy, precision, sensitivity, specificity and F1 score of each batch multiplied by the number of samples, calculate the weighted average, and get the final classification result.

[0122] like Figure 3 As shown, the classification of cervical cells is completed using the cervical cell classification system developed based on PyQt5, including the following steps:

[0123] First, enter the login interface and enter the user name and password. Then enter the function interface and enter the patient information; upload the cervical cell image; select the cervical cell classification; call the cervical cell test model; get the cervical cell classification results. Finally, save the data.

[0124] Step 1: Import the libraries you need to use, including sys, PyQt5.QtWidgets, PyQt5.QtGui, and PyQt5.QtCore.

[0125] Step 2: Define a class named LoginDialog and specify that it inherits from the QDialog class. Define the __init__() function, which accepts 1 parameter: parent is None. Call the super().__init__() function to ensure that the model is initialized correctly. Set the window title to 'Login' and fix the window size to 1200×800. Use the self.titleLabel.setObjectName() method to create a title label and use the QLabel() class to set its text to 'Cervical Cell Classification Software Login'. Then use the self.titleLabel.setStyleSheet() method to set the style of the label, with a font size of 72px, bold, and a color of #555.

[0126] Step 3: Create a logo label logoLabel and load an image named 'logo.png' to display the image in the label and set the image size to 600×450 to keep the aspect ratio and center alignment. Use QVBoxLayout() to create a vertical layout mainLayout. Call the mainLayout.setSpacing(10) method to set the spacing between widgets in the layout to 10 pixels. Call the mainLayout.setContentsMargins(10,10,10,10) method to set the margins of the four edges of the layout to 10 pixels. Call the mainLayout.addWidget(self.titleLabel) method to add the title label to the main layout. Call the mainLayout.addWidget(self.logoLabel) method to add the logo label to the main layout.

[0127] Step 4: Use the QLabel() class to create a label object to display "Username:". Use QLineEdit() to create a single-line text input box object to enter the username. Use the QLabel() class to create a label object to display "Password:". Use QLineEdit() to create a single-line text input box object to enter the password. Use self.passwordLineEdit.setEchoMode() to set the display mode of the password input box to password mode. Use QPushButton() to create a button for login, and set the text displayed on the button to "Login". Use loginButton.clicked.connect(self.handleLogin) to connect the button's click event to the handleLogin function.

[0128] Step 5: Use QVBoxLayout() to create a vertical layout for placing username, password labels, and corresponding input boxes. Use formLayout.addWidget(usernameLabel) to add the username label to the form layout. Use formLayout.addWidget(self.usernameLineEdit) to add the username input box to the form layout. Use formLayout.addWidget(passwordLabel) to add the password label to the form layout. Use formLayout.addWidget(self.passwordLineEdit) to add the password input box to the form layout. Use formLayout.addWidget(loginButton) to add the login button to the form layout. Use formLayout.setAlignment(Qt.AlignCenter) to center the widgets in the form layout. Use mainLayout.addLayout(formLayout) to add the form layout to the main layout. Use self.setLayout(mainLayout) to set the main layout as the layout of the current window.

[0129] Step 6: Use def handleLogin(self) to define a function that handles the login button click event. Use an if statement to check whether the entered username and password are correct. Call the self.accept() method. If the username and password match, close the dialog box and open the main window. Use the QMessageBox.warning() function. If the username or password does not match, pop up a warning dialog box to prompt that the username or password is incorrect.

[0130] Step 7: Define a class called EyeDiseaseAnalysisApp and specify that it inherits from the QWidget class. Define the __init__() function. Call the super().__init__() function to ensure that the model is initialized correctly. self.initUI(): Call the initUI() method to initialize the user interface.

[0131] Step 8: Use self.setWindowTitle() to set the window title. Use self.setGeometry() to set the window position and size. The parameters are the x-coordinate, y-coordinate, width, and height of the upper left corner of the window. Call the setupWidgets() method to set the widgets in the window. Call the setupLayout() method to set the layout in the window.

[0132] Step 9: Use QLabel() to create a QLabel widget to display the label "Name:". Use QLineEdit() to create a QLineEdit widget for entering a name. Use QLabel() to create a QLabel widget to display the label "Age:". Use QLineEdit() to create a QLineEdit widget for entering age. Use QPushButton() to create a QPushButton widget to confirm the input information. Use self.confirmButton.clicked.connect(self.displayPatientInfo) to connect the click event of the confirmation button to the displayPatientInfo() method so that the patient information is displayed when the button is clicked. Use QTextEdit() to create a QTextEdit widget to display the patient information. Use self.patientInfoDisplay.setReadOnly(True) to set the patient information display box to read-only mode, and the user cannot edit it. Use self.patientInfoDisplay.setMaximumHeight(50): Set the maximum height of the patient information display box to 50 pixels.

[0133] Step 10: Create a QPushButton widget using the QPushButton() class to import the cervical cell image. Use importButton.clicked.connect(lambda:self.importImage('original')) to connect the click event of the import button to the anonymous function and call the importImage() method to import the original image. Create a QPushButton widget using the QPushButton() class to perform cervical cell classification. lesionClassificationButton.clicked.connect(): Connect the click event of the cervical cell classification button to the classifyLesion() method. Create a QPushButton widget using the QPushButton() class to save patient data. Use self.saveButton.clicked.connect() to connect the button's click event to a function called self.savePatientData. When the button is clicked, the function associated with it, self.savePatientData, will be called. Use self.classificationResult.setReadOnly(True): Set the self.classificationResult object to read-only mode to prevent users from editing the text in it. Use setMaximumHeight() to set the maximum height of a component to ensure that its size in the interface does not exceed a certain limit.

[0134] Step 11: Use QVBoxLayout() to create a vertical layout manager object layout to arrange the components vertically. Use QHBoxLayout() to create a horizontal layout manager object infoLayout to arrange the information-related components horizontally. Use the addWidget() function to add the name label component, name edit box component, age label component, age edit box component, and confirmation button component to the infoLayout horizontal layout. Use the addLayout() function to add the infoLayout horizontal layout to the main vertical layout. Use the addWidget() function to add the patient information display component to the main vertical layout layout.

[0135] Step 12: Use QHBoxLayout() to create a horizontal layout manager object buttonLayout to arrange the button widgets horizontally. Use the addWidget() function to add the import button and lesion classification button to the buttonLayout horizontal layout. Use the addLayout() function to add the buttonLayout horizontal layout to the main vertical layout. Use the addWidget() function to add the classification result display widget to the main vertical layout. Use the addWidget() function to add the save button to the buttonLayout horizontal layout.

[0136] Step 13: Use QGridLayout() to create a grid layout manager object imageDisplayLayout to place the image display component. Use the addLayout() function to add the image display layout manager to the main vertical layout. Use the addWidget() function to add the image display component to the center of the imageDisplayLayout grid layout. Call the setLayout() method to apply the final main vertical layout to the current window or component.

[0137] Step 14: Define a method called displayPatientInfo to display patient information. Use self.nameEdit.text() and self.ageEdit.text() to get the text content in the name and age text boxes. Use HTML format to build a string that contains the name and age so that it can be displayed on the GUI interface, with the name and age arranged on the left and right. Use HTML format to set the patient information display component () to display the patient information on the interface.

[0138] Step 15: Define a method called importImage to import an image. Use QFileDialog.getOpenFileName() to let the user select the image file to be imported and get the file path selected by the user. Use an if statement to check whether the user has selected an image file. Call the displayImage method and pass it the image file path and processing type selected by the user to display the image.

[0139] Step 16: Define a method called displayImage to display the image. Create a QPixmap object using QPixmap(imagePath). Use pixmap.isNull() to check whether the created QPixmap object is valid, that is, whether the image is loaded successfully. Set the QPixmap object to the corresponding image display component and scale the image to the specified size using the scaled() method, keeping its aspect ratio unchanged. If the image fails to load, an error dialog box is displayed.

[0140] Step 17: Define a method called classifyLesion for cervical cell classification. Use subprocess.Popen() to execute the test script. Use the communicate() method to interact with the subprocess and obtain the output information of the subprocess. Use the if statement to check whether there is an error message. If there is an error message, a message box with a severity level is displayed in the GUI, indicating that the classification failed and the error message is displayed. If the classification is successful, get the classification result from the output of the subprocess and remove the leading and trailing blank characters. Set the classification result to the self.classificationResult text box to display the classification result on the interface.

[0141] Step 18: Define a method named savePatientData to save patient data. Use QFileDialog.getExistingDirectory() to get the path of the save folder selected by the user. Use the if statement to return without performing the save operation if the user deselects the save folder. Use nameEdit.text() and ageEdit.text() to get the text content in the name and age text boxes. Build a string containing patient information, including name and age. Get the text content in the classification result text box. Add the classification result to the patient information string. Use the with statement to open a file and prepare to write patient information. Use file.write() to write the patient information to the text file. Use for key in self.imageDisplays to traverse each key in the image display component dictionary. Use self.imageDisplays[key]: Get the image display component corresponding to the current key. Use label.pixmap() to get the QPixmap object in the image display component. Use ().isNull() to check whether the QPixmap object is valid and whether the image is loaded successfully. If the image is loaded successfully, it is saved as a PNG format file with the file name prefixed with the image type. Use QMessageBox.information() to display a message box in the GUI to prompt the user that the save operation has been successful.

[0142] Step 19: Use if__name__ == '__main__': to check if the current module is being run directly, rather than being imported into another module. Create a QApplication object, which manages the control flow and main settings of a GUI application. Create a LoginDialog object named login, which is an instance of the login dialog box. Use the login.show() function to display the login dialog box. Use the app.setStyleSheet() method to apply the style sheet to the entire application. Wait for the login dialog box to execute until the dialog box is closed. The exec_() method blocks the code until the dialog box is closed. If the return value of the dialog box is QDialog.Accepted, it means that the user clicked the login button. Create an EyeDiseaseAnalysisApp object named ex, which is an instance of the main window. Use the ex.show() function to display the main window. Run the main event loop of the application. app.exec_() blocks the program until the main window is closed, and then returns the exit code of the main event loop. If the user cancels the login or closes the dialog box, the application exits directly and returns an exit code of 0, indicating a normal exit.

[0143] The technical solution and technical effects of this implementation are further described below in conjunction with specific experimental data. Figure 4 The figure shows the results of cervical cell classification. The horizontal axis is the true value and the vertical axis is the predicted value. Figure 4 (a) is a schematic diagram of the classification results of the original DenseNet121 network. Figure 4 (b) is a schematic diagram of the classification results of the improved DenseNet121 network; class1 represents normal epithelial squamous cells, class2 represents normal middle-layer squamous cells, class3 represents normal columnar cells, class4 represents low-grade squamous abnormal cells, class5 represents moderate squamous abnormal cells, class6 represents severe squamous abnormal cells, and class7 represents carcinoma in situ. Figure 5 Shown is the classification result of cervical cells in the classification software, showing the software function interface.

[0144] It will be appreciated by those skilled in the art that the features described in the various embodiments and / or claims of the present disclosure may be combined or coupled in a variety of ways, even if such combinations or couplings are not explicitly described in the present disclosure. In particular, the various embodiments and of the present disclosure may be combined in a variety of ways without departing from the spirit and teachings of the present disclosure. All of these combinations fall within the scope of the present disclosure.

[0145] Although preferred embodiments of the present invention have been described, additional changes and modifications may be made to these embodiments by those skilled in the art once the basic inventive concepts are known. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention. Obviously, those skilled in the art may make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. A method for classifying cervical cancer cell images, characterized in that: The image classification method comprises the following steps: Step 1: obtaining a cervical cancer cell image of the Herlev data set, and preprocessing the cervical cancer cell image; Step 2: Use the improved DenseNet121 network model to classify the cervical cell images preprocessed in step 1; Step 3: Integrate the SE attention module into the cervical cancer cell image classified in step 2 to complete the classification of the cervical cancer cell image.

2. The cervical cancer cell image classification method according to claim 1, characterized in that: Step one also includes the steps of flipping, rotating and amplifying the Herlev data set.

3. The cervical cancer cell image classification method according to claim 1, characterized in that: The improved DenseNet121 network model includes four steps of constructing, training, verifying and testing the DenseNet121 network model.

4. The cervical cancer cell image classification method according to claim 3, characterized in that: The construction of the DenseNet121 network model includes the following steps: S1.1, input feature image of any size; S1.2, define an adaptive average pooling layer, perform adaptive average pooling on the feature image of any size input by S1.1, and finally output a feature image of fixed size; S1.3, normalizing the feature image output in S1.2; S1.4, compressing the normalized feature image; S1.

5. Call the defdensenet121 function to complete the construction of the DenseNet121 model.

5. The cervical cancer cell image classification method according to claim 3, characterized in that: The DenseNet121 network model training includes the following steps: S2.

1. Import the database required by the DenseNet121 model; S2.2, use the database to load the cervical cancer cell image; S2.

3. Use the if statement to select the device to be used, and move the created improved DenseNet12 model to the selected device; S2.

4. Create a learning rate scheduler to save the correct accuracy; and define two empty lists to store the training loss and validation loss of each epoch; S2.

5. Use a for loop to loop through each epoch empty list to count the variables of loss value, number of correct predictions and total number of samples during training. Calculate the training set accuracy under each epoch empty list, add the training accuracy of the epoch to the list storing the training accuracy, and complete the training.

6. The cervical cancer cell image classification method according to claim 3, characterized in that: The DenseNet121 network model verification includes the following steps: S3.

1. Obtain a validation data set, use a for loop to traverse the validation set data, move the validation set input data to the selected device; input the validation set input data into the DenseNet121 network model to obtain the output result; calculate the loss value of the model on the validation set; and count the total number of samples in the validation set; S3.

2. Calculate and obtain the validation set accuracy under the epoch empty list, that is, the ratio of the number of correctly predicted input data to the total number of input data; S3.

3. Use the if statement to compare whether the verification set accuracy exceeds the correct accuracy; if the verification set accuracy exceeds the correct accuracy, update the correct accuracy value to complete the verification.

7. The cervical cancer cell image classification method according to claim 3, characterized in that: The DenseNet121 network model test includes the following steps: S4.

1. Get the test data set, use a for loop to traverse the test data set images and labels, and move the images and labels to the device for calculation; S4.

2. Calculate the accuracy, precision, sensitivity, specificity and F1 score of the test data set, and calculate the weighted average to obtain the final classification result.

8. A cervical cancer cell image classification system, characterized in that: The image classification system comprises: A preprocessing module, used for acquiring cervical cancer cell images of the Herlev data set and preprocessing the cervical cancer cell images; A pre-classification module is used to classify the pre-processed cervical cell images using an improved DenseNet121 network model; The classification module is used to integrate the classified cervical cancer cell images into the SE attention module to complete the classification of cervical cancer cell images.

9. A computer device comprising a memory and a processor, characterized in that A computer program is stored in the memory. When the processor runs the computer program stored in the memory, the processor executes the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Client identity authentication method and device, electronic equipment and medium

    CN116383791A

  • Pasteur smear cervical cell image classification method and system

    CN117218443A