Nuclear magnetic image brain tumor detection method and system based on improved YOLOv8
By improving the backbone, neck structure, and detection head of the YOLOv8 network, and combining data augmentation and loss function optimization, the problems of missed detection of small lesions and insufficient accuracy in MRI brain tumor detection were solved, achieving efficient and real-time MRI brain tumor detection and improving the ability to identify low-contrast tumors.
Patent Information
- Application Number
- CN202511261102.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-05
- Publication Date
- 2025-12-19
AI Technical Summary
The existing YOLOv8 network has problems in MRI brain tumor detection, such as limited backbone network feature reuse capability, insufficient cross-scale information fusion, insufficient detection head resolution, and large regression error of loss function on lesions with extreme aspect ratios, resulting in missed detection of small lesions and insufficient detection accuracy.
By redesigning the backbone network to CSP-DenseNet, KernelWarehouse, and CBAM attention mechanism, improving the neck structure to Dense-connected GFPN and adding a high-resolution detection head, and combining the Inner-GIoU loss function and data augmentation strategy, the training process is optimized to improve detection accuracy.
It significantly improves the recall and detection accuracy of small lesions, reduces computational complexity and resource consumption, supports real-time MRI brain tumor detection, and further improves the identification of low-contrast tumors through PET-MRI multimodal fusion.
Smart Images

Figure CN121170516A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of medical image processing, and in particular to a nuclear magnetic image brain tumor detection method and system based on an improved YOLOv8. BACKGROUND
[0002] Magnetic resonance imaging (MRI) has become the gold standard for early screening and precise diagnosis and treatment of brain tumors due to its excellent soft tissue contrast. However, clinical MRI data generally has problems such as large tumor size difference (millimeter to centimeter), blurred benign and malignant boundary, and easy missed detection of small lesions.
[0003] The current mainstream YOLOv8 network performs excellently in general target detection tasks, but still faces the following shortcomings when directly migrated to MRI brain tumor detection:
[0004] (1) The C2f module of the backbone network has limited feature reuse capability, making it difficult to capture high-dimensional pathological details;
[0005] (2) The FPN+PANet cross-scale information fusion of the neck structure is insufficient, leading to missed detection of small targets;
[0006] (3) The detection head part only has three scale detection heads, with the highest resolution of only 80x80, which cannot effectively identify small tumors less than 16 pixels;
[0007] (4) The loss function CIoU has large regression error on extreme aspect ratio lesions;
[0008] (5) The training strategy lacks anchor box and data augmentation design specific to MRI characteristics.
[0009] Therefore, there is an urgent need for an improved YOLOv8 detection method and system for MRI brain tumor characteristics. SUMMARY
[0010] (I) Technical problems solved
[0011] Therefore, the present application proposes a nuclear magnetic image brain tumor detection method and system based on an improved YOLOv8, which re-designs the backbone network, neck structure, detection head part, and training strategy to achieve high-precision and real-time detection of small lesions, solving the problems raised in the above background technology.
[0012] (II) Technical solutions
[0013] To achieve the above purpose, the present application adopts the following technical solutions:
[0014] A nuclear magnetic image brain tumor detection method and system based on an improved YOLOv8, comprising the following steps:
[0015] S1 data preparation: obtain the initial MRI brain tumor image dataset, re-cluster the anchor box using the K-means++ algorithm, then expand the sample through multi-dimensional data enhancement such as rotation, flipping, Gaussian noise, and random affine, and divide it into training set, validation set and test set in the ratio of 7:2:1;
[0016] S2 backbone network reconstruction: replace the original YOLOv8 C2f module with a lightweight and efficient backbone that integrates CSP-DenseNet, KernelWarehouse dynamic convolution, and CBAM attention mechanism, wherein
[0017] CSP-DenseNet improves gradient flow and feature reuse rate through dense connection,
[0018] KernelWarehouse dynamically generates convolution kernel parameters based on input features to reduce redundant calculations,
[0019] CBAM uses channel attention and spatial attention to weight key pathological features in sequence;
[0020] S3 neck structure improvement: upgrade the classic FPN+PANet to GFPN with Dense connection, and embed BRA(Bi-directional Routing Attention) module in each layer of the pyramid to capture long-distance context dependence and enhance cross-scale information fusion;
[0021] S4 detection head expansion: add a 160x160 high-resolution small target detection head based on the original 3 detection heads(20x20, 40x40, 80x80) to detect micro tumors smaller than 16x16 pixels;
[0022] S5 training strategy: load the public dataset Br35H pre-trained weights for transfer learning, freeze the shallow parameters, fine-tune the deep parameters, and use the Inner-GIoU loss function to alleviate the regression error of extreme aspect ratio lesions through dynamic auxiliary boxes;
[0023] S6 inference output: input the MRI image to be detected into the trained model to obtain the brain tumor location, category and confidence, and support optional PET-MRI multi-modal fusion(channel concatenation or attention weighting) to further improve accuracy.
[0024] Further, the CSP-DenseNet structure in S2 reduces gradient vanishing and improves feature reuse rate through dense connection of convolution blocks; KernelWarehouse dynamic convolution dynamically generates convolution kernel parameters based on input features; CBAM attention mechanism uses channel attention and spatial attention to weight key features in sequence.
[0025] Further, the S3 fuses multi-scale features through cross-layer Dense connections; the BRA attention module captures long-distance context dependencies based on a bidirectional routing mechanism.
[0026] Further, the S4 adds a 160x160 detection head to capture small tumor lesions smaller than 16x16 pixels, and outputs prediction results in parallel with the original three-scale detection heads
[0027] Further, the S5 migration learning includes freezing shallow network parameters, fine-tuning deep parameters, and using an Inner-GIoU loss function to optimize bounding box regression accuracy.
[0028] An improved YOLOv8-based brain tumor detection system for magnetic resonance images, specifically comprising
[0029] A data acquisition module for performing data collection, K-means++ anchor box clustering, data augmentation, and data set division in S1;
[0030] A model construction module for improving and assembling the backbone network, neck structure, and detection head in S2-S4;
[0031] A transfer learning module for loading pre-trained weights, fine-tuning parameters, and training models in S5;
[0032] A detection output module for performing model inference and result output in S6, and the system circuit includes a power module, a data processing module, and a Bluetooth module.
[0033] A computer device comprising a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the improved YOLOv8-based brain tumor detection method for magnetic resonance images according to any one of claims 1-5.
[0034] A computer-readable storage medium storing instructions, which, when executed on a computer, cause the computer to perform the improved YOLOv8-based brain tumor detection method for magnetic resonance images according to any one of claims 1-5.
[0035] (III) Beneficial Effects
[0036] Compared with the prior art, the improved YOLOv8-based brain tumor detection method and system for magnetic resonance images have the following beneficial effects:
[0037] The comparative experiment on the BraTS2023 private test set shows that the improved YOLOv8 model proposed in the application improves the mAP@0.5 index by 4.7 percentage points compared with the original YOLOv8n. This gain is mainly due to the full mining of high-dimensional pathological features by CSP-DenseNet and KernelWarehouse dynamic convolution: CSP-DenseNet directly transmits gradient flow to the shallow layer through dense connection, so that the model can more effectively capture the subtle texture of millimeter tumors in the back propagation process, and KernelWarehouse generates the optimal convolution kernel in real time according to the input features, avoiding the lack of adaptability of traditional static convolution in the scene with large differences between cases. At the same time, the CBAM attention further suppresses the noise response of non-lesion regions such as skull and ventricle through double weighting in channel and spatial dimensions, thereby improving the detection confidence as a whole.
[0038] For the micro-lesion recall rate that is most concerned by clinicians, the newly added 160x160 high-resolution detection head brings a significant improvement of 11.2%. The detection head corresponds to the tumor area within 8mm of the original image, and still retains an effective resolution of 16x16 pixels or more on the feature map, so that the model can fully utilize the fine-grained texture difference to distinguish early-stage glioma from normal vascular space. With the dynamic auxiliary frame mechanism introduced by the Inner-GIoU loss function, the extremely long and narrow or flat tumors obtain additional geometric constraints when the boundary is regressed, significantly reducing the missed detection and deviation caused by the shape mismatch between the anchor frame and the real frame.
[0039] In terms of computing efficiency, although the model parameter amount increases by only 6.8% compared with YOLOv8n, through the sparse dynamic convolution of KernelWarehouse and the cross-layer parameter reuse of GFPN, the floating-point operation amount in the inference stage is actually reduced by 4.3%, so that the real-time performance on a single RTX 3090 graphics card can still maintain not less than 55FPS, fully meeting the needs of clinical real-time reading; At the same time, the transfer learning strategy combined with the Br35H pre-training weight shortens the training period from the original 120epoch to 85epoch, and the K-means++ re-clustering anchor frame makes the model close to convergence in the first round of training, greatly reducing the occupation time of GPU resources and power cost.
[0040] More importantly, when the system accesses the PET-MRI multi-modal fusion module, the metabolic information introduced through channel concatenation or attention weighting further improves the recognition of low-contrast and infiltrative tumors: the weight of the PET high uptake area on the attention map is significantly amplified, while the fine anatomical structure provided by the MRI effectively suppresses the PET false positives, and the complementarity of the two makes the overall mAP@0.5:0.95 increase by 3.1%, providing a more reliable basis for subsequent radiotherapy target delineation and surgical planning. BRIEF DESCRIPTION OF DRAWINGS
[0041] Figure 1 It is a schematic diagram of the overall process of the method of the present application;
[0042] Figure 2 It is a detailed view of the CSP-DenseNet+KernelWarehouse+CBAM structure of the present application;
[0043] Figure 3 It is a schematic diagram of the GFPN+BRA cross-scale fusion of the present application;
[0044] Figure 4 It is a four-detection-head layout and anchor box configuration diagram of the present application;
[0045] Figure 5 It is a principle diagram of the Inner-GIoU dynamic auxiliary frame of the present application;
[0046] Figure 6 It is a hardware block diagram of the system of the present application. DETAILED DESCRIPTION
[0047] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative labor fall within the scope of protection of the present application.
[0048] Embodiment one
[0049] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative labor fall within the scope of protection of the present application.
[0050] As Figures 1 to 6As shown, the embodiment provides a magnetic resonance imaging brain tumor detection method based on improved YOLOv8, which simultaneously completes algorithm verification and clinical deployment within the same end-to-end process; specifically including:
[0051] 1. Data acquisition and preprocessing
[0052] The data of the embodiment is derived from a hospital PACS system, and is automatically received in C-STORE SCP mode through the DCMTK library built in the data acquisition module. If offline testing is performed on site, the public brain tumor MRI data set (DICOM or NIfTI format) is directly read.
[0053] All sequences are uniformly resampled to 512x512x1 (single slice mode) or 512x512x32 (3D neighborhood mode) using pydicom and SimpleITK, and the grayscale is normalized to [0, 1].
[0054] Subsequently, the K-means++ algorithm is used to cluster all the bounding boxes (a total of 9847, covering tumor diameters of 2.3mm-49.6mm), the distance measure is 1-IoU, the number of cluster centers is 9, and the anchor box sizes are automatically generated: (4, 5), (6, 8), (8, 10), (10, 13), (13, 16), (16, 22), (22, 29), (29, 37), (37, 51).
[0055] In the data augmentation stage, Albumentations library is used to perform real-time operations: random rotation angle -30°~+30°, probability 0.5; horizontal flip probability 0.5; Gaussian noise σ∈[0.01, 0.02]; random affine scaling 0.8-1.2, translation ±20 pixels, skew ±10°. The total number of samples after augmentation is about 4.2 times the original.
[0056] Finally, GroupKFold is used for stratified sampling by case ID, with 3674 training samples, 1050 validation samples, and 525 test samples, and the tumor pixel ratio difference between the three is <0.5%, ensuring consistent distribution.
[0057] 2. Model construction (training stage)
[0058] In the embodiment, all 6 C2f modules in the official YOLOv8n.yaml are replaced by a "CSP-DenseNet-CBAM-KernelWarehouse" composite module, and the specific structure is as shown in Figure 2
[0059] Dense Block: growth rate k=32, dense layers=6, bottleneck ratio θ=0.5;
[0060] KernelWarehouse: maintain 16 base kernels for each 3x3 convolution, routing temperature τ = 30, Gumbel-Softmax is used in training stage, argmax is used in inference stage;
[0061] CBAM: first channel attention (global average pooling + max pooling → 1x1 convolution → Sigmoid), then spatial attention (7x7 convolution → Sigmoid), output is multiplied with original feature element by element.
[0062] Parameter amount increased from 3.15M to 3.36M (↑6.8%), FLOPs decreased from 8.7G to 8.3G (↓4.3%) due to dynamic convolution sparse activation.
[0063] Neck part adopts four layers of GFPN, structure as Figure 3 Each layer up-sampling rate 2, Dense connection mode: the i-th layer receives the concatenated features of {0, 1,..., i-1} layers after 1x1 convolution dimension reduction. BRA (Bi-directional Routing Attention) module is inserted after each up-sampling, window size 8x8, hidden dimension 32, head number 8, computational complexity O(n√n). Experiments show that BRA brings 0.8% mAP improvement, and GPU delay only increases 0.3ms.
[0064] On the basis of the original P3 (80x80), P4 (40x40), P5 (20x20) detection heads, a P2 (160x160) small target detection head is added, anchor scale (4, 5, 6), responsible for the region with pixel size ≤16x16. This head uses depth separable convolution, channel number 256→128→3x(5+cls). During training, the positive sample matching threshold IoU≥0.25, and the negative sample IoU<0.2; In the inference stage, the four head outputs are spliced and DIoU-NMS is uniformly performed, threshold 0.5.
[0065] AdamW optimizer is used in the training stage, initial lr=1e-3, weight decay=5e-4, batch size=32, epoch=85. Transfer learning strategy: freeze stem and first two layers of CSP-DenseNet for the first 20 epochs, and unfreeze and fine-tune for the last 65 epochs; Learning rate is annealed to 1e-4 using cosine; The loss function is Inner-GIoU, where the auxiliary box magnification coefficient α increases linearly: α=0.1→0.5. Training time is about 4.2 hours (RTX 3090x2, DDP), which is 30% shorter than starting from scratch.
[0066] 3. Inference and evaluation
[0067] Single 512x512 slice end-to-end inference time 18ms (preprocessing 2ms, network forward 14ms, postprocessing 2ms), GPU memory peak 3.7GB.
[0068] Test set results: mAP@0.5 = 0.902, mAP@0.5:0.95 = 0.674; small lesion (<8mm) recall rate 93.8%, false positives per slice 0.27. Figure 4 Give a typical case visualization, add P2 head can detect a diameter of 2.3mm early glioma high signal lesions.
[0069] After training, the system automatically calls TensorRT 8.6 to generate FP16 engine, memory usage drops from 3.7GB to 2.1GB; INT8 quantization drops to 1.5GB, mAP drops only 0.5%.
[0070] 4. System-level deployment (clinical landing)
[0071] The system uses micro-service architecture, and each module is containerized:
[0072] Data acquisition module: C-STORE SCP based on DCMTK, automatically receive DICOM sequence pushed by PACS; use pydicom to parse the label and resample to 512x512 PNG, and call K-means++ clustering service and online enhancement service at the same time. The module supports HL7 / FHIR interface and can be seamlessly connected with hospital RIS.
[0073] Model construction module: export the weight file (.pt) generated by TensorRT to generate FP16 / INT16 engine, the module provides RESTful API, input is DICOM, output is JSON format tumor box coordinates and probability.
[0074] Transfer learning module: provides a web front end, doctors can upload ≥50 local labeled data, the system automatically unfreezes the last two layers of CSP-DenseNet and starts 20 epoch incremental training, which takes about 12 minutes. The training process displays the Loss curve and validation set mAP in real time.
[0075] Detection output module: after inference, JSON results are written back to RIS through HL7 ORU message; browser uses CornerstoneJS to superimpose boundary box and probability heat map, supports one-key export PDF report. The module delay is <30ms, and concurrent 50 cases have no queuing.
[0076] Optional PET-MRI fusion unit: If both PET and MRI sequences are received, first use NIfTI format rigid alignment, then channel concatenation (MRI 1 channel + PET 1 channel = 2 channel input) or Cross-Attention weighted fusion. On the test set, the latter improves mAP by 1.9%, significantly reducing PET false positives.
[0077] 5. Electronic device and storage medium
[0078] The embodiment also provides an electronic device, comprising a processor, a memory, and a computer program stored in the memory and executable in the processor, wherein the processor implements each step of the above-mentioned method for detecting brain tumors from magnetic resonance images when executing the program.
[0079] Meanwhile, the embodiment provides a computer-readable storage medium, which stores instructions, wherein the instructions make a computer execute each step of the above-mentioned method for detecting brain tumors from magnetic resonance images when the instructions are executed in the computer.
[0080] Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments. In this document, the term "embodiments" means that the specific features, structures or characteristics described in connection with the embodiments can be included in at least one embodiment of the present application. The appearance of this phrase in various places in the specification does not necessarily mean that the same embodiment is being referred to, nor does it mean that the embodiments are mutually exclusive or alternative. It will be apparent to those skilled in the art from the embodiments described herein that the embodiments described herein can be combined with other embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the present application.
[0081] Although the embodiments of the present application have been shown and described, those skilled in the art can understand that various changes, modifications, replacements and variations can be made to the embodiments without departing from the principles and spirit of the present application, and the scope of the present application is defined by the claims and their equivalents.
Claims
1. A method for detecting brain tumors using MRI images based on an improved YOLOv8, characterized in that, Includes the following steps: S1. Obtain the initial MRI brain tumor image dataset, re-cluster the anchor boxes using the K-means++ algorithm, and then perform various data augmentation processes such as rotation, flipping, and noise reduction before dividing the dataset into training, validation, and test sets. S2. Replace the original YOLOv8 backbone network section; The original YOLOv8 used the C2f module as the core of feature extraction. The C2f module is composed of multiple Bottleneck structures stacked together. It reduces the amount of computation through cross-stage local connections (CSP), but it has problems such as insufficient feature reuse and poor dynamic adaptability. The improvement to the backbone network of YOLOv8 is to replace the original C2f structure with a lightweight and efficient backbone that integrates CSP-DenseNet, KernelWarehouse dynamic convolution and CBAM attention mechanism, thereby improving feature extraction capability and computational efficiency. S3. Replace the neck structure of the original YOLOv8; The original YOLOv8 used a combination of FPN and PANet for multi-scale feature fusion, but cross-layer information interaction was limited and small target features were easily lost. The improvement to the neck structure of YOLOv8 is to upgrade the original FPN+PANet to a Dense-connected GFPN and embed the BRA attention module to enhance cross-scale information fusion and global context awareness. S4. Replace the original YOLOv8 detection head. The original YOLOv8 is only equipped with three-scale detection heads: 20×20, 40×40, and 80×80. The highest resolution of 80×80 is difficult to capture tiny tumors of less than 16×16 pixels. The improved YOLOv8 detection head section expands from the original three detection heads to four detection heads, and adds a 160×160 high-resolution small target detection head, which significantly enhances the detection capability of small tumors; S2, S3, and S4 form an improved YOLOv8 model; S5. Transfer learning is performed on the improved YOLOv8 model using the publicly available Br35H pre-trained weights to obtain an MRI brain tumor detection model. S6. Input the above initial image dataset into the MRI brain tumor detection model for detection and output the brain tumor detection results.
2. The method for detecting brain tumors using MRI images based on improved YOLOv8 according to claim 1, characterized in that, In S2, the CSP-DenseNet structure reduces gradient vanishing and improves feature reuse through densely connected convolutional blocks; the KernelWarehouse dynamic convolution dynamically generates convolutional kernel parameters based on input features; and the CBAM attention mechanism sequentially uses channel attention and spatial attention to weight key features.
3. The method for detecting brain tumors using MRI images based on improved YOLOv8 according to claim 1, characterized in that, In S3, GFPN fuses multi-scale features through cross-layer Dense connections; The BRA attention module captures long-distance contextual dependencies based on a bidirectional routing mechanism.
4. The method for detecting brain tumors using MRI images based on improved YOLOv8 according to claim 1, characterized in that, The newly added 160×160 detection head in S4 is used to capture tiny tumor lesions smaller than 16×16 pixels, and outputs prediction results in parallel with the original three-scale detection head.
5. The method for detecting brain tumors using MRI images based on improved YOLOv8 according to claim 1, characterized in that, The transfer learning in S5 includes freezing the shallow parameters of the backbone network, fine-tuning the deep parameters, and using the Inner-GIoU loss function to optimize the bounding box regression accuracy.
6. A brain tumor detection system based on MRI images using an improved YOLOv8, characterized in that, Applied to the method for detecting brain tumors using MRI images based on an improved YOLOv8 as described in any one of claims 1-5: specifically including The data acquisition module is used to perform data collection, K-means++ anchor box clustering, data augmentation, and dataset partitioning in S1; The model building module is used to perform improvements and assembly of the backbone network, neck structure, and detection head in S2-S4; The transfer learning module is used to perform pre-trained weight loading, parameter fine-tuning, and model training in S5. The detection output module is used to perform model inference and result output in S6. The system circuit includes a power module, a data processing module, and a Bluetooth module.
7. A computer device, comprising a memory and a processor, characterized in that, The memory stores a computer program, and when the processor executes the computer program, it implements the method for detecting brain tumors based on magnetic resonance imaging according to any one of claims 1-5.
8. A computer-readable storage medium, characterized in that, The storage medium stores instructions that, when executed on a computer, cause the computer to perform the method for detecting brain tumors using magnetic resonance imaging based on an improved YOLOv8, as described in any one of claims 1-5.