Brain tumor detection method based on VanilaNet improved YOLOv8n
By introducing the VanillaNet module into the YOLOv8n model, the model architecture is simplified, and the problem of high demand for computing resources and hardware resources in YOLOv8n is solved, and it is stable and efficient in a limited hardware resource environment, which is suitable for more medical institutions.
Patent Information
- Application Number
- CN202410204035.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-23
- Publication Date
- 2024-12-20
AI Technical Summary
The complex structure of the YOLOv8n model leads to a high demand for computing resources and hardware resources, and has stability and reliability challenges, especially in hospital environments where hardware resources are limited.
Add the VanillaNet module to the YOLOv8n model, replace its backbone, simplify the model architecture, reduce computing resource requirements, improve system stability and reliability, and enable the model to run on weaker hardware.
It significantly reduces the complexity and computing requirements of the model, improves the overall stability and reliability of the system, simplifies the debugging and maintenance process, and achieves efficient operation on weaker hardware, suitable for more medical institutions.
Smart Images

Figure CN119168937A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of medicine and computer vision technology, and in particular to a brain tumor detection method based on VanillaNet-improved YOLOv8n. Background Art
[0002] Brain tumors, as a serious health hazard, pose a huge threat to the life and health of patients. Timely and accurate detection of brain tumors is crucial for medical diagnosis and treatment. Every diagnosis is not only related to the patient's future quality of life, but may also be directly related to the length of the patient's life. Brain CT images are a commonly used examination method in current medical diagnosis. They can clearly and meticulously present the brain structure, especially in showing brain lesions, edema, etc. However, due to the complexity of the brain structure, many tiny abnormal areas are easily overlooked. Doctors need to find lesions that may be only a few millimeters in size in complex images, which places extremely high demands on their professional knowledge and experience.
[0003] The auxiliary detection function in the examination equipment often uses the high-performance YOLOv8n model. The YOLOv8n model can determine the specific location of brain tumors in advance, which can not only help doctors screen and locate diseases more quickly, but also reduce doctors' work pressure and improve work efficiency to a certain extent.
[0004] However, YOLOv8n's complex model has high requirements for computing and hardware resources. When conventional hardware is used as its carrier, YOLOv8n's network structure may lead to challenges in stability and reliability, which increases the risk of application in hospital environments with limited hardware resources and has some limitations in the medical field. Summary of the invention
[0005] In view of the technical problems that the above-mentioned YOLOv8n model has a complex structure, high requirements for computing resources and hardware resources, and is not suitable for medical equipment, the present technical solution provides a brain tumor detection method for improving YOLOv8n based on VanillaNet, adds the VanillaNet module to the YOLOv8n model, replaces the backbone of the YOLOv8n model, simplifies the architecture of the YOLOv8n model, and the simplified architecture not only reduces the demand for computing resources, but also improves the overall stability and reliability of the system; enables the YOLOv8n model based on VanillaNet to run on hardware with weaker performance, thereby enabling more medical institutions to use advanced brain tumor detection technology; and can effectively solve the above-mentioned problems.
[0006] The present invention is achieved through the following technical solutions:
[0007] A brain tumor detection method based on VanillaNet improved YOLOv8n, comprising the steps of:
[0008] Step 1: Collect CT images of brain tumors, process the images, expand them and build a data set;
[0009] Step 2: Labelling is used to annotate the collected data set in XML format. The XML is converted into a txt file format and randomly divided into training set, validation set, and test set according to the ratio of 7:2:1.
[0010] Step 3: Design the VanillaNet module to improve the YOLOv8n model backbone and replace the YOLOv8n backbone with the VanillaNet module. The specific operation is as follows:
[0011] Step 3.1: For the VanillaNet module, accept 3-channel input data of size 4×4 and use C convolution kernels for convolution operation with a stride of 4, and map the image with 3 channels to features with C channels; in the convolution stages 1, 2, and 3, use a maximum pooling layer with a stride of 2 to reduce the size of the feature map; in the 4th stage, do not increase the number of channels, follow the average pooling layer; the last layer is a fully connected layer for outputting the classification result;
[0012] Step 3.2: The kernel size of each convolutional layer is 1×1, which keeps the feature map information while using the minimum computational cost for each layer. The activation function is applied after each 1×1 convolutional layer. In order to simplify the training process of the network, batch normalization is also added after each layer.
[0013] Step 3.3: For the activation function A(x), combine it with the identity mapping, which can be formulated as:
[0014] A′(x)=(1-λ)A(x)+λx
[0015] Where: λ is a hyperparameter used to balance the nonlinearity of the modified activation function A′(x);
[0016] Step 4: Combine the activation function of the backbone with the identity mapping. When the training converges, convert each batch normalization layer and its previous convolution into a single convolution. After the conversion, merge the two 1×1 convolutions. The specific operation is as follows:
[0017] Step 4.1: Convert each batch normalization layer and its previous convolution into a single convolution. The combined weight matrix and bias matrix are:
[0018]
[0019]
[0020] Where: W is the weight of the convolution kernel, B is the bias of the convolution kernel, γ is the scale in batch normalization, β is the offset, μ is the mean, σ is the variance, and the subscript i∈{1,2,...,C out} represents the value in the i-th output channel;
[0021] Step 4.2: After combining convolution with batch normalization, start combining two 1×1 convolutions. The convolution formula is:
[0022] y=W*x=W·im2col(x)=W·X
[0023] Where: x is the input feature, y is the output feature; * represents the convolution operation; · represents the matrix multiplication; im2col is to expand the pixels at each window position into a column and then convert the input into a matrix corresponding to the kernel shape;
[0024] Step 4.3: For the 1×1 convolution, the im2col operation becomes a simple reshaping operation, without the need for sliding kernels with overlap; the two convolutions without activation functions are formulated as:
[0025] y=W 1 *(W 2 *x)=W 1 ·W 2 im2col(x)=(W 1 ·W 2 )*X
[0026] Where: The weight matrices of the two convolutional layers are represented as W 1 and W 2 ;
[0027] Step 5: Improve the nonlinearity of the backbone neural network by serially superimposing the activation functions to increase the nonlinearity of each activation layer;
[0028] Step 6: Using the training set to train an improved YOLOv8n detection model based on VanillaNet to obtain a detection model;
[0029] Step 7: Input the test set into the improved YOLOv8n detection model based on VanillaNet, output the detection result of brain tumor, and realize detection.
[0030] Furthermore, the image processing described in step 1 specifically includes the following steps:
[0031] Step 1.1: Use OpenCV in Python to open the original brain tumor CT image;
[0032] Step 1.2: Invert the collected CT images of brain tumors upside down and left to right. Each image needs to be inverted twice.
[0033] Step 1.3: Combine the original image, left-right inverted image, and top-down inverted image into a folder to get the dataset.
[0034] Furthermore, in the step 2, after converting the xml to the txt file format, the label category, height and width of the image need to be stored in the txt file.
[0035] Furthermore, the nonlinearity of the backbone neural network is improved as described in step 5 by serially superimposing the activation functions to increase the nonlinearity of each activation layer; the specific operation method includes the following steps:
[0036] Step 5.1: Denote the single activation function of the neural network input x as A(x); the simultaneous superposition formula of A(x) is:
[0037]
[0038] Where: n represents the number of stacked activation functions; a i , b i are the scale and bias of each activation respectively; the nonlinearity of the activation function can be greatly enhanced by stacking them simultaneously; this formula can be viewed mathematically as a series, which is an operation that adds many quantities;
[0039] Step 5.2: To further enrich the approximation ability of the series, the series-based function can learn global information by changing the input of the neighbors; specifically, given an input feature x, where H, W, and C are its width, height, and number of channels, the activation function formula is:
[0040]
[0041] Where: h∈{1,2,...,H}, w∈{1,2,...,W}, c∈{1,2,...,C};
[0042] When n = 0, the activation function A based on the series s (x) degenerates into a pure activation function A(x), which means that the proposed method can be regarded as a general extension of existing activation functions; ReLU is used as the basic activation function to construct the sequence; ReLU is the most effective for inference in GPU;
[0043] Step 5.3: The computational complexity of the proposed activation function is further analyzed compared with the corresponding convolutional layer. in Input channel and C out The computational complexity of the convolution layer of the output channel is:
[0044] O(CONV)=H×W×C in ×C out ×k 2
[0045] The computational cost of its cascade activation layer is:
[0046] O(SA)=H×W×C in ×n 2
[0047] So we get:
[0048]
[0049] Take the fourth stage in VanillaNet as an example, where C out = 2048, k = 1, n = 7, and the ratio is about 84. The computational cost of the proposed activation function is much lower than that of the convolutional layer.
[0050] Furthermore, in step 6, the training set is trained with an improved YOLOv8n detection model based on VanillaNet to obtain a detection model, and basic parameters of the improved YOLOv8n model based on VanillaNet need to be set; the specific operation method of the basic parameter setting includes the steps of:
[0051] Step 6.1: To ensure that the model is fully learned in the dataset, the number of training rounds (epochs) is set to 300;
[0052] Step 6.2: To prevent overfitting of the final test results, early stopping (patience) is set to 100;
[0053] Step 6.3: In order to better help the model understand the global information, the number of batch processed images (batch) is set to 4;
[0054] Step 6.4: The size of the input image (imgsz) is set to 640;
[0055] Step 6.5: The training device is NVIDIA GeForce RTX 3060Laptop GPU;
[0056] Step 606: The number of workers during data loading is set to 0; the optimizer used in this training is SGD, an algorithm for adjusting model parameters to minimize the loss function;
[0057] Step 6.7: To print detailed output, set verbose to True;
[0058] Step 6.8: To ensure that the results of each run are certain under the same input and are not affected by randomness, set Deterministic to True;
[0059] Step 6.9: This training does not use regularization (dropout) and is set to 0;
[0060] Step 6.10: The initial learning rate (lr0) for this training is set to 0.0;
[0061] Step 6.11: The version of Opencv used in this training is 4.8.0; the version of Pytorch is 1.12.1; and the version of ultralytics is 8.0.1.
[0062] Furthermore, in step 7, the test set is input into the improved YOLOv8n brain tumor detection model based on VanillaNet, and the detection results are output, including the steps of:
[0063] Step 7.1: Input the test set data into the brain tumor detection model based on VanillaNet improved YOLOv8n that has been trained in step 5 for detection;
[0064] Step 7.2: After the detection is completed by the improved YOLOv8n brain tumor detection model based on VanillaNet, the detected category information and the specific coordinates and confidence of the box are returned;
[0065] Step 7.3: Display the detection results in the test set.
[0066] Beneficial Effects
[0067] The brain tumor detection method based on VanillaNet improved YOLOv8n proposed in the present invention has the following beneficial effects compared with the prior art:
[0068] (1) In the present invention, the VanillaNet module is added to the YOLOv8n model, replacing the backbone of the YOLOv8n model, simplifying the architecture of the YOLOv8n model. VanillaNet, with its simplicity as its core advantage, helps medical personnel to quickly understand and use it, greatly reducing the possibility of system errors. The simple structure of VanillaNet not only makes it easy to debug and maintain in a hospital environment, but also shows significant advantages compared to the currently used medical systems with complex architectures such as YOLOv8.
[0069] (2) When VanillaNet is used to replace the backbone network of YOLOv8n in the present invention, its simplified architecture not only reduces the demand for computing resources, but also improves the overall stability and reliability of the system. This replacement enables the YOLOv8n model based on VanillaNet to run on hardware with weaker performance, thereby enabling more medical institutions to utilize advanced brain tumor detection technology.
[0070] (3) In the present invention, by replacing the YOLOv8n backbone structure with VanillaNet, the complexity of the model is significantly reduced, making the debugging and maintenance process simpler and more direct. The simplicity of this structure helps to quickly locate and solve problems, and has the function of easy debugging and maintenance, which is crucial for rapid response in clinical environments.
[0071] (4) VanillaNet in the present invention simplifies the network structure and reduces the computing resources required during the training process. This means that compared with the original YOLOv8n model, the YOLOv8n based on VanillaNet can complete the training at a faster speed and has the effect of fast training speed. This is particularly important for medical applications that require frequent model updates to adapt to new data.
[0072] (5) The present invention also has the advantage of reducing computing requirements. In an environment with limited computing resources, the original YOLOv8n model may be difficult to run efficiently. The introduction of VanillaNet significantly reduces the computing requirements of the entire model, which not only speeds up training and reasoning, but also enables the model to run on lower-configuration computing devices, providing technical support for a wider range of medical institutions.
[0073] (6) By combining VanillaNet with YOLOv8, the present invention not only overcomes the limitations of the original model in terms of maintenance, training speed, and computing requirements, but also improves the usability and efficiency of the model in practical medical applications. This improvement provides a more practical solution for the rapid and accurate detection of brain tumors. BRIEF DESCRIPTION OF THE DRAWINGS
[0074] Figure 1This is the overall structure diagram of the YOLOv8n model on which the present invention is based.
[0075] Figure 2 This is the overall structure diagram of the VanillaNet network model of the present invention.
[0076] Figure 3 These are the loss function graph, precision graph, and recall graph of the present invention.
[0077] Figure 4 This is the F1 curve diagram of the present invention.
[0078] Figure 5 This is the accuracy diagram of the present invention.
[0079] Figure 6 This is the accuracy regression diagram of the present invention.
[0080] Figure 7 This is a brain tumor detection diagram of the present invention.
[0081] Figure 8 This is a brain tumor detection diagram of the present invention. DETAILED DESCRIPTION
[0082] The following will be combined with the accompanying drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. The described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Under the premise of not departing from the design concept of the present invention, various modifications and improvements made by ordinary persons in the art to the technical solutions of the present invention should all fall within the protection scope of the present invention.
[0083] Embodiment 1:
[0084] A brain tumor detection method based on VanillaNet improved YOLOv8n specifically includes the following steps:
[0085] The first step is to collect CT images of brain tumors, invert the images up and down and left and right, expand them, and establish a data set.
[0086] Step 1.1: For brain tumor detection, the amount and diversity of data are critical. Upside-down inversion can help the model better recognize and adapt to tumors of various morphologies, especially those that appear at different angles. Left-right inversion can increase the diversity of the data, making the model more robust when facing tumors viewed from different directions. Increasing the size of the dataset will improve the generalization ability of the model.
[0087] Step 1.2: Use the programming tool OpenCV in Python to open the original CT image. OpenCV provides a set of simple and easy-to-understand APIs for Python, which enables complex image processing tasks to be completed with less code.
[0088] Step 1.3: Combine the images into a folder to get the dataset.
[0089] The second step is to use the Labelling algorithm to annotate the collected data set in XML format, and then convert the XML into TXT file format, and randomly divide it into training set, validation set, and test set according to 7:2:1.
[0090] Step 2.1: Use the Labelling algorithm to annotate the data images of brain tumors;
[0091] Step 2.2: Convert the XML file to the txt file format, and save the image label category, height and width in the txt file;
[0092] Step 2.3: Randomly divide the dataset into training set, validation set, and test set according to the ratio of 7:2:1.
[0093] The third step is to design the VanillaNet module to improve the YOLOv8n model. Replace the main part of YOLOv8n with the VanillaNet module and improve the main part of the YOLOv8n model. Figure 1 and Figure 2 shown.
[0094] Step 3.1: For the VanillaNet module, accept 3-channel input data of size 4×4 and perform convolution operation using C convolution kernels with a stride of 4, and map the image with 3 channels to features with C channels. In the convolution 1, 2, and 3 stages, a maximum pooling layer with a stride of 2 is used to reduce the size of the feature map. In the 4th stage, the number of channels is not increased, followed by an average pooling layer. The last layer is a fully connected layer for outputting the classification result.
[0095] Step 3.2: The kernel size of each convolutional layer is 1×1, which keeps the feature map information while using the minimum computational cost for each layer. The activation function is applied after each 1×1 convolutional layer. To simplify the training process of the network, batch normalization is also added after each layer.
[0096] Step 3.3: For the activation function A(x) (which can be common functions such as ReLU and Tanh), combine it with the identity mapping, which can be formulated as:
[0097] A′(x)=(1-λ)A(x)+λx
[0098] Where: λ is a hyperparameter used to balance the nonlinearity of the modified activation function A′(x).
[0099] The fourth step combines the activation function of the backbone with the identity mapping. When the training converges, each batch normalization layer and its previous convolution are converted into a single convolution. After the conversion, two 1×1 convolutions are merged.
[0100] Step 4.1: Convert each batch normalization layer and its previous convolution into a single convolution. The combined weight matrix and bias matrix are:
[0101]
[0102]
[0103] Where: W and B are the weight and bias of the convolution kernel; γ is the scale in batch normalization; β is the offset; μ is the mean; σ is the variance; subscript i∈{1,2,...,C out} represents the value in the i-th output channel.
[0104] Step 4.2: After combining convolution with batch normalization, start combining two 1×1 convolutions. The convolution formula is:
[0105] y=W*x=W·im2col(x)=W·X
[0106] Where: x and y are input and output features; * represents convolution operation; · represents matrix multiplication; im2col expands the pixels at each window position into a column and then converts the input into a matrix corresponding to the kernel shape.
[0107] Step 4.3: For the 1×1 convolution, the im2col operation becomes a simple reshaping operation, without the need for sliding kernels with overlap. The two convolutions without activation functions are formulated as:
[0108] y=W 1 *(W 2 *x)=W 1 ·W 2 im2col(x)=(W 1 ·W 2 )*X
[0109] Where: The weight matrices of the two convolutional layers are represented as W 1 and W 2 .
[0110] The fifth step is to improve the nonlinearity of the backbone neural network by serially superimposing the activation functions and increasing the nonlinearity of each activation layer.
[0111] Step 5.1: Denote the single activation function of the neural network input x as A(x). The simultaneous superposition of A(x) can be formulated as:
[0112]
[0113] Where: n represents the number of stacked activation functions; a i , b i are the scale and bias of each activation, respectively. The nonlinearity of the activation function can be greatly enhanced by stacking them simultaneously. This formula can be viewed mathematically as a series, which is an operation that adds many quantities together.
[0114] Step 5.2: To further enrich the approximation ability of the series, the series-based function can learn global information by changing the input of the neighbors. Specifically, given an input feature x, where H, W, and C are its width, height, and number of channels, the activation function formula is:
[0115]
[0116] Where: h∈{1,2,...,H}, w∈{1,2,...,W}, c∈{1,2,...,C}.
[0117] When n = 0, the activation function A based on the series s (x) degenerates into a pure activation function A(x), which means that the proposed method can be regarded as a general extension of existing activation functions. The sequence is constructed using ReLU as the basic activation function, which is the most effective for inference in GPU.
[0118] Step 5.3: The computational complexity of the proposed activation function is further analyzed compared with the corresponding convolutional layer. in Input channel and C out The computational complexity of the convolution layer of the output channel is:
[0119] O(CONV)=H×W×C in ×C out ×k 2
[0120] The computational cost of its cascade activation layer is:
[0121] O(SA)=H×W×C in ×n 2
[0122] So we have:
[0123]
[0124] Take the fourth stage in VanillaNet as an example, where C out = 2048, k = 1, n = 7, and the ratio is about 84. The computational cost of the proposed activation function is still much lower than that of the convolutional layer.
[0125] The sixth step is to train the training set with an improved YOLOv8n detection model based on VanillaNet to obtain a detection model.
[0126] Step 6.1: To ensure that the model fully learns the dataset, set the number of training epochs to 300. This gives the model enough time to train on the entire dataset for 300 epochs. This ensures that the model has enough opportunities to learn various patterns, features, and relationships in the data, thereby improving performance. By increasing the number of training epochs, the model can understand the data more fully and generalize better to new data samples.
[0127] Step 6.2: To prevent the model from overfitting in the final stages of training, set early stopping (patience) to 100. During the model training process, the performance of the model on the validation set is checked regularly. If the performance of the model does not improve in 100 consecutive rounds of training, the training will end early. This strategy aims to prevent the model from overfitting the training data in the later stages so that it can perform well on the validation set.
[0128] Step 6.3: The number of images processed in a batch is set to 4, which means that 4 images will be processed simultaneously each time the model is trained. Increasing the batch size can effectively utilize computing resources and speed up parameter updates. This can improve training efficiency, especially when computing resources such as GPUs are available.
[0129] Step 6.4: The size of the input image (imgsz) is set to 640, which is the size of the input image accepted by the model. Larger image sizes generally provide more detailed information and help the model understand the image content more accurately. This helps the model process high-resolution images and better capture subtle features in the task.
[0130] Step 6.5: The training device is an NVIDIA GeForce RTX 3060 Laptop GPU. The parallel computing capability of the GPU makes it an ideal choice for accelerating model training, which can significantly reduce training time.
[0131] Step 6.6: Set the number of workers during data loading to 0. Single-threaded data loading can avoid potential concurrency issues and ensure the stability of data loading.
[0132] Step 6.7: Output detailed information during the training process by setting verbose to True. This is very useful for monitoring the progress of training in real time, diagnosing problems, and understanding model performance. Detailed output can help you better understand the situation of model training.
[0133] Step 6.8: To ensure the reproducibility of the experiment, set Deterministic to True. This means that under the same input conditions, the results of each run will be deterministic and not affected by randomness. This is very important for studying and reproducing experimental results.
[0134] Step 6.9: In this training, we will not use regularization and set it to 0. Regularization is a technique to reduce overfitting of the model, but it may sometimes reduce the capacity of the model. Choosing not to use regularization can help the model fit the training data better.
[0135] Step 6.10: The initial learning rate (lr0) is set to 0.01, which is the initial value of the learning rate in model training. The learning rate controls the update speed of the model parameters in each training iteration. The appropriate initial learning rate setting can affect the convergence speed of the model.
[0136] Step 6.11: The version of Opencv used in this training is 4.8.0; the version of Pytorch is 1.12.1; and the version of ultralytics is 8.0.1.
[0137] In the seventh step, the test set is input into the improved YOLOv8n detection model based on VanillaNet, and the detection result of the brain tumor is output to achieve detection.
[0138] Step 7.1: Input the test set data into the improved YOLOv8n brain tumor detection model based on VanillaNet that has been trained in S500 for detection;
[0139] After completing the improved YOLOv8n detection model based on VanillaNet, we entered the testing phase of the model. The main purpose of the testing phase is to verify the performance of the model on unknown data and provide a reliable reference for deployment in practical applications. First, the test set separated from the overall data set was used for this verification. These test set data have not been touched by the model before, so they can well simulate the working state of the model in real scenes. Each image in the test set is input into the improved YOLOv8n detection model based on VanillaNet. Considering the characteristics of VanillaNet, the model can effectively process a large amount of information in the image and extract key features from it, and then YOLOv8n performs target detection.
[0140] Step 7.2: After the detection is completed by the improved YOLOv8n brain tumor detection model based on VanillaNet, the detected category information and the specific coordinates and confidence of the box are returned;
[0141] After analyzing each image, the model will output the detection results. These results include not only the detected brain tumors, but also the specific location, size, and confidence level of each target in the image. On the detected image, the brain tumor area identified by the model will be marked with a rectangular box of a specific color, and the corresponding category and confidence level will be marked next to it to intuitively display the model's detection results.
[0142] Step 7.3: Display the detection results in the test set.
[0143] Diagnosis results such as Figure 3 , Figure 4 , Figure 5 , Figure 6 , Figure 7 and Figure 8 shown. Figure 3 A total of three loss curves are given: accuracy, mAP@50, and mAP@95. Figure 4 is the F1 curve graph, Figure 5 is the accuracy diagram of the present invention, Figure 6 This is the accuracy regression diagram of the present invention. Figure 7 and Figure 8 This is a graph showing the model’s detection results for brain tumors.
[0144] Positioning loss (box_loss): The error between the predicted box and the calibrated box (GIoU). The smaller the error, the more accurate the positioning.
[0145]
[0146] Where: IoU represents the intersection over union of the predicted box and the calibrated box; C represents the area of the circumscribed rectangle of the predicted box and the calibrated box; U represents the area of the union of the predicted box and the calibrated box.
[0147] Confidence loss (obj_loss): Calculates the confidence of the network. The smaller the confidence, the more accurate the ability to judge as a target.
[0148] obj_loss=-(y true ·log(y pred )+(1-y true )·log(1-y pred ))
[0149] Where: y_true indicates whether the calibration box contains the target; y_pred indicates the confidence prediction value of the model.
[0150] Classification loss (cls_loss): Calculates whether the anchor box and the corresponding calibration classification are correct. The smaller the anchor box, the more accurate the classification.
[0151] cls_loss=-∑(y true ·log(y pred ))
[0152] Where: y true Represents the true category of the calibration box; y pred Represents the model's class prediction probability distribution.
[0153] Precision:
[0154]
[0155] Where: TP (True Positive) is the true positive example, that is, the number of positive categories correctly predicted as positive categories; FP (False Positive) is the false positive example, that is, the number of negative categories incorrectly predicted as positive categories.
[0156] Recall: The accuracy of true positives, that is, how many positive samples were found. Recall describes how many true positive examples in the test set were picked out by the binary classifier from the perspective of real results, that is, how many true positive examples were recalled by the binary classifier.
[0157] F1 Score: It is the harmonic mean of precision and recall, and can be regarded as a balance between precision and recall. When the F1 value is high, it means that the model has achieved good results in both precision and recall.
[0158]
[0159] F1 curve graph: The F1 score is the harmonic mean of precision and recall. This curve graph shows the F1 score of the model at different thresholds. Usually, as the threshold increases, the F1 score increases first and then decreases, forming a peak. The peak appears at the threshold of 0.53, which means that the model has achieved the best balance between precision and recall at this threshold.
[0160] mAP: The area enclosed by using Precision and Recall as the two axes. m represents the average. The number behind it represents the threshold for determining IoU as a positive or negative sample. 0.5:0.95 means taking the average of the thresholds of 0.5:0.05:0.95.
[0161] mAP@50: This graph shows the performance of the model on the first metric. In the first 100 rounds, the mAP@50 value rises rapidly, showing the model's improvement in identifying objects with large overlapping areas. After 100 rounds, this value gradually stabilizes and eventually converges. The final mAP@50 value is about 0.981, which shows that the model has high recognition accuracy under a looser matching standard.
[0162] mAP@95: For this stricter metric, the graph shows a similar trend. In the first 100 epochs of model training, the mAP@95 value grows rapidly, indicating that the model gradually becomes more accurate in identifying objects in highly overlapping regions. After 100 epochs, the growth rate slows down and eventually stabilizes, but due to the high IoU threshold, the final mAP@95 value is lower than mAP@50.
[0163] The algorithm of the present invention is compared with the traditional YOLOv5 and YOLOv8n algorithms, as shown in Table 1.
[0164] Table 1
[0165]
[0166] It can be clearly seen from the table that the algorithm of the present invention has a shorter training time than YOLOv8n, which only takes 2.873 hours, while YOLOv8n takes 4.666 hours, which means that the algorithm of the present invention has a clear advantage in training speed. The algorithm of the present invention performs better in terms of average precision, reaching 0.981, while YOLOv8n only has 0.819. This shows that the algorithm of the present invention has higher precision in object detection tasks and more accurately locates and identifies targets. The recall rate of the algorithm of the present invention is also high, at 0.916, while YOLOv8n is 0.826. This means that the algorithm of the present invention can better capture the real target and reduce the possibility of missed detection.
[0167] The above embodiments are only for illustrating the technical concept and features of the present invention, and their purpose is to enable people familiar with the technology to understand the content of the present invention and implement it accordingly, and they cannot be used to limit the protection scope of the present invention. Any equivalent transformation or modification made according to the spirit of the present invention should be included in the present invention.
Claims
1. A brain tumor detection method based on VanillaNet improved YOLOv8n, characterized in that: Includes steps: Step 1: Collect CT images of brain tumors, process the images, expand them and build a data set; Step 2: Labelling is used to annotate the collected data set in XML format. The XML is converted into a txt file format and randomly divided into training set, validation set, and test set according to the ratio of 7:2:
1. Step 3: Design the VanillaNet module to improve the YOLOv8n model backbone and replace the YOLOv8n backbone with the VanillaNet module. The specific operation is as follows: Step 3.1: For the VanillaNet module, accept 3-channel input data of size 4×4 and use C convolution kernels for convolution operation with a stride of 4, and map the image with 3 channels to features with C channels; in the convolution stages 1, 2, and 3, use a maximum pooling layer with a stride of 2 to reduce the size of the feature map; in the 4th stage, do not increase the number of channels, follow the average pooling layer; the last layer is a fully connected layer for outputting the classification result; Step 3.2: The kernel size of each convolutional layer is 1×1, the activation function is applied after each 1×1 convolutional layer, and batch normalization is added after each layer; Step 3.3: For the activation function A(x), combine it with the identity mapping, which can be formulated as: A′(x)=(1-λ)A(x)+λx Where: λ is a hyperparameter used to balance the nonlinearity of the modified activation function A′(x); Step 4: Combine the activation function of the backbone with the identity mapping. When the training converges, convert each batch normalization layer and its previous convolution into a single convolution. After the conversion, merge the two 1×1 convolutions. The specific operation is as follows: Step 4.1: Convert each batch normalization layer and its previous convolution into a single convolution. The combined weight matrix and bias matrix are: Where: W is the weight of the convolution kernel, B is the bias of the convolution kernel, γ is the scale in batch normalization, β is the offset, μ is the mean, σ is the variance, and the subscript i∈{1,2,...,C out } represents the value in the i-th output channel; Step 4.2: After combining convolution with batch normalization, start combining two 1×1 convolutions. The convolution formula is: y=W*x=W·im2col(x)=W·X Where: x is the input feature, y is the output feature; * represents the convolution operation; · represents the matrix multiplication; im2col is to expand the pixels at each window position into a column and then convert the input into a matrix corresponding to the kernel shape; Step 4.3: For 1×1 convolution, the im2col operation does not require sliding kernels with overlap; the two convolutions without activation functions are formulated as: y=W 1 *(W 2 *x)=W 1 ·W 2 ·im2col(x)=(W 1 ·W 2 )*X Where: The weight matrices of the two convolutional layers are represented as W 1 and W 2 ; Step 5: Improve the nonlinearity of the backbone neural network by serially superimposing the activation functions to increase the nonlinearity of each activation layer; Step 6: Using the training set to train an improved YOLOv8n detection model based on VanillaNet to obtain a detection model; Step 7: Input the test set into the improved YOLOv8n detection model based on VanillaNet, output the detection result of brain tumor, and realize detection.
2. The brain tumor detection method based on VanillaNet improved YOLOv8n according to claim 1, characterized in that: The specific operation of processing the image in step 1 includes the following steps: Step 1.1: Use OpenCV in Python to open the original brain tumor CT image; Step 1.2: Invert the collected CT images of brain tumors upside down and left to right. Each image needs to be inverted twice. Step 1.3: Combine the original image, left-right inverted image, and top-down inverted image into a folder to get the dataset.
3. The brain tumor detection method based on VanillaNet improved YOLOv8n according to claim 1, characterized in that: In the step 2, after converting the xml to the txt file format, the label category, height and width of the image need to be stored in the txt file.
4. The brain tumor detection method based on VanillaNet improved YOLOv8n according to claim 1, characterized in that: The specific operation method of step five includes the following steps: Step 5.1: Denote the single activation function of the neural network input x as A(x); the simultaneous superposition formula of A(x) is: Where: n represents the number of stacked activation functions; a i , b i are the scale and bias of each activation, respectively; Step 5.2: Given an input feature x, where H, W, and C are its width, height, and number of channels, the activation function formula is: Where: h∈{1,2,...,H}, w∈{1,2,...,W}, c∈{1,2,...,C}; When n = 0, the activation function A based on the series s (x) degenerates into a pure activation function A(x), using ReLU as the basic activation function to construct the sequence; Step 5.3: For a kernel with K size, C in Input channel and C out The computational complexity of the convolution layer of the output channel is: O(CONV)=H×W×C in ×C out ×k 2 The computational cost of its cascade activation layer is: O(SA)=H×W×C in ×n 2 So we get: Take the fourth stage in VanillaNet as an example, where C out =2048, k=1, n=7, the ratio is about 84.
5. The brain tumor detection method based on VanillaNet improved YOLOv8n according to claim 1, characterized in that: The detection model obtained in step 6 requires basic parameter setting of the improved YOLOv8n model based on VanillaNet; the specific operation method of basic parameter setting includes the following steps: Step 6.1: To ensure that the model is fully learned in the dataset, the number of training rounds (epochs) is set to 300; Step 6.2: To prevent overfitting of the final test results, early stopping (patience) is set to 100; Step 6.3: In order to better help the model understand the global information, the number of batch processed images (batch) is set to 4; Step 6.4: The size of the input image (imgsz) is set to 640; Step 6.5: The training device is NVIDIA GeForce RTX 3060Laptop GPU; Step 606: The number of workers during data loading is set to 0; the optimizer used in this training is SGD, an algorithm for adjusting model parameters to minimize the loss function; Step 6.7: To print detailed output, set verbose to True; Step 6.8: To ensure that the results of each run are certain under the same input and are not affected by randomness, set Deterministic to True; Step 6.9: This training does not use regularization (dropout) and is set to 0; Step 6.10: The initial learning rate (lr0) for this training is set to 0.0; Step 6.11: The version of Opencv used in this training is 4.8.0; the version of Pytorch is 1.12.1; and the version of ultralytics is 8.0.
1.
6. The brain tumor detection method based on VanillaNet improved YOLOv8n according to claim 1, characterized in that: In step 7, the test set is input into the improved YOLOv8n brain tumor detection model based on VanillaNet, and the detection results are output, including the following steps: Step 7.1: Input the test set data into the brain tumor detection model based on VanillaNet improved YOLOv8n that has been trained in step 5 for detection; Step 7.2: After the detection is completed by the improved YOLOv8n brain tumor detection model based on VanillaNet, the detected category information and the specific coordinates and confidence of the box are returned; Step 7.3: Display the detection results in the test set.
