Wood surface defect detection and sorting method based on Bayesian network, computer readable storage medium and computer program product
Through Bayesian network combined with YOLO object detection algorithm, the problem of ambiguity and complex relationship processing in wood surface defect detection is solved, the detection accuracy and robustness are improved, more scientific grading standards are provided, and the multi-category is enhanced The processing capability of object detection.
Patent Information
- Application Number
- CN202411168554.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-23
- Publication Date
- 2024-12-10
AI Technical Summary
It is difficult for the prior art to accurately deal with the ambiguity and complex relationships in the detection of wood surface defects, resulting in inaccurate or inconsistent classification results. Especially when dealing with small-size defects and complex defect shapes, false detection and missed detection are more common.
Using the wood surface defect detection and sorting method based on Bayesian network, features are extracted through image preprocessing, and Bayesian network model is constructed. Combined with the YOLO object detection algorithm, Bayesian classifier comprehensively considers the location and type of defects. statistical relationship, calculate posterior probability for classification decisions.
It improves the accuracy and robustness of wood surface defect detection, can handle complex uncertainty more effectively, provides more scientific grading standards, enhances the processing ability of multi-category object detection, and reduces the misjudgment rate.
Smart Images

Figure CN119107304A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of wood defect detection, and more specifically, relates to a wood surface defect detection and sorting method based on a Bayesian network, a computer-readable storage medium, and a computer program product. Background Art
[0002] Wood surface defect detection is a vital task in the wood industry. Wood veneer surface defects may be caused by a variety of reasons, such as growth environment factors, tree factors, felling and processing processes, and storage and transportation links. Accurately detecting wood surface defects and accurately grading them can help manufacturers improve product quality, achieve reasonable grading, and reduce production costs. However, wood surface defect detection is not an easy task. First of all, there are many types of defects on the wood surface, such as dry scars, slipknots, cracks, etc. These defects vary in shape, size and color. Some defects are not much different from the texture and color of normal wood, and are easily misjudged, requiring the model to have a high degree of generalization ability.
[0003] Chinese patent document CN117876663A discloses a wood defect detection method and system based on deep neural network, which includes the following steps: obtaining a wood defect data set, and dividing the defect data set into a training set, a validation set and a test set; constructing an initial defect detection model based on the YOLOv8 model, including: replacing the Conv module of the Neck network in the YOLO model with the RFCA module; and replacing the ReLU activation function in the RFCA attention mechanism with the SiLU activation function. A small target decoupling detection head is added to the head part to improve the detection ability of small targets. Secondly, the CIoU loss function is replaced by the Wise-IoU loss function. Finally, the idea of transfer learning is introduced to construct an improved YOLOv8 model. The initial defect detection model is trained using the training set to obtain the final defect detection model; the validation set is input into the final defect detection model, and the detection results are output. Then the test set, local video and real-time collected images on the mobile terminal are input into the wood defect intelligent detection system, and the detection results are output.
[0004] Compared with traditional object detection, YOLO (You Only Look Once) object detection uses convolutional neural networks (CNN) for end-to-end training and detection. YOLO divides the entire image into fixed grids, each of which predicts multiple bounding boxes and their category probabilities to achieve single-shot detection. This method is not only fast and suitable for real-time applications, but also has high detection accuracy thanks to the use of global information. YOLO takes into account global context information when processing images, while traditional methods usually rely only on local features.
[0005] However, YOLO's detection results may still have certain errors and inaccuracies, especially for small-sized or different defects in the same annotation box, which may cause missed detection or false detection, resulting in inaccurate statistics on the number and type of defects. Secondly, the calculation of the defect area may be restricted by the detection algorithm. Factors such as the accuracy of the bounding box and the complexity of the defect shape will affect the accuracy of the area calculation. For some small defects that may affect the quality of veneer, ignoring their area may cause errors. Therefore, the detection algorithm needs to have strong robustness and adaptability.
[0006] At the same time, due to differences in upstream and downstream production processes, the sorting process may have problems with inconsistent standards and significant differences in sorting effects. Traditional image processing methods are difficult to properly handle complex defect situations, so deep learning technology has been increasingly used in this field in recent years. It can automatically learn features with a large amount of data to improve the accuracy and robustness of detection. By using the trained YOLO model to detect new wood images, the bounding box, category, and confidence level of each defect are output. For each detected defect, its location and size are recorded, and the quality grading standard for veneer is defined based on the type and size of the detected defect.
[0007] However, relying solely on the set threshold size to judge the veneer grading has limitations in dealing with uncertainty and correlation issues. The threshold method is usually difficult to accurately handle the ambiguity and complex interrelationships in actual situations, which may lead to inaccurate or inconsistent classification results. For the same veneer, there are statistical laws in the correlations between defects, including quantity correlation, position correlation, type correlation, size correlation, direction correlation and time correlation. For example, some defect types may tend to cluster in a specific area, or the quantity and size of some defect types may affect each other, and the directionality of defects may be correlated. Bayesian networks can capture these statistical laws, comprehensively consider the type, quantity, location and interrelationship of defects, and form a more comprehensive and accurate quality assessment model, thereby improving the reliability and accuracy of veneer grading. This method can more effectively deal with complex and uncertain quality assessment problems and provide more scientific grading standards.
[0008] In view of the above problems, the present invention proposes a wood surface defect detection and sorting method based on Bayesian network to classify the wood and realize wood sorting. Summary of the invention
[0009] In view of the shortcomings of the prior art, the present invention provides a wood surface defect detection and sorting method based on a Bayesian network to solve the problem that the prior art is difficult to accurately handle the ambiguity and complex relationships in actual situations, which may lead to inaccurate or inconsistent classification results.
[0010] The invention also discloses a computer-readable storage medium for implementing the above method.
[0011] The invention also discloses a program product for realizing the method. Summary of the invention:
[0013] The present invention first preprocesses the wood defect image and uses advanced image processing technology to extract multiple features including dry scars, cracks, slip knots, dead knots, etc. These features are used to construct a Bayesian network, which can capture the dependencies between features. Based on the learned Bayesian network structure and parameters, a wood defect classifier is constructed. The classifier can calculate the posterior probability that the wood sample belongs to each category based on the observed values of the input features and make classification decisions. In this way, the Bayesian network can not only utilize the information of each feature itself, but also utilize the relationship between the features, thereby improving the accuracy of the classifier. Compared with the traditional naive Bayes classifier, this method has higher classification accuracy and robustness in the wood defect classification task.
[0014] The detailed technical scheme of the present invention is as follows:
[0015] A method for detecting and sorting wood surface defects based on a Bayesian network, the method comprising:
[0016] S1, obtaining veneer defect image data and preprocessing the image data to extract a data set;
[0017] S2, building a Bayesian network based on the preprocessed extracted data set, and modeling these relationships through the Bayesian network;
[0018] S3, constructing a Bayesian classifier based on the Bayesian network structure and parameters;
[0019] S4. Use the target detection algorithm YOLO to perform preliminary target detection on the image, obtain the target's position, shape and preliminary category prediction information, and input this information as features into the Bayesian classifier. The Bayesian classifier comprehensively considers prior knowledge and target features obtained from YOLO, accurately calculates the posterior probability that the target belongs to each category, and predicts the grade of the veneer.
[0020] Preferably, according to the present invention, the preprocessing of the image data refers to:
[0021] S11. Increase the number of minority class samples by using the data oversampling method to make the number of samples of the majority class and the minority class the same. At the same time, use the image weighting strategy to adjust the weight according to the number of samples during the model training process, give a larger weight to the category with a smaller number of image samples, and give a smaller weight to the category with a larger number of image samples. The purpose of this is to make the model pay more attention to the sample category with a smaller number during training, thereby improving the model's processing ability and generalization performance for samples of different categories, and avoiding the model's excessive bias towards the category with a larger number and ignoring the category with a smaller number;
[0022] S12, using vertical flipping, horizontal flipping, random rotation, adding noise, random cropping, adding noise and mixing to increase the amount of data to improve the performance of the computer vision model and form a target detection data set;
[0023] The target detection dataset consists of images and annotation files. The annotation file contains five fields. The first field indicates the defect type; the second field indicates the X-axis center coordinate X_center of a certain type of defect position; the third field indicates the Y-axis center coordinate Y_center of a certain type of defect position; the fourth field indicates the width Width of the defect real box; the fifth field indicates the height Height of the defect real box;
[0024] S13. Convert the target detection dataset into a classification dataset. According to the defect type, location and size information recorded in the annotation file, slice the dataset, that is, crop the original image into a single defect image, and store it in a directory classified by defect category. The processed defect detection dataset consists of seven directories: 0GB, 1HJ, 2LF, 3QK, 4SJ, 5SP and 6KD, which represent dry scars, slip knots, cracks, gaps, dead knots, bark and knife blades, respectively, to construct the dataset required for the subsequent steps.
[0025] Preferably according to the present invention, the Bayesian network consists of a directed acyclic graph and the probability of each variable, defined as B = (G, P), wherein G = (V, E) is a directed acyclic graph representing the network structure, V represents a node set, E represents an edge set, P is a vector of conditional probabilities, and the nodes represent causal relationships through directed arcs, as described below: for a node v∈V, the parent node of v is a node with a directed connection pointing to v; the direction of the arc from node to node indicates that one variable affects another variable; the node from which the arrow starts is called a parent, and the node to which the arrow points is called a child; the directed graph can represent causal dependencies, and loops are not allowed in the graph; each node has its own conditional probability distribution.
[0026] Preferably, according to the present invention, the construction of the Bayesian network means that the Bayesian network is mainly composed of nodes and parameters. The present invention first constructs an 8-node Bayesian network, including defect nodes 0GB, 1HJ, 2LF, 3QK, 4SJ, 5SP, 6KD and a grading node Grade node; wherein the prior probability of the 0-6 defect nodes is obtained according to the statistics of the preprocessed data set, and the prior probability of the Grade node is obtained according to the grading standard in the aforementioned data set. 1 is set to represent excellent grading and 0 to represent inferior grading. In addition, in the grading operation, 3QK and 5SP defects are more important. When these two types of defects appear, the grade is directly determined to be inferior, that is, P(Grade=0|3QK=1)=1, P(Grade=0|5SP=1)=1;
[0027] Then a defect number node FlawNum is introduced, with a value of 40% for High and 60% for Low, that is, P(Grade=0|FlawNum=High)=1, which means that when the defect number is High, the Grade is directly determined to be 0; the High and Low are determined according to the number of defects, because if there are too many defects in a piece of veneer, it is directly determined to be inferior, so when the defect number is High, the Grade is directly determined to be 0.
[0028] However, as far as the collected data set images are concerned, there is a certain correlation between the various defect types in a picture. The Bayesian network mainly relies on prior knowledge to achieve posterior prediction. Therefore, it is necessary to calculate the correlation coefficients between various defects based on correlation analysis to further optimize the structure of the Bayesian network, such as the Pearson correlation coefficient, to quantify the strength and direction of the linear relationship between various defects. The situation where the correlation coefficient is close to 1 or -1 indicates that there is a strong positive or negative correlation, which further improves the Bayesian network.
[0029] Preferably, according to the present invention, constructing a Bayesian classifier means, based on the preprocessed wood defect data set, combined with the constructed Bayesian network structure, to construct an improved defect classifier, and the construction process mainly includes the following steps: according to the prior probability and conditional probability, the posterior probability is calculated using the Bayesian theorem to make classification decisions. First, all the variables contained in the Bayesian network structure and the dependencies between them are clarified. These variables are divided into two categories: input variables (features) and output variables (classification labels). The data is used to estimate the conditional probability distribution of each node in the Bayesian network. Specifically, the conditional probability of each variable given its parent node value needs to be calculated;
[0030] The following is the process of using the Bayesian formula to find the maximum posterior probability of the extracted wood defect features to classify the veneer grade:
[0031] The variables D1, D2, D3, D4, D5, D6, D7, and D7 represent the types of wood defects. C represents the veneer grade, with high quality being C1 and low quality being C2. The prior probability is estimated by counting the frequency of different grades in the past records of grading a large number of veneers. The conditional probability is as follows:
[0032] P(D1|C): probability of dry scar given category C;
[0033] P(D2|D1,C): probability of a slipknot given class C and dry scar D1;
[0034] P(D3|C): probability of a crack given category C;
[0035] P(D4|D2,C): probability of a gap given class C and slipknot D2;
[0036] P(D5|D2,C): probability of a dead knot given class C and slipknot D2;
[0037] P(D6|D4,C): probability of bark given category C and gap D4;
[0038] P(D7|D6,C): probability of carrying a knife given category C and bark D6;
[0039] According to Bayes' theorem, we have:
[0040]
[0041] In formula (1):
[0042] P(C K | D1, D2, ..., D7) is the veneer classification grade C for a given defect K The posterior probability of
[0043] P(D1,D2,...,D7|C K ) can be decomposed into P(D1, D2, ..., D7|C according to the conditional independence in the Bayesian network. K )=P(D1∣C)·P(D2∣D1,C)·P(D3∣C)·P(D4∣D2,C)·P(D5∣D2,C)·P(D6∣D4,C)·P(D7∣D6,C);
[0044] P(C K ) is the classification level C K The prior probability of
[0045] P(D1, D2, ..., D7) is the overall probability of observing defects D1, D2, ..., D7;
[0046] The posterior probabilities of the high-quality category C1 and the low-quality category C2 are calculated by the above formula, and then the category with the larger posterior probability is selected as the quality classification result of the veneer.
[0047] A computer-readable storage medium stores computer instructions, which can implement the steps of the above method when executed by a processor.
[0048] A computer program product loaded with the above method comprises computer instructions, which can implement the steps of the above method when executed by a processor.
[0049] Compared with the prior art, the present invention has the following beneficial effects:
[0050] The present invention combines a Bayesian network, a Bayesian classifier and a target detection algorithm. The target detection algorithm is responsible for accurately locating and identifying defects, while the Bayesian classifier comprehensively considers the location information of the defects and the statistical information between defects of different categories. This synergistic effect helps to more accurately detect and classify different grades of wood surface defects. In addition, the Bayesian classifier has been proven to be able to efficiently deal with multi-category target detection problems. In wood surface defect detection, there are many different types of defects, such as cracks, dead knots, loose knots, etc. By combining the Bayesian classifier, we can effectively improve the detection performance between these different types of defects, and the Bayesian network focuses on the probabilistic statistical relationship between different types of defects, thereby achieving a complementary relationship with the target detection algorithm. This method can not only improve the accuracy of defect detection, but also handle uncertainty, reduce dimensionality, support multi-category detection, and focus on the statistical relationship between different defects. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] Figure 1 It is a flow chart of a method for detecting and sorting wood surface defects based on Bayesian network according to the present invention;
[0052] Figure 2 is a structural diagram of a wood detection and sorting system in an embodiment of the present invention;
[0053] Figure 3 7 types of defects on the veneer surface in the embodiment of the present invention;
[0054] Figure 4 is a schematic diagram of oversampling in an embodiment of the present invention;
[0055] Figure 5 is a veneer surface defect diagram in an embodiment of the present invention;
[0056] Figure 6is a graph after data enhancement in an embodiment of the present invention;
[0057] Figure 7 It is a data set image and annotation file in an embodiment of the present invention;
[0058] Figure 8 is a defect detection data set processed in an embodiment of the present invention;
[0059] Fig. 9 is a correlation analysis result diagram in an embodiment of the present invention;
[0060] Fig.10 The Bayesian network structure diagram in the embodiment of the present invention is
[0061] Fig.11 Network structure diagram in the embodiment of the present invention;
[0062] Fig.12 A structural diagram of the Backbone part in an embodiment of the present invention;
[0063] Fig.13 Output diagram of the YOLO detection result in an embodiment of the present invention. DETAILED DESCRIPTION
[0064] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0065] Embodiment 1,
[0066] like Figure 1 As shown, a method for detecting and sorting wood surface defects based on a Bayesian network comprises the following steps:
[0067] S1, obtaining veneer defect image data and preprocessing the image data to extract a data set;
[0068] S2, building a Bayesian network based on the preprocessed extracted data set, and modeling these relationships through the Bayesian network;
[0069] S3, constructing a Bayesian classifier based on the Bayesian network structure and parameters;
[0070] S4. Use the target detection algorithm YOLO to perform preliminary target detection on the image, obtain the target's position, shape and preliminary category prediction information, and input this information as features into the Bayesian classifier. The Bayesian classifier comprehensively considers prior knowledge and target features obtained from YOLO, accurately calculates the posterior probability that the target belongs to each category, and predicts the grade of the veneer.
[0071] Data Acquisition
[0072] The data used in the present invention comes from a self-built data set, which is collected by a sorting system located on site (such as Figure 2 ) in the image acquisition unit, using the high frame rate industrial camera in the upper part of the device to quickly take pictures of the veneer veneer running on the assembly line, and obtain veneer defect pictures with a resolution of 2048×1500. A total of about 2,500 image data were collected, including seven types of defects, mainly including dry scars, slip knots, cracks, gaps, dead knots, bark, and knife-carrying (such as Figure 3 ), which was manually annotated by staff to form a data set. The "Shanhe" supercomputing platform provides a strong computing power foundation for model training.
[0073] Data preprocessing
[0074] The collected images are prone to extremely unbalanced defect categories, such as Figure 5 As shown, Isrc is InitialSource, and the part marked by Isrc represents the original image. Imain is Intermediate Image, which represents the main image. Result: represents the final result image, that is, the output image after YOLO detection. Category imbalance may cause the model to tend to predict common categories and ignore rare categories, thereby reducing the model's detection ability for all categories. The defect dataset used in the experiment is unbalanced. In order to solve this problem, a data oversampling method is introduced to increase the minority class data. Oversampling diagram (as shown in Figure 4 ), by increasing the number of minority class samples, the number of data of different categories is balanced. At the same time, the image weighting strategy is used to adjust the weight according to the number of samples during the model training process. For example, if the number of image samples of a certain category is small, then this type of sample will be given a larger weight; while the sample category with a larger number may be given a smaller weight. The purpose of this is to make the model pay more attention to the sample category with a smaller number during training, thereby improving the model's processing ability and generalization performance for samples of different categories, and avoiding the model's excessive bias towards the category with a large number and ignoring the category with a small number.
[0075] In order to improve the generalization ability of the model, data augmentation is an important strategy. Vertical flipping, horizontal flipping, random rotation, adding noise, random cropping, adding noise and mixing (such as Figure 6 ) to increase the amount of data to improve the performance of computer vision models.
[0076] The processed dataset is a target detection dataset, which consists of images and label files. The images are JPG format images with a resolution of 2048×1500, and each image corresponds to a txt file (such as Figure 7), which is the label file of this image. The format contains five fields. The first field indicates the defect category. There are seven categories here, namely, dry scar (0), slipknot (1), crack (2), gap (3), dead knot (4), bark (5), and knife (6); the second field indicates the X-axis center coordinate (X_center) of a certain type of defect position; the third field indicates the Y-axis center coordinate (Y_center) of a certain type of defect position; the fourth field indicates the width (Width) of the real frame of the defect; the fifth field indicates the height (Height) of the real frame of the defect. It is worth noting that the coordinate position information of the defect is a normalized value.
[0077] This study aims to use Bayesian networks to grade veneer, that is, to establish the probabilistic relationship between defect type, quantity and grade. To achieve this goal, the object detection dataset needs to be converted into a classification dataset. The idea is to slice the dataset according to the defect type, location and size information recorded in the annotation file, that is, to crop the original image into a single defect image and store it in a catalog according to the defect category.
[0078] The processed defect detection dataset is as follows Figure 8 As shown: It consists of 7 directories, namely 0GB: 73724 files, 1HJ: 40462 files, 2LF: 28189 files, 3QK: 29046 files, 4SJ: 1927 files, 5SP: 73596 files, 6KD: 906 files, to construct the data set required for subsequent experiments.
[0079] Building a Bayesian Network
[0080] The Bayesian network is a probabilistic model that uses Bayesian reasoning for probability calculation. It models conditional dependencies and causal relationships through directed edges in a directed graph. The directed edges represent the impact of the cause node to the effect node. The Bayesian network is similar to the naive Bayes method, both of which are probability-based classification algorithms. Unlike the naive Bayes classifier, which assumes that each indicator is independent of each other, the Bayesian network relaxes this assumption and learns the dependencies between each indicator.
[0081] The Bayesian network consists of a graphical model (i.e., a directed acyclic graph) and the probability of each variable, defined as B = (G, P), where G = (V, E) is a directed acyclic graph representing the network structure, V represents the node set, E represents the edge set, P is a vector of conditional probabilities, and the nodes represent causal relationships through directed arcs, as described below. For a node v∈V, the parent node of v is the node with a directed connection pointing to v. The direction of the arc from node to node indicates that one variable affects another variable. The node from which the arrow starts is called the parent, and the node to which the arrow points is called the child. A directed graph can represent causal dependencies, and loops are not allowed in the graph. Each node has its own conditional probability distribution.
[0082] The modeling process of the Bayesian network usually includes the following steps: first, determine the random variables involved in the problem, which can be discrete or continuous; then, infer the network structure based on the relationship between these variables, and ensure that the network structure is a directed acyclic graph, that is, there is no path from a node back to itself along the directed edges; then, assign an appropriate probability distribution to each node; then, evaluate the performance and degree of fit of the established Bayesian network; finally, use the constructed Bayesian network for inference and prediction.
[0083] The Bayesian network is mainly composed of nodes and parameters. In the present invention, a Bayesian network with 8 nodes is first constructed, and the defective nodes are 0GB, 1HJ, 2LF, 3QK, 4SJ, 5SP, 6KD, and the graded node Grade node.
[0084] The prior probability of 0-6 defect nodes can be obtained according to the statistics of the data set; the prior probability of Grade nodes should also be obtained according to the grading standards in the aforementioned data set. Since the grading standards of different requirements and different customers are not uniform in the actual wood grading system, this study assumes that 30% of the Grade nodes are 1 and 70% are 0 for the convenience of work. Among them, 1 represents excellent grading and 0 represents inferior grading; the entire prior probability is shown in the following table:
[0085] x P(x=1) P(x=0) 0GB 0.297454 0.702545 1HJ 0.163251 0.836748 2LF 0.113734 0.886265 3Q 0.117191 0.882808 4SJ 0.007774 0.992225 5SP 0.296937 0.703062 6KD 0.003655 0.996344
[0086] In addition, in actual grading operations, 3QK and 5SP defects are more important. When these two types of defects occur, the grade is directly judged as inferior, that is, P(Grade=0|3QK=1)=1, P(Grade=0|5SP=1)=1.
[0087] A defect number node (FlawNum) is introduced, with a value of 40% for High and 60% for Low, that is, P(Grade=0|FlawNum=High)=1, indicating that when the defect number is High, the Grade is directly determined to be 0).
[0088] However, as far as the collected data set images are concerned, there is a certain correlation between the various defect types in a picture. The Bayesian network mainly relies on prior knowledge to achieve posterior prediction, so it is necessary to further optimize the structure of the Bayesian network based on correlation analysis. By calculating the correlation coefficient between two defects, such as the Pearson correlation coefficient, we can quantify the strength and direction of the linear relationship between the two defects. The situation where the correlation coefficient is close to 1 or -1 indicates that there is a strong positive or negative correlation. According to the correlation analysis (such as Fig. 9 )The correlation coefficient between 0GB and 1HJ is 0.331850, the correlation coefficient between 2LF and 0GB is 0.217474, and the correlation coefficient between 4SJ and 1HJ is 0.200520. To further improve the Bayesian network, Fig.10 , where Grade: This is the central node, representing the grade of defects on the wood surface. This variable is the target variable, and its value is determined by other related variables. FlawNum: Represents the number of defects. It points to `Grade` through an arrow, indicating that the number of defects has a direct impact on the grade of defects in wood. Other nodes (5SP, 6KD, 4SJ, 3QK, 0GB, 2LF, 1HJ): These nodes represent seven types of defects. These nodes point to `Grade` through arrows, indicating that they have a direct impact on the grade of defects. The direction of each arrow represents a causal relationship or a conditional dependency. For example, `6KD` points to `Grade`, indicating that the value of `6KD` affects the value of `Grade`. Some nodes (such as `0GB` and `1HJ`) are also connected by arrows, indicating that there may be mutual influence or association between these features. That is, this Bayesian network shows how the grade of wood surface defects (`Grade`) is affected by multiple features (such as `FlawNum` and other feature nodes). The conditional dependencies between the feature nodes indicate that they may not be independent, but may affect the final veneer grade through their relationships. This structure in the Bayesian network can be used for reasoning and decision-making to infer the value of `Grade`.
[0089] Building a Bayesian Classifier
[0090] In the Bayesian classifier, it is usually assumed that these features are independent or semi-dependent. However, this assumption may not be completely true in practical applications, resulting in low classification accuracy. In order to improve the accuracy of classification, we preprocessed the defect image and extracted information that can describe the image features. Based on these feature information, a Bayesian network was constructed, which can more accurately model the relationship between features. The Bayesian classifier is a classification method based on the Bayesian theory. A defect classifier was constructed based on the wood defect dataset and the established Bayesian network structure.
[0091] Bayesian classifier is a classification method based on Bayesian theory. This method calculates the posterior probability of a sample belonging to each category and classifies it according to the maximum a posteriori probability principle (MAP). Although the Naive Bayes Classifier performs well in dealing with many classification problems, its assumption of feature independence limits its performance in some complex tasks. To solve this problem, we designed an improved defect classifier based on the wood defect dataset and the constructed Bayesian network structure.
[0092] The construction process of the Bayesian classifier mainly includes the following steps: calculating the prior probability and conditional probability, calculating the posterior probability according to the Bayesian theorem, and making classification decisions. First, clarify all the variables contained in the Bayesian network structure and the dependencies between them. These variables can be divided into two categories: input variables (features) and output variables (classification labels). Use data to estimate the conditional probability distribution of each node in the Bayesian network. Specifically, it is necessary to calculate the conditional probability of each variable given the value of its parent node.
[0093] The following is the process of using the Bayesian formula to find the maximum posterior probability of the extracted wood defect features to classify the veneer grade:
[0094] Assume that there are variables D1 (dry scar), D2 (slip knot), D3 (crack), D4 (notch), D5 (dead knot), D6 (bark), D7 (carrier knife) to represent the types of wood defects, C represents the veneer grade (high quality C1, low quality C2), and the prior probability is based on the past records of grading a large number of veneers. The prior probability can be estimated by counting the frequency of occurrence of different grades. The conditional probability is as follows:
[0095] P(D1|C): The probability of a dry scar given category C.
[0096] P(D2|D1,C): probability of a slipknot given class C and dry scar D1.
[0097] P(D3|C): The probability of a crack given class C.
[0098] P(D4|D2,C): probability of a gap given class C and slipknot D2.
[0099] P(D5|D2,C): probability of a dead knot given class C and slipknot D2.
[0100] P(D6|D4,C): probability of bark given class C and gap D4.
[0101] P(D7|D6,C): probability of carrying a knife given category C and bark D6.
[0102] According to Bayes' theorem, we have:
[0103]
[0104] in:
[0105] P(C K | D1, D2, ..., D7) is the veneer classification grade C for a given defect K The posterior probability of
[0106] P(C K ) is the classification level C K The prior probability of
[0107] P(D1, D2, ..., D7) is the overall probability of observing defects D1, D2, ..., D7;
[0108] P(D1,D2,...,D7|C K ) can be decomposed into P(D1, D2, ..., D7|C) according to the conditional independence in the Bayesian network. K )=P(D1∣C)·P(D2∣D1,C)·P(D3∣C)·P(D4∣D2,C)·P(D5∣D2,C)·P(D6∣D4,C)·P(D7∣D6,C)
[0109] The posterior probabilities of the high-quality category C1 and the low-quality category C2 are calculated by the above formula, and then the category with the larger posterior probability is selected as the quality classification result of the veneer.
[0110] Specifically, we first preprocessed the wood defect images and extracted a variety of features including dry scars, cracks, slip knots, and dead knots using advanced image processing techniques. These features were used to construct a Bayesian network that can capture the dependencies between features. Based on the learned Bayesian network structure and parameters, a wood defect classifier was constructed. The classifier can calculate the posterior probability that the wood sample belongs to each category based on the observed values of the input features and make classification decisions. In this way, the Bayesian network can not only utilize the information of each feature itself, but also utilize the relationship between features to improve the accuracy of the classifier. Compared with the traditional naive Bayes classifier, this method has higher classification accuracy and robustness in the wood defect classification task.
[0111] In summary, the present invention proposes an improved Bayesian classifier method by preprocessing and extracting features from wood defect images and combining it with a Bayesian network structure. This method effectively overcomes the limitations of traditional naive Bayesian classifiers and can provide higher classification accuracy and reliability in practical applications.
[0112] Bayesian classifier combined with YOLO
[0113] As an advanced target detection algorithm, YOLO can simultaneously predict multiple bounding boxes and category probabilities in a single forward propagation, thereby quickly locating the target object in the image. However, YOLO may not classify accurately or ambiguously for some complex scenes or target categories with similar features.
[0114] On this basis, the Bayesian classifier is introduced. Based on the Bayesian theorem, the Bayesian classifier makes classification decisions by calculating the prior probability of the category and the conditional probability under given features. In the process of combining with YOLO, YOLO is first used to perform preliminary target detection on the input image to obtain the target's location, shape and preliminary category prediction information.
[0115] This information is then input as features into a Bayesian classifier, which takes into account prior knowledge, such as the probability of different categories of objects appearing in a specific scene, the distribution of common features of objects, and the object features obtained from YOLO to accurately calculate the posterior probability that the object belongs to each category.
[0116] The main idea is to first downsample the input data and extract features through a series of convolution and residual alternating structures in the YOLO backbone network. This part will obtain feature maps of three different scales: 80×80, 40×40, and 20×20; then further upsampling and tensor concatenation are performed to extract features, and finally the wood defect features extracted by the network are output (such as Fig.13 As shown). Then we enter the feature classification part. Considering that the defect features extracted by the neural network have many dimensions, which affects the recognition efficiency, we first use PCA to reduce the dimension of the defect features to reduce the dimension of the features; then integrate the Bayesian classifier in the Head (before applying the Bayesian classifier, the features are normalized according to zero mean and unit variance, and then classified using the Bayesian classifier. For a given image, the Bayesian classifier can find the maximum posterior probability of belonging to the class in many categories, so that the defects can be correctly classified). The defect features that have been reduced in dimension are classified. The output layer has 7 categories from 0 to 6, and finally the classification category and prediction box of the wood defects are obtained. The network structure diagram is as follows Fig.11 As shown, the Backbone structure diagram is as follows Fig.12As shown. Input->Backbone->Neck->Head->Output: This path represents the flow of data in the YOLOv8 network, starting from the input image data, through feature extraction, feature fusion, and finally reaching the detection output. Input: Input layer, representing the image data input to the network, i.e., the veneer surface image. Neck: The middle layer connecting the backbone network and the head, responsible for further fusion and processing of features. Common Neck components include FPN (Feature Pyramid Network), PAN (Path Aggregation Network), etc. Backbone: Backbone network, responsible for extracting basic features from the input image. Head: The head of the network, responsible for converting the extracted features into the final output of the target detection task. Output: Output layer, representing the final output result of the network, i.e., the detected object information. C stands for CSP (Cross Stage Partial): An improved network module that can reduce the amount of computation and model size while maintaining the depth of the network. P stands for PAN (Path Aggregation Network): Path aggregation network, used to enhance the expressiveness of features and further improve detection accuracy. Conv: Convolutional layer is used to extract local features. C2f: CrossStage Partial with Focus, reduces computational complexity and improves model performance through partial convolution and cross-fusion of features. SPPF: Spatial Pyramid Pooling-Fast, extracts multi-scale features by performing pooling operations of different scales on feature maps.
Claims
1. A method for detecting and sorting wood surface defects based on Bayesian networks, characterized in that: The method comprises the following steps: S1, obtaining veneer defect image data and preprocessing the image data to extract a data set; S2, building a Bayesian network based on the preprocessed extracted data set, and modeling these relationships through the Bayesian network; S3, constructing a Bayesian classifier based on the Bayesian network structure and parameters; S4. Use the target detection algorithm YOLO to perform preliminary target detection on the image, obtain the target's position, shape and preliminary category prediction information, and input them as features into the Bayesian classifier. The Bayesian classifier uses prior knowledge and target features obtained from YOLO to calculate the posterior probability that the target belongs to each category, which is used to predict the grade of the veneer.
2. A method for detecting and sorting wood surface defects based on Bayesian network according to claim 1, characterized in that: The preprocessing of the image data refers to: S11. Increase the number of minority class samples by using the data oversampling method so that the number of samples of the majority class and the minority class are the same. At the same time, use the image weighting strategy to adjust the weight according to the number of samples during the model training process, giving a larger weight to the class with a smaller number of image samples and a smaller weight to the class with a larger number of image samples; S12, vertical flipping, horizontal flipping, random rotation, adding noise, random cropping, adding noise and mixing are used to increase the amount of data to form a target detection data set; The target detection dataset consists of images and annotation files. The annotation file contains five fields. The first field indicates the defect type; the second field indicates the X-axis center coordinate X_center of a certain type of defect position; the third field indicates the Y-axis center coordinate Y_center of a certain type of defect position; the fourth field indicates the width Width of the defect real box; the fifth field indicates the height Height of the defect real box; S13. Convert the target detection dataset into a classification dataset. According to the defect type, location and size information recorded in the annotation file, slice the dataset, that is, crop the original image into a single defect image, and store it in a directory classified by defect category. The processed defect detection dataset consists of seven directories: 0GB, 1HJ, 2LF, 3QK, 4SJ, 5SP and 6KD, which represent dry scars, slip knots, cracks, gaps, dead knots, bark and knife blades, respectively, to construct the dataset required for the subsequent steps.
3. A method for detecting and sorting wood surface defects based on Bayesian network according to claim 1, characterized in that: The Bayesian network consists of a directed acyclic graph and the probability of each variable, defined as B = (G, P), where G = (V, E) is a directed acyclic graph representing the network structure, V represents a node set, E represents an edge set, P is a vector of conditional probabilities, and the causal relationship between nodes is represented by directed arcs, as described below: for a node v∈V, the parent node of v is a node with a directed connection pointing to v; the direction of the arc from node to node indicates that one variable affects another variable; the node from which the arrow starts is called the parent, and the node to which the arrow points is called the child; the directed graph can represent causal dependencies, and loops are not allowed in the graph; each node has its own conditional probability distribution.
4. A method for detecting and sorting wood surface defects based on Bayesian network according to claim 1, characterized in that: The Bayesian network construction means that the Bayesian network includes nodes and parameters. First, an 8-node Bayesian network is constructed, including defect nodes 0GB, 1HJ, 2LF, 3QK, 4SJ, 5SP, 6KD and a grading node Grade node; wherein the prior probability of the defect nodes 0-6 is obtained according to the statistics of the preprocessed data set, and the prior probability of the Grade node is obtained according to the grading standard in the aforementioned data set. 1 is set to represent excellent grading and 0 to represent inferior grading. In addition, in the grading operation, the two types of defects 3QK and 5SP are directly judged to be inferior, that is, P(Grade=0|3QK=1)=1, P(Grade=0|5SP=1)=1; Then, a defect number node FlawNum is introduced, with a value of 40% for High and 60% for Low, that is, P(Grade=0|FlawNum=High)=1, which means that when the defect number is High, the Grade is directly determined to be 0; However, as far as the collected data set images are concerned, there is a certain correlation between the various defect types in a picture. The Bayesian network relies on prior knowledge to achieve posterior prediction, so it is necessary to calculate the correlation coefficients between various defects based on correlation analysis to further optimize the structure of the Bayesian network.
5. The method for detecting and sorting wood surface defects based on Bayesian network according to claim 1, characterized in that: Building a Bayesian classifier means building an improved defect classifier based on the preprocessed wood defect data set and the constructed Bayesian network structure. The construction process includes the following steps: According to the prior probability and conditional probability, the posterior probability is calculated using the Bayesian theorem to make classification decisions: First, all the variables contained in the Bayesian network structure and their dependencies are clarified. These variables are divided into two categories: input variables are features, and output variables are classification labels. The data is used to estimate the conditional probability distribution of each node in the Bayesian network. Specifically, the conditional probability of each variable given the value of its parent node needs to be calculated; The following is the process of using the Bayesian formula to find the maximum posterior probability of the extracted wood defect features to classify the veneer grade: The variables D1, D2, D3, D4, D5, D6, D7, and D7 represent the types of wood defects. C represents the veneer grade, with high quality being C1 and low quality being C2. The prior probability is estimated by counting the frequency of different grades in the past records of grading a large number of veneers. The conditional probability is as follows: P(D1|C): probability of dry scar given category C; P(D2|D1,C): probability of a slipknot given class C and dry scar D1; P(D3|C): probability of a crack given category C; P(D4|D2,C): probability of a gap given class C and slipknot D2; P(D5|D2,C): probability of a dead knot given class C and slipknot D2; P(D6|D4,C): probability of bark given category C and gap D4; P(D7|D6,C): probability of carrying a knife given category C and bark D6; According to Bayes' theorem, we have: In formula (1): P(C K | D1, D2, ..., D7) is the veneer classification grade C for a given defect K The posterior probability of P(D1,D2,...,D7|C K ) can be decomposed into P(D1, D2, ..., D7|C according to the conditional independence in the Bayesian network. K )=P(D1∣C)·P(D2∣D1,C)·P(D3∣C)·P(D4∣D2,C)·P(D5∣D2,C)·P(D6∣D4,C)·P(D7∣D6,C); P(C K ) is the classification level C K The prior probability of P(D1, D2, ..., D7) is the overall probability of observing defects D1, D2, ..., D7; The posterior probabilities of the high-quality category C1 and the low-quality category C2 are calculated by the above formula, and then the category with the larger posterior probability is selected as the quality classification result of the veneer.
6. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the computer program instructions are executed by a processor, they are used to implement the steps of the method as described in any one of claims 1 to 5.
7. A computer program product comprising computer instructions, characterized in that When the computer instruction is executed by a processor, it is used to implement the steps of the method according to any one of claims 1 to 5.
Citation Information
Cited By
Laminated container floor detection method, system and device
CN120605879A
