Shaving board surface defect identification method and system based on twin network and supervised contrast learning

By combining Siamese networks with supervised contrastive learning, along with feature extraction backbone, multi-scale feature fusion, and adaptive coordinate attention, the problem of low accuracy and weak generalization ability in particleboard surface defect identification under small sample conditions is solved, achieving efficient and accurate automated detection.

CN121982013APending Publication Date: 2026-05-05NANJING FORESTRY UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610187848.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-02-10
Publication Date
2026-05-05

AI Technical Summary

Technical Problem

Under small sample conditions, the accuracy of particleboard surface defect identification is low and the model has weak generalization ability. Existing deep learning methods are difficult to effectively identify various defects against complex wood grain backgrounds.

Method used

We employ a method based on Siamese networks and supervised contrastive learning. We use the pre-trained visual Transformer model ViT-S/14 reg4 DINOv2 as the backbone for feature extraction, combined with the lightweight multi-scale feature fusion pyramid structure LDPPN and the residual adaptive coordinate attention module RACA. Through joint optimization of cross-entropy classification loss and supervised contrastive loss, we construct a Siamese supervised contrastive network model to achieve efficient and accurate defect identification.

Benefits of technology

Under small sample conditions, it significantly improves the accuracy and generalization ability of particleboard surface defect identification, can be deployed in real time on the production line, and has efficient and accurate automated quality inspection capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121982013A_ABST
    Figure CN121982013A_ABST
Patent Text Reader

Abstract

The invention discloses a particle board surface defect identification method and system based on a twin network and supervised comparative learning, and the method comprises the steps: (1) collecting a particle board surface image, carrying out the preprocessing, constructing a small sample data set containing various defects, and dividing the small sample data set into a training set and a test set; (2) constructing an improved twin supervised contrast network model, wherein the model comprises a feature extraction backbone network, an LDFPN and a classification contrast learning head; (3) training the twin supervised comparison network model by using the training set, and adopting joint optimization of cross entropy classification loss and supervised comparison loss during training; and (4) performing defect identification and classification on the shaving board surface image by using the trained twin supervision comparison network model. The method and the system aim at solving the problems of low particle board surface defect identification accuracy and weak model generalization ability under the condition of small samples, efficient and accurate automatic quality detection is realized, and the method and the system have the potential of real-time deployment on a production line.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of intelligent manufacturing and computer vision technology in wood processing, specifically to an intelligent identification method and system for particleboard surface defects based on twin networks and supervised contrastive learning under small sample conditions. Background Technology

[0002] Particleboard, as a major category of engineered wood products, is widely used in furniture manufacturing, interior decoration, and building components. Its surface quality directly affects the aesthetics and performance of the products. However, due to factors such as the heterogeneity of wood raw materials, uneven distribution of adhesives, and fluctuations in hot-pressing processes, particleboard surfaces are prone to various defects, including glue spots, scratches, sand leakage, contamination, and damage.

[0003] Currently, most domestic manufacturers still rely on manual visual inspection for defect detection and grading. This method suffers from low efficiency, high subjectivity, and susceptibility to errors due to visual fatigue. Furthermore, it poses safety hazards for personnel working near high-speed operating equipment. In recent years, deep learning-based visual inspection methods (such as those based on YOLO and Faster R-CNN frameworks) have been introduced into the field of industrial quality inspection, achieving good results in some scenarios.

[0004] However, these deep learning methods typically require a large number of labeled samples to achieve ideal performance. In actual particleboard production, as technology improves, the defect rate continues to decrease, resulting in scarce defect samples and high acquisition costs, creating a typical small-sample learning scenario. Under these conditions, traditional deep learning methods are prone to overfitting and have severely insufficient generalization ability.

[0005] To address the problem of limited sample sizes, Siamese Networks and Contrastive Learning techniques have gained attention. Siamese Networks classify samples by comparing their similarity, making them naturally suitable for scenarios with insufficient samples. Supervised Contrastive Learning, on the other hand, can utilize limited label information to explicitly bring similar samples closer together and push dissimilar samples further away in the feature embedding space, thereby learning more discriminative feature representations. However, combining these advanced learning paradigms with the unique visual characteristics of particleboard surface defects (such as complex wood grain backgrounds, variable defect scales, and strong texture interference) to construct an efficient, robust, and easily deployable identification method and system remains a major challenge for current technology. Summary of the Invention

[0006] The purpose of this invention is to overcome the shortcomings of existing technologies and provide a method and system for identifying surface defects in particleboard based on Siamese networks and supervised contrastive learning. This method and system aim to solve the problems of low accuracy and weak model generalization ability in identifying surface defects in particleboard under small sample conditions, achieving efficient and accurate automated quality inspection, and possessing the potential for real-time deployment on production lines.

[0007] To achieve the above-mentioned technical objectives, the technical solution adopted by the present invention is as follows:

[0008] A method for identifying surface defects in particleboard based on Siamese networks and supervised contrastive learning includes the following steps:

[0009] (1) Collect images of particleboard surface, preprocess them to construct a small sample dataset containing multiple types of defects, and divide it into training set and test set;

[0010] (2) Construct an improved Siamese supervised contrastive network model, wherein the Siamese supervised contrastive network model includes:

[0011] Feature extraction backbone network: The pre-trained visual Transformer model ViT-S / 14 reg4 DINOv2 is used;

[0012] Lightweight Multi-Scale Feature Fusion Pyramid Structure LDPPN: Performs multi-scale fusion and enhancement on the output features of the backbone network;

[0013] Classification and contrastive learning head: includes parallel classification and projection branches;

[0014] (3) The training set is used to train the Siamese supervised contrastive network model. During training, the cross-entropy classification loss and supervised contrastive loss are jointly optimized.

[0015] (4) Use the trained twin supervised contrast network model to identify and classify defects in particleboard surface images.

[0016] As a further improvement of the present invention, step (1) specifically includes:

[0017] Acquire images of the particleboard surface;

[0018] The collected images of the particleboard surface were processed by background removal and cropping, and divided into 512×512 image blocks.

[0019] Construct a small sample dataset containing five types of defects: glue spots, scratches, sand leakage, contamination, and damage;

[0020] The dataset was randomly divided into training and test sets in an 8:2 ratio.

[0021] As a further improved technical solution of the present invention, the visual Transformer model ViT-S / 14 reg4 DINOv2 in step (2) has an input token sequence containing CLS token, patch tokens and 4 register tokens, and performs global context modeling through a self-attention mechanism; the weights of the backbone network are frozen during training.

[0022] As a further improved technical solution of the present invention, the lightweight multi-scale feature fusion pyramid structure LDPPN in step (2) includes: using a lightweight downsampling module based on depthwise separable convolution to downsample the input feature map step by step to obtain multi-scale feature maps; upsampling the feature maps of different scales to the same spatial resolution, and then fusion them through 1×1 convolution after concatenation in the channel dimension; using an improved coordinate attention mechanism to enhance the fused features; and converting the enhanced feature map into a feature vector of a unified dimension through global average pooling.

[0023] As a further improvement of the present invention, the improved coordinate attention mechanism is a Residual Adaptive Coordinate Attention Module (RACA), which includes: performing global average pooling on the input feature map along the height and width directions respectively to obtain a height feature vector and a width feature vector; concatenating the feature vectors in the two directions in the spatial dimension and performing channel compression through 1×1 convolution; splitting the compressed features into height and width components, and generating attention weights in the height and width directions respectively through convolution and a sigmoid activation function; adding the original input features and the features weighted by the attention weights through a learnable scaling factor to obtain the enhanced output feature map.

[0024] As a further improvement of the present invention, the joint loss function in step (3) is:

[0025] ;

[0026] in, To compare the loss weights; Cross-entropy classification loss, To monitor and compare losses.

[0027] As a further improvement of the present invention, the supervised comparison loss function is defined as:

[0028] ;

[0029] Where M is the total number of sample views in the batch, To be consistent with the sample A set of positive samples with the same label; τ is the L2 normalized eigenvector; τ is the temperature coefficient.

[0030] As a further improvement of the present invention, the training configuration of step S3 includes: using the Adam optimizer, with an initial learning rate of 0.0001, training for 150 epochs, and a batch size of 16.

[0031] As a further improvement to the present invention, the training and inference of the twin-supervised contrastive network model adopt different network architecture modes:

[0032] (a) During the training phase, the Siamese supervised contrastive network model operates as a Siamese network:

[0033] (a1) For each defective image in the training set, generate two random augmented views to form a positive sample pair;

[0034] (a2) Input these two views into the dual branches of the network with shared parameters, and then pass them through the feature extraction backbone network, the lightweight multi-scale feature fusion pyramid structure LDPPN, and the classification contrast learning head;

[0035] (a3) Optimization is achieved through a joint loss function, in which the classification branch uses cross-entropy loss for multi-class defect identification supervision, while the features output by the projection branch are used to calculate the supervised contrast loss, in order to bring similar samples closer together and push away dissimilar samples;

[0036] (b) During the inference phase, the Siamese supervised contrastive network model is converted into a single-branch multi-classification network:

[0037] (b1) Forward propagation is performed only on a single image to be tested;

[0038] (b2) After the features are extracted by the feature extraction backbone network and the lightweight multi-scale feature fusion pyramid structure LDPPN, the scores of each category are directly output by the classification branch in the classification contrast learning head;

[0039] (b3) The category with the highest score is taken as the final defect identification result.

[0040] To achieve the above-mentioned technical objectives, another technical solution adopted by the present invention is as follows:

[0041] A particleboard surface defect detection system, comprising: connected in sequence:

[0042] Image acquisition module, used to acquire raw images of the particleboard surface;

[0043] The preprocessing module is used to remove the background from the original image and crop it into image blocks of a set size;

[0044] The defect identification module loads and runs the Siamese supervised contrastive network model trained according to any one of claims 1-9 to extract features and classify the input image blocks.

[0045] The result output module is used to output the defect category identification result and confidence level of the image block.

[0046] The beneficial effects of this invention are as follows:

[0047] 1. Excellent small-sample adaptability: In the Siamese network architecture, the ViT-S / 14 reg4 DINOv2 visual Transformer is used as the backbone for feature extraction, replacing the traditional convolutional neural network backbone. On the one hand, ViT-S / 14 reg4DINOv2 relies on large-scale self-supervised pre-training, which can still provide high-level semantic features with good generalization ability under limited labeled sample conditions; on the other hand, its global modeling mechanism based on multi-head self-attention can capture long-range dependencies in complex wood grain and messy texture backgrounds, thereby alleviating the overfitting problem in small-sample particleboard defect recognition scenarios and helping to more stably characterize the subtle differences between different defect categories.

[0048] 2. Powerful multi-scale defect perception capability: The designed LDPPN structure can effectively capture defects of different sizes, from small glue spots to large-scale damage, through lightweight depth-separable convolution downsampling and multi-scale feature fusion.

[0049] A lightweight multi-scale feature fusion pyramid (LDFPN) is constructed on top of the backbone network as the neck structure. An efficient downsampling module based on depthwise separable convolutions is introduced during the downsampling process to enhance multi-scale feature representation capabilities while significantly reducing the number of parameters and computational cost. This structure, on the one hand, fully integrates semantic information of different scales through top-down and lateral connections, enabling the network to simultaneously address minute defects such as glue spots as well as large-scale defects such as extensive contamination and damage. On the other hand, depthwise separable convolutions reduce model complexity while maintaining an effective receptive field, making small-sample training more stable and easier to deploy on actual particleboard production lines.

[0050] 3. Precise feature focusing and anti-interference capability: The proposed RACA module can adaptively enhance the feature response of defect-related regions by encoding spatial coordinate information and adaptively weighting residuals, and effectively suppress noise interference from complex wood grain backgrounds, thereby improving the discriminative power of features.

[0051] A Residual Adaptive Coordinate Attention (RACA) module is designed to encode positional information along the horizontal and vertical directions based on the fused features. Oriented pooling is used to capture the spatial distribution pattern of defects on the board surface, generating corresponding coordinate attention weights. Channels highly correlated with defect areas are adaptively enhanced. Simultaneously, RACA adaptively balances the original features and attention-enhanced features through residual connections and learnable fusion coefficients. This approach highlights defect-related responses while effectively suppressing complex wood grain backgrounds and noise interference, resulting in a more robust and discriminative feature representation.

[0052] 4. Efficient Deployment Architecture: It adopts a flexible architecture of "using twins for training and single-branch for inference". During training, it uses twin contrastive learning to improve feature quality; during inference, it only requires a single forward computation, which balances high performance and low latency, making it very suitable for real-time deployment on the production line.

[0053] A joint optimization strategy combining cross-entropy classification loss and supervised contrastive loss is adopted. On the one hand, cross-entropy is used to ensure the discrimination performance of various defects. On the other hand, supervised contrastive loss explicitly constrains the clustering of similar samples and the separation of dissimilar samples in the feature embedding space under small sample conditions, which alleviates the feature aliasing and overfitting problems caused by insufficient samples, thereby improving the recognition ability of particleboard surface under small sample conditions.

[0054] 5. Complete system solution: It not only provides core algorithms, but also builds a complete detection system solution from image acquisition, preprocessing, intelligent recognition to result output, which has direct industrial application value. Attached Figure Description

[0055] Figure 1 This is a schematic diagram of the overall structure of a particleboard surface defect identification method based on Siamese networks and supervised comparative learning.

[0056] Figure 2 This is a schematic diagram of a traditional twin neural network structure.

[0057] Figure 3 This is a schematic diagram of the ViT-S / 14 reg4 DINOv2 structure, which serves as the backbone network for feature extraction.

[0058] Figure 4 This is a schematic diagram of the Lightweight Multi-Scale Feature Fusion Pyramid Downsampling (LDFPN) structure.

[0059] Figure 5 This is a schematic diagram of the Residual Adaptive Coordinate Attention Module (RACA).

[0060] Figure 6 The images are schematic diagrams of five types of defects.

[0061] Figure 7 This is a graph showing the training loss of this method.

[0062] Figure 8 This is a graph showing the test accuracy of this method. Detailed Implementation

[0063] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments.

[0064] A method for identifying surface defects in particleboard based on Siamese networks and supervised contrastive learning includes the following steps:

[0065] Step (1): Collect images of the particleboard surface, perform preprocessing to construct a small sample dataset containing multiple types of defects, and divide it into training set and test set.

[0066] Step (1) specifically includes: preprocessing the collected particleboard surface image dataset: background removal, cropping, dividing the original large image into 512*512 image blocks, and filtering to obtain 5 types of small sample defect image datasets (glue spots, scratches, sand leakage, pollution, damage, etc.). Figure 6 (As shown in the figure); the acquired particleboard image data is randomly divided into training set and test set in a ratio of 8:2.

[0067] Step (2): Construct an improved Siamese supervised contrastive network model, which includes: (1) a feature extraction backbone network: using a pre-trained visual Transformer model ViT-S / 14 reg4 DINOv2; (2) a lightweight multi-scale feature fusion pyramid structure LDPPN: performing multi-scale fusion and enhancement on the output features of the backbone network; and (3) a classification contrastive learning head: containing parallel classification and projection branches. The network structure is as follows: Figure 1 As shown. Figure 1 It includes: a dataset input module, a feature extraction and multi-scale feature fusion module consisting of a shared backbone network and a lightweight multi-scale feature fusion pyramid downsampling structure, a residual adaptive coordinate attention module connected to the feature map, a classification head for outputting multi-class defect prediction results, and a projection head for supervised contrastive learning, as well as a joint optimization module based on cross-entropy loss and supervised contrastive loss. Figure 1 The processing flow is as follows: After preprocessing and cropping the collected particleboard surface defect images, two data augmentation views (X1 and X2) are generated. These views are then input into two twin branches with shared weights. High-dimensional features are extracted by the backbone network and enhanced through lightweight multi-scale feature fusion and coordinate attention to obtain G. W (X1) and G W(X2), one branch is fed into the classification head for defect category prediction, and two branches are fed into the projection head to construct the supervised contrastive loss, thereby simultaneously achieving multi-class defect recognition and structural constraints in the feature embedding space. Where G... W (X) is the feature extraction network, which includes the backbone network ViT-S / 14 reg4 DINOv2 and LDPPN.

[0068] Figure 2 This is a schematic diagram of a traditional twin neural network structure; Figure 2 It includes: two feature extraction subnetworks with identical structures and shared parameters, dual input ports for inputting reference images and test images respectively, an embedding space for output feature vectors, and a similarity measurement unit and a contrast loss calculation unit based on Euclidean distance. Figure 2 The processing procedure shown is as follows: A pair of image samples (X1, X2) are input into two feature extraction networks G with shared weights, one on the left and one on the right. w1 In (X), the corresponding eigenvector G is obtained. w1 (X1) and G w1 (X2), and then the characteristic distance E between the two is obtained through the Euclidean distance calculation unit. w The network is trained by incorporating similar / dissimilar labels Y into the contrastive loss function, so that images with defects of the same type are close to each other in the feature space, while images with defects of different types are far apart from each other.

[0069] The improved twin-supervised contrastive network model presented in this paper is introduced below:

[0070] The feature extraction backbone network is a pre-trained model ViT-S / 14 reg4DINOv2 (DINOv2-S / 14 for short) based on visual Transformer. It can more effectively characterize the long-range correlation and cross-regional texture differences of particleboard surface defects in a large-scale texture background, and is suitable for scenarios with diverse textures but limited labeled sample size.

[0071] ViT-S / 14 reg4 DINOv2 inherits the DINOv2 large-scale self-supervised pre-training framework. Through teacher-student self-distillation, it learns general visual representations on massive amounts of unlabeled images, achieving strong transfer and generalization capabilities. Building upon this, ViT-S / 14 reg4 DINOv2 introduces four additional register tokens into the input token sequence. These, along with the CLS token and patch tokens, are input into the Transformer encoder and participate in global context modeling through a self-attention mechanism. This helps aggregate long-range dependencies and reduces the modeling burden of the CLS token. For small-sample particleboard defect datasets, it adopts a paradigm of "first learning general features with a large model, then reusing / fine-tuning on a small number of samples," effectively improving the stability of feature representation and cross-defect type generalization ability without requiring large-scale labeled data. The overall structure of ViT-S / 14 reg4 DINOv2 is as follows: Figure 3 As shown. Considering the sensitivity of small sample scenarios to model capacity, the ViT-S / 14 reg4DINOv2 backbone is frozen during training, and only the neck structure and classification head are fine-tuned to make full use of pre-trained features, reduce trainable parameters, and reduce the risk of overfitting.

[0072] Figure 3 This is a schematic diagram of the ViT-S / 14 reg4 DINOv2 structure, which serves as the backbone network for feature extraction. The diagram includes: a patch embedding layer that divides the input particleboard defect image into fixed-size image patches; a category token (CLS token) used to represent the entire image; multiple register tokens used to enhance global semantic aggregation capabilities; patch tokens formed by each image patch; a location encoding module that encodes the location information of each token; and a Transformer encoder structure composed of multiple layers of multi-head self-attention and feedforward networks stacked together. Figure 3 The processing procedure is as follows: the preprocessed defect image is converted into a token sequence, and a CLS token and several register tokens are appended to the sequence. Finally, the CLS token, four REG tokens, and all Patch tokens are concatenated into a complete sequence, which is used as the input to the Transformer encoder. The long-range correlation and cross-regional texture differences in the complex texture background of particleboard are modeled through a multi-head self-attention mechanism. Finally, a high-dimensional feature map containing global semantic information is extracted at the output end, which is used as the input to the subsequent lightweight multi-scale feature pyramid and coordinate attention module.

[0073] The Lightweight Down-sampling Feature Pyramid Network (LDFPN) takes a single high-dimensional feature map output from the backbone network as input and achieves multi-scale modeling through stepwise downsampling and feature fusion. Figure 4 This is a schematic diagram of the Lightweight Multi-Scale Feature Fusion Pyramid Downsampling (LDFPN) structure. Figure 4 It includes: a progressive downsampling module that takes the high-resolution feature map F3 output by the backbone network as input; a depthwise separable convolutional unit consisting of depthwise convolution and pointwise convolution; a multi-level downsampling path for obtaining medium-scale and low-scale feature maps F4 and F5; an upsampling unit that upsamples F4 and F5 to the same spatial size as F3; a feature fusion unit that performs multi-scale feature stitching in the channel dimension; and an output unit that performs 1×1 convolution and subsequent enhancement processing on the fused features. Figure 4 The processing procedure is as follows: First, the feature map F3 output by the backbone network is passed through a downsampling module based on depthwise separable convolution to obtain feature maps F4 and F5 at different scales. Then, the low-scale features are upsampled to the same spatial resolution as F3 and concatenated in the channel dimension. 1×1 convolution is used to achieve feature compression and fusion, which effectively reduces the number of parameters and computation while ensuring the ability to model semantics at multiple scales, and provides multi-scale input for subsequent coordinate attention enhancement and global feature aggregation.

[0074] An LDPPN structure is introduced after the backbone network. This downsampling structure obtains feature maps of different scales through stepwise downsampling based on depthwise separable convolutions, and achieves multi-scale feature fusion through upsampling and channel concatenation to enhance the representation ability of defects of different sizes. Its working principle can be divided into the following steps:

[0075] (1) The output characteristics of the backbone network are: F3∈R C×H×W Where C, H, and W represent the number of channels, height, and width, respectively. To obtain feature representations of defects at different scales in particleboard, this embodiment uses a downsampling module based on depthwise separable convolution to construct a feature pyramid, the calculation process of which can be expressed as follows:

[0076] ;

[0077] in: This represents a depthwise convolution with a stride of 2, used to extract local spatial features; This represents pointwise convolution, used for reassembling channel information; and These represent batch normalization and ReLU activation functions, respectively.

[0078] (2) Through the above operations, features at different scales are obtained sequentially:

[0079] , ;

[0080] in This represents a lightweight downsampling process.

[0081] (3) In order to achieve effective fusion between features at different scales, this embodiment upsamples F4 and F5 to the same spatial resolution as F3 to achieve effective fusion between features at different scales:

[0082] = , = ;

[0083] in This indicates a single upsampling process.

[0084] (4) Then, the layers are stitched together along the channel dimension and fused using a 1×1 convolution:

[0085] .

[0086] (5) Based on this, the improved coordinate attention mechanism RACA is introduced to enhance the fused features:

[0087] ;

[0088] in: This is a learnable scalar parameter, initialized to 0; This indicates an improved coordinate attention module.

[0089] (6) Finally, a feature vector of uniform dimension is obtained through global average pooling, which serves as the input for classification and contrastive learning:

[0090] .in This indicates global average pooling.

[0091] A lightweight multi-scale feature pyramid downsampling structure significantly improves computational efficiency while maintaining multi-scale semantic modeling capabilities. This structure achieves efficient downsampling through depthwise separable convolutions and employs a one-time multi-scale feature alignment and fusion strategy, making the overall structure more concise and efficient; it also exhibits good compatibility with the reconstructed two-dimensional feature form. An improved coordinate attention mechanism is introduced in the feature fusion stage, effectively enhancing the representation effect and recognition accuracy of particleboard defects.

[0092] The core idea of ​​the Improved Coordinate Attention Module (RACA) is to decompose the two-dimensional global modeling into one-dimensional aggregation along the height and width directions, preserving explicit location information while introducing long-range dependencies. By performing a series of operations on the input features, joint modeling of spatial location information and channel features is achieved. The RACA module introduces residual connections and learnable attention scaling coefficients.

[0093] Figure 5 This is a schematic diagram of the Residual Adaptive Coordinate Attention Module (RACA). Figure 5 The system includes: a directional pooling unit that performs global average pooling on the input feature map in the horizontal and vertical directions respectively; a feature fusion and compression unit that concatenates the two directional contexts in the spatial dimension and performs channel compression through 1×1 convolution, normalization, and nonlinear activation; a coordinate attention weight generation unit that splits the intermediate features along the spatial dimension and generates attention weights in the height and width directions respectively; an attention weighting unit that performs multiplicative recalibration on the original features; and an adaptive residual fusion unit that introduces a learnable global scaling coefficient and performs residual superposition with the original features. Figure 5 The processing steps are as follows: First, global average pooling is performed on the input feature map in both the width and height directions to obtain two direction-sensitive context descriptions. Then, the features are concatenated in the spatial dimension and compressed through 1×1 convolution, batch normalization, and non-linear activation to form intermediate features. Subsequently, the intermediate features are split into two branches, which are then converted into height and width coordinate attention weights through 1×1 convolution and Sigmoid activation, respectively, to recalibrate the input features in both directions. Finally, a learnable scaling factor with Sigmoid constraint is introduced at the attention recalibration output, and added to the original features in the form of residuals to achieve adaptive enhancement of the response of defect-related channels and suppression of complex wood grain background noise.

[0094] Improvements to the coordinate attention module RACA, specifically including:

[0095] (1) Direction pooling:

[0096] Global average pooling is performed along both width and height to obtain two directional context descriptions:

[0097] , ;

[0098] Among them, the input feature map , , In reality, it is usually... Transpose In order to communicate with The pieces are joined together in the spatial dimension.

[0099] (2) Feature fusion and compression:

[0100] By concatenating the two directional features in space, we obtain:

[0101] ;

[0102] Then, 1×1 convolution is used for channel compression, and intermediate features are obtained by combining normalization and nonlinear activation:

[0103] ;

[0104] in Represents the ReLU nonlinear activation function; For batch normalization operators; mip is the intermediate channel dimension.

[0105] (3) Generate coordinate attention weights:

[0106] Split f along the spatial dimension into and Attention weights in the height and width directions are obtained by performing 1×1 convolutions followed by a sigmoid function:

[0107] , ;

[0108] in This represents the Sigmoid activation function.

[0109] (4) Attention recalibration:

[0110] Original coordinate attention typically reweights the input using a multiplicative approach, resulting in the following output:

[0111] ;

[0112] in This indicates element-wise multiplication and broadcasting by dimension.

[0113] (5) Introduce residual connections and learnable global scaling coefficients at the attention recalibration output, and first obtain the attention recalibration features in the original way:

[0114] ;

[0115] Then, a learnable parameter β is introduced, and it is constrained to the (0,1) interval by the Sigmoid function: ; These are the attention scaling factors after Sigmoid mapping. The final output is in residual form:

[0116] .

[0117] The RACA module adaptively superimposes enhanced attention onto the original features through residual connections and learnable attention scaling factors. This preserves the ability to model the coordinate attention space while maintaining the identity propagation path of features, thus mitigating the suppression of subtle defect information by attention estimation bias under small sample conditions. By learning a global scaling factor, the model can dynamically adjust the attention intensity based on training feedback, thereby more stably and robustly highlighting defect region features against complex particleboard texture backgrounds.

[0118] Step (3): Use the training set to train the Siamese supervised contrastive network model. During training, the cross-entropy classification loss and supervised contrastive loss are jointly optimized.

[0119] To simultaneously improve classification discrimination ability and the compactness of the same category and the separability of different categories in the feature embedding space, a joint optimization strategy of cross-entropy classification loss and supervised contrastive loss is adopted; the joint loss function is described in detail below.

[0120] (1) Cross-entropy classification loss:

[0121] For input view x, the classification header output logits is (K is the number of classes), its softmax probability is:

[0122] ;

[0123] Given the true labels y∈{1,…,K}, the cross-entropy loss is defined as:

[0124] ;

[0125] This directly supervised model completes defect category identification, ensuring the final classification performance. This represents the predicted probability corresponding to the true category y.

[0126] (2) Monitored and compared loss:

[0127] To enhance the discriminative power of feature representations under small sample conditions, this paper introduces supervised contrastive loss to impose structural constraints on the embedding space. Assuming a batch contains N samples, and each sample generates two views, the feature set size for contrastive learning is M = 2N. The projector output features, after L2 normalization, are obtained as follows:

[0128] ;

[0129] in Feature vectors used for contrastive learning; Indicates the projection head; This indicates an enhanced view.

[0130] For any anchor point feature z i Its positive samples only include the set of samples in the batch that have the same anchor label as itself:

[0131] ;

[0132] All samples that differ from the anchor category label constitute its negative sample set. Using a temperature coefficient τ to adjust the similarity distribution, the supervised contrastive loss can be written as:

[0133] .

[0134] in Indicates the number of positive samples; p represents the index of the positive samples; The similarity (dot product) between features is represented; τ is a temperature coefficient used to adjust the sharpness of the softmax distribution.

[0135] This loss constructs positive and negative sample pairs using label information, which clusters similar defect features in the embedding space and separates dissimilar defect features, thereby improving the ability to distinguish defects and generalize performance.

[0136] The final total loss function for training is a weighted sum of the two:

[0137] ;

[0138] in This indicates the weight of the comparative loss.

[0139] This joint optimization strategy utilizes cross-entropy to ensure the discrimination performance of various defects. On the other hand, it uses supervised contrastive loss to explicitly constrain the clustering of similar samples and the separation of dissimilar samples in the feature embedding space under small sample conditions, thereby alleviating the feature aliasing and overfitting problems caused by insufficient samples and improving the recognition ability of particleboard surfaces under small sample conditions.

[0140] Step (4): Use the trained twin supervised contrastive network model to identify and classify defects in particleboard surface images.

[0141] The training and inference of the twin-supervised contrastive network model adopt different network architecture modes:

[0142] (a) During the training phase, the Siamese supervised contrastive network model operates as a Siamese network:

[0143] (a1) For each defective image in the training set, generate two random augmented views to form a positive sample pair;

[0144] (a2) Input these two views into the dual branches of the network with shared parameters, and then pass them through the feature extraction backbone network, the lightweight multi-scale feature fusion pyramid structure LDPPN, and the classification contrast learning head to obtain the corresponding feature vector G. w (X1) and G w (X2);

[0145] (a3) Optimization is performed through a joint loss function, in which the classification branch (classification head) uses cross-entropy loss for multi-class defect identification supervision, and the features output by the projection branch (projection head) are used to calculate the supervision contrast loss, so as to bring similar samples closer and push away dissimilar samples.

[0146] (b) During the inference phase, the Siamese supervised contrastive network model is converted into a single-branch multi-classification network:

[0147] (b1) Forward propagation is performed only on a single image to be tested;

[0148] (b2) After the features are extracted by the feature extraction backbone network and the lightweight multi-scale feature fusion pyramid structure LDPPN, the scores of each category are directly output by the classification branch in the classification contrast learning head;

[0149] (b3) The category with the highest score is taken as the final defect identification result.

[0150] The following examples are used to illustrate the present invention, but are not intended to limit the scope of the invention.

[0151] Example 1: Dataset Preparation

[0152] On a particleboard production line, a high-resolution industrial camera is used to capture surface images of a standard particleboard (1220mm × 2440mm × 18mm), with an original resolution of 8192 × 16800 pixels. After background removal and cropping, a 512 × 512 pixel image block is obtained. Figure 6 As shown, five types of defects—glue spots, scratches, sand leakage, contamination, and damage—were marked by professional quality inspectors, resulting in 393 valid defect samples. These were randomly divided at an 8:2 ratio to obtain a training set of 313 samples and a test set of 80 samples.

[0153] Example 2: Network Model Construction and Training

[0154] according to Figure 1 The structure shown is used to construct the Siamese supervised contrastive network SSCL-PSDR model.

[0155] 1. Backbone network: Load the pre-trained ViT-S / 14 reg4 DINOv2 model and freeze all its parameters.

[0156] 2. LDPPN Construction: Set the downsampling step size to 2, and the number of channels to 256, 512, and 1024 respectively. Initialize the learnable scaling factor β in the RACA module to 0.

[0157] 3. Algorithm Flow:

[0158] This embodiment improves upon the classic Siamese network by retaining the dual-branch structure and introducing supervised contrastive learning during the training phase, while using only a single-branch multi-class classification network during the inference phase. The proposed model performs multi-class defect identification within the Siamese contrastive learning framework, mitigating overfitting under small sample conditions and improving generalization performance. The specific operation is as follows:

[0159] (1) After sharing the backbone and neck, a linear classification head is added to directly map the global features of a single image into multi-class logits, and cross-entropy is used for supervision, so that the network can be naturally extended from "similarity discrimination" to multi-class prediction that supports multi-class defects.

[0160] (2) The Siamese training is retained, and two enhanced views are generated for each defective image. Two projection features are obtained through a shared network, and a contrast constraint of "positive for the same class and negative for the opposite class" is constructed through SupConLoss. Joint cross-entropy optimization is used to maintain the good ability of the Siamese network to cluster the same class and separate the opposite class under the multi-class setting.

[0161] (3) Set up a classification head for softmax discrimination and a projection head for contrastive learning respectively, so that the two can be optimized independently in their respective feature spaces: the classification branch focuses on learning clear multi-class decision boundaries, and the contrastive branch strengthens the embedding space structure, so as to balance multi-class performance and metric learning ability without interfering with each other.

[0162] (4) During inference, features are calculated forward for a single image and the scores of each category are output through the classification head. The maximum value is taken as the prediction result. That is, the twin / contrast paradigm is retained in the training stage, and the inference stage is consistent with the standard multi-classification model, which is convenient for deployment and application in actual small sample particleboard surface defect recognition scenarios.

[0163] 4. Training configuration: The Adam optimizer is used, with an initial learning rate of 0.0001, training for 150 epochs, and a batch size of 16. The supervised contrastive loss temperature coefficient τ = 0.07, and the balancing weight λ = 0.5.

[0164] 5. Training Process: Each training sample generates two augmented views which are input into the dual-branch network. The joint loss function optimizes both the classification and feature space simultaneously.

[0165] Example 3: Model Evaluation and Comparative Analysis:

[0166] To comprehensively evaluate the model's performance, this embodiment uses four key metrics: accuracy, precision, recall, and F1 score. These metrics comprehensively reflect the model's predictive ability. Accuracy is the overall sample-level accuracy; precision, recall, and F1 score are all calculated using a macro-average method based on the confusion matrix.

[0167] To verify the effectiveness of the proposed SSCL-PSDR method in this embodiment, the same experiment was conducted on the original Siamese network architecture (Resnet50) for comparative evaluation. The experimental results are shown in Table 1.

[0168] Table 1. Validation of the method:

[0169] method Acc / % Prec / % Rec / % F1 / % SSCL-PSDR 88.2 86.3 87.0 86.7 Twin Network 82.9 83.0 81.6 82.7

[0170] Experimental results show that, under the same dataset and training settings, the proposed method improves accuracy to 88.2%, precision to 86.3%, recall to 87.0%, and F1 score to 86.7%.

[0171] Figure 7 The training loss curve shows how the model's loss value on the training set changes as the number of training epochs increases. The curve shows a rapid decline followed by a gradual stabilization, indicating that the model is effectively learning from the training data, the optimizer is working properly, and the loss value eventually stabilizes at a low level. This means that the model has fitted the training set well, the training process is stable and convergent, and there are no abnormal oscillations or failures to decrease the loss value, laying the foundation for obtaining a good model.

[0172] Figure 8 The Test Accuracy Curve shows how the model's classification accuracy on the test set changes with the number of test epochs (typically smoothed to observe the overall trend). The curve shows a rapid rise followed by a stabilization at a high level. This further confirms the success of the training and the reliability of the model from a performance metric perspective.

[0173] In summary, Figure 7 (Loss Decrease) and Figure 8 The increase in accuracy forms a perfect corroboration: the decrease in loss means that the gap between the model's predictions and the true labels is narrowing; the increase in accuracy directly indicates that the proportion of correct judgments made by the model is increasing.

[0174] To verify the effectiveness of the proposed surface defect identification algorithm, this embodiment designed six ablation experiments to quantitatively evaluate the independent contribution and synergistic effect of each improved module, and compared them with the baseline model. The experimental setup and results are shown in Table 2, where √ indicates that the module was used, and the baseline backbone is ResNet50.

[0175] Table 2. Ablation test results:

[0176] Serial Number DINOv2-S / 14 LDFPN RACA Acc / % Prec / % Rec / % F1 / % 1 √ 85.0 84.6 86.8 85.7 2 √ 82.3 83.9 83.1 83.2 3 √ 83.1 84.2 83.1 83.8 4 √ √ 85.8 86.5 84.5 86.1 5 √ √ 86.4 84.7 85.5 85.3 6 √ √ 84.5 85.0 84.6 84.9 7 √ √ √ 88.2 86.3 87.0 86.7

[0177] Replacing the feature extraction network with DINOv2-S / 14, which is based on self-supervised pre-training, improved all the model's metrics. DINOv2's pre-training on large-scale data gives the backbone a stronger ability to represent general features, enabling it to better capture the differences between particleboard texture and defects even with fewer defect samples. Meanwhile, the ViT structure inherently possesses global modeling capabilities, which helps suppress irrelevant texture interference in complex backgrounds, thereby improving the ability to distinguish defect categories.

[0178] We introduce LDPPN to construct a multi-scale feature pyramid, which is then fused through upsampling and channel concatenation. Multi-scale features help to simultaneously focus on large-scale textured backgrounds and local fine-grained defect regions. After adding LDPPN, the model's recall rate slightly decreased, but accuracy, precision, and F1-score all improved. Experimental results demonstrate that this LDPPN structure effectively enhances the model's defect representation ability.

[0179] A RACA module is introduced into the neck region, which explicitly encodes positional information and recalibrates channels through two-dimensional global average pooling, making the network more attentive to potential defect areas on the particleboard surface. The module employs a residual structure with learnable parameters to adaptively adjust the attention intensity and avoid feature degradation. Experiments show that, except for a slight decrease in recall and F1-score, all other metrics are improved, validating the effectiveness of RACA in enhancing defect perception and suppressing background interference.

[0180] In summary, using only the DINOv2-S / 14 backbone: accuracy 85.0%. Adding LDPPN: accuracy improved to 85.8%. Further adding the RACA module (i.e., the complete SSCL-PSDR): accuracy reached a maximum of 88.2%. After introducing the three modules DINOv2-S / 14, LDPPN, and RACA into the Siamese network, accuracy, precision, recall, and F1 score all improved, significantly enhancing model performance. Ablation experiments demonstrated the effectiveness of each innovative module and the performance gains they brought synergistically.

[0181] To evaluate the defect recognition performance of SSCL-PSDR, mainstream image recognition models were used for comparison. All experiments used the same data partitioning, input size, and training strategy, and the results are shown in Table 3.

[0182] Table 3. Comparative Experiment Results:

[0183] Model Acc / % Prec / % Rec / % F1 / % Vgg16 75.1 78.1 78.7 78.3 Resnet34 74.7 78.3 74.0 75.6 Resnet50 76.0 80.3 76.0 76.7 WideResNet-101 84.8 85.0 83.6 84.4 EfficientNetV2-m 86.3 84.8 85.8 85.2 DenseNet-169 84.1 82.9 83.4 83.0 Swin-T 86.0 87.2 85.9 86.2 DeiT-Tiny 83.4 85.1 82.7 84.3 PVTv2-B0 85.2 86.2 84.8 84.9 SSCL-PSDR 88.2 86.3 87.0 86.7

[0184] Comparative analysis revealed that among the aforementioned backbone networks, the twin-comparison-based particleboard defect identification method proposed in this paper achieved the best results, with improvements in accuracy, precision, recall, and F1 score. SSCL-PSDR's accuracy outperformed models such as VGG16 (75.1%), ResNet50 (76.0%), EfficientNetV2-m (86.3%), and Swin-T (86.0%). This demonstrates that SSCL-PSDR has achieved a leading level in small-sample particleboard defect identification tasks.

[0185] Example 4: System Integration and Deployment

[0186] The trained SSCL-PSDR model was deployed into the particleboard surface defect detection system.

[0187] The particleboard surface defect detection system includes the following components connected in sequence:

[0188] Image acquisition module, used to acquire raw images of the particleboard surface;

[0189] The preprocessing module is used to remove the background from the original image and crop it into image blocks of a set size;

[0190] The defect identification module loads and runs the Siamese supervised contrastive network model trained according to any one of claims 1-9 to extract features and classify the input image blocks.

[0191] The result output module is used to output the defect category identification result and confidence level of the image block.

[0192] The workflow of the particleboard surface defect detection system is as follows:

[0193] 1. The image acquisition module captures images of particleboard online;

[0194] 2. The preprocessing module automatically completes image cropping and generates a block stream of images to be inspected;

[0195] 3. The inference engine in the defect identification module performs fast forward computation on each image block in a single-branch mode;

[0196] 4. The results output module displays "Defect Type - Confidence Level" in real time and triggers the sorting mechanism or stores the data in the quality database.

[0197] This system achieves full automation from image input to result output, meeting the production line cycle time requirements.

[0198] Industrial application prospects:

[0199] The method and system proposed in this invention can be directly applied to the online quality inspection process of particleboard, medium-density fiberboard (MDF), oriented strand board (OSB) and other engineered wood products production lines, replacing manual visual inspection, greatly improving inspection efficiency, consistency and product quality management level, and has significant economic benefits and broad prospects for industrial application.

[0200] in conclusion:

[0201] (1) To address the problem of identifying defects in small-sample particleboard, a particleboard surface defect identification method based on twin network and supervised comparison, SSCL-PSDR, is proposed to achieve accurate identification of five types of small-sample defects (glue spots, scratches, sand leakage, contamination, and damage).

[0202] (2) In this paper, the traditional CNN backbone is replaced with DINOv2-S / 14 in the Siamese network architecture, which enables the model to maintain strong feature extraction capabilities under small sample conditions. The LDPPN neck structure and efficient downsampling based on depthwise separable convolution are introduced to effectively enhance multi-scale feature fusion, enabling the network to pay attention to both small and large-scale defects. At the same time, the RACA module is designed to encode position information along the horizontal and vertical directions, adaptively enhance the channel response highly correlated with the defect region, and suppress background noise through residual connections and learnable fusion coefficients, thereby obtaining a more robust and discriminative feature representation. According to the experimental results, the proposed SSCL-PSDR method has an accuracy of 88.2%, precision of 86.3%, recall of 87.0%, and F1 score of 86.7%.

[0203] The scope of protection of this invention includes, but is not limited to, the above embodiments. The scope of protection of this invention is defined by the claims. Any substitutions, modifications, or improvements to this technology that are easily conceived by those skilled in the art fall within the scope of protection of this invention.

Claims

1. A method for identifying surface defects in particleboard based on Siamese networks and supervised contrastive learning, characterized in that, Includes the following steps: (1) Collect images of particleboard surface, preprocess them to construct a small sample dataset containing multiple types of defects, and divide it into training set and test set; (2) Construct an improved Siamese supervised contrastive network model, wherein the Siamese supervised contrastive network model includes: Feature extraction backbone network: The pre-trained visual Transformer model ViT-S / 14 reg4 DINOv2 is used; Lightweight Multi-Scale Feature Fusion Pyramid Structure LDPPN: Performs multi-scale fusion and enhancement on the output features of the feature extraction backbone network; Classification and contrastive learning head: includes parallel classification and projection branches; (3) The training set is used to train the Siamese supervised contrastive network model. During training, the cross-entropy classification loss and supervised contrastive loss are jointly optimized. (4) Use the trained twin supervised contrast network model to identify and classify defects in particleboard surface images.

2. The method according to claim 1, characterized in that, Step (1) specifically includes: Acquire images of the particleboard surface; The collected images of the particleboard surface were processed by background removal and cropping, and divided into 512×512 image blocks. Construct a small sample dataset containing five types of defects: glue spots, scratches, sand leakage, contamination, and damage; The dataset was randomly divided into training and test sets in an 8:2 ratio.

3. The method according to claim 1, characterized in that, The visual Transformer model ViT-S / 14 reg4 DINOv2 in step (2) has an input token sequence containing a CLS token, patch tokens, and four register tokens. It performs global context modeling through a self-attention mechanism and freezes the weights of the backbone network during training.

4. The method according to claim 1, characterized in that, The lightweight multi-scale feature fusion pyramid structure LDPPN in step (2) includes: A lightweight downsampling module based on depthwise separable convolution is used to downsample the input feature map step by step to obtain multi-scale feature maps; Feature maps of different scales are upsampled to the same spatial resolution, concatenated along the channel dimension, and then fused using a 1×1 convolution. An improved coordinate attention mechanism is used to enhance the fused features; Global average pooling is used to convert the enhanced feature map into a feature vector of uniform dimension.

5. The method according to claim 4, characterized in that, The improved coordinate attention mechanism is the Residual Adaptive Coordinate Attention Module (RACA), which includes: Global average pooling is performed along the height and width directions respectively to obtain the height feature vector and the width feature vector; The feature vectors from the two directions are concatenated in the spatial dimension and then channel compression is performed using a 1×1 convolution. The compressed features are split into height and width components, and attention weights in the height and width directions are generated by convolution and sigmoid activation functions, respectively. The original input features are added to the features weighted by the attention weights using a learnable scaling factor to obtain the enhanced output feature map.

6. The method according to claim 1, characterized in that, The joint loss function in step (3) is: ; in, To compare the loss weights; Cross-entropy classification loss, To monitor and compare losses.

7. The method according to claim 6, characterized in that, The supervised comparison loss function is defined as follows: ; Where M is the total number of sample views in the batch, To be consistent with the sample A set of positive samples with the same label; τ is the L2 normalized eigenvector; τ is the temperature coefficient.

8. The method according to claim 1, characterized in that, The training configuration in step S3 includes: using the Adam optimizer, an initial learning rate of 0.0001, training for 150 epochs, and a batch size of 16.

9. The method according to claim 1, characterized in that, The training and inference of the twin-supervised contrastive network model adopt different network architecture modes: (a) During the training phase, the Siamese supervised contrastive network model operates as a Siamese network: (a1) For each defective image in the training set, generate two random augmented views to form a positive sample pair; (a2) Input these two views into the dual branches of the network with shared parameters, and then pass them through the feature extraction backbone network, the lightweight multi-scale feature fusion pyramid structure LDPPN, and the classification contrast learning head; (a3) Optimization is achieved through a joint loss function, in which the classification branch uses cross-entropy loss for multi-class defect identification supervision, while the features output by the projection branch are used to calculate the supervised contrast loss, in order to bring similar samples closer together and push away dissimilar samples; (b) During the inference phase, the Siamese supervised contrastive network model is converted into a single-branch multi-classification network: (b1) Forward propagation is performed only on a single image to be tested; (b2) After the features are extracted by the feature extraction backbone network and the lightweight multi-scale feature fusion pyramid structure LDPPN, the scores of each category are directly output by the classification branch in the classification contrast learning head; (b3) The category with the highest score is taken as the final defect identification result.

10. A particleboard surface defect detection system, characterized in that, Including those connected sequentially: Image acquisition module, used to acquire raw images of the particleboard surface; The preprocessing module is used to remove the background from the original image and crop it into image blocks of a set size; The defect identification module loads and runs the Siamese supervised contrastive network model trained according to any one of claims 1-9 to extract features and classify the input image blocks. The result output module is used to output the defect category identification result and confidence level of the image block.