A visual inspection method and system for surface scratches on wood grain aluminum panels
By using multi-scale fusion of feature extraction networks and adaptive grouping of frequency domain statistics, combined with optimization of rotated bounding box parameters and angle penalty weights, the problem of distinguishing between complex textured backgrounds and subtle linear defects is solved, achieving high-precision scratch detection.
Patent Information
- Application Number
- CN202611361767.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-03
- Publication Date
- 2026-11-17
AI Technical Summary
Existing technologies cannot accurately distinguish between complex textured backgrounds and subtle linear defects, resulting in inaccurate scratch detection and positioning, especially poor angle regression accuracy for slender scratches.
A feature extraction network is used for multi-scale fusion feature extraction. It combines frequency domain statistics with adaptive grouping and cross-group interaction. The rotating bounding box parameters are used to regress the slender scratch. End-to-end optimization is performed through a joint loss function. In particular, the angle loss penalty weight increases monotonically with the ratio of the major and minor axes.
It significantly improves the accuracy of angle prediction and positioning of fine scratches, reduces background information redundancy, and enhances the overall performance of detection.
Smart Images

Figure CN123118560A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of machine vision technology. More specifically, this invention relates to a visual inspection method and system for surface scratches on imitation wood grain aluminum panels. Background Technology
[0002] Wood-grain aluminum panels, as a building decoration material that combines excellent physical properties with rich aesthetic expression, feature a surface texture resembling wood grain formed through processes such as heat transfer or roller coating. During production, transportation, and installation, the surface of aluminum panels is highly susceptible to scratches due to friction and impact. These scratches, especially fine linear scratches, severely disrupt the continuity and overall aesthetic appeal of the wood grain pattern, affecting the product's grade and market value.
[0003] The wood grain background itself contains a large number of complex textures with varying directions and rich frequencies. These textures are easily confused with subtle scratch defects at the feature level. Convolutional operations process all image regions in a homogeneous manner, failing to reliably decouple background textures from target defects, resulting in insufficient feature discrimination and a high risk of false alarms or missed detections. Scratch defects typically exhibit elongated shapes and arbitrary orientations. Using traditional horizontal bounding boxes for annotation and regression introduces a large amount of irrelevant background information, reducing localization accuracy. Although rotating bounding boxes can better fit the scratch shape, existing models often penalize angular deviations of different target shapes equally in the loss function during optimization. For elongated targets with extremely high aspect ratios, even small angular deviations can lead to huge intersection-over-union (IoU) losses, making model training unstable and resulting in poor angle regression accuracy. Therefore, how to develop a dedicated detection model that can accurately distinguish complex textured backgrounds from subtle linear defects and accurately regress orientation and shape is a pressing challenge that needs to be addressed in current technology. Summary of the Invention
[0004] To address the technical problems of existing technologies being unable to accurately distinguish between complex textured backgrounds and subtle linear defects, and the inability to precisely regress the direction and shape of defects using specialized detection models, this invention proposes a visual detection method and system for scratches on the surface of wood grain aluminum panels. This method can decouple the wood grain background from the scratch features and improve the accuracy of predicting and locating the angle of slender scratches.
[0005] In a first aspect, the present invention provides a visual detection method for surface scratches on a wood-grain aluminum panel, comprising: acquiring a surface image of the wood-grain aluminum panel to be detected, performing normalization and data augmentation preprocessing, and inputting the preprocessed image into a feature extraction network; using the multi-scale fusion features output by the feature extraction network, regressing the rotation bounding box parameters of candidate scratches through a detection head, wherein the rotation bounding box parameters include center point coordinates, major axis, minor axis, and rotation angle; and in the model training stage, performing end-to-end optimization using a joint loss function, wherein the joint loss function includes classification loss, bounding box regression loss, and shape-guided angle loss, wherein the penalty weight of the angle loss for the angle deviation between the predicted bounding box and the real bounding box is determined by a function that monotonically increases with the ratio of the major and minor axes of the real bounding box.
[0006] By adopting the above technical solution, the surface image of the wood grain aluminum panel to be detected is acquired and normalized and data augmented preprocessing is performed, providing a standardized and more generalized input for subsequent feature extraction. The multi-scale fusion features output by the feature extraction network are used to regress the rotation bounding box parameters, including the center point coordinates, major axis, minor axis, and rotation angle, which can more tightly fit the slender shape and arbitrary direction of the scratch, significantly reducing the redundancy of background information. During the model training stage, a joint loss function including classification loss, bounding box regression loss, and shape-guided angle loss is used for end-to-end optimization. The penalty weight of the angle loss increases monotonically with the ratio of the major and minor axes of the real bounding box, making the model more sensitive to the angle deviation of the slender scratch, thereby driving the model to achieve high-precision angle prediction and bounding box regression. This effectively solves the problem of inaccurate localization of targets with extremely large aspect ratios in traditional methods, and improves the overall performance of scratch detection.
[0007] Preferably, the feature extraction network performs grouping and cross-group interaction operations in at least one specified convolutional layer, obtains the frequency domain coefficient matrix for each channel through a two-dimensional discrete cosine transform, and calculates frequency domain statistics to represent the concentration of energy towards mid-to-high frequency distribution; inputs the frequency domain statistics of all channels into a learnable lightweight submodule to generate a high-frequency assignment probability for each channel, uses Gumbel-Sigmoid to convert the assignment probability into a binary mask, and logically separates the input feature map into a high-frequency feature map and a low-frequency feature map while maintaining the total number of channels; for high-frequency features... The high-frequency feature map is convolved within a group using a set of kernels consisting of asymmetric or one-dimensional convolution kernels in multiple directions. The low-frequency feature map is convolved within a group using a standard two-dimensional symmetric convolution kernel. The convolution output feature maps of the two groups are subjected to bidirectional asymmetric interaction. By fusing the global context information and frequency domain statistics of each group, and generating modulation weights through a gating module with fixed dimensions, the feature maps of the corresponding groups are weighted channel by channel to achieve mutual enhancement and suppression of cross-group features. Combined with binary masks, the input feature map is logically separated into high-frequency feature maps and low-frequency feature maps while keeping the total number of channels unchanged.
[0008] By adopting the above technical solution, channel grouping and cross-group interaction based on frequency domain statistics are introduced into the designated convolutional layers of the feature extraction network. Through two-dimensional discrete cosine transform and energy concentration analysis, the expressive tendency of each feature channel for high-frequency details or low-frequency textures can be quantified. Using learnable lightweight sub-modules combined with Gumbel-Sigmoid technology, adaptive and differentiable binarization grouping of channels is achieved, logically separating high-frequency and low-frequency feature maps while maintaining the total number of channels, thus decoupling subtle scratches from complex wood grain backgrounds at the feature level. This dynamic grouping mechanism enables more targeted subsequent processing and is a key prerequisite for improving feature discriminative power and avoiding confusion between background and defect features.
[0009] Preferably, the step of logically separating the input feature map into a high-frequency feature map and a low-frequency feature map while maintaining the total number of channels using the binary mask includes: performing a two-dimensional discrete cosine transform on each input feature map channel of size H×W to obtain an H×W coefficient matrix; using the sum of the absolute values of the AC component coefficients where the coordinates u and v in the matrix satisfy u+v>T as a frequency domain statistic S representing the energy distribution to the mid-to-high frequency range, where T is a preset frequency threshold; constructing a vector from the statistics S of all channels and inputting it into a submodule consisting of two fully connected layers and one Sigmoid activation function, outputting a home probability vector of the same length as the number of channels; performing binarization sampling on the home probability vector using Gumbel-Sigmoid to generate a binary mask of the same length as the number of channels; multiplying the input feature map with the binary mask in the channel dimension to obtain a high-frequency feature map with the same total number of channels; and multiplying the input feature map with the inverse mask obtained by inverting the binary mask in the channel dimension to obtain a low-frequency feature map with the same total number of channels.
[0010] By employing the above technical solution, performing a two-dimensional discrete cosine transform on each channel and calculating the sum of the absolute values of the mid-to-high frequency AC component coefficients as a frequency domain statistic, the concentration of energy in the mid-to-high frequency distribution can be accurately captured, effectively distinguishing the high-frequency channel carrying scratch details from the low-frequency channel carrying background texture. A lightweight submodule consisting of fully connected layers and a sigmoid activation function is used to learn the affiliation probability, ensuring computational efficiency and allowing the network to automatically learn the optimal grouping strategy. Differentiable binarization sampling using Gumbel-Sigmoid ensures effective gradient backpropagation during training and generates clear binary masks and inverse masks that separate high-frequency and low-frequency feature maps, keeping the total number of channels in both feature maps constant, thus laying a solid foundation for subsequent differential processing.
[0011] Preferably, the intra-group convolution of the high-frequency feature map using a set of kernels consisting of multiple asymmetric or one-dimensional convolution kernels in multiple directions includes: the kernel set consisting of a first convolution branch with multiple 1×k horizontal convolution kernels, a second convolution branch with multiple k×1 vertical convolution kernels, and a third convolution branch with multiple k×k diagonal convolution kernels, where k is an odd number greater than 1; the high-frequency feature map is convolved in parallel using the above three convolution branches, so that the number of output feature map channels of each branch is consistent with the number of input channels of the high-frequency feature map; the output feature maps of the three convolution branches are added element by element to obtain the intra-group convolution result.
[0012] By adopting the above technical solution, and considering the linear and multi-directional characteristics of scratches, this method specifically designs parallel convolution branches consisting of three sets of asymmetric or one-dimensional convolution kernels: horizontal, vertical, and diagonal. Using 1×k, k×1, and k×k multi-directional convolution kernels, it can accurately capture the continuous edges and linear features of slender scratches in different directions, significantly enhancing the response capability to scratches in any direction compared to traditional symmetric convolution kernels. Through parallel computation and ensuring that the number of output channels of each branch remains consistent with the input, and then fusing the multi-directional responses element-wise, it retains the sensitive features of each direction while enriching the expression of high-frequency details, thereby significantly improving the detection capability of subtle linear defects and suppressing interference from background textures.
[0013] Preferably, the step of performing intra-group convolution on the low-frequency feature map using a standard two-dimensional symmetric convolution kernel includes: uniformly using a standard 3×3 square symmetric convolution kernel to perform convolution operation on the low-frequency feature map.
[0014] Preferably, the method for achieving mutual enhancement and suppression of cross-group features includes: performing global average pooling on the convolutional output of the low-frequency feature map to obtain a global context vector of the same length as the total number of channels. Multiply the frequency domain statistics vector S of all channels element-wise with the binary mask to obtain a vector of the same length as the total number of channels. ,Will and Input a first gating module with fixed dimensions to generate modulation weights. Modulation weights After multiplying with the binary mask, the enhanced high-frequency features are multiplied channel-by-channel by the convolution output of the high-frequency feature map. To enhance the low-frequency features, global average pooling is performed on the convolution output of the high-frequency feature map to obtain a global context vector of the same length as the total number of channels. Multiply the frequency domain statistics vector S of all channels element-wise with the inverse mask to obtain a vector of the same length as the total number of channels. ,Will and After concatenation, the input is given to a second gating module with a fixed dimension to generate modulation weights of the same length as the total number of channels. Modulation weights After multiplying with the inverse mask, it is then multiplied channel by channel with the convolution output of the low-frequency feature map to obtain the enhanced low-frequency features.
[0015] Preferably, the multi-scale fusion features output by the feature extraction network include: extracting feature maps C3, C4, and C5 output from stages 3, 4, and 5 of the feature extraction network; adopting a feature pyramid network structure, unifying the number of channels in each layer through 1×1 convolution, upsampling the high-level feature maps by a factor of 2 from top to bottom, and adding them element-wise with the adjacent next-layer feature maps to generate fused multi-scale feature maps P3, P4, and P5.
[0016] Preferably, the penalty weight for the angle loss on the angle deviation between the predicted bounding box and the real bounding box is determined by a function that monotonically increases with the ratio of the major and minor axes of the real bounding box, including: denoting the major axis of the real bounding box as l and the minor axis as w, and obtaining the ratio r of the major and minor axes by dividing the major axis l by the minor axis w; the penalty weight for the angle loss is W = 1 + log(max(r,1)); when calculating the total loss, the angle loss term is multiplied by the weight w.
[0017] Preferably, the step of acquiring the surface image of the wood grain aluminum panel to be detected, performing normalization and data augmentation preprocessing, and inputting the preprocessed image into the feature extraction network includes: dividing the original value of each pixel in the image within the range of 0 to 255 by 255 to complete the normalization operation; performing horizontal flipping with a probability of 50%, vertical flipping with a probability of 50%, random rotation within the range of -15° to 15° on the normalized image, and applying motion blur with a kernel size of 5×5 and an angle randomly selected between 0° and 180°.
[0018] Secondly, the present invention provides a visual inspection system for surface scratches on imitation wood grain aluminum panels, comprising the following modules: an input module for acquiring a surface image of the imitation wood grain aluminum panel to be inspected, performing normalization and data augmentation preprocessing, and inputting the preprocessed image into a feature extraction network; an output module for using the multi-scale fusion features output by the feature extraction network to regress the rotation bounding box parameters of candidate scratches through a detection head, wherein the rotation bounding box parameters include the center point coordinates, major axis, minor axis, and rotation angle; and a model training module for performing end-to-end optimization using a joint loss function, wherein the joint loss function includes classification loss, bounding box regression loss, and shape-guided angle loss, wherein the penalty weight of the angle loss for the angle deviation between the predicted bounding box and the real bounding box is determined by a function that monotonically increases with the ratio of the major and minor axes of the real bounding box.
[0019] By adopting the above technical solutions, a complete end-to-end visual inspection scheme was constructed. The input module normalizes and performs data augmentation preprocessing on the acquired aluminum panel surface images, providing the system with standardized and robust input. The output module utilizes multi-scale fusion features to regress a rotated bounding box containing the center point coordinates, major axis, minor axis, and rotation angle, which can optimally fit slender scratches in any direction, providing high-precision localization and shape description. The model training module adopts a joint loss function including shape-guided angle loss, whose penalty weight increases with the ratio of the target's major and minor axes, allowing the system to focus on improving the angle regression accuracy for highly challenging slender scratches during the optimization process, thereby improving the overall accuracy and practicality of scratch detection on the surface of wood grain aluminum panels.
[0020] The present invention has the following beneficial effects: This invention utilizes frequency domain statistics to adaptively group channels, decoupling the feature map into two groups: high-frequency details and low-frequency textures. The high-frequency group uses multi-directional asymmetric convolution to capture the linear features of scratches, while the low-frequency group uses standard symmetric convolution to extract background textures. Features are mutually enhanced through bidirectional gating cross-group interaction. The rotating bounding box is used to tightly fit the scratch shape, and a shape-guided angle loss is used during training. The penalty weight increases monotonically with the ratio of the major and minor axes of the target, driving the model to achieve high-precision localization and angle regression of slender scratches.
[0021] Furthermore, using the sum of the absolute values of the frequency domain AC component coefficients as statistics, a differentiable binary mask is generated through a lightweight network and Gumbel-Sigmoid to achieve channel grouping. The high-frequency group uses horizontal, vertical, and diagonal convolution branches in parallel and adds them element by element to fuse multi-directional responses, while the low-frequency group uniformly uses 3×3 standard convolution. When interacting across groups, the global pooling context of the other group and the frequency domain statistics filtered by the mask are fused, and the modulation weights are generated by the gating module and then weighted channel by channel. The angle loss weight uses a logarithmically increasing function so that the angle deviation of the slender scratch is penalized according to the shape. Attached Figure Description
[0022] Figure 1 This is a flowchart of a visual inspection method for surface scratches on wood grain aluminum panels. Figure 2 This is a schematic diagram of multi-directional convolutional fusion of high-frequency features. Detailed Implementation
[0023] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are some embodiments of the present invention, but not all embodiments.
[0024] This invention discloses a visual inspection method for surface scratches on imitation wood grain aluminum panels, referring to... Figure 1This includes steps S1-S4: S1. Obtain the surface image of the wood grain aluminum panel to be detected, and perform normalization and data augmentation preprocessing. Input the preprocessed image into the feature extraction network. Grayscale or color images with a resolution of 2048×2048 pixels were acquired at an angle perpendicular to the aluminum panel surface. The images were then uniformly scaled to 512×512 pixels using the `cv2.resize` function in the OpenCV image processing library. Normalization was achieved by dividing the image pixel values by 255, followed by subtracting the channel mean from the ImageNet dataset and dividing by the channel standard deviation. Data augmentation included random horizontal and vertical flips, random rotations within a range of -10 to +10 degrees with a probability of 0.5, and random adjustments to image brightness, contrast, and saturation.
[0025] In one possible embodiment, a surface image of the wood grain aluminum panel to be detected is acquired, and normalization and data augmentation preprocessing are performed. The preprocessed image is then input into a feature extraction network, including: Normalization is performed by dividing the original value of each pixel in the image, which is in the range of 0 to 255, by 255. The normalized image is then subjected to horizontal flipping with a 50% probability, vertical flipping with a 50% probability, random rotation within the range of -15° to 15°, and motion blur with a kernel size of 5×5 and an angle randomly selected between 0° and 180°.
[0026] The acquired RGB image, with pixel values ranging from 0 to 255, is loaded, converted to a 32-bit floating-point data type, and normalized by dividing each pixel by 255. During model training, a series of online data augmentation operations are performed on the normalized image. The image is horizontally flipped with a probability of 0.5. The image is vertically flipped with a probability of 0.5. An angle is randomly sampled from a uniform distribution between -15 and 15 degrees. The image is rotated, and the resulting blank areas are filled with 0 values. Motion blur is applied, with a fixed 5×5 convolution kernel size and random sampling of blur directions from a uniform distribution of 0 to 180 degrees. During all geometric transformations—flipping, rotation, etc.—the corresponding ground truth bounding box annotations must also be synchronously affine.
[0027] S11, the feature extraction network performs grouping and cross-grouping interaction operations in at least one specified convolutional layer. The operation obtains the frequency domain coefficient matrix for each channel of the input feature map through two-dimensional discrete cosine transform, and calculates frequency domain statistics to represent the degree of energy concentration in the mid-to-high frequency distribution.
[0028] For an input feature map of dimension C×H×W, iterate through C channels. For each H×W two-dimensional feature map, call the `torch.fft.dct_2d` function in the PyTorch library to perform a two-dimensional discrete cosine transform, obtaining a frequency domain coefficient matrix of the same size. To calculate the frequency domain statistics, divide the frequency domain coefficient matrix into four quadrants. Exclude the first quadrant, which represents DC and low-frequency components in the upper left corner. Calculate the sum of the absolute values of all coefficients in the remaining three quadrants, i.e., the mid-to-high frequency region, and then divide by the sum of the absolute values of all coefficients in the entire matrix to obtain a scalar value representing the proportion of high-frequency energy in that channel, i.e., the frequency domain statistics.
[0029] S12 inputs the frequency domain statistics of all channels into the learnable lightweight submodule, generates a high-frequency assignment probability for each channel, and uses Gumbel-Sigmoid to convert the assignment probability into a binary mask. The binary mask is then used to logically separate the input feature map into a high-frequency feature map and a low-frequency feature map while keeping the total number of channels constant.
[0030] The frequency domain statistics of C channels are concatenated into a one-dimensional vector of length C. The lightweight submodule is a multilayer perceptron (MLP) consisting of two fully connected layers, torch.nn.Linear. The first fully connected layer maps the C-dimensional input to C / r dimensions, where r is the reduction ratio, such as 4, followed by a ReLU activation function. The second fully connected layer then maps the C / r dimensions back to C dimensions, obtaining the log odds (logits) for each channel. The logits are then input into the sigmoid activation function torch.sigmoid to obtain the high-frequency attribution probabilities between 0 and 1. During the training phase, the Gumbel-Sigmoid reparameterization technique is used, i.e., random noise following a Gumbel distribution is added to the logits before passing them through a sigmoid function with an adjustable temperature parameter, generating differentiable approximate binary probabilities to achieve gradient backpropagation. During the inference phase, the probability of the Sigmoid output is binarized with a threshold of 0.5 to generate a 0-1 binary mask. The input feature map is multiplied by the binary mask in the channel dimension to obtain the high-frequency detail group feature map with a mask value of 1. At the same time, the input feature map is multiplied by the inverse mask obtained by inverting the binary mask to obtain the low-frequency texture group feature map. The number of channels of both feature maps remains unchanged at C.
[0031] In one possible implementation, the frequency domain statistics of all channels are input into a learnable lightweight submodule to generate a high-frequency assignment probability for each channel. The assignment probability is then converted into a binary mask using Gumbel-Sigmoid. This binary mask logically separates the input feature map into a high-frequency feature map and a low-frequency feature map, maintaining the total number of channels. This includes: For each input feature map channel of size H×W, a two-dimensional discrete cosine transform is performed to obtain an H×W coefficient matrix. The sum of the absolute values of the AC component coefficients where the coordinates u and v in the matrix satisfy u+v>T is used as the frequency domain statistic S representing the energy distribution to the mid-to-high frequency range, where T is a preset frequency threshold. The statistics S of all channels are constructed into a vector and input into a submodule consisting of two fully connected layers and one Sigmoid activation function, outputting an assignment probability vector of the same length as the number of channels. The assignment probability vector is binarized using Gumbel-Sigmoid to generate a binary mask of the same length as the number of channels. The input feature map is multiplied with the binary mask in the channel dimension to obtain a high-frequency feature map with the same total number of channels. The input feature map is multiplied with the inverse mask obtained by inverting the binary mask in the channel dimension to obtain a low-frequency feature map with the same total number of channels.
[0032] Perform a Type II two-dimensional discrete cosine transform independently on each H×W channel to generate a C×H×W frequency domain coefficient matrix. Set a frequency threshold T, with a preferred value of (H+W) / 4. For the i-th channel, the frequency domain statistics... The formula is obtained by taking the absolute values of all coefficients (u,v) in the coefficient matrix that satisfy u+v>T and summing them. Statistics for all channels , ,..., A vector S of length C is constructed and input into a lightweight neural network submodule.
[0033] The submodule is a neural network for generating channel assignment probabilities. The input to this neural network is a frequency domain statistics vector S of length C. The output is an assignment probability vector P of length C. The structure of this neural network consists of: a fully connected layer with input feature dimension C and output feature dimension C / 4; a ReLU activation function; another fully connected layer with input feature dimension C / 4 and output feature dimension C; and a Sigmoid activation function. To achieve differentiable binarization, Gumbel-Sigmoid is used. During training, Gumbel noise is applied to the logits of probability P and divided by a temperature coefficient. A soft mask is generated; during the inference phase, the probability P is binarized to a hard mask M of 0 or 1 with a threshold of 0.5. Based on the value of mask M, the input feature map is multiplied by mask M to obtain a high-frequency feature map with C physical channels, and the input feature map is multiplied by (1-M) to obtain a low-frequency feature map with C physical channels.
[0034] S13 uses a set of kernels consisting of asymmetric or one-dimensional convolution kernels in multiple directions to perform intra-group convolution on high-frequency feature maps, and uses standard two-dimensional symmetric convolution kernels to perform intra-group convolution on low-frequency feature maps.
[0035] The input feature map channels are logically separated into two groups using a binary mask. For the high-frequency detail group feature map, which maintains the same total number of channels, three independent torch.nn.Conv2d convolutional layers are used in parallel. The first convolutional layer has a kernel size of 1×k, the second has a kernel size of k×1, and the third has a kernel size of k×k, where k is typically 3 or 5. The output feature maps of the three convolutions are fused element-wise by addition. For the low-frequency texture group feature map, which also maintains the same total number of channels, a standard torch.nn.Conv2d convolutional layer is used with a kernel size of k×k, for example, 3×3, to perform standard convolution operations.
[0036] In one possible embodiment, intra-group convolution is performed on the high-frequency feature map using a set of kernels consisting of asymmetric or one-dimensional convolution kernels in multiple directions, including: The kernel set consists of a first convolutional branch with multiple 1×k horizontal convolutional kernels, a second convolutional branch with multiple k×1 vertical convolutional kernels, and a third convolutional branch with multiple k×k diagonal convolutional kernels, where k is an odd number greater than 1. For high-frequency feature maps, the above three convolutional branches are used in parallel to perform convolution operations, so that the number of output feature maps of each branch is consistent with the number of input channels of the high-frequency feature maps. The output feature maps of the three convolutional branches are added element by element to obtain the intra-group convolution result.
[0037] To reliably detect linear features of scratches in the C input channels of the high-frequency detail group, parallel multi-directional convolution operations are employed. The kernel size parameter k is set to 7. Three parallel convolutional branches are constructed, each employing depthwise separable convolution with the number of groups equal to the number of input channels C. This ensures that the number of channels in the output feature map of each branch is consistent with the number of input channels C of the high-frequency feature map: the first convolutional branch has a set of multiple 1×7 horizontal convolutional kernels, with padding set to (0,3) to maintain the feature map size; the second convolutional branch has a set of multiple 7×1 vertical convolutional kernels, with padding set to (3,0); and the third convolutional branch has a set of multiple 7×7 diagonal convolutional kernels, with padding set to (3,3). The input feature map of the high-frequency detail group is simultaneously fed into the three convolutional branches for convolution, resulting in three output feature maps of the same size and number of channels. The output feature maps of the three convolutional branches are then element-wise summed at corresponding positions to fuse the responses in the three directions. (See [reference needed]). Figure 2 As shown, the output features of the high-frequency detail group are obtained.
[0038] In one possible embodiment, intra-group convolution is performed on the low-frequency feature map using a standard two-dimensional symmetric convolution kernel, including: performing convolution operation on the low-frequency feature map using a standard 3×3 square symmetric convolution kernel.
[0039] For the C input channels of the low-frequency texture group, which contain background texture information, complex orientation sensitivity is not required. A standard 2D symmetric convolutional layer with a kernel size of 3×3, specifically a depthwise separable convolution, is uniformly used to extract features. The kernel size of this convolutional layer is 3×3, with both the number of input and output channels being C, and the number of groups is also set to C, ensuring that the number of output channels of this convolutional layer is equal to the number of input channels of the low-frequency feature map. Padding is set to 1 to ensure that the spatial dimensions and channel dimensions of the output feature map are consistent with those of the input feature map. This operation extracts local spatial context information within each low-frequency channel.
[0040] S14 performs bidirectional asymmetric interaction on the convolutional output feature maps of the two groups. By fusing the global context information and frequency domain statistics of each group, and generating modulation weights through a gating module with fixed dimensions, the feature maps of the corresponding groups are weighted channel by channel to achieve mutual enhancement and suppression of cross-group features.
[0041] Output characteristic map of high frequency group Performing a global average pooling operation yields a channel descriptor of length C. Simultaneously, the frequency domain statistics vector S of all channels is obtained and multiplied element-wise by the inverse mask to obtain a vector of length C. .Will and After concatenation along the dimension, the input is fed into a fixed-dimensional gated module consisting of two fully connected layers (torch.nn.Linear). This module has a structure of fully connected layer-ReLU-fully connected layer-Sigmoid, which generates a weight vector of length C for modulating the low-frequency group. Similarly, the output feature map of the low-frequency group... Perform global average pooling to obtain The frequency domain statistics vector obtained by multiplying S and the mask. After splicing, a weight vector for modulating the high-frequency group is generated through another gated module with the same structure. .Will Multiply by the binary mask and then Channel-by-channel multiplication yields the enhanced high-frequency feature map. Multiply by the inverse mask and then The enhanced low-frequency feature map is obtained by multiplying each channel. Then, the two enhanced feature maps are added element by element using the torch.add function. Since the number of channels remains constant at C, the cross-group interaction is completed after the addition.
[0042] In one possible embodiment, bidirectional asymmetric interaction is performed on the convolutional output feature maps of the two groups. By fusing global context information and frequency domain statistics of each group, and generating modulation weights via a gating module, the feature maps of the corresponding groups are weighted channel-by-channel to achieve mutual enhancement and suppression of cross-group features, including: To enhance high-frequency features, global average pooling is performed on the convolutional output of the low-frequency feature map to obtain a global context vector of the same length as the total number of channels. Multiply the frequency domain statistics vector S of all channels element-wise with the binary mask to obtain a vector of the same length as the total number of channels. ,Will and After concatenation, the input is given to a first gating module with a fixed dimension to generate modulation weights of the same length as the total number of channels. Modulation weights After multiplying with the binary mask, it is then multiplied channel by channel with the convolution output of the high-frequency feature map to obtain the enhanced high-frequency features; To enhance low-frequency features, global average pooling is performed on the convolutional output of the high-frequency feature map to obtain a global context vector of the same length as the total number of channels. Multiply the frequency domain statistics vector S of all channels element-wise with the inverse mask to obtain a vector of the same length as the total number of channels. ,Will and After concatenation, the input is given to a second gating module with a fixed dimension to generate modulation weights of the same length as the total number of channels. Modulation weights After multiplying with the inverse mask, it is then multiplied channel by channel with the convolution output of the low-frequency feature map to obtain the enhanced low-frequency features.
[0043] To enhance the characteristics of high-frequency groups The dimensions are C×H×W, and the low-frequency group characteristics are... The vector has dimensions C×H×W, and global average pooling is performed to obtain a context vector of length C. Simultaneously, based on the binary mask M generated during grouping, the original vector of frequency domain statistics for all channels, S, is multiplied element-wise by the mask M, retaining the statistics of the high-frequency groups, thus forming a vector of fixed length C. .Will and Concatenating along the dimensions yields a fused information vector of length 2C. This vector is then fed into a gating module, which consists of a fully connected layer with a dimensionality reduction ratio of 4. Specifically, this module is configured with: input dimension 2C, output dimension C / 4, ReLU activation, a fully connected layer with increased dimensionality, and Sigmoid activation, generating modulation weights of length C. .Will After filtering out irrelevant channels by multiplying with the mask M, then multiplying with... Each channel is multiplied by its corresponding weight to enhance the features. Low-frequency group features are enhanced in a symmetrical manner. :right Global average pooling is performed to obtain The statistics of the low-frequency group are obtained by multiplying the inverse mask. splicing and The data is then fed into a second independent gating module to generate weights of length C. The weights are then multiplied by the inverse mask and applied to... Finally, the enhanced features from the two channels are added element-wise to output a complete feature map with C channels.
[0044] S2. Utilize the multi-scale fusion features output by the feature extraction network to regress the rotation bounding box parameters of the candidate scratches through the detection head. The rotation bounding box parameters include the center point coordinates, major axis, minor axis, and rotation angle.
[0045] The feature extraction network serves as the backbone network, outputting feature maps at three stages with different depths. This constructs a Feature Pyramid Network (FPN), such as torchvision.ops.FeaturePyramidNetwork, generating multi-scale feature maps (P3, P4, P5, etc.). The detection head contains two parallel branches: classification and regression. Each branch consists of four 3×3 torch.nn.Conv2d convolutional layers and one 1×1 convolutional layer. For each scale of feature map, the classification branch outputs the number of channels equal to the number of classes, while the regression branch outputs five channels, corresponding to the five offsets of the rotated bounding box parameters relative to the preset anchor boxes. , , , , The network output offset is converted into actual center point coordinates (x and y), major axis (w), minor axis (h), and rotation angle ranging from -90 degrees to +90 degrees using a decoding formula. .
[0046] In one possible embodiment, the multi-scale fused features output by the feature extraction network are utilized, including: Feature maps C3, C4, and C5 are extracted from stages 3, 4, and 5 of the feature extraction network. A feature pyramid network structure is adopted. The number of channels in each layer is unified by 1×1 convolution. The high-level feature maps are upsampled by 2 times from top to bottom and then added element by element with the adjacent next layer feature maps to generate fused multi-scale feature maps P3, P4, and P5.
[0047] Assuming the feature extraction network is based on the ResNet-50 architecture, stages 3, 4, and 5 output feature maps C3, C4, and C5, respectively, with dimensions and number of channels of (80×80, 512), (40×40, 1024), and (20×20, 2048). Applying 1×1 convolutions to C3, C4, and C5 reduces their channel count to a uniform 256, resulting in... , , Constructing a top-down fusion path: P5 directly from... We obtained P5 by doubling upsampling and using nearest neighbor interpolation to make its size 40×40, and then compared it with... Element-wise addition is performed to obtain P4. Then, P4 is upsampled by a factor of 2 to 80×80 and compared with... Element-wise summation yields P3. To eliminate aliasing effects that may arise from upsampling and summation, a 3×3 convolution is applied to each of the generated P3, P4, and P5 for smoothing. The resulting feature pyramid {P3, P4, P5}, with 256 channels each, is then fed into the subsequent detection head for prediction.
[0048] S3. During the model training phase, a joint loss function is used for end-to-end optimization. The joint loss function includes classification loss, bounding box regression loss, and shape-oriented angle loss. The angle loss is the penalty weight for the angle deviation between the predicted bounding box and the real bounding box, which is determined by a function that monotonically increases with the ratio of the major and minor axes of the real bounding box.
[0049] The classification loss uses FocalLoss, which can be achieved by calling the torchvision.ops.focal_loss function to address the imbalance between positive and negative samples. The bounding box regression loss uses SmoothL1Loss (torch.nn.SmoothL1Loss) for the center point coordinates, major and minor axes, and four other parameters. The shape-guided angle loss is obtained by multiplying the weight term and the base angle loss term, which also uses SmoothL1Loss to calculate the difference between the predicted and true angles. The weight term W is based on the major and minor axis ratios of the true bounding box. The calculation, specifically in function form, is as follows: ,in For hyperparameters, such as 0.2, the larger the aspect ratio of a thin, elongated scratch, the greater the penalty for angle prediction errors; the total loss is the sum of the three.
[0050] In one possible embodiment, the penalty weight of the angle loss for the angular deviation between the predicted bounding box and the true bounding box is determined by a function that monotonically increases with the ratio of the major and minor axes of the true bounding box, including: Let the major axis of the real bounding box be l and the minor axis be w. The ratio r of the major axis and the minor axis is obtained by dividing the major axis l by the minor axis w. The penalty weight for angle loss is w = 1 + log(max(r, 1)); When calculating the total loss, the angle loss term is multiplied by the weight w.
[0051] When calculating the loss function, for each positive sample, obtain the major axis of the true rotated bounding box. and short axis Calculate the ratio of the major and minor axes. ,in It is a very small positive number, such as 1e-6, to prevent division by zero. The penalty weight for the angle loss is calculated as w = 1 + log(max(r,1)). The weight monotonically increases with the ratio of the major and minor axes, and has a minimum value of 1. For example, for a long, thin scratch with an aspect ratio of 50:1, r = 50, and the weight W ≈ 4.91; while for a shorter defect with an aspect ratio of 1.5:1, r = 1.5, and the weight W ≈ 1.405. Let the original loss between the model-predicted angle and the true angle be... For example, for SmoothL1 loss, the angle loss term included in the total loss is W· .
[0052] Based on any of the above embodiments, a visual detection method for surface scratches on imitation wood grain aluminum panels is provided. This application also provides a visual detection system for surface scratches on imitation wood grain aluminum panels, comprising the following modules: an input module for acquiring a surface image of the imitation wood grain aluminum panel to be detected, performing normalization and data augmentation preprocessing, and inputting the preprocessed image into a feature extraction network; an output module for using the multi-scale fusion features output by the feature extraction network to regress the rotation bounding box parameters of candidate scratches through a detection head, the rotation bounding box parameters including center point coordinates, major axis, minor axis, and rotation angle; and a model training module for end-to-end optimization using a joint loss function, the joint loss function including classification loss, bounding box regression loss, and shape-guided angle loss, wherein the angle loss penalty weight for the angle deviation between the predicted bounding box and the real bounding box is determined by a function that monotonically increases with the ratio of the major and minor axes of the real bounding box.
[0053] The above are merely embodiments of this specification and are not intended to limit this specification. Various modifications and variations can be made to this specification by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of the claims of this specification.
Claims
1. A visual inspection method for surface scratches on imitation wood grain aluminum panels, characterized in that, include: The surface image of the wood grain aluminum panel to be detected is acquired, and normalization and data augmentation preprocessing are performed. The preprocessed image is then input into the feature extraction network. Using the multi-scale fusion features output by the feature extraction network, the rotation bounding box parameters of the candidate scratch are regressed by the detection head. The rotation bounding box parameters include the center point coordinates, major axis, minor axis and rotation angle. During the model training phase, end-to-end optimization is performed using a joint loss function, which includes classification loss, bounding box regression loss, and shape-oriented angle loss. The angle loss penalizes the angle deviation between the predicted bounding box and the real bounding box by a function that monotonically increases with the ratio of the major and minor axes of the real bounding box.
2. The method according to claim 1, characterized in that, The feature extraction network performs grouping and cross-group interaction operations in at least one specified convolutional layer. It obtains the frequency domain coefficient matrix for each channel through a two-dimensional discrete cosine transform and calculates frequency domain statistics to represent the concentration of energy towards mid-to-high frequency distributions. The frequency domain statistics of all channels are input into a learnable lightweight submodule to generate a high-frequency assignment probability for each channel. The assignment probability is then converted into a binary mask using Gumbel-Sigmoid. Logically, the input feature map is separated into a high-frequency feature map and a low-frequency feature map while maintaining the total number of channels. For high-frequency features… The feature map is convolved within a group using a set of kernels consisting of asymmetric or one-dimensional convolution kernels in multiple directions. For low-frequency feature maps, standard two-dimensional symmetric convolution kernels are used for intra-group convolution. Bidirectional asymmetric interaction is performed on the convolution output feature maps of the two groups. By fusing global context information and frequency domain statistics of each group, and generating modulation weights through a gating module with fixed dimensions, the feature maps of the corresponding groups are weighted channel by channel to achieve mutual enhancement and suppression of cross-group features. Combined with binary masks, the input feature map is logically separated into high-frequency feature maps and low-frequency feature maps while keeping the total number of channels unchanged.
3. The method according to claim 2, characterized in that, The step of logically separating the input feature map into a high-frequency feature map and a low-frequency feature map while maintaining the total number of channels, using the binary mask, includes: performing a two-dimensional discrete cosine transform on each input feature map channel of size H×W to obtain an H×W coefficient matrix; using the sum of the absolute values of the AC component coefficients where the coordinates u and v in the matrix satisfy u+v>T as a frequency domain statistic S representing the energy distribution to the mid-to-high frequency range, where T is a preset frequency threshold; constructing a vector from the statistics S of all channels and inputting it into a submodule consisting of two fully connected layers and one Sigmoid activation function, outputting a home probability vector of the same length as the number of channels; performing binarization sampling on the home probability vector using Gumbel-Sigmoid to generate a binary mask of the same length as the number of channels; multiplying the input feature map with the binary mask in the channel dimension to obtain a high-frequency feature map with the same total number of channels; and multiplying the input feature map with the inverse mask obtained by inverting the binary mask in the channel dimension to obtain a low-frequency feature map with the same total number of channels.
4. The method according to claim 2, characterized in that, The step of performing intra-group convolution on the high-frequency feature map using a set of kernels consisting of asymmetric or one-dimensional convolution kernels in multiple directions includes: The kernel set consists of a first convolutional branch with multiple 1×k horizontal convolutional kernels, a second convolutional branch with multiple k×1 vertical convolutional kernels, and a third convolutional branch with multiple k×k diagonal convolutional kernels, where k is an odd number greater than 1. For the high-frequency feature map, the three convolution branches are used in parallel to perform convolution operations, so that the number of output feature map channels of each branch is consistent with the number of input channels of the high-frequency feature map. The output feature maps of the three convolution branches are added element by element to obtain the intra-group convolution result.
5. The method according to claim 2, characterized in that, The step of performing intra-group convolution on the low-frequency feature map using a standard two-dimensional symmetric convolution kernel includes: For the low-frequency feature maps, a standard 3×3 square symmetric convolution kernel is uniformly used for convolution operation.
6. The method according to claim 3, characterized in that, The method for achieving mutual enhancement and suppression of cross-group features includes: performing global average pooling on the convolutional output of the low-frequency feature map to obtain a global context vector of equal length to the total number of channels. Multiply the frequency domain statistics vector S of all channels element-wise with the binary mask to obtain a vector of the same length as the total number of channels. ,Will and Input a first gating module with fixed dimensions to generate modulation weights. Modulation weights After multiplying with the binary mask, the enhanced high-frequency features are multiplied channel-by-channel by the convolution output of the high-frequency feature map. To enhance the low-frequency features, global average pooling is performed on the convolution output of the high-frequency feature map to obtain a global context vector of the same length as the total number of channels. Multiply the frequency domain statistics vector S of all channels element-wise with the inverse mask to obtain a vector of the same length as the total number of channels. ,Will and After concatenation, the input is given to a second gating module with a fixed dimension to generate modulation weights of the same length as the total number of channels. Modulation weights After multiplying with the inverse mask, it is then multiplied channel by channel with the convolution output of the low-frequency feature map to obtain the enhanced low-frequency features.
7. The method according to claim 1, characterized in that, The multi-scale fusion features output by the feature extraction network include: Feature maps C3, C4, and C5 are extracted from stages 3, 4, and 5 of the feature extraction network. A feature pyramid network structure is adopted. The number of channels in each layer is unified by 1×1 convolution. The high-level feature maps are upsampled by 2 times from top to bottom and then added element by element with the adjacent next layer feature maps to generate fused multi-scale feature maps P3, P4, and P5.
8. The method according to claim 1, characterized in that, The penalty weight for the angle loss on the angle deviation between the predicted bounding box and the true bounding box is determined by a function that monotonically increases with the ratio of the major and minor axes of the true bounding box, including: Let the major axis of the real bounding box be l and the minor axis be w. The ratio r of the major axis and the minor axis is obtained by dividing the major axis l by the minor axis w. The penalty weight for angle loss is W = 1 + log(max(r,1)); When calculating the total loss, the angle loss term is multiplied by the weight w.
9. The method according to claim 1, characterized in that, The process involves acquiring a surface image of the wood grain aluminum panel to be detected, performing normalization and data augmentation preprocessing, and then inputting the preprocessed image into a feature extraction network, including: Normalization is performed by dividing the original value of each pixel in the image, which is in the range of 0 to 255, by 255. The normalized image is then subjected to a series of random rotations: horizontal flipping with a 50% probability, vertical flipping with a 50% probability, random rotation within the range of -15° to 15°, and motion blur with a kernel size of 5×5 and an angle randomly selected between 0° and 180°.
10. A visual inspection system for surface scratches on imitation wood grain aluminum panels, characterized in that, Includes the following modules: The input module is used to acquire the surface image of the wood grain aluminum panel to be detected, and perform normalization and data augmentation preprocessing. The preprocessed image is then input into the feature extraction network. The output module is used to utilize the multi-scale fusion features output by the feature extraction network to regress the rotation bounding box parameters of the candidate scratches through the detection head. The rotation bounding box parameters include the center point coordinates, major axis, minor axis, and rotation angle. The model training module is used for end-to-end optimization using a joint loss function, which includes classification loss, bounding box regression loss, and shape-oriented angle loss. The angle loss penalizes the angle deviation between the predicted bounding box and the real bounding box by a function that monotonically increases with the ratio of the major and minor axes of the real bounding box.
