A multi-stage decoupling-based distillation increment wood defect detection method and device
Patent Information
- Application Number
- CN202611149334.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-31
- Publication Date
- 2026-10-09
- Estimated Expiration
- 2046-07-31
AI Technical Summary
[0007]本发明旨在克服上述现有技术的至少一种缺陷,提供一种基于多级解耦的蒸馏增量木材缺陷检测方法,以解决随着木材来源和加工工艺的变化,不断出现新的缺陷类型,现有的检测模型在学习新缺陷类型时,容易出现灾难性遗忘现象的问题
(1)本发明提供的一种基于多级解耦的蒸馏增量木材缺陷检测方法和装置,所公开的特征层蒸馏摒弃了传统的矩形边界框硬掩码,直接提取内部注意力响应图作为先验软掩码。该机制能够精准包裹斜向裂纹、树脂渗出等不规则缺陷的物理边缘,将正常木材纹理的蒸馏权重降至趋近于零,从而缓解了特征空间中过度约束的问题,使模型对新生缺陷的学习可塑性及收敛速度提升显著。
Smart Images

Figure CN122657144B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the technical field of image data processing, and more specifically, relates to a method and apparatus for detecting defects in distilled incremental wood based on multi-level decoupling. Background Technology
[0002] In the wood processing and manufacturing industry, automated detection of wood surface defects (such as cracks, live knots, dead knots, resin, blue stain, etc.) is crucial for wood grading and quality control. With the development of deep learning technology, object detection algorithms based on convolutional neural networks (CNNs) have been widely applied in this field. However, in actual industrial production lines, new defect types often emerge continuously due to changes in wood sources and processing techniques. Existing object detection models, when learning new defect types—an incremental task—are prone to "catastrophic forgetting," meaning that while the model acquires the ability to detect new defects, it loses the ability to detect older defects.
[0003] Chinese patent document CN119130921A discloses a lightweight RGB-D rail surface defect detection method based on multi-teacher knowledge distillation, including a training phase and a testing phase. In the training phase, a knowledge distillation framework is used, comparing hyperspherical feature map distillation, frequency domain attention distillation, and corresponding prediction map distillation, to transfer knowledge from a dual-stream multi-teacher network to a relatively lightweight single-stream student network. This maximizes the performance of the student model while keeping the number of parameters in the single-stream student model to a minimum. The data-augmented rail surface defect image is input into a convolutional neural network for training, obtaining a salient rail surface defect prediction map. In the testing phase, the rail surface defect image to be detected is input into the single-stream student network training model to obtain a salient rail surface defect prediction map.
[0004] While some incremental target detection methods based on knowledge distillation exist, these methods suffer from the following serious drawbacks when applied to wood defect detection: Background features are heavily coupled: wood defects often exhibit highly irregular shapes (such as thin, elongated cracks). Existing hard mask distillation methods based on bounding boxes include a large amount of normal wood background texture. During incremental learning, forcibly constraining features within the bounding box prevents the model from learning new defects in the background region, severely limiting the model's adaptability to new defects.
[0005] Fine-grained categories are easily confused: Wood defects have very fine-grained features (such as "live knots" and "dead knots" being very similar in appearance). Existing linear classifiers are prone to weight bias during incremental learning, leading to blurred boundaries and confusion between new and old categories in the feature space.
[0006] Rigid localization of fuzzy boundaries: Since the edges of wood defects are often gradual and fuzzy, existing rigid coordinate regression distillation (such as Smooth L1 loss) requires the student model to be absolutely aligned with the coordinate prediction of the teacher model, resulting in the model lacking the ability to adaptively fine-tune when facing defects with fuzzy boundaries, and thus reducing localization accuracy. Summary of the Invention
[0007] The present invention aims to overcome at least one of the defects of the prior art and provide a distillation incremental wood defect detection method based on multi-level decoupling, in order to solve the problem that as the source of wood and processing technology change, new defect types constantly emerge, and existing detection models are prone to catastrophic forgetting when learning new defect types.
[0008] The detailed technical solution of this invention is as follows: A method for detecting defects in incremental wood distillation based on multi-level decoupling, the method comprising: S1. Construct a basic target detection network model for identifying defects in wood images. Obtain an old defect dataset of wood images and pre-train it to obtain the basic training model for the incremental stage.
[0009] S2. Construction and parameter initialization of the teacher-student dual-state incremental network; When the production line receives an incremental dataset including new defects Incremental learning is then performed. First, construct a teacher-student dual-state incremental network: Building a teacher model The pre-trained base training model Copy and instantiate as a teacher model Throughout the incremental training process, the cross-attention branch of AFEM in the teacher model is disabled, only the self-attention branch is enabled, and the system is forcibly frozen. Stop updating parameters after all backpropagated gradients are exhausted; Building a student model Student Model With teacher model They share the same basic network structure, namely the backbone feature extraction network, the region proposal network (RPN), and the ROI head, and use the teacher model. pre-trained weights For student models During initialization, the cross-attention branch in the AFEM of the student model is enabled throughout the incremental training process. Then, the category dimension of the ROI detection head network of the student model is expanded to cover both the old defect categories and the newly added defect categories.
[0010] S3. Multi-level decoupled joint feature extraction and distillation based on the physical properties of wood; Teacher Model and student model Incremental training is performed, and in each iteration of incremental training, the incremental dataset is... The same image of wood defects was simultaneously input into the teacher model. and student model Perform forward propagation: Teacher Model Keep the parameters frozen and only output the features, proposal boxes, classification results and regression results of the old defect categories as supervision signals for old knowledge; Student Model Based on the current incremental image, output the features, proposal boxes, classification results, and regression results of the incremental category, and use them as the objects to be optimized in subsequent loss calculations.
[0011] Based on the above teacher-student bistate forward propagation results, the target detection loss is constructed as a joint optimization objective and iteratively updated until the network converges.
[0012] S4, end-to-end joint optimization and deployment of applications; Student model based on joint optimization objective The parameters are updated until the total loss converges, resulting in a converged student model, which is then deployed to the edge computing nodes of the automated timber sorting production line.
[0013] Furthermore, S1 specifically includes: S11. Construct and optimize the basic target detection network model; The basic object detection network model adopts a two-stage object detection model Faster R-CNN, which includes a backbone feature extraction network, a region proposal network (RPN), and a region of interest (ROI) head. Attention feature enhancement module (AFEM) is embedded after the backbone feature extraction network and before the region proposal network. S12. Construct the mathematical execution logic of the attention feature enhancement module, which includes: parallel self-attention branches and cross-attention branches, as well as feature fusion; Let the query, key, and value matrices obtained by mapping the feature maps extracted by the backbone feature extraction network be respectively... The dimension of the key vector is ; First, the self-attention branch of the attention feature enhancement module is based on the self-attention response matrix S. Used to characterize the degree of feature correlation between different spatial locations:
[0014] This region corresponds to the salient texture location of wood defects, from which the self-attention weight matrix highlighting key wood defect regions is calculated. , And generate a self-attention feature map. , ; Secondly, the cross-attention branch of the attention feature enhancement module is used to introduce old defect knowledge retained by the teacher model during the incremental learning phase; The subsequent student model generates a new knowledge query matrix based on incremental wood defect images. The teacher model provides a matrix of prior knowledge keys. Sum matrix ; Cross-attention branch utilization and Calculate the attention weight between new and old knowledge, and then apply this attention weight to... Perform weighted summation to generate cross-attention feature maps. : (1) in, Represents the old knowledge key matrix, Represents the matrix of old knowledge values. This represents the new knowledge query matrix.
[0015] Enhanced feature maps obtained from student models It is then passed to the RPN and ROI heads for candidate box generation and classification regression.
[0016] However, during the teacher model training phase, since no new defect category samples have been introduced, the model does not have a cross-stage correspondence between new knowledge query features and old knowledge key-value features. Therefore, the cross attention branch is turned off, and only the self attention branch is enabled to generate stable enhanced features for old defect categories. The final teacher model outputs an enhanced feature map. = .
[0017] S13. Obtain the old defect dataset of wood images, including The basic wood defect dataset with existing defect categories Defect types include dead knots and live knots; Supervised pre-training is performed on the optimized basic object detection network model. After training, the network weight parameters are fixed. That is, pre-training weights to obtain the basic trained model. This serves as a teacher model for the subsequent incremental phase.
[0018] Furthermore, the constructed target detection loss is a joint optimization target. The loss is calculated as a weighted sum of the standard Faster R-CNN object detection loss and the multi-level decoupling distillation loss calculated in the backbone feature extraction network, the region proposal network (RPN), and the classification and regression layers in the ROI head, respectively. (2) in, To balance the hyperparameters of the magnitude of each loss term, For soft mask feature distillation loss, For RPN distillation loss with mask gating, The classification loss is calculated by weighting the KL divergence of the proposal box. For the combined regression distillation loss, The loss is the standard Faster R-CNN object detection loss; (1) Distillation in the backbone feature extraction network is attention-guided soft mask feature distillation: extract the self-attention response matrix output by the teacher model AFEM, generate pixel-level continuous soft masks, and calculate the feature distillation loss by weighting the soft masks; (2) Distillation in the Regional Proposal Network (RPN) is based on asymmetric confidence truncation of the RPN proposal box: construct an asymmetric one-way truncation Boolean mask, and calculate the RPN distillation loss with mask gating through mask gating; (3) Classification layer distillation in the ROI head is classification distillation based on uncertainty perception and information entropy dynamic weights: quantify the uncertainty of the teacher model classification prediction, generate dynamic weights, and calculate the classification loss of the proposal box weighted KL divergence. (4) The regression layer distillation in the ROI head is a weighted regression distillation based on the sharing of classification uncertainty: the dynamic weights of the uncertainty of the shared classification layer are used to calculate the joint regression distillation loss.
[0019] The specific optimization objectives are as follows: Backbone Feature Extraction Network: Based on attention-guided soft mask feature distillation, it solves the background coupling deadlock problem. The construction of the attention-guided soft mask feature distillation loss specifically includes: Extracting the teacher model The self-attention weight matrix AW output by the AFEM module is aggregated and reconstructed according to the spatial location of the feature map output by the backbone feature extraction network of the teacher model, resulting in a two-dimensional attention response map corresponding to the spatial size of the teacher feature map. The two-dimensional attention response map This is used to characterize the spatial regions that the teacher model focuses on in the old wood defect detection task. The higher the response value, the more likely the location corresponds to the key texture region of the old defect; the lower the response value, the more likely the location corresponds to the normal wood background texture region.
[0020] To avoid the problem of traditional hard masks using only 0 or 1 to distinguish between defect areas and background areas, which leads to excessive constraint on the wood texture background, this invention is based on a two-dimensional attention response map. Generate pixel-level continuous soft mask matrix .
[0021] Specifically, a soft mask temperature coefficient is introduced. ,right The response values at each spatial location are smoothed and normalized to obtain... (3) in, i and j These represent the spatial location indices in the teacher feature map. Used to adjust the smoothness of the soft mask; The larger the value, the smoother the weight difference between different spatial locations. The smaller the value, the more prominent the weight of the high-response defect region.
[0022] Received The values are continuous weights, used to represent the importance of each spatial location in feature distillation. For the core regions of old defects that the teacher model highly focuses on, Larger values require the student model to more strictly align with the feature representation of the teacher model; for normal wood texture backgrounds or areas unrelated to old defects, When the value is small, the distillation constraint at the corresponding position is weakened, thus reserving space for parameter updates for the student model to learn new defect features.
[0023] In obtaining the soft mask matrix Then, it is applied to the teacher model via tensor broadcasting. and student model Based on the difference in feature tensors output from the corresponding feature layers, an attention-guided soft mask feature distillation loss is constructed: (4) Where C, H, and W represent the number of channels, height, and width of the feature map, respectively; This represents the weight value of the soft mask matrix at spatial location (h, w); Teacher model The feature value at the position of the c-th channel, the h-th row, and the w-th column; Student model The feature value at the corresponding position; h and w represent the spatial position index of the feature map, respectively.
[0024] Preferably, for the old defect core region that the teacher model is certain of ( ), imposing harsh punishments to prevent forgetting; for normal wood background areas ( The distillation gradient is adaptively diluted to free up parameter update space to fit nascent defects.
[0025] Region Proposal Network (RPN): Based on asymmetric confidence truncation, RPN distillation addresses the problem of suppressing novel blind zones. The construction of the RPN distillation loss specifically includes: Based on the same input image, the same scale feature layer, and the same anchor box or the m-th RPN proposal box after sorting and alignment, the target confidence scores output by the teacher model and the student model are obtained respectively. , and bounding box regression coordinates , ,in: Target confidence score , This is the target probability after Softmax normalization, and its value ranges from [0,1]. Bounding box regression coordinates , The center point offset and width / height offset are adopted in the same way as those used in the RPN training phase.
[0026] To retain only the teacher model's reliable supervision on old defect proposal boxes and mask the teacher model's low-confidence suppression of new defect proposal boxes, this invention constructs an asymmetric Boolean mask based on a step indicator function. ; (5) in, Indicates the first Asymmetric one-way truncated Boolean mask corresponding to each RPN proposal box; Indicates the index of the suggestion box; (·) represents a step indicator function, which takes the value of 1 when the condition in the parentheses is true, and takes the value of 0 otherwise. Teacher model For the first m The target confidence score is output by each suggestion box; Student model For the first The target confidence score is output by each suggestion box; This indicates the preset confidence deviation threshold, and A constant greater than 0, used to limit the target confidence of the teacher model to be at least higher than that of the student model. Only then is the proposed box considered to belong to the older defect candidate box, which is more reliable in the teacher model.
[0027] After obtaining the asymmetric Boolean mask, only for Apply distillation constraints to the RPN proposal box with a value of 1, and calculate the RPN distillation loss with mask gating: (6) in, Indicates the number of RPN proposal frames involved in the distillation calculation; Teacher model For the first The bounding box regression coordinates output by each proposal box; Student model For the first The bounding box regression coordinates output by each proposal box; Used to measure the difference in target confidence between teacher and student models. Used to measure the difference between the teacher and student models on the regression coordinates of the proposal box. After gating, the distillation loss of the proposal box is calculated only when the teacher model is more confident in the old goal and the student model has a tendency to forget.
[0028] The classification layer in the ROI header: Based on uncertainty perception and dynamic weighting of information entropy, classification distillation addresses the problem of dark knowledge misleading. The construction of the classification loss based on the weighted KL divergence of the proposal box specifically includes: First, a temperature smoothing mechanism is introduced: For the b-th proposal box, the logical value output by the teacher model's classification head is obtained. Introducing a preset distillation temperature coefficient Calculate its smoothed soft probability distribution : (7) This amplifies the implicit dark knowledge in non-target categories.
[0029] Secondly, we quantify cognitive uncertainty: For the b-th proposal box, we calculate the Shannon entropy of the teacher's prediction probability as a quantitative indicator of their cognitive uncertainty. (8) in, Teacher model The uncertainty measure of the current proposal box classification prediction result, namely Shannon entropy; K represents the total number of classification categories; c represents the defect category index; Teacher model The smoothed probability that the b-th proposal box belongs to the c-th type of defect; This represents a very small constant to prevent logarithmic operations from going wrong.
[0030] Then, adaptive weights and weighted loss are constructed: the entropy value of the teacher is converted using an exponentially decaying mapping. Transform into an interval Dynamic distillation weight : (9) in, γ represents the entropy decay coefficient, used to control the suppression strength of uncertainty on distillation weights. Since w decreases as H increases, when the teacher model's classification result is relatively certain, w approaches 1, retaining a strong classification distillation constraint; when the teacher model's classification result is uncertain, w approaches 0, reducing the distillation constraint of the proposal box on the student model and avoiding the transfer of unreliable knowledge from the teacher model to the student model.
[0031] Finally, this weight term is removed from the computation graph and treated as a constant, and the KL divergence-based classification loss is weighted for each proposal box: (10) Where N represents the total number of proposal boxes participating in the categorical distillation calculation; This represents the dynamic distillation weight corresponding to the b-th proposal box; T represents the distillation temperature coefficient. Student model The classification logic value output for the b-th suggestion box; Teacher model The smooth soft probability distribution output for the b-th proposal box; This represents the KL divergence, used to measure the difference between the classification distributions of the student model and the teacher model. Weighting the classification distillation loss for each proposal box allows the student model to prioritize learning the old class knowledge that the teacher model is confident in, while mitigating the misleading effects of uncertain regions in the teacher model.
[0032] The regression layer in the ROI header: a weighted regression distillation based on shared classification uncertainty, used to fit location-based confidence coupling. The construction of the joint regression distillation loss specifically includes: First, cross-branch confidence distribution: directly extract the uncertain dynamic weights calculated based on the teacher classification output from the classification layer. This weight is used as a gating indicator for the credibility of teachers' regression outputs and shared across branches to the regression layer. Secondly, construct the weighted Huber distillation loss: Let the coordinate vectors of the regression boxes output by the student model and the teacher model for the d-th proposal box be respectively... and .
[0033] To ensure robustness to outliers, Huber loss is used as the base function for regression alignment, and shared weights are incorporated. Constructing a joint regression distillation loss : (11) Where N represents the number of proposal boxes participating in the regression distillation calculation; d represents the proposal box index; This represents the dynamic distillation weight corresponding to the d-th proposal box. This weight is calculated from the classification uncertainty of the teacher model in the S33 classification layer and reused in the regression layer. Student model For the first The bounding box regression coordinates output by each proposal box; Teacher model The bounding box regression coordinates output for the d-th proposal box; δ represents the control threshold of the Huber loss, used to control the conversion between L1 loss and L2 loss.
[0034] Furthermore, S4 specifically includes: S41. Gradient Backpropagation and Parameter Update: Based on Total Loss The gradients of the student model parameters are calculated, and backpropagation and parameter updates are performed using the SGD optimizer. During backpropagation, only the student model is processed. Update the parameters of the teacher model. Keep frozen at all times.
[0035] S42. Model Convergence: Repeat the above forward inference and backpropagation steps until the network converges.
[0036] Repeat the above forward propagation, loss calculation, back propagation, and student model parameter update steps until the student model... In incremental dataset Total loss The training process converges, or reaches the preset number of training epochs. After convergence, the student model... The system has completed learning of the newly added defect categories in the current round and maintains the ability to detect existing defect categories under multi-level decoupled distillation constraints.
[0037] S43. Model Deployment and Application: After this round of incremental learning is completed, the converged student model will be... This is the currently deployable detection model. A teacher model is no longer required during deployment. Participation in reasoning can be limited to student models. The edge computing nodes are deployed to the automated timber sorting production line to enable real-time detection of both new and old timber defect categories that have already been learned. If new defect categories continue to appear on the industrial production line, the student model that has converged in the previous round is used as the new base model to rebuild the frozen teacher model and the student model to be trained, and the next round of incremental learning is started.
[0038] In another aspect of the invention, an apparatus is provided for implementing a distillation-based incremental wood defect detection method based on multi-level decoupling, the apparatus comprising: At least one processor; and The memory stores instructions that, when executed by the at least one processor, cause the at least one processor to perform a distillation incremental wood defect detection method based on multi-level decoupling as described above.
[0039] In another aspect of the invention, a computer-readable storage medium is also provided, which stores executable instructions that, when executed, cause the machine to perform a distillation incremental wood defect detection method based on multi-level decoupling as described above.
[0040] Compared with the prior art, the beneficial effects of the present invention are as follows: (1) The present invention provides a method and apparatus for incremental wood defect detection based on multi-level decoupling distillation. The disclosed feature layer distillation abandons the traditional rectangular bounding box hard mask and directly extracts the internal attention response map as a prior soft mask. This mechanism can accurately wrap the physical edges of irregular defects such as oblique cracks and resin exudation, and reduce the distillation weight of normal wood texture to close to zero, thereby alleviating the problem of excessive constraints in the feature space and significantly improving the model's learning plasticity and convergence speed for new defects.
[0041] (2) The present invention provides a method and apparatus for incremental wood defect detection based on multi-level decoupling distillation. Addressing the unique pain point of "background misjudgment" in incremental target detection, it innovatively establishes a unidirectional distillation screening mechanism through an asymmetric confidence truncation mechanism at the RPN layer. This mechanism not only forces the student model to memorize the location of old defects but also immunizes the teacher model from issuing erroneous negative guidance due to cognitive blind spots, greatly improving the initial recall rate of newly emerging small wood defects.
[0042] (3) The present invention provides a method and apparatus for incremental wood defect detection based on multi-level decoupling through distillation. It introduces dynamic weights based on information entropy and utilizes Shannon entropy to quantify the prediction uncertainty of the teacher model. By adaptively applying exponentially decaying distillation weights to high-entropy (high-uncertainty) regions, a weighting mechanism for filtering high-confidence distillation information is constructed. This prevents the student model from overfitting the teacher model's prediction results in high-uncertainty regions, greatly ensuring the purity of the feature decision boundary in incremental learning.
[0043] (4) The present invention provides a method and apparatus for detecting defects in distilled incremental wood based on multi-level decoupling. Based on the physical consensus that “classification uncertainty is correlated with positioning reliability”, the uncertainty weight of the classification layer is directly distributed and shared to the regression layer. Under the premise of ensuring that the defect position does not shift, the rigid coordinate alignment constraint of the fuzzy defect edge region is reduced, which significantly improves the target detection box wrapping accuracy of defects with fuzzy gradient edge (such as resin, blue stain, etc.) in industrial field. The confidence is shared across modes, and the adaptive elastic penalty of regression positioning is realized, which enhances the cooperative constraint between the classification branch and the regression branch. Attached Figure Description
[0044] Figure 1 This is a flowchart of a distillation-incremental wood defect detection method based on multi-level decoupling, as described in this invention.
[0045] Figure 2 This is a schematic diagram of the AFEM module in Embodiment 1 of the present invention.
[0046] Figure 3 This is a schematic diagram of characteristic distillation in Embodiment 1 of the present invention.
[0047] Figure 4 This is a schematic diagram of RPN distillation in Embodiment 1 of the present invention.
[0048] Figure 5 This is a schematic diagram of ROI HEAD distillation in Embodiment 1 of the present invention. Detailed Implementation
[0049] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0050] It should be noted that the following detailed descriptions are exemplary and intended to provide further illustration of the invention. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains.
[0051] It should be noted that the terminology used herein is only for describing specific embodiments, and is not intended to limit the exemplary embodiments according to the present invention. As used herein, unless the context clearly dictates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprise" and / or "include" are used in this specification, they indicate the presence of features, steps, operations, devices, components and / or combinations thereof.
[0052] Embodiments of the present invention and features in the embodiments can be combined with each other without conflict.
[0053] Example 1 Referring Figure 1 , this embodiment provides a distillation incremental wood defect detection method based on multi-level decoupling, the method comprises: S1, Stage One: Construction and pre-training of a base model based on an attention feature enhancement module (AFEM).
[0054] In this embodiment, the base object detection network model adopts Faster R-CNN, a two-stage object detection model including a backbone feature extraction network, a region proposal network RPN, and an ROI head. An input wood defect image is firstly subjected to extraction of an initial feature map by the backbone feature extraction network; then, the initial feature map is input into the region proposal network RPN to generate candidate boxes; finally, the ROI head performs defect category classification and bounding box regression based on the candidate boxes and their corresponding features.
[0055] Before training on the basic wood defect data, the underlying modification of the object detection network architecture is firstly carried out, and an attention mechanism is introduced to improve the accuracy of feature expression and the anti-forgetting ability of subsequent incremental learning.
[0056] Specifically, said S1 specifically comprises: S11, constructing a base object detection network model and performing optimization; Base object detection network model adopts Faster R-CNN, a two-stage object detection model including a backbone feature extraction network, a region proposal network RPN and an ROI head; meanwhile, an attention feature enhancement module AFEM is embedded after the backbone feature extraction network and before the region proposal network, as shown in Figure 2 ; S12, constructing the mathematical execution logic of the attention feature enhancement module (AFEM); The attention feature enhancement module purifies the space and semantics of the initial feature map extracted by the backbone network, so that the model automatically focuses on tiny wood defects (such as fine cracks and small wormholes) and ignores large-area normal wood textures.
[0057] The attention feature enhancement module includes parallel self-attention branches and cross-attention branches, as well as feature fusion; its processing logic is as follows: Let the query, key, and value matrices obtained by mapping the feature maps extracted by the backbone feature extraction network be as follows: The dimension of the key vector is .
[0058] First, the self-attention branch of the attention feature enhancement module is based on the self-attention response matrix S. Used to characterize the feature relationships between different spatial locations: This region corresponds to the prominent texture locations of defects such as cracks, wormholes, blue stain, and resin exudation. Based on this, a self-attention weight matrix highlighting key wood defect areas is calculated. , And generate self-attention feature maps. , ; With the generation of self-attention feature maps In parallel with the branches, the Attention Feature Enhancement Module (AFEM) also sets up cross-attention branches to introduce old defect knowledge retained by the teacher model during the incremental learning phase.
[0059] Specifically, the subsequent student model generates a new knowledge query matrix based on incremental wood defect images. The teacher model provides a matrix of prior knowledge keys. Sum matrix ; Cross-attention branch utilization and Calculate the attention weight between new and old knowledge, and then apply this attention weight to... Perform a weighted summation to generate the cross-attention feature map Fcross: (1) in, Represents the old knowledge key matrix, Represents the matrix of old knowledge values. This represents the new knowledge query matrix.
[0060] Enhanced feature maps obtained from student models It is then passed to the RPN and ROI heads for candidate box generation and classification regression.
[0061] However, during the teacher model training phase, since no new defect category samples have been introduced, the model does not have a cross-stage correspondence between new knowledge query features and old knowledge key-value features. Therefore, the cross attention branch is turned off, and only the self attention branch is enabled to generate stable enhanced features for old defect categories. The final teacher model outputs an enhanced feature map. = It is then passed to the RPN and ROI heads for candidate box generation and classification regression.
[0062] S13, Pre-training on the basic dataset: Obtain an old dataset of defects in wood images, including The basic wood defect dataset with existing defect categories Defect types include dead knots and live knots; Supervised pre-training is performed on the optimized basic object detection network model. After training, the network weight parameters are fixed. That is, pre-training weights to obtain the basic trained model. This serves as a teacher model for the subsequent incremental phase.
[0063] S2, Phase Two: Construction and Parameter Initialization of the Teacher-Student Dual-State Incremental Network; When industrial production lines are flooded with incremental datasets containing new defects At that time, the incremental learning process is initiated, and new defects such as blue staining and resin exudation are added. A new category.
[0064] First, construct a teacher-student dual-state incremental network: The pre-trained base training model Copy and instantiate as a teacher model Throughout the incremental training process, the cross-attention branch of AFEM in the teacher model is disabled, only the self-attention branch is enabled, and the system is forcibly frozen. Stop updating parameters after all backpropagated gradients are exhausted; Building a student model Student Model With teacher model They share the same basic network structure, namely the backbone feature extraction network, the region proposal network (RPN), and the ROI head, and use the teacher model. pre-trained weights For student models Initialization is performed; throughout the incremental training process, the cross-attention branch in the AFEM of the student model is enabled. Since the student model is initialized by copying the weights from the teacher model, the self-attention branch in the student model's AFEM is enabled by default. Then, the category dimension of the ROI detection head network of the student model is expanded to cover both existing and newly added defect categories.
[0065] Specifically, S2 includes: S21. Freeze the teacher model to retain old knowledge; The pre-trained base model Copy and instantiate as "Teacher Model" (denoted as ) The cross-attention branch in the teacher model AFEM is closed and forcibly frozen throughout the incremental training process. All backpropagation gradients are stopped, and parameter updates are halted, thus solidifying the "memory" of the old defects.
[0066] S22. Initialize the student model to expand new knowledge; Constructing a "student model" (denoted as ), Construction and Teacher Model Student models with the same basic network structure and using teacher models pre-trained weights For student models The backbone feature extraction network, region proposal network (RPN), and shared parameters in the ROI head are initialized so that the student model inherits the teacher model's basic detection capability for old wood defect categories at the start of incremental training.
[0067] After the student model is initialized, the cross-attention branch in the student model AFEM is enabled. Since the student model is initialized by copying the weights from the teacher model, the self-attention branch in the student model AFEM is enabled by default. The cross-attention branch is disabled during the pre-training phase of the base model and the frozen teacher model, and is only enabled during the incremental training phase of the student model. For incremental datasets Contains To introduce new defect categories, the ROI detection head network of the student model is expanded in terms of category dimensions, enabling it to cover both existing and newly added defect categories: Preferably, let the number of old defect categories already learned by the teacher model be... Then the output dimension of the classification branch in the ROI detection head of the student model will be changed from... Expand to + And the output dimension of the category-related bounding box regression branch is changed from 4 Expand to 4 ( + The classification and regression parameters for the old categories are inherited from the teacher model weights, while the classification and regression parameters for the new categories are generated using a random initialization method.
[0068] S3, Stage Three: Multi-level Decoupling Joint Feature Extraction and Distillation Based on Wood Physical Properties After completing the teacher model Freeze and student model After initialization, the incremental training phase begins. In each iteration of incremental training, the incremental dataset is... The same image of wood defects was simultaneously input into the teacher model. and student model Perform forward propagation: Teacher Model Keeping the parameters frozen, only outputting the features, proposals, classification results, and regression results corresponding to the old defect categories as supervision signals for old knowledge; student model Based on the current incremental image, output the features, proposal boxes, classification results, and regression results corresponding to the incremental category, and use them as the objects to be optimized in subsequent loss calculations.
[0069] Based on the above teacher-student bistate forward propagation results, the target detection loss is constructed as a joint optimization objective and iteratively updated until the network converges.
[0070] Preferably, the object detection loss is constructed as a joint optimization objective, including: in addition to the standard Faster R-CNN object detection loss, multi-level decoupled distillation losses are calculated in the backbone feature extraction network, the region proposal network (RPN), and the classification and regression layers in the ROI head, respectively, to constrain the student model to retain the detection capability of old defect categories while learning new defect categories. S31. Backbone Feature Extraction Network: Wood defects often present highly irregular shapes (such as oblique, thin cracks). Traditional distillation forcibly constrains the entire rectangular bounding box, leading to up to 70% of normal wood texture features being incorrectly locked, causing the student model to lose its plasticity in learning new defects. Attention-guided soft mask feature distillation solves the background coupling deadlock problem, such as... Figure 3 As shown.
[0071] Extracting the teacher model The self-attention weight matrix AW output by the AFEM module is aggregated and reconstructed according to the spatial location of the enhanced feature map output by the backbone feature extraction network of the teacher model, resulting in a two-dimensional attention response map corresponding to the spatial size of the enhanced feature map. The two-dimensional attention response map This is used to characterize the spatial regions that the teacher model focuses on in the old wood defect detection task. The higher the response value, the more likely the location corresponds to the key texture region of the old defect; the lower the response value, the more likely the location corresponds to the normal wood background texture region.
[0072] To avoid the problem of traditional hard masks using only 0 or 1 to distinguish between defect areas and background areas, which leads to excessive constraint on the wood texture background, this invention is based on a two-dimensional attention response map. Generate pixel-level continuous soft mask matrix Specifically, a soft mask temperature coefficient is introduced. ,right The response values at each spatial location are smoothed and normalized to obtain: (3) in, and These represent the spatial location indices in the teacher feature map. Used to adjust the smoothness of the soft mask; The larger the value, the smoother the weight difference between different spatial locations. The smaller the value, the more prominent the weight of the high-response defect region.
[0073] Received The values are continuous weights, used to represent the importance of each spatial location in feature distillation. For the core regions of old defects that the teacher model highly focuses on, Larger values require the student model to more strictly align with the feature representation of the teacher model; for normal wood texture backgrounds or areas unrelated to old defects, When the value is small, the distillation constraint at the corresponding position is weakened, thus reserving space for parameter updates for the student model to learn new defect features.
[0074] In obtaining the soft mask matrix Then, it is applied to the teacher model via tensor broadcasting. and student model Based on the difference in feature tensors output from the corresponding feature layers, an attention-guided soft mask feature distillation loss is constructed: (4) Where C, H, and W represent the number of channels, height, and width of the feature map, respectively; This represents the weight value of the soft mask matrix at spatial location (h, w); Teacher model The feature value at the position of the c-th channel, the h-th row, and the w-th column; Student model The feature value at the position of the c-th channel, the h-th row, and the w-th column; h and w represent the spatial location index of the enhanced feature map, respectively.
[0075] For the old defect core area that the teacher model is certain of ( ), imposing harsh punishments to prevent forgetting; for normal wood background areas ( The distillation gradient is adaptively diluted to free up parameter update space to fit nascent defects.
[0076] S32. Region Proposal Network (RPN): During incremental training, the teacher model is a detection model trained solely on existing wood defect categories. Its RPN branch does not learn the texture morphology, edge transition features, and local color changes of newly added defect categories. Therefore, for candidate regions containing only newly added defects or with newly added defects as the primary target, the teacher model tends to classify these regions as normal wood background and outputs low target confidence scores close to the background category. If the student model is unconditionally constrained to maintain consistency with the teacher model on the aforementioned candidate regions, the teacher model's cognitive blind spot regarding newly added defects will be distilled and passed to the student model as a supervisory signal. This suppresses the student model's target-oriented response to newly added defect proposal boxes in the early stages of training, thereby reducing the probability of retaining newly added defect candidate boxes and subsequent classification and regression optimization. RPN distillation based on asymmetric confidence truncation addresses the problem of suppressing novel types of blind zones, such as... Figure 4 As shown.
[0077] Based on the same input image, the same scale feature layer, and the same anchor box or the m-th RPN proposal box after sorting and alignment, the target confidence scores output by the teacher model and the student model are obtained respectively. , and bounding box regression coordinates , ; The target confidence score is the target probability after Softmax normalization, with a value range of [0,1]. The bounding box regression coordinates adopt the center point offset, width and height offset or their equivalent parameterization forms consistent with the RPN training phase.
[0078] To retain only the teacher model's reliable supervision on old defect proposal boxes and to mask the teacher model's low-confidence suppression of new defect proposal boxes, this invention constructs an asymmetric Boolean mask based on a step indicator function.
[0079] (5) in, This represents the asymmetric one-way truncated Boolean mask corresponding to the m-th RPN proposal box; m represents the proposal box index. (·) represents a step indicator function, which takes the value of 1 when the condition in the parentheses is true, and takes the value of 0 otherwise. Teacher model The target confidence score is output for the m-th proposal box; Student model The target confidence score is output for the m-th proposal box; This indicates the preset confidence deviation threshold, and A constant greater than 0, used to limit the target confidence level of the teacher model to be at least higher than that of the student model. Only then is the proposed box considered to belong to the older defect candidate box, which is more reliable in the teacher model.
[0080] After obtaining the asymmetric Boolean mask, only for Apply distillation constraints to the RPN proposal box with a value of 1, and calculate the RPN distillation loss with mask gating: (6) in, Indicates the number of RPN proposal frames involved in the distillation calculation; Teacher model For the first The bounding box regression coordinates output by each proposal box; Student model For the first The bounding box regression coordinates output by each proposal box; Used to measure the difference in target confidence between teacher and student models. Used to measure the difference in the teacher-student model's regression coordinates on the proposal box. After gating, the distillation loss of the proposal box is calculated only when the teacher model is more confident in the old goal and the student model has a tendency to forget.
[0081] This loss function constructs a "one-way distillation screening mechanism," which only triggers punishment when "the teacher model has high confidence in the old target and the student has forgotten it"; when the student discovers a new type of target ( When ), the mask returns 0, reducing the negative suppression of the teacher model on the newly added category candidate regions.
[0082] S33. Classification layer in the ROI head: The morphology of wood surface defects often exhibits strong transitional and ambiguous characteristics (e.g., confusion between early blue stain and normal shading, the transition period from live knot to dead knot). This causes the teacher model to exhibit fluctuating classification confidence distribution when facing some difficult proposals. Traditional knowledge distillation methods indiscriminately align all predictions, forcing the student model to "memorize" the teacher's "doubts" or even "errors," injecting low-quality "hidden knowledge" into the student network and severely interfering with the feature decision boundaries between old and new categories. Classification distillation based on uncertainty perception and dynamic weights of information entropy addresses the problem of dark knowledge misleading, such as... Figure 5 As shown.
[0083] (1) Introducing a temperature smoothing mechanism: For the first Each suggestion box retrieves the logits output from the teacher model's classification header. Introducing a preset distillation temperature coefficient (Usually set to 1.5~3.0), calculate its smoothed soft probability distribution: (7) This amplifies the implicit dark knowledge in non-target categories.
[0084] (2) Quantifying cognitive uncertainty: For the first Each frame calculates the Shannon entropy of the teacher's predicted probability as a quantitative indicator of their cognitive uncertainty. (8) Where H represents the teacher model The uncertainty measure of the classification prediction result of the current proposal box is the Shannon entropy; K represents the total number of classification categories. Indicates the defect category index; Teacher model The smoothed probability that the b-th proposal box belongs to the c-th type of defect; Represents a very small constant to prevent logarithmic aberrations (e.g.) The larger the value of H, the less certain the teacher model is about classifying the current proposal box; the smaller the value of H, the more certain the teacher model is about classifying the current proposal box.
[0085] (3) Constructing adaptive weights and weighted loss: Through exponential decay mapping, the entropy value of the teacher is converted into a weighted loss. Transform into an interval Dynamic distillation weight : (9) Here, γ represents the entropy decay coefficient, used to control the suppression strength of uncertainty on the distillation weights. Since w decreases as H increases, when the teacher model's classification result is relatively certain, w approaches 1, retaining a strong classification distillation constraint; when the teacher model's classification result is uncertain, w approaches 0, reducing the distillation constraint of the proposal box on the student model and avoiding the transfer of unreliable knowledge from the teacher model to the student model.
[0086] Subsequently, this weight term is removed from the computation graph (Detach) and treated as a constant, and the KL divergence-based classification loss is weighted on a proposal-by-proposal basis: (10) Where N represents the total number of proposal boxes participating in the categorical distillation calculation; Indicates the first The dynamic distillation weights corresponding to each proposal box; T represents the distillation temperature coefficient; Student model For the first The classification logic values output by each suggestion box; Teacher model For the first A smooth soft probability distribution of each proposal box output; This represents the KL divergence, used to measure the difference between the classification distributions of the student model and the teacher model. Weighting the classification distillation loss for each proposal box allows the student model to prioritize learning the old class knowledge that the teacher model is confident in, while mitigating the misleading effects of uncertain regions in the teacher model.
[0087] This step constructs a "dynamic weight selection mechanism" within the classification flow. For older defects (minimal entropy, low weight) with clear features and high teacher model confidence, this addresses these issues. ), retaining strong distillation constraints to consolidate old knowledge; for regions with fuzzy features and where the teacher himself is uncertain (maximum entropy, weight) The system then adaptively reduces the distillation constraint weight in that region. This mechanism eliminates the transmission of erroneous prior knowledge at its source, reducing the interference of erroneous priors on the classification boundary of the student model.
[0088] S34. Regression Layer in the ROI Header: In object detection, "what is the target (classification)" and "where is the target (regression)" have a strong physical correlation. Especially in wood processing, defects and normal textures often have blurred boundaries. If the teacher model is unsure even "what kind of defect is inside the bounding box," then the "defect boundary coordinates" it regresses will likely have serious dimensional deviations and positioning drift. Applying rigid coordinate distillation alignment to these unreliable bounding boxes will greatly restrict the student model's ability to adaptively fine-tune the blurred defect edges; Weighted regression distillation based on shared classification uncertainty is used to fit location-based reliability coupling, such as... Figure 5 As shown.
[0089] (1) Cross-branch confidence distribution: Directly extract the uncertainty dynamic weights calculated based on the teacher classification output in the S33 classification layer. This weight is used as a gating indicator for the credibility of teachers' regression outputs and shared across branches to the regression layer.
[0090] (2) Constructing a weighted Huber distillation loss: Assume that the student model and the teacher model are for the first... The coordinate vectors of the regression boxes output by the suggestion boxes are respectively and To ensure robustness to outliers, Huber loss is used as the base function for regression alignment, and shared weights are incorporated. Construct a joint regression distillation loss: (11) Where N represents the number of proposal boxes participating in the regression distillation calculation; Indicates the index of the suggestion box; Indicates the first The dynamic distillation weights corresponding to each proposal box are calculated from the classification uncertainty of the teacher model in the S33 classification layer and reused in the regression layer. Student model For the first The bounding box regression coordinates output by each proposal box; Teacher model For the first The bounding box regression coordinates output by each proposal box; The control threshold representing Huber loss is used to control the transition between L1 and L2 losses; This layer design establishes a linkage constraint between classification uncertainty and regression distillation, achieving differentiated regression distillation constraints. For old-class defect regions with certain classification, strict bounding box coordinate alignment is applied to ensure that the core location of historical defects does not shift due to forgetting; while for regions with highly ambiguous classification (such as transitional zones that spread along the wood grain and have difficult-to-define edges), the boundary box coordinates are aligned according to the classification weight. As the coordinates decay, the system automatically and synchronously cuts off the rigid alignment constraints of the position coordinates. This allows the student model to retain adaptive adjustment space for the boundary when facing complex and blurred wood texture boundaries, reducing the risk of decreased positioning accuracy caused by rigid coordinate alignment.
[0091] S35. Construct the overall joint optimization objective: For student models The standard Faster R-CNN object detection loss is calculated based on the prediction results of new defects in the incremental dataset. The loss includes RPN classification loss, RPN bounding box regression loss, detector head classification loss, and detector head bounding box regression loss; This is then weighted and summed with the four decoupled distillation losses to construct the overall joint optimization objective: (2) in, To balance the magnitude of the hyperparameters for each loss term, For soft mask feature distillation loss, For RPN distillation loss with mask gating, The classification loss is calculated by weighting the KL divergence of the proposal box. For the combined regression distillation loss, This is the standard Faster R-CNN object detection loss.
[0092] S4, Phase Four: End-to-End Joint Optimization and Deployment of Applications S41. Gradient Backpropagation and Parameter Update: Based on Total Loss The gradients of the student model parameters are calculated, and backpropagation and parameter updates are performed using the SGD optimizer. During backpropagation, only the student model is processed. Update the parameters of the teacher model. Keep frozen at all times.
[0093] S42. Model Convergence: Repeat the above forward inference and backpropagation steps until the network converges.
[0094] Repeat the above forward propagation, loss calculation, back propagation, and student model parameter update steps until the student model... In incremental dataset Total loss The training process converges, or reaches the preset number of training epochs. After convergence, the student model... The system has completed learning of the newly added defect categories in the current round and maintains the ability to detect existing defect categories under multi-level decoupled distillation constraints.
[0095] This completes the incremental learning process for this round.
[0096] S43. Model Deployment and Application: After this round of incremental learning is completed, the converged student model will be... This is the currently deployable detection model. A teacher model is no longer required during deployment. Participation in reasoning can be limited to student models. The edge computing nodes are deployed to the automated timber sorting production line to enable real-time detection of both new and old timber defect categories that have already been learned. If new defect categories continue to appear on the industrial production line, the student model that has converged in the previous round is used as the new base model to rebuild the frozen teacher model and the student model to be trained, and the next round of incremental learning is started.
[0097] Experimental results: Table 1. Experimental results of 9 types of incremental additions and 1 type.
[0098] To verify the effectiveness of our incremental learning method in long-tailed distribution scenarios, a 9+1 category incremental experiment was designed. First, a baseline model was trained on nine categories of wood defect data. Then, with the original model parameters fixed, a tenth category, resin, was incrementally introduced, and the model's performance across all ten categories was evaluated. Experimental results show that the mAP (mean Average Precision) of the original nine categories after incremental learning was 72.6%, compared to 74.3% for the baseline before the incremental learning, with a forgetting rate of only 2.3%. This indicates that our method effectively retains knowledge of the original categories and mitigates the catastrophic forgetting problem in incremental learning. The mAP of the newly added resin category reached 76.2%, higher than some original categories (such as 61.2% for knots and 63.9% for live knots), demonstrating that the model can establish effective feature representations for the new category without accessing old category data. The overall mAP for all ten categories was 73.4%, only 1.9 percentage points lower than the 75.3% achieved through joint training of the ten categories. This performance loss is within an acceptable range without replaying any old category samples. Additionally, blank entries (—) in the table indicate that the category was not included in the current experimental setup. During the "9 categories" base class training phase, only the first 9 categories were included; newly added categories were not involved in training and evaluation, and therefore their AP values were not reported. The same applies to blank entries in other experimental results.
[0099] Table 2. Results of the five incremental experiments.
[0100] In the 5+5 incremental learning setting, the model was first trained on 5 basic categories, and then 5 new categories were introduced for incremental learning. Experimental results show that after incremental learning, the model's average performance on the old categories decreased from 75.08% to 71.46%, a reduction of only 3.62 percentage points, indicating that the proposed method can effectively mitigate catastrophic forgetting during incremental learning. Meanwhile, the model achieved an average performance of 73.00% on the new categories, demonstrating its good ability to learn new knowledge. Compared with the results of joint training on 10 categories, the overall average performance under the 5+5 incremental learning setting decreased by only 3.11 percentage points, indicating that the method can still achieve recognition results close to those of joint training without completely retraining.
[0101] Table 3 Results of four basic multi-step incremental steps
[0102] In the 4+2+2+2 multi-step incremental experimental setup, the model needs to complete three consecutive category expansions, making the task significantly more difficult than single-step incremental learning. Experimental results show that the model ultimately achieves an average performance of 70.61% across 10 categories, a decrease of only 4.73 percentage points compared to the 75.34% achieved through joint training of 10 categories. This indicates that the proposed method maintains good overall recognition ability in multi-step incremental scenarios. As the incremental stages progress, the model performance gradually decreases from 76.63% to 70.61%, but the decline is relatively gradual in subsequent incremental stages, indicating that the model has a certain degree of stability in continuous learning. Meanwhile, the average performance of the basic categories decreases by 6.83 percentage points, indicating that the method can alleviate the forgetting of old categories to some extent; the average performance of the newly added categories reaches 71.15%, indicating that the model still has effective learning ability for new categories. Overall, the results validate the effectiveness of the proposed method in multi-category continuous expansion tasks.
[0103] Example 2 This embodiment provides an apparatus for implementing a distillation-based incremental wood defect detection method based on multi-level decoupling, the apparatus comprising: At least one processor; and The memory stores instructions that, when executed by the at least one processor, cause the at least one processor to perform a distillation incremental wood defect detection method based on multi-level decoupling as described above.
[0104] In this embodiment, the device may be an electronic device, which may include, but is not limited to: personal computer, server computer, workstation, desktop computer, laptop computer, notebook computer, mobile computing device, smartphone, tablet computer, cellular phone, personal digital assistant (PDA), handheld device, messaging device, wearable computing device, consumer electronic device, etc.
[0105] Example 3 This embodiment also provides a machine-readable storage medium storing executable instructions that, when executed, cause the machine to perform the distillation incremental wood defect detection method based on multi-level decoupling as described above.
[0106] Specifically, a system or apparatus equipped with a readable storage medium may be provided, on which software program code implementing the functions of any of the embodiments described above is stored, and the computer or processor of the system or apparatus can read and execute the instructions stored in the readable storage medium.
[0107] In this case, the program code read from the readable medium itself can perform the functions of any of the above embodiments, and therefore the machine-readable code and the readable storage medium storing the machine-readable code constitute a part of this specification.
[0108] Examples of readable storage media include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD-RW), magnetic tapes, non-volatile memory cards, and ROMs. Alternatively, program code can be downloaded from a server computer or the cloud via a communication network.
[0109] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the technical solutions of the present invention, and are not intended to limit the specific implementation of the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the claims of the present invention should be included within the protection scope of the claims of the present invention.
Claims
1. A method for detecting defects in incremental wood distillation based on multi-level decoupling, characterized in that, The method includes: S1. Construct a basic target detection network model for identifying defects in wood images. Obtain an old defect dataset of wood images and pre-train it to obtain the basic training model for the incremental stage. The basic object detection network model adopts a two-stage object detection model Faster R-CNN, which includes a backbone feature extraction network, a region proposal network (RPN), and a region of interest (ROI) head. Attention feature enhancement module (AFEM) is embedded after the backbone feature extraction network and before the region proposal network. S2. When an incremental dataset including new defects floods the production line, incremental learning is performed to construct a teacher-student bi-state incremental network: To build a teacher model, copy and instantiate the pre-trained base model. During the entire incremental training process, disable the cross attention branch of AFEM in the teacher model, enable only the self attention branch, forcibly freeze all backpropagation gradients of the teacher model, and stop parameter updates. A student model is constructed and initialized with the same basic network structure as the teacher model. During the entire incremental training process, the cross attention branch and self attention branch in the AFEM of the student model are enabled; and the category dimension of the ROI detection head network of the student model is expanded. S3. Incrementally train the teacher model and the student model. In each iteration of incremental training, the same wood defect image from the incremental dataset is synchronously input into the teacher model and the student model for forward propagation. The teacher model keeps its parameters frozen and only outputs the features, proposal boxes, classification results, and regression results of the old defect categories as supervision signals for old knowledge. The student model outputs features, proposal boxes, classification results, and regression results for the incremental category based on the current incremental image, and participates in subsequent loss calculations as the object to be optimized. Based on the above teacher-student two-state forward propagation results, the target detection loss is constructed as a joint optimization objective; S4. Update the parameters of the student model based on the joint optimization objective until the total loss converges, obtain the converged student model, and deploy it to the edge computing node of the automated timber sorting production line.
2. The method for detecting defects in incremental wood distillation based on multi-stage decoupling according to claim 1, characterized in that, S1 further includes: The mathematical execution logic for constructing the attention feature enhancement module is described. The attention feature enhancement module includes: parallel self-attention branches and cross-attention branches, as well as feature fusion. Let the query, key, and value matrices obtained by mapping the feature maps extracted by the backbone feature extraction network be respectively... The dimension of the key vector is ; First, the self-attention branch of the attention feature enhancement module is based on the self-attention response matrix S. ; This region corresponds to the salient texture location of wood defects, from which the self-attention weight matrix highlighting key wood defect regions is calculated. , And generate a self-attention feature map. , ; Secondly, the cross-attention branch of the attention feature enhancement module is used to introduce the teacher model during the incremental learning phase. Retained knowledge of past defects; Subsequent student models Generating a new knowledge query matrix based on incremental wood defect images The teacher model provides a matrix of prior knowledge keys. Sum matrix ; Cross-attention branch utilization and Calculate the attention weight between new and old knowledge, and then apply this attention weight to... Perform a weighted summation to generate the cross-attention feature map Fcross: (1) in, Represents the old knowledge key matrix, Represents the matrix of old knowledge values. Represents the new knowledge query matrix; Enhanced feature maps obtained from student models This data is then passed to the RPN and ROI headers for candidate box generation and classification regression. During the teacher model training phase, the cross-attention branch is turned off, and only the self-attention branch is enabled to generate stable enhancement features for the old defect categories; The final teacher model outputs an enhanced feature map. = ; Obtain an old dataset of defects in wood images, including The basic wood defect dataset with existing defect categories ; Supervised pre-training is performed on the optimized basic object detection network model. After training, the network weight parameters are fixed. That is, pre-training weights to obtain the basic trained model. .
3. The method for detecting defects in incremental wood distillation based on multi-stage decoupling according to claim 2, characterized in that, The constructed target detection loss is a joint optimization target. The loss is calculated as a weighted sum of the standard Faster R-CNN object detection loss and the multi-level decoupling distillation loss calculated in the backbone feature extraction network, the region proposal network (RPN), and the classification and regression layers in the ROI head, respectively. (2) in, To balance the hyperparameters of the magnitude of each loss term, For soft mask feature distillation loss, For RPN distillation loss with mask gating, The classification loss is calculated by weighting the KL divergence of the proposal box. For the combined regression distillation loss, The loss is the standard Faster R-CNN object detection loss; (1) Distillation in the backbone feature extraction network is attention-guided soft mask feature distillation: extract the self-attention response matrix output by the teacher model AFEM, generate pixel-level continuous soft masks, and calculate the feature distillation loss by weighting the soft masks; (2) Distillation in the Regional Proposal Network (RPN) is based on asymmetric confidence truncation of the RPN proposal box: construct an asymmetric one-way truncation Boolean mask, and calculate the RPN distillation loss with mask gating through mask gating; (3) Classification layer distillation in the ROI head is classification distillation based on uncertainty perception and information entropy dynamic weights: quantify the uncertainty of the teacher model classification prediction, generate dynamic weights, and calculate the classification loss of the proposal box weighted KL divergence. (4) The regression layer distillation in the ROI head is a weighted regression distillation based on the sharing of classification uncertainty: the dynamic weights of the uncertainty of the shared classification layer are used to calculate the joint regression distillation loss.
4. The method for detecting defects in incremental wood distillation based on multi-stage decoupling according to claim 3, characterized in that, The construction of the attention-guided soft mask feature distillation loss specifically includes: Extracting the teacher model The self-attention weight matrix AW output by the AFEM module is aggregated and reconstructed according to the spatial location of the feature map output by the backbone feature extraction network of the teacher model, resulting in a two-dimensional attention response map corresponding to the spatial size of the teacher feature map. ; Then based on the two-dimensional attention response map Generate pixel-level continuous soft mask matrix Introducing a soft mask temperature coefficient And then The response values at each spatial location are smoothed and normalized: (3) in, i and j These represent the spatial location indices in the teacher feature map. Used to adjust the smoothness of the soft mask; Received The values are continuous weights, used to represent the importance of each spatial location in feature distillation; In obtaining the soft mask matrix Then, it is applied to the teacher model via tensor broadcasting. and student model Based on the difference in feature tensors output from the corresponding feature layers, an attention-guided soft mask feature distillation loss is constructed: (4) Where C, H, and W represent the number of channels, height, and width of the feature map, respectively; This represents the weight value of the soft mask matrix at spatial location (h, w); Teacher model The feature value at the position of the c-th channel, the h-th row, and the w-th column; Student model The feature value at the position of the c-th channel, the h-th row, and the w-th column; h and w represent the spatial location index of the enhanced feature map, respectively.
5. The method for detecting defects in incremental wood distillation based on multi-stage decoupling according to claim 3, characterized in that, The construction of the mask-gated RPN distillation loss specifically includes: Based on the same input image, the same scale feature layer, and the same anchor box or the m-th RPN proposal box after sorting and alignment, the target confidence scores output by the teacher model and the student model are obtained respectively. , and bounding box regression coordinates , ,in: Target confidence score , The target probability is obtained after Softmax normalization, with a value range of [0,1]; bounding box regression coordinates. , It adopts the same form of center point offset and width / height offset as the RPN training phase; Then, construct an asymmetric Boolean mask based on the step indicator function. ; (5) in, Indicates the first Asymmetric one-way truncated Boolean mask corresponding to each RPN proposal box; (·) represents a step indicator function, which takes the value of 1 when the condition in the parentheses is true, and takes the value of 0 otherwise. Teacher model The target confidence score is output for the m-th proposal box; Student model For the first The target confidence score is output by each suggestion box; This indicates the preset confidence level deviation threshold; After obtaining the asymmetric Boolean mask, only for Apply distillation constraints to the RPN proposal box with a value of 1, and calculate the RPN distillation loss with mask gating: (6) in, Indicates the number of RPN proposal frames involved in the distillation calculation; Teacher model For the first The bounding box regression coordinates output by each proposal box; Student model Regress the bounding box coordinates of the m-th proposal box; Used to measure the difference in target confidence between teacher and student models. Used to measure the difference between the teacher and student models on the regression coordinates of the proposal box.
6. The method for detecting defects in incremental wood distillation based on multi-stage decoupling according to claim 3, characterized in that, The construction of the classification loss based on the weighted KL divergence of the proposal box specifically includes: First, a temperature smoothing mechanism is introduced: For the b-th proposal box, the logical value output by the teacher model's classification head is obtained. Introducing a preset distillation temperature coefficient Calculate its smoothed soft probability distribution : (7) Secondly, quantifying cognitive uncertainty: For the b-th frame, calculate the Shannon entropy of the teacher's predicted probability as a quantitative indicator of their cognitive uncertainty. (8) in, Teacher model The uncertainty measure of the current proposal box classification prediction result, namely Shannon entropy; K represents the total number of classification categories; c represents the defect category index; Teacher model The smoothed probability that the b-th proposal box belongs to the c-th type of defect; Represents a very small constant to prevent abnormal logarithmic operations; Then, adaptive weights and weighted loss are constructed: the entropy value of the teacher is converted using an exponentially decaying mapping. Transform into an interval Dynamic distillation weight : (9) in, γ This represents the entropy decay coefficient, used to control the strength of the suppression of uncertainty on the distillation weight; Finally, this weight term is removed from the computation graph and treated as a constant, and the KL divergence-based classification loss is weighted for each proposal box: (10) Where N represents the total number of proposal boxes participating in the categorical distillation calculation; This represents the dynamic distillation weight corresponding to the b-th proposal box; T represents the distillation temperature coefficient. Student model The classification logic value output for the b-th suggestion box; Teacher model The smooth soft probability distribution output for the b-th proposal box.
7. The method for detecting defects in incremental wood distillation based on multi-stage decoupling according to claim 3, characterized in that, The construction of the joint regression distillation loss specifically includes: First, cross-branch confidence distribution: directly extract the uncertain dynamic weights calculated based on the teacher classification output from the classification layer. This weight is used as a gating indicator for the credibility of teachers' regression outputs and shared across branches to the regression layer. Secondly, construct the weighted Huber distillation loss: Let the coordinate vectors of the regression boxes output by the student model and the teacher model for the d-th proposal box be respectively... and ; Huber loss is used as the basic function for regression alignment, and shared weights are incorporated. Constructing a joint regression distillation loss : (11) Where N represents the number of proposal boxes participating in the regression distillation calculation; d represents the proposal box index; This represents the dynamic distillation weight corresponding to the d-th proposal box. This weight is calculated from the classification uncertainty of the teacher model in the classification layer and reused in the regression layer. Student model For the first The bounding box regression coordinates output by each proposal box; Teacher model The bounding box regression coordinates output for the d-th proposal box; δ represents the control threshold of the Huber loss, used to control the conversion between L1 loss and L2 loss.
8. An apparatus for implementing a distillation-based incremental wood defect detection method based on multi-stage decoupling, characterized in that, The device includes: processor; A memory on which computer programs that can run on the processor are stored; When the computer program is executed by the processor, it implements the steps of the distillation incremental wood defect detection method according to any one of claims 1 to 7.
9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Lightweight RGB-D rail surface defect detection method based on multi-teacher knowledge distillation
CN119130921A
Electrical equipment defect detection and identification method based on improved YOLOv8
CN120672686A
Industrial part defect detection method, device and equipment and storage medium
CN121661017A