A wood defect detection method based on an improved YOLOv8 model
Patent Information
- Application Number
- CN202510236000.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-28
- Publication Date
- 2026-08-28
AI Technical Summary
[0005]为了解决现有木材缺陷检测方法模型过于复杂、检测精度较低、检测速度过慢的问题,本发明提出一种基于YOLOv8模型的木材缺陷检测方法,本方法训练简便,能够实现低成本、高精度的木材缺陷检测,本发明阐述了目标检测算法的理论依据并给出具体的实施步骤,为木材缺陷的选取提供理论依据与方法
[0020] This invention can detect defects in wood, specifically determining the type, quantity, and coordinate location of these defects. The method offers high accuracy and speed, and avoids the problems of complex training and high training costs associated with complex models.
Smart Images

Figure CN122656964A_ABST
Abstract
Description
Technical Field
[0001] This invention pertains to intelligent wood defect detection technology, specifically involving a wood defect detection method based on an improved YOLOv8 model. Background Technology
[0002] The surface quality of wood plays a crucial role in the quality of wood products, and it is greatly affected by surface defects. Wood defects refer to abnormal and irregular parts that reduce the commercial value of wood, decrease its strength, and affect the quality and appearance of processing and decoration. During wood processing, wood with surface defects needs to be removed. However, currently, there are no mature wood surface defect detection systems in production in China, and defect detection relies entirely on manual visual inspection. This leads to visual fatigue among workers due to prolonged work, resulting in high rates of missed and false detections, and incurring high costs in terms of labor, finances, and time.
[0003] To address the above issues, an increasing number of wood defect detection technologies are being applied in the field of wood defect detection. Traditional non-destructive testing technologies such as X-ray inspection, ultrasonic inspection, and infrared inspection have drawbacks such as low detection accuracy, slow detection speed, and high equipment costs, making it impossible to truly put them into mass production in the wood processing industry.
[0004] With the rapid development of computer vision and deep learning in the field of artificial intelligence, some deep learning-based methods for wood defect detection have emerged. However, these methods suffer from numerous problems: complex model structures, high training difficulty and cost, insufficient accuracy, low robustness and generalization ability, and difficulty in balancing detection accuracy and speed, making it difficult to meet the real-time requirements of modern wood processing inspection. Therefore, this paper proposes an intelligent wood defect detection method to achieve intelligent wood detection while improving detection accuracy without increasing training costs. Summary of the Invention
[0005] To address the problems of overly complex models, low detection accuracy, and slow detection speed in existing wood defect detection methods, this invention proposes a wood defect detection method based on the YOLOv8 model. This method is easy to train and can achieve low-cost, high-precision wood defect detection. This invention elucidates the theoretical basis of the target detection algorithm and provides specific implementation steps, offering a theoretical basis and method for selecting wood defects.
[0006] The technical solution of the present invention includes the following steps:
[0007] Step 1: Image Acquisition. The camera captures images of the wood surface, and the images are then labeled.
[0008] Step 2: Dataset Creation. The labeled image data is augmented using image augmentation techniques. The augmented dataset is then divided into training, validation, and test sets in a 7:2:1 ratio to obtain the final dataset.
[0009] Step 3: Model Construction. The YOLOv8 object detection model is improved to obtain the improved DCCA-YOLOv8 object detection model.
[0010] Step 4: Model Training. Train the improved DCCA-YOLOv8 object detection model, save the parameters of the model with the highest recognition accuracy, and obtain the optimal model.
[0011] Step 5: Defect Detection. Use the optimal model to detect defects in the wood.
[0012] The dataset consists of wood defect images captured by industrial cameras, including three categories: knots, cracks, and decay.
[0013] Furthermore, in step 1, labels are used to annotate defects in the image to obtain a label file containing the type, location, and quantity of defects.
[0014] Furthermore, in step 2, random data augmentation methods are used to expand the dataset, including random flipping, rotation, cropping, brightness adjustment, noise addition, and image erasure.
[0015] Furthermore, a wood defect detection method based on an improved YOLOv8 model is characterized in that: in the network model in step 3, deformable convolution is introduced in the Bottleneck module of the C2f module in the backbone feature extraction network to compensate for the poor performance of square convolution kernels in extracting defect features such as wood cracks, thereby improving the accuracy of wood defect detection.
[0016] Furthermore, a wood defect detection method based on an improved YOLOv8 model is characterized in that: in the network model in step 3, a CA attention mechanism is introduced at the end of the backbone feature extraction network and before the strengthening feature extraction network, thereby improving the model's ability to accurately locate defect location information without increasing the computational load.
[0017] Furthermore, a wood defect detection method based on an improved YOLOv8 model is characterized in that: in the network model of step 3, the SPPF module in the enhanced feature extraction network is replaced with the SPPFCSPC module, which combines the advantages of the SPPF module and the SPPCSPC module to effectively improve the multi-scale feature expression capability and computational efficiency of the model.
[0018] Furthermore, a wood defect detection method based on an improved YOLOv8 model is characterized in that: in the network model in step 3, Inner-IoU and GIoU loss functions are introduced into the loss calculation of bounding box regression. Inner-IoU is introduced into GIoU to construct a new loss function Inner-GIoU to replace the original IoU loss function, thereby improving the accuracy of the network.
[0019] The advantages of this invention are:
[0020] This invention can detect defects in wood, specifically determining the type, quantity, and coordinate location of these defects. The method offers high accuracy and speed, and avoids the problems of complex training and high training costs associated with complex models. Attached Figure Description
[0021] Figure 1 Flowchart of the present invention
[0022] Figure 2 DCCA-YOLOv8 Network Structure Diagram
[0023] Figure 3 DCCA-Bottleneck network structure diagram
[0024] Figure 4 DCCA-C2f network structure diagram
[0025] Figure 5 SPPFCSPC Network Structure Diagram
[0026] Figure 6 CA Attention Module Structure Diagram
[0027] Figure 7 Inner-IoU diagram
[0028] Figure 8 Test result image Detailed Implementation
[0029] To make the objectives, technical solutions, and effects of this invention clearer, the invention will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of the invention.
[0030] like Figure 1 As shown, the present invention provides a wood defect detection method based on the YOLOv8 model, which specifically includes the following steps:
[0031] Step 1: Collect wood image data and annotate the images.
[0032] The dataset consists of images of wood defects captured by industrial cameras at wood processing sites, including three categories: knots, cracks, and decay.
[0033] Step 2: Use data augmentation to expand the labeled wood defect dataset and split the dataset.
[0034] Image data augmentation includes methods such as random flipping, rotation, cropping, scaling, brightness adjustment, noise addition, and random cropping. The dataset is divided into training, validation, and test sets in a ratio of 7:2:1.
[0035] Step 3: Construct an improved YOLOv8 object detection network model;
[0036] The improved YOLOv8 network model structure is as follows: Figure 2 As shown;
[0037] In the backbone feature extraction network, stacking convolutional modules and DC-C2f modules is used to extract deep features from the input features;
[0038] Introducing the deformable convolutional layer DCNv4 into the BottleNeck module, replacing the second and third convolutional layers with DCNv4, constructs the DCCA-BottleNeck module, with the network structure as follows: Figure 3 As shown, the DCCA-BottleNeck module can adaptively adjust the size, shape, and position of the convolutional kernels to more accurately match the actual features of the target for feature extraction. The DCCA-BottleNeck module replaces the original BottleNeck module to construct the DCCA-C2f module, which in turn replaces the C2f module, increasing the network depth and receptive field. This improves feature extraction capabilities, especially for wood crack defects, without increasing computational cost. The network structure is shown below. Figure 4 As shown;
[0039] The feature enhancement network mainly consists of four parts: SPPFCSPC module, PAA module, PAN module, and CA attention module. Based on the original feature enhancement network, the SPPF module is replaced with the SPPFCSPC module, and a CA attention module is added before and after the SPPFCSPC module. The main task is to process the feature maps extracted from the backbone feature extraction network. By fusing the SPPFCSPC, PAA, and PAN modules, multi-scale feature fusion and enhancement are achieved. The CA attention module makes the model more focused on key features and suppresses redundant features, thereby improving the accuracy and speed of wood defect target detection.
[0040] The SPPFCSPC module optimizes SPPF by combining the advantages of SPPCSPC. The network structure is as follows: Figure 5 As shown, the SPPFCSPC module integrates multiple capabilities such as spatial pyramid pooling, cross-stage partial connectivity, and spatially related partial connectivity. By efficiently stitching feature maps of different scales, it significantly enhances the model's ability to detect targets of various sizes, ensuring accurate target recognition in various complex scenarios.
[0041] The PAA module is responsible for intelligent bounding box assignment, which improves the model's feature learning ability by optimizing the selection mechanism of positive and negative samples; the PAN module enhances the expressive power of the feature map by aggregating features at different levels through bottom-up and top-down paths.
[0042] The main function of the CA attention module is to enhance key features, and its structure is as follows: Figure 6 As shown, the CA attention mechanism model can weight the features of wood defects, making the model pay more attention to effective features, thereby improving the recognition and detection of defect targets in the image;
[0043] The prediction output consists of three output layers. Each output layer includes a detection head and a classification head, responsible for actual object detection and bounding box regression. It processes the feature maps passed from the feature enhancement network through convolutional layers, outputting the object class probability, bounding box coordinates, and confidence score, and finally integrates them into a complete detection result. The detection head includes a series of convolutional and deconvolutional layers to generate detection results, predict the bounding box regression value and object confidence score for each anchor box. The classification head uses global average pooling to classify the feature maps, reducing the dimensionality of the feature maps, and outputs the probability distribution for each class.
[0044] Step 4: Train the improved YOLOv8 object detection model, save the parameters of the model with the highest recognition accuracy, and obtain the optimal model;
[0045] The calculation of the loss function includes two parts: classification loss and bounding box loss. The classification loss uses the binary cross-entropy loss function, and the bounding box loss uses the Inner-CIoU loss function to replace the original CIoU loss function to make up for the weaknesses of CIoU in terms of weak generalization ability and slow convergence speed.
[0046] Inner-IoU introduces a scale factor ratio to control the size of the auxiliary bounding box, thereby accurately calculating the matching degree between the predicted and ground truth bounding boxes. An illustration of Inner-IoU is shown below. Figure 7 As shown, the calculation formula is as follows:
[0047]
[0048] union = (w gt *h gt )*(ratio) 2+(w*h)*(ratio) 2 -inter
[0049]
[0050] L Inner-IoU =1-IoU inner
[0051] Where w, h, and b represent the width, height, and center point of the predicted bounding box, respectively. gt ,h gt ,b gt The bounding box represents the width, height, and center point of the boundary; ratio represents the scale factor; b gt ,b represents the calculated results of the ground truth bounding box and the predicted bounding box, (x c ,y c () indicates the center point inside the anchor frame and the internal anchor point;
[0052] The formula for calculating Inner-CioU is as follows:
[0053] L Inner-GIoU =L GIoU +IoU-IoU inner
[0054] YOLOv8 hyperparameter settings: input image pixel size 640*640, training 100 epochs, batch_size 16, num_workers 4, Adam optimizer, decay weight coefficient 5*10-4, initial learning rate 1*10-5, and an IoU threshold of 0.5 for testing on the test set. Step 5: Use the trained model to detect defects in wood:
[0055] The test results are shown in the image below. Figure 8 As shown.
Claims
1. A method for detecting wood defects based on an improved YOLOv8 model, characterized in that... The implementation steps are as follows: Step 1: Collect wood image data and annotate the images. Step 2: Expand the image data and divide the dataset into training, validation and test sets in a ratio of 7:2:
1. Step 3: Build an improved YOLOv8 object detection model. Step 4: Train the improved YOLOv8 object detection model, save the model parameters with the highest recognition accuracy, and obtain the optimal model. Step 5: Use the optimal model to detect defects in the wood.
2. The wood defect detection method based on the improved YOLOv8 model according to claim 1, characterized in that: In step 2, data augmentation employs methods such as random flipping, rotation, cropping, scaling, brightness adjustment, noise addition, and random cutting.
3. The wood defect detection method based on the improved YOLOv8 model according to claim 1, characterized in that: The basic structure of the target detection model in step 3 is the improved YOLOv8 model structure, which mainly includes four parts: input image, backbone feature extraction network, feature enhancement network, and prediction output. The input image is a 640*640*3 image. The backbone feature extraction network replaces the original C2f module with the Ds-C2f module, and is mainly composed of stacked Conv and Ds-C2f modules. The Conv module consists of convolutional layers, batch normalization layers, and SiLU activation functions. The convolutional layers extract local spatial information by performing convolution operations on the input image, and the batch normalization layers normalize the feature value distribution. Finally, the activation function introduces nonlinear transformation capabilities, thereby realizing the transformation and extraction of input features. The improved backbone feature extraction network replaces the C2f module with the Ds-C2f module. The Ds-C2f module is an important feature fusion module. When the feature map is input, it first undergoes a convolution to adjust the number of channels to twice the number of input channels. Then, the Split module divides the feature map into two parts. One part is used to gradually extract features through multiple Bottlenecks, and then it is concatenated with the other part. Finally, a convolution adjusts the concatenated feature map to the required number of channels. The feature enhancement network replaces the original SPPF module with the SPPFCSPC module and mainly consists of three parts: the SPPFCSPC module, the PAA module, and the PAN module. Its main task is to process the feature maps extracted from the backbone and achieve multi-scale feature fusion and enhancement by fusing the SPPFCSPC, PAA, and PAN modules. The SPPFCSPC module combines the advantages of SPPF and SPPCSPC, significantly enhancing the model's ability to detect targets of various sizes by efficiently stitching feature maps of different scales, ensuring accurate target recognition in various complex scenes. The PAA module is responsible for intelligent bounding box assignment, improving the model's feature learning ability by optimizing the positive and negative sample selection mechanism. The PAN module enhances the expressive power of the feature maps by aggregating features at different levels through bottom-up and top-down paths. The prediction output consists of three output layers. Each output layer includes a detection head and a classification head, responsible for actual object detection and bounding box regression. Convolutional layers process the feature maps passed from the feature enhancement network, outputting object class probabilities, bounding box coordinates, and confidence scores, which are then integrated into a complete detection result. The detection head includes a series of convolutional and deconvolutional layers to generate detection results, predicting the bounding box regression value and object confidence score for each anchor box. The classification head uses global average pooling to classify the feature maps, reducing their dimensionality and outputting the probability distribution for each class.
4. The wood defect detection method based on the improved YOLOv8 model according to claim 1, characterized in that: The model uses the Inner-GIoU loss function to calculate the loss for bounding box regression: union=(w gt *h gt )*(ratio) 2 +(w*h)*(ratio) 2 -inter L Inner-IoU =1-IoU inner L Inner-GIoU L GIoU +IoU-IoU inner To address the shortcomings and deficiencies of traditional IoU-based bounding box regression methods, this paper generates auxiliary bounding boxes of different scales by controlling the value of the scale factor ratio, thereby accelerating the bounding box regression process, reducing the model algorithm's over-reliance on a single newly added loss term, promoting the model's convergence process, and improving the model's detection performance and generalization ability in wood defect detection.
5. The wood defect detection method based on the improved YOLOv8 model according to claim 1, characterized in that: In the network model of step 3, a serpentine dynamic convolution is introduced in the Bottleneck module of the C2f module in the backbone feature extraction network to compensate for the poor performance of square convolution kernels in extracting wood crack defect features and improve the accuracy of wood defect detection.
6. The wood defect detection method based on the improved YOLOv8 model according to claim 1, characterized in that: In the network model of step 3, a CA attention mechanism is introduced at the end of the backbone feature extraction network and before the enhanced feature extraction network, which improves the model's ability to accurately locate defect location information without increasing the amount of computation.
7. The wood defect detection method based on the improved YOLOv8 model according to claim 1, characterized in that: In the network model of step 3, the SPPF module in the enhanced feature extraction network is replaced with the SPPFCSPC module, which has a stronger feature learning capability. Combining the advantages of the SPPF module and the SPPCSPC module, the multi-scale feature expression capability and computational efficiency of the model are effectively improved.