A lens defect detection method based on a space-frequency dual-domain hybrid target detection model
By using a spatial-frequency dual-domain hybrid target detection model, combined with DynaNet and Neck networks, the problems of low efficiency in traditional methods and insufficient robustness of deep learning are solved, achieving high-precision and high-efficiency lens defect detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- JIANGXI GAORUI OPTOELECTRONICS CO LTD
- Filing Date
- 2025-07-28
- Publication Date
- 2026-06-05
AI Technical Summary
Traditional manual visual inspection methods are inefficient and highly subjective, making it difficult to meet the needs of high-precision lens defect detection. Furthermore, deep learning-based methods lack robustness in detecting complex backgrounds and minute defects.
A spatial-frequency dual-domain hybrid target detection model is adopted, which combines DynaNet network, Neck network and detection head. Through frequency domain feature analysis and dynamic convolution mechanism, the convolution kernel parameters are adaptively adjusted to achieve multi-scale feature fusion and efficient detection.
It significantly improves the accuracy and robustness of lens defect detection, effectively identifies minute defects in complex backgrounds, and ensures real-time detection speed and high efficiency.
Smart Images

Figure CN121053069B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of defect detection technology, specifically relating to a lens defect detection method based on a spatial-frequency dual-domain hybrid target detection model. Background Technology
[0002] In the manufacturing process of optical lenses, appearance defects (such as scratches, impurities, and uneven coatings) directly affect the optical performance and user experience of the product. Traditional manual visual inspection methods are inefficient, highly subjective, and unable to meet the demands of high-precision inspection. With the development of machine vision technology, image processing-based automatic inspection methods, such as edge detection, template matching, and morphological analysis, have gradually become mainstream. However, these methods often lack generalization ability when faced with complex backgrounds, multiple types of defects, or distortions in curved lenses, making it difficult to achieve high-precision and high-efficiency inspection.
[0003] In recent years, breakthroughs in deep learning in the field of object detection have provided a new technological path for lens inspection. Compared with traditional algorithms, deep learning-based methods can automatically extract defect features, significantly improving detection accuracy and robustness. Taking the YOLO (You Only Look Once) series of algorithms as an example, its single-stage detection architecture combines real-time performance with high accuracy, making it particularly suitable for the online inspection needs of industrial production lines. However, this algorithm still faces challenges in practical applications, such as detecting minute defects, complex background interference, and sample imbalance. Therefore, this paper proposes a high-precision, high-efficiency, and highly robust object detection method to ensure effective identification of target defects in lenses in complex industrial environments. Summary of the Invention
[0004] The purpose of this invention is to address the above-mentioned problems by proposing a lens defect detection method based on a spatial-frequency dual-domain hybrid target detection model, which has high precision, high efficiency and high robustness.
[0005] To achieve the above objectives, the technical solution adopted by the present invention is as follows:
[0006] The present invention proposes a lens defect detection method based on a spatial-frequency dual-domain hybrid target detection model, comprising the following steps:
[0007] S1. Acquire different lens images and label them with defect categories to form a lens image set;
[0008] S2. Preprocess the lens images in the lens image set. The preprocessing involves sequentially extracting the ROI region, sharpening the image, and detecting the edge to form a sharpening map and an edge feature map.
[0009] S3. Establish a space-frequency dual-domain hybrid target detection model, which includes a DynaNet network, a Neck network, and a detection head connected in sequence.
[0010] S4. Input the sharpened image and edge feature image of the lens image set into the spatial frequency dual-domain hybrid target detection model to complete the training;
[0011] S5. Input the sharpened image and edge feature image of the lens under test into the corresponding trained spatial frequency dual-domain hybrid target detection model to obtain the defect detection results of the lens under test.
[0012] S6. Determine whether all defect detection results of the lens under test are less than or equal to the preset defect threshold. If not, the lens is considered unqualified; otherwise, the lens is considered qualified.
[0013] Preferably, the DynaNet network includes a first feature extraction module, a feature pyramid, and a dynamic feature extraction module connected in sequence. The first feature extraction module includes four concatenated convolutional layers. The feature pyramid includes a downsampling unit, a first multi-scale enhancement feedforward module, a downsampling unit, a second multi-scale enhancement feedforward module, a downsampling unit, a third multi-scale enhancement feedforward module, a downsampling unit, and a fourth multi-scale enhancement feedforward module connected in sequence. The dynamic feature extraction module includes a first gated dynamic feature aggregation module, a downsampling unit, and a second gated dynamic feature aggregation module connected in sequence. The input features of the fourth multi-scale enhancement feedforward module are also used as input features of the first gated dynamic feature aggregation module, and the output features of the fourth multi-scale enhancement feedforward module are also used as input features of the second gated dynamic feature aggregation module.
[0014] Preferably, each multi-scale enhancement feedforward module performs the following operations:
[0015] The input features of the current multi-scale enhancement feedforward module are added together before and after passing through the depthwise separable convolutional layer to form the first enhancement feature;
[0016] The first enhanced feature is passed through a normalization layer, a multi-scale feature fusion module, an SE attention module, and a feedforward network in sequence to form the second enhanced feature. The multi-scale feature fusion module is used to input the first enhanced feature after the normalization layer into a parallel 3×3 convolutional layer, a dilated convolutional layer, a 1×1 convolutional layer, an identity mapping, and a depthwise separable convolutional layer for concatenation.
[0017] The first and second enhancement features are added together to obtain the third enhancement feature, which is regarded as the output feature of the corresponding multi-scale enhancement feedforward module.
[0018] Preferably, each gated dynamic feature aggregation module performs the following operations:
[0019] All input features of the current gated dynamic feature aggregation module are concatenated and fused to form composite features;
[0020] The composite features are added together before and after passing through the depthwise separable convolutional layer to form a fourth enhanced feature.
[0021] The fourth enhancement feature is passed sequentially through a normalization layer and a gated dynamic spatial attention module to form the fifth enhancement feature;
[0022] The fourth and fifth enhancement features are added together to form the sixth enhancement feature;
[0023] The sixth enhancement feature is passed through a normalization layer and a feedforward network to form the seventh enhancement feature;
[0024] The sixth enhanced feature, the seventh enhanced feature, and all the input features of the current gating dynamic feature aggregation module are added together as the output features of the previous layer to form the first aggregated feature, which is regarded as the output feature of the corresponding gating dynamic feature aggregation module.
[0025] Preferably, the gated dynamic spatial attention module performs the following operations:
[0026] The input features of the gated dynamic spatial attention module are extracted using the first branch module and the second branch module respectively, and the first spatial features and the second spatial features are obtained accordingly. The first branch module includes a context-mixed dynamic convolution and an SE attention module connected in sequence, and the second branch module includes a convolutional layer and a SILU activation function connected in sequence.
[0027] The first and second spatial features are multiplied element-wise and then passed through a convolutional layer to generate dynamic attention weights, which are the fifth enhancement features.
[0028] Preferably, the context-mixed dynamic convolution satisfies the following formula:
[0029] ;
[0030] ;
[0031] ;
[0032] ;
[0033] Where X represents the input feature of the context-mixed dynamic convolution, The query vector represents the input features of the context-mixed dynamic convolution. The key vector representing the input features of the context-mixed dynamic convolution. Represents the affinity matrix. The output features of the context-mixed dynamic convolution are represented. Representative 1 The grouped convolution operation is 1, RS represents the shape reshaping operation, and ADP represents the adaptive pooling operation. Represents the Sofmax function. Represents a linear layer. This represents element-wise multiplication. Represents matrix multiplication. This represents a convolution operation using a global awareness kernel, + represents matrix addition, and T represents transpose.
[0034] Preferably, the feedforward network includes a normalized layer, a convolutional layer, a depth-separable convolutional layer, and another convolutional layer connected in sequence.
[0035] Preferably, the Neck network includes a first frequency domain feature extraction module, a second frequency domain feature extraction module, a third frequency domain feature extraction module, and a second feature extraction module. The second feature extraction module adopts the Neck module of the YOLO12 model. The input of the first frequency domain feature extraction module is connected to the output of the second multi-scale enhanced feedforward module, and the output is connected to the large target detection input of the YOLO12 model Neck module. The input of the second frequency domain feature extraction module is connected to the output of the fourth multi-scale enhanced feedforward module, and the output is connected to the medium target detection input of the YOLO12 model Neck module. The input of the third frequency domain feature extraction module is connected to the output of the second gated dynamic feature aggregation module, and the output is connected to the small target detection input of the YOLO12 model Neck module.
[0036] Each frequency domain feature extraction module includes a third feature extraction module, a fourth feature extraction module, and a cross-attention module connected in sequence, wherein:
[0037] The third feature extraction module includes a 2D convolutional layer, a ReLU activation function, and another 2D convolutional layer connected in sequence.
[0038] The fourth feature extraction module includes a parallel frequency domain phase extraction module and a frequency domain amplitude extraction module. The frequency domain phase extraction module includes a phase spectrum extraction unit, a 2D convolutional layer, a ReLU activation function, a pooling module, a concatenation operation, a 2D convolutional layer, a Sigmoid activation function, and a multiplication operation, all connected in sequence. The input features of the multiplication operation in the frequency domain phase extraction module also include the input features of the phase spectrum extraction unit. The frequency domain amplitude extraction module includes an amplitude spectrum extraction unit, a 2D convolutional layer, a ReLU activation function, a pooling module, a concatenation operation, a 2D convolutional layer, a Sigmoid activation function, and a multiplication operation, all connected in sequence. The input features of the multiplication operation in the frequency domain amplitude extraction module also include the input features of the amplitude spectrum extraction unit. The phase spectrum extraction unit and the amplitude spectrum extraction unit are used to extract the phase spectrum and amplitude spectrum respectively through fast Fourier transform. The pooling module includes parallel max pooling and average pooling operations.
[0039] The cross-attention module employs a two-branch cross-attention mechanism.
[0040] Preferably, the cross-attention module satisfies the following formula:
[0041] ;
[0042] ;
[0043] ;
[0044] in, This represents the output characteristics of the frequency domain phase extraction module. This represents the output feature of the frequency domain amplitude extraction module. A query vector representing the phase in the frequency domain. The key vector representing the phase in the frequency domain. The value vector representing the phase in the frequency domain. The query vector representing the frequency domain amplitude. The key vector representing the amplitude and phase in the frequency domain. A vector of values representing the amplitude in the frequency domain. This represents the output characteristics of the CASF module. Represents a linear layer. LayerNorm represents a convolutional layer, and LayerNorm represents a normalization layer. Represents transpose. + represents matrix multiplication, and + represents matrix addition. This represents element-wise multiplication.
[0045] Preferably, the defect categories include seven types: dirt, scratches, white core, reddish discoloration, light ink, gaps, and black spots;
[0046] ROI region extraction involves cropping the lens image to extract the ROI region.
[0047] Image sharpening involves using an unsharpening mask method to sharpen the cropped lens image, creating a sharpened image. The unsharpening mask method is detailed below:
[0048] A 5×5 Gaussian kernel was used to perform low-pass filtering on the cropped lens image;
[0049] The high-frequency components are obtained by subtracting the low-pass filtered lens image from the cropped lens image.
[0050] The high-frequency components are multiplied by a preset enhancement factor and then superimposed onto the cropped lens image to form a sharpened image;
[0051] Edge detection, as detailed below:
[0052] After converting the sharpened image to grayscale, the Scharr operator is used to extract edge features, obtaining the gradient in the x-direction and the gradient in the y-direction.
[0053] The gradients in the x and y directions are converted to their absolute values, then linearly fused with equal weights and normalized to form the edge feature map.
[0054] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0055] This method significantly improves detection accuracy by combining frequency domain feature analysis with a dynamic convolution mechanism. Specifically, the spatial-frequency dual-domain hybrid target detection model includes a DynaNet network, a Neck network, and a detection head connected sequentially. By using the DynaNet network as the backbone, the DynaNet network can adaptively adjust the convolution kernel parameters and establish long-distance feature dependencies through a cross-layer dynamic convolution mechanism. This not only enhances the model's ability to capture multi-scale defect features but also significantly improves the model's parameter computation efficiency. During feature extraction, the multi-level feature map output by the DynaNet network first passes through the frequency domain feature extraction module of the Neck network. The frequency domain feature extraction module converts spatial features into frequency domain representations and extracts amplitude spectrum features and phase spectrum features respectively. Among them, the amplitude spectrum features mainly reflect the intensity distribution information of surface defects, while the phase spectrum features retain the structural contour features of the defects. These frequency domain features (amplitude spectrum features and phase spectrum features) are then deeply fused with the original spatial features (input features from the frequency domain phase extraction module or the frequency domain amplitude extraction module). Through a cross-domain feature interaction mechanism, a more discriminative feature representation is constructed. This innovative dual-domain (frequency domain and spatial domain) collaborative working mechanism enables the model to adaptively focus on important features in different frequency bands. While ensuring real-time detection speed, it achieves multi-scale feature fusion, significantly improving the detection capability for complex defects such as tiny scratches and low-contrast bubbles. This results in high accuracy, high efficiency, and high robustness of the model detection. Attached Figure Description
[0056] Figure 1 The flowchart shows the lens defect detection method based on the spatial frequency dual-domain hybrid target detection model of the present invention.
[0057] Figure 2 These are schematic diagrams of the lens image (a), the cropped lens image (b), the sharpened image (c), and the edge feature image (d) of the present invention.
[0058] Figure 3 This is a schematic diagram of a partial magnified view (a) of the lens image, a partial magnified view (b) of the sharpened image, and a partial magnified view (c) of the edge feature image of the present invention.
[0059] Figure 4This is a schematic diagram of the spatial-frequency dual-domain hybrid target detection model of the present invention;
[0060] Figure 5 This is a schematic diagram of the context-mixed dynamic convolution structure of the present invention;
[0061] Figure 6 This is a schematic diagram of the frequency domain feature extraction module of the present invention;
[0062] Figure 7 This is a schematic diagram of the CASF module of the present invention;
[0063] Figure 8 This is a schematic diagram of the defect detection results (a) of the sharpened image and (b) of the edge feature image of the present invention. Detailed Implementation
[0064] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0065] It should be noted that when a component is referred to as being "connected" to another component, it can be directly connected to the other component or there may be an intervening component. Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art. The terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the scope of the application.
[0066] like Figures 1-8 As shown, a lens defect detection method based on a spatial-frequency dual-domain hybrid target detection model includes the following steps:
[0067] S1. Acquire different lens images and label them with defect categories to form a lens image set.
[0068] S2. Preprocess the lens images in the lens image set. The preprocessing involves sequentially extracting the ROI region, sharpening the image, and detecting the edge to form a sharpened image and an edge feature map.
[0069] In one embodiment, the defect categories include seven types: dirt, scratches, white core, reddish, light ink, gaps, and black spots.
[0070] ROI region extraction involves cropping the lens image to extract the ROI region.
[0071] Image sharpening involves using an unsharpening mask method to sharpen the cropped lens image, creating a sharpened image. The unsharpening mask method is detailed below:
[0072] A 5×5 Gaussian kernel was used to perform low-pass filtering on the cropped lens image;
[0073] The high-frequency components are obtained by subtracting the low-pass filtered lens image from the cropped lens image.
[0074] The high-frequency components are multiplied by a preset enhancement factor and then superimposed onto the cropped lens image to form a sharpened image;
[0075] Edge detection, as detailed below:
[0076] After converting the sharpened image to grayscale, the Scharr operator is used to extract edge features, obtaining the gradient in the x-direction and the gradient in the y-direction.
[0077] The gradients in the x and y directions are converted to their absolute values, then linearly fused with equal weights and normalized to form the edge feature map.
[0078] Specifically, a high-definition camera is used to take pictures of different lenses from different angles, and the lens images are classified and labeled using the Elf Labeling Assistant. The labeled defect categories include: dirt, scratches, core white, reddish, light ink, gaps, and black spots, totaling 7 types. The specific defect categories can also be set according to actual needs.
[0079] Specifically, the preprocessing process is as follows:
[0080] 1) Region of Interest (ROI) Extraction: First, the lens image is precisely cropped to extract the region of interest (ROI) containing the main body of the lens, effectively removing irrelevant background parts such as borders and clamps from the lens image. The cropping method is a technique well-known to those skilled in the art, such as determining the effective area of the lens image through preset geometric constraints to ensure that subsequent processing can analyze only the surface features of the lens.
[0081] 2) Image Sharpening: An unsharpened mask method is used to enhance the details of the cropped lens image. First, a 5×5 Gaussian kernel (standard deviation σ=2.0) is used to perform low-pass filtering on the cropped lens image to extract low-frequency background components. Then, a weighted difference (cropped lens image × 1.0 - blurred image × 1.0) is performed between the cropped lens image and the low-pass filtered lens image (blurred image) to obtain high-frequency components containing defect features. Finally, the high-frequency components are superimposed back onto the cropped lens image with a preset enhancement coefficient of 2.0 to form a sharpened image, significantly improving the contrast between lens surface defects and the background.
[0082] 3) Edge Detection: Edge features are extracted by applying the Scharr operator to the sharpened image. Specifically, the sharpened image is first converted to grayscale, and then the first-order derivatives in the x and y directions are calculated separately (using the Scharr operator kernel) to obtain a 16-bit signed gradient map. After converting the absolute values of the gradients in the two directions, they are linearly fused with an equal weight of 0.5 to generate an intensity map containing complete edge information. The normalized result (0-255) is then output as the edge feature map. This edge detection process preserves the edge features of subtle defects while effectively suppressing noise interference.
[0083] The preprocessing process, through stepwise enhancement and feature extraction, not only significantly improved the visual contrast of the defective area but also accurately preserved its contour features. For example... Figure 2 As shown, (a) is a lens image, (b) is a cropped lens image, (c) is a sharpened image, and (d) is an edge feature image. The various lens images obtained during the preprocessing process clearly highlight the defect areas. Figure 3 The image further demonstrates the detailed edge features under magnification. (a) is a magnified view of the lens image, (b) is a magnified view of the sharpened image, and (c) is a magnified view of the edge feature map. Finally, the edge feature map and the sharpened image are input into FreqMix-YOLO for shallow scratch detection and other defect type detection. For example, the edge feature map is used to detect scratches, while the sharpened image is used to detect six other defects (dirt, core whitening, reddish tint, light ink, gaps, and black spots). Since scratches are generally shallow and their features are not very obvious in the lens image, the processed edge feature map can enhance the features of shallow scratches. However, it will lose some information about other defect features. Therefore, it is necessary to process the edge feature map and the sharpened image separately to form a complementary effect, which is beneficial for further improving detection accuracy.
[0084] S3. Establish a space-frequency dual-domain hybrid target detection model, which includes a DynaNet network, a Neck network, and a detection head connected in sequence.
[0085] In one embodiment, the DynaNet network includes a first feature extraction module, a feature pyramid, and a dynamic feature extraction module connected in sequence. The first feature extraction module includes four concatenated convolutional layers. The feature pyramid includes a downsampling unit, a first multi-scale enhancement feedforward module, a downsampling unit, a second multi-scale enhancement feedforward module, a downsampling unit, a third multi-scale enhancement feedforward module, a downsampling unit, and a fourth multi-scale enhancement feedforward module connected in sequence. The dynamic feature extraction module includes a first gated dynamic feature aggregation module, a downsampling unit, and a second gated dynamic feature aggregation module connected in sequence. The input features of the fourth multi-scale enhancement feedforward module are also used as input features of the first gated dynamic feature aggregation module, and the output features of the fourth multi-scale enhancement feedforward module are also used as input features of the second gated dynamic feature aggregation module.
[0086] In one embodiment, each multi-scale enhancement feedforward module performs the following operations:
[0087] The input features of the current multi-scale enhancement feedforward module are added together before and after passing through the depthwise separable convolutional layer to form the first enhancement feature;
[0088] The first enhanced feature is passed through a normalization layer, a multi-scale feature fusion module, an SE attention module, and a feedforward network in sequence to form the second enhanced feature. The multi-scale feature fusion module is used to input the first enhanced feature after the normalization layer into a parallel 3×3 convolutional layer, a dilated convolutional layer, a 1×1 convolutional layer, an identity mapping, and a depthwise separable convolutional layer for concatenation.
[0089] The first and second enhancement features are added together to obtain the third enhancement feature, which is regarded as the output feature of the corresponding multi-scale enhancement feedforward module.
[0090] In one embodiment, each gated dynamic feature aggregation module performs the following operations:
[0091] All input features of the current gated dynamic feature aggregation module are concatenated and fused to form composite features;
[0092] The composite features are added together before and after passing through the depthwise separable convolutional layer to form a fourth enhanced feature.
[0093] The fourth enhancement feature is passed sequentially through a normalization layer and a gated dynamic spatial attention module to form the fifth enhancement feature;
[0094] The fourth and fifth enhancement features are added together to form the sixth enhancement feature;
[0095] The sixth enhancement feature is passed through a normalization layer and a feedforward network to form the seventh enhancement feature;
[0096] The sixth enhanced feature, the seventh enhanced feature, and all the input features of the current gating dynamic feature aggregation module are added together as the output features of the previous layer to form the first aggregated feature, which is regarded as the output feature of the corresponding gating dynamic feature aggregation module.
[0097] In one embodiment, the gated dynamic spatial attention module performs the following operations:
[0098] The input features of the gated dynamic spatial attention module are extracted using the first branch module and the second branch module respectively, and the first spatial features and the second spatial features are obtained accordingly. The first branch module includes a context-mixed dynamic convolution and an SE attention module connected in sequence, and the second branch module includes a convolutional layer and a SILU activation function connected in sequence.
[0099] The first and second spatial features are multiplied element-wise and then passed through a convolutional layer to generate dynamic attention weights, which are the fifth enhancement features.
[0100] In one embodiment, context-blended dynamic convolution satisfies the following formula:
[0101] ;
[0102] ;
[0103] ;
[0104] ;
[0105] Where X represents the input feature of the context-mixed dynamic convolution, The query vector represents the input features of the context-mixed dynamic convolution. The key vector representing the input features of the context-mixed dynamic convolution. Represents the affinity matrix. The output features of the context-mixed dynamic convolution are represented. Representative 1 The grouped convolution operation is 1, RS represents the shape reshaping operation, and ADP represents the adaptive pooling operation. Represents the Sofmax function. Represents a linear layer. This represents element-wise multiplication. Represents matrix multiplication. This represents a convolution operation using a global awareness kernel, + represents matrix addition, and T represents transpose.
[0106] In one embodiment, the feedforward network includes a normalized layer, a convolutional layer, a depth-separable convolutional layer, and another convolutional layer connected in sequence.
[0107] In one embodiment, the Neck network includes a first frequency domain feature extraction module, a second frequency domain feature extraction module, a third frequency domain feature extraction module, and a second feature extraction module. The second feature extraction module adopts the Neck module of the YOLO12 model. The input of the first frequency domain feature extraction module is connected to the output of the second multi-scale enhanced feedforward module, and the output is connected to the large target detection input of the YOLO12 model Neck module. The input of the second frequency domain feature extraction module is connected to the output of the fourth multi-scale enhanced feedforward module, and the output is connected to the medium target detection input of the YOLO12 model Neck module. The input of the third frequency domain feature extraction module is connected to the output of the second gated dynamic feature aggregation module, and the output is connected to the small target detection input of the YOLO12 model Neck module.
[0108] Each frequency domain feature extraction module includes a third feature extraction module, a fourth feature extraction module, and a cross-attention module connected in sequence, wherein:
[0109] The third feature extraction module includes a 2D convolutional layer, a ReLU activation function, and another 2D convolutional layer connected in sequence.
[0110] The fourth feature extraction module includes a parallel frequency domain phase extraction module and a frequency domain amplitude extraction module. The frequency domain phase extraction module includes a phase spectrum extraction unit, a 2D convolutional layer, a ReLU activation function, a pooling module, a concatenation operation, a 2D convolutional layer, a Sigmoid activation function, and a multiplication operation, all connected in sequence. The input features of the multiplication operation in the frequency domain phase extraction module also include the input features of the phase spectrum extraction unit. The frequency domain amplitude extraction module includes an amplitude spectrum extraction unit, a 2D convolutional layer, a ReLU activation function, a pooling module, a concatenation operation, a 2D convolutional layer, a Sigmoid activation function, and a multiplication operation, all connected in sequence. The input features of the multiplication operation in the frequency domain amplitude extraction module also include the input features of the amplitude spectrum extraction unit. The phase spectrum extraction unit and the amplitude spectrum extraction unit are used to extract the phase spectrum and amplitude spectrum respectively through fast Fourier transform. The pooling module includes parallel max pooling and average pooling operations.
[0111] The cross-attention module employs a two-branch cross-attention mechanism.
[0112] In one embodiment, the cross-attention module satisfies the following formula:
[0113] ;
[0114] ;
[0115] ;
[0116] in, This represents the output characteristics of the frequency domain phase extraction module. This represents the output feature of the frequency domain amplitude extraction module. A query vector representing the phase in the frequency domain. The key vector representing the phase in the frequency domain. The value vector representing the phase in the frequency domain. The query vector representing the frequency domain amplitude. The key vector representing the amplitude and phase in the frequency domain. A vector of values representing the amplitude in the frequency domain. This represents the output characteristics of the CASF module. Represents a linear layer. LayerNorm represents a convolutional layer, and LayerNorm represents a normalization layer. Represents transpose. + represents matrix multiplication, and + represents matrix addition. This represents element-wise multiplication.
[0117] like Figure 4 The image shows a schematic diagram of the Spatial-Frequency Dual-Domain Mixed-You Only Look Once (SFDMix-YOLO model). Specifically:
[0118] 1) DynaNet network
[0119] The DynaNet network (as the backbone network) employs a hierarchical, progressive feature extraction architecture, structured as follows: Figure 4 As shown, its processing flow starts with the input image (Input, i.e., edge feature map and sharpening map), and first goes through four consecutive convolutional layers (Conv... The initial feature extraction is performed using 4×3 convolutional layers, which progressively capture the low-level texture and edge features of the image using small kernels. Subsequently, a downsampling operation (downsampling factor 2) is used to compress the feature map size and expand the receptive field. This is followed by the core processing stage, which consists of multiple multi-scale enhancement feedforward modules (Basic Blocks). The multi-scale enhancement feedforward module stage employs a hierarchical design, comprising four sub-stages N1 to N4 (corresponding to the first multi-scale enhancement feedforward module (Basic Block × N1), the second multi-scale enhancement feedforward module (Basic Block × N2), the third multi-scale enhancement feedforward module (Basic Block × N3), and the fourth multi-scale enhancement feedforward module (Basic Block × N4) respectively). These sub-stages are connected by downsampling units, forming a feature pyramid structure. In the deep network, gated dynamic feature aggregation modules (Dynamic Blocks) are also introduced, including the first and second gated dynamic feature aggregation modules. These modules dynamically adjust the convolutional kernel weights using learnable parameters, adaptively optimizing the feature representation. Throughout the processing flow, the DynaNet network gradually achieves multi-scale feature extraction from local details to global semantics through alternating feature transformations and downsampling operations. The multi-scale enhancement feedforward module is responsible for constructing stable feature representations, while the gated dynamic feature aggregation module achieves adaptive feature optimization. The two work together to enable the DynaNet network to maintain the stability of traditional convolutional networks while obtaining dynamically adjustable feature representation capabilities.
[0120] ① Multi-Scale Enhanced Feed-Forward Block (MSEFFB): The MSEFFB employs a composite processing flow combining depthwise separable convolutional layers and multi-scale feature fusion. Its input features are processed through a 3×3 depthwise separable convolutional layer (DWConv) to extract spatial features, which are then added to the input features to achieve efficient and lightweight feature enhancement. This significantly reduces computational complexity while maintaining representational power. Subsequently, a normalization layer (Norm) stabilizes the feature distribution, and a multi-scale feature fusion module (Dilated RepConv) with multi-scale perception capabilities is then connected. This module performs multi-scale feature fusion using a five-branch parallel structure (3×3 convolutional layer, dilated convolutional layer, 1×1 convolutional layer, identity mapping, and depthwise separable convolutional layer) and then concatenates the results to capture contextual information from different receptive fields. Next, the output features of the multi-scale feature fusion module are fed into the SE attention module (Squeeze-Activation Layer, SE Layer) for adaptive recalibration of the channel dimensions, highlighting the contribution of important feature channels. The SE attention module is a well-known technique and will not be elaborated further here. Finally, a feedforward network (ConvFFN) consisting of a normalization layer, a 1×1 convolutional layer, a depthwise separable convolutional layer, and another 1×1 convolutional layer performs nonlinear feature transformation. The processed features (i.e., the output features of the feedforward network) are added to the first enhanced feature through residual connections, thus preserving low-level feature information while incorporating high-level semantic features. The entire processing flow ensures efficiency through depthwise separable convolutional layers, enhances representation capabilities through multi-scale feature fusion, and ensures gradient propagation through residual connections, forming an efficient and robust feature extraction unit.
[0121] ② Gated Dynamic Feature Aggregation Module (GDFAM): Employs a collaborative mechanism of feature-level and weight-level operation. First, the context prior Pi and the first feature map Zi are concatenated and fused to construct a composite feature. Regarding the context prior Pi and the first feature map Zi, for the first gated dynamic feature aggregation module, the input features of the fourth multi-scale enhancement feedforward module are considered the context prior, and the output features of the fourth multi-scale enhancement feedforward module are considered the first feature map. The fourth multi-scale enhancement feedforward module is directly connected to the first gated dynamic feature aggregation module, serving as its upper layer. The output features of the fourth multi-scale enhancement feedforward module are the output features of the upper layer from all the input features of the first gated dynamic feature aggregation module, while cross-layer input features serve as the context prior. Similarly, for the second gated dynamic feature aggregation module, the output features of the fourth multi-scale enhancement feedforward module are considered the context prior, and the output features of the upper layer (upsampling unit) of the second gated dynamic feature aggregation module are considered the first feature map. The composite features are then passed through a depthwise separable convolutional layer, and feature enhancement is achieved by adding the features before passing through the depthwise separable convolutional layer through residual connections. Subsequently, the features pass through a normalization layer and a gated dynamic spatial attention (GDSA) module.
[0122] In the Gated Dynamic Spatial Attention (GDSA) module, the input features are fed into a dual-path dynamic adjustment structure: one path contains a context-mixed dynamic convolution (ContMix) and an SE attention module connected sequentially, focusing on modeling long-range dependencies between channels; the other path uses a 1×1 convolution and the SILU activation function to effectively extract local spatial features. The outputs of the two paths are multiplied element-wise to achieve feature interaction and adaptive fusion, and then passed through a 1×1 convolution to generate spatially aware dynamic attention weights. These weights are then added to the fourth enhanced feature (the feature obtained after residual connection of the composite feature) to obtain the dynamically adjusted feature map (the sixth enhanced feature). Finally, the dynamically adjusted feature map is passed sequentially through a normalization layer and a feedforward network (ConvFFN) for feature transformation to form the seventh enhanced feature. The sixth enhanced feature, the seventh enhanced feature, and all the input features of the current gated dynamic feature aggregation module are added as the output features of the previous layer (the first feature map Zi) to output the optimized feature representation (the first aggregated feature).
[0123] ③ Context-mixed dynamic convolution (ContMix): such as Figure 5 As shown, a dual-branch parallel structure is used to process its input feature X: in the query branch, its input feature X directly generates the query matrix W through 1×1 convolution (1×1 Conv).q The query vector is obtained after the shape reshaping operation. Meanwhile, in the key-value branch, the input feature X is first convolved with a 1×1 layer, and then the key-value matrix W is generated through an adaptive pooling layer. k The key vector is obtained after the reshape operation. Subsequently, W after the reshaping operation is calculated using matrix multiplication. q With W k The affinity matrix A is obtained and passed through a linear layer ( The softmax function (softmax) is used to reshape it into a global awareness kernel weight. This weight serves as the global awareness kernel ( The input feature map X (denoted as the original feature map) is multiplied by the context-mixed dynamic convolution, and then reshaped to the size of the original feature map X. Simultaneously, the original feature map X is enhanced with channel diversity through a depthwise separable convolution. Finally, the feature map processed by the global awareness kernel is added element-wise with the output feature of the depthwise separable convolution, achieving a synergistic optimization of local feature extraction and global context modeling, outputting an enhanced feature representation. Figure 5 middle, Representative 1 1 represents grouped convolution, and ⊙ represents element-wise multiplication. This represents matrix multiplication. DWConv represents the convolution kernel as... The depth of the separable convolutional layer This represents the number of groups in the grouped convolution. Channels representing the input features of context-mixed dynamic convolution. The height of the input feature representing the context-mixed dynamic convolution. The width of the input feature represents the context-mixed dynamic convolution. Represents spatial scale, and Transpose represents transposition.
[0124] 2) Neck network:
[0125] For a multi-branch hybrid architecture design, the output features of the DynaNet network, including the output features of the second multi-scale enhancement feedforward module, the fourth multi-scale enhancement feedforward module, and the second gated dynamic feature aggregation module, are sequentially processed by the first, second, and third frequency domain feature extraction modules for frequency domain feature enhancement. These enhancements are then input into the second feature extraction module (using the YOLO12 model's Neck model). Specifically, the output features of the first frequency domain feature extraction module serve as the input features for large target detection in the YOLO12 model's Neck module; the output features of the second frequency domain feature extraction module serve as the input features for medium target detection in the YOLO12 model's Neck module; and the output features of the third frequency domain feature extraction module serve as the input features for small target detection in the YOLO12 model's Neck module. The frequency domain feature extraction module is also known as the FrepBlock module.
[0126] The Neck model of the YOLO12 model is an existing technology, such as a first target extraction module and a second target extraction module. The first target extraction module includes a concat operation (denoted as the first concat operation), an upsampling unit, an A2C2f module (adaptive attention cross-stage fusion module, denoted as the first A2C2f module), a concat operation (denoted as the second concat operation), an upsampling unit, and an A2C2f module (denoted as the second A2C2f module) connected in sequence. The second target extraction module includes an A2C2f module (denoted as the third A2C2f module), a convolutional layer (Conv), a concat operation (denoted as the third concat operation), and an A2C2f module connected in sequence. The system consists of a block (referred to as the fourth A2C2f module), a convolutional layer (Conv), a concat operation (referred to as the fourth Concat operation), and a C3k2 module. The first Concat operation is connected to the third A2C2f module, the first A2C2f module is connected to the third Concat operation, and the second A2C2f module is connected to the fourth Concat operation. The inputs of the first Concat operation, the second Concat operation, and the second A2C2f module are sequentially connected to the first frequency domain feature extraction module, the second frequency domain feature extraction module, and the third frequency domain feature extraction module. The outputs of the third A2C2f module, the fourth A2C2f module, and the C3k2 module are sequentially input to the detection head for large target detection, medium target detection, and small target detection, respectively.
[0127] A multi-scale feature pyramid is constructed through Concat operations and upsampling. Furthermore, the A2C2f module is combined with Area Attention (A) to dynamically adjust weights and achieve refined fusion of cross-layer features. Simultaneously, the C3k2 module performs feature compression and information integration. The entire process achieves multi-level feature interaction through bidirectional data flow (top-down and bottom-up), ultimately outputting an optimized feature map that balances detail and semantic information, providing a highly discriminative feature representation for subsequent detection heads.
[0128] The detection head employs a multi-resolution parallel architecture, identical to the YOLO12 model's detection head structure, containing three structurally similar detection branches that process features at different scales. Each detection branch utilizes a dual-path decoupled design: the classification branch dynamically enhances key feature channels through cascaded 3×3 depthwise separable convolutional layers, significantly improving classification accuracy; the regression branch adaptively adjusts the receptive field using deformable convolutional kernels and combines this with Gaussian bounding box parameterization to achieve high-precision modeling of target locations. The three detection branches complement each other across scales through a hierarchical feature fusion strategy (Neck network), ultimately outputting uniformly calibrated detection results, effectively achieving multi-scale target detection while maintaining real-time performance.
[0129] The FrepBlock module employs a feature extraction mechanism that combines frequency and spatial domains, enabling multi-scale detection of surface defects on lenses through dual-path analysis. This module first processes the input feature maps with 3×3 2D convolution, ReLU activation, and another 3×3 2D convolution to obtain the basic feature F. Subsequently, feature enhancement is achieved through parallel processing paths: In the frequency domain phase path, the phase spectrum extraction unit (FFT PCA) performs a fast Fourier transform on the basic feature F and extracts the phase spectrum. After processing with 3×3 2D convolution, ReLU activation function, pooling module (parallel max pooling operation Max and average pooling operation Average), concatenation operation, 3×3 2D convolution, and Sigmoid activation function to generate spatial attention weights, it is then multiplied with the basic feature F to effectively capture subtle phase distortions caused by defects such as scratches and bubbles. In the frequency domain amplitude path, the amplitude spectrum extraction unit (FFT ACA) separates the amplitude spectrum, and then processes it with 3×3 2D convolution, ReLU activation function, pooling module (parallel max pooling operation Max and average pooling operation Average), concatenation operation, 3×3 2D convolution, and Sigmoid activation function to generate spatial attention weights, which are then multiplied with the basic feature F to achieve multi-scale detection of brightness anomalies and texture defects. Then, the frequency domain phase extraction module and the frequency domain amplitude extraction module are fused using a Cross-Attentional Symmetric Fusion Block (CASF module). This frequency-space joint modeling approach can simultaneously detect high-frequency fine scratches and low-frequency large-area stains or uneven coating, significantly improving the model's detection sensitivity and robustness. The structure is as follows: Figure 6 As shown.
[0130] The CASF module employs a two-branch cross-attention mechanism to process input features. First, the input features (output features from the frequency domain phase extraction module) are processed. Output features of the frequency domain amplitude extraction module Initial feature extraction is performed using two 3×3 convolutional layers, followed by normalization using a Layer Norm layer, and then three sets of vectors are generated via a linear layer. The output features of the frequency domain phase extraction module are... The branch produces three sets of vectors , , Output features of the frequency domain amplitude extraction module The branch produces three sets of vectors , , Then, cross-attention calculation is performed: and After calculating the attention score, multiply it by the scaling factor S. R Obtain the first scaling feature S 1 , and After calculating the attention score, multiply it by the scaling factor S. R We obtain the second scaling feature S², and the first scaling feature S. 1 The second scaling feature S² corresponds to and , Cross-multiplication yields two weighted features. These two weighted features are then summed, and finally, a 3×3 convolution is applied to them and added to the original features to output the fused feature. This structure achieves cross-branch information complementarity through bidirectional feature interaction, as exemplified by the CASF module. Figure 7 As shown.
[0131] This method significantly improves detection accuracy by combining frequency domain feature analysis with a dynamic convolution mechanism. Using the DynaNet network as the backbone, the DynaNet network adaptively adjusts the convolution kernel parameters and establishes long-distance feature dependencies through cross-layer dynamic convolution. This not only enhances the model's ability to capture multi-scale defect features but also significantly improves the model's parameter computation efficiency. During feature extraction, the multi-level feature map output by the DynaNet network first passes through a frequency-domain feature extraction module (FrepBlock module). The FrepBlock module converts spatial features into a frequency domain representation using a Fast Fourier Transform and extracts amplitude spectrum features and phase spectrum features respectively. The amplitude spectrum features mainly reflect the intensity distribution information of surface defects, while the phase spectrum features preserve the structural contour features of the defects. These frequency domain features (amplitude spectrum features and phase spectrum features) are then deeply fused with the original spatial features (input features from the frequency domain phase extraction module or the frequency domain amplitude extraction module). Through a cross-domain feature interaction mechanism, a more discriminative feature representation is constructed. This innovative dual-domain (frequency domain and spatial domain) collaborative working mechanism enables the model to adaptively focus on important features in different frequency bands, significantly improving the detection capability for complex defects such as tiny scratches and low-contrast bubbles while ensuring real-time detection speed.
[0132] S4. Input the sharpened image and edge feature map of the lens image set into the spatial frequency dual-domain hybrid target detection model to complete the training.
[0133] Specifically, in practical applications, the lens image set can be divided into a training set, a validation set, and a test set in an 8:1:1 ratio. The sharpened image and edge feature map of the training set are input into the spatial-frequency dual-domain hybrid target detection model for training, and the model is validated and tested using the validation set and the test set to obtain the trained spatial-frequency dual-domain hybrid target detection model. This technique is well known to those skilled in the art and will not be elaborated here.
[0134] S5. Input the sharpened image and edge feature image of the lens under test into the trained spatial frequency dual-domain hybrid target detection model to obtain the defect detection results of the lens under test.
[0135] S6. Determine whether all defect detection results of the lens under test are less than or equal to the preset defect threshold. If not, the lens is considered unqualified; otherwise, the lens is considered qualified.
[0136] Step S6 is a post-processing step, which compares the defect detection results of the lens under test (such as scratch length, dirt area, etc.) with a preset defect threshold, which can be set according to actual needs. If any defect parameter in all defect detection results (including the defect detection results corresponding to both the edge feature map and the sharpened map of the lens image under test) exceeds the preset defect threshold, the lens is judged as NG (unacceptable); conversely, when all defect parameters are within the allowable range, the lens is judged as OK (acceptable). The defect detection results are as follows: Figure 8 As shown, (a) is the defect detection result of the sharpened image, and (b) is the defect detection result of the edge feature image.
[0137] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0138] The embodiments described above are merely specific and detailed examples of the embodiments described in this application, and should not be construed as limiting the scope of the application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these modifications and improvements all fall within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the appended claims.
Claims
1. A lens defect detection method based on a spatial-frequency dual-domain hybrid target detection model, characterized in that: Includes the following steps: S1. Acquire different lens images and label them with defect categories to form a lens image set; S2. Preprocess the lens images in the lens image set. The preprocessing includes sequentially performing ROI region extraction, image sharpening, and edge detection to form a sharpened image and an edge feature image. S3. Establish a space-frequency dual-domain hybrid target detection model, which includes a DynaNet network, a Neck network, and a detection head connected in sequence. The DynaNet network includes a first feature extraction module, a feature pyramid, and a dynamic feature extraction module connected in sequence. The first feature extraction module includes four convolutional layers connected in series. The feature pyramid includes a downsampling unit, a first multi-scale enhanced feedforward module, a downsampling unit, a second multi-scale enhanced feedforward module, a downsampling unit, a third multi-scale enhanced feedforward module, a downsampling unit, and a fourth multi-scale enhanced feedforward module connected in sequence. The dynamic feature extraction module includes a first gated dynamic feature aggregation module, a downsampling unit, and a second gated dynamic feature aggregation module connected in sequence. The input features of the fourth multi-scale enhanced feedforward module are also used as input features of the first gated dynamic feature aggregation module, and the output features of the fourth multi-scale enhanced feedforward module are also used as input features of the second gated dynamic feature aggregation module. The Neck network includes a first frequency domain feature extraction module, a second frequency domain feature extraction module, a third frequency domain feature extraction module, and a second feature extraction module. The second feature extraction module adopts the Neck module of the YOLO12 model. The input of the first frequency domain feature extraction module is connected to the output of the second multi-scale enhanced feedforward module, and the output is connected to the large target detection input of the YOLO12 model Neck module. The input of the second frequency domain feature extraction module is connected to the output of the fourth multi-scale enhanced feedforward module, and the output is connected to the medium target detection input of the YOLO12 model Neck module. The input of the third frequency domain feature extraction module is connected to the output of the second gated dynamic feature aggregation module, and the output is connected to the small target detection input of the YOLO12 model Neck module. Each of the frequency domain feature extraction modules includes a third feature extraction module, a fourth feature extraction module, and a cross-attention module connected in sequence, wherein: The third feature extraction module includes a 2D convolutional layer, a ReLU activation function, and a 2D convolutional layer connected in sequence. The fourth feature extraction module includes a parallel frequency domain phase extraction module and a frequency domain amplitude extraction module. The frequency domain phase extraction module includes a phase spectrum extraction unit, a 2D convolutional layer, a ReLU activation function, a pooling module, a concatenation operation, a 2D convolutional layer, a Sigmoid activation function, and a multiplication operation connected in sequence. The input features of the multiplication operation of the frequency domain phase extraction module also include the input features of the phase spectrum extraction unit. The frequency domain amplitude extraction module includes an amplitude spectrum extraction unit, a 2D convolutional layer, a ReLU activation function, a pooling module, a concatenation operation, a 2D convolutional layer, a Sigmoid activation function, and a multiplication operation connected in sequence. The input features of the multiplication operation of the frequency domain amplitude extraction module also include the input features of the amplitude spectrum extraction unit. The phase spectrum extraction unit and the amplitude spectrum extraction unit are used to extract the phase spectrum and amplitude spectrum respectively through fast Fourier transform. The pooling module includes parallel max pooling and average pooling operations. The cross-attention module employs a dual-branch cross-attention mechanism; The detection head has the same structure as the detection head of the YOLO12 model; S4. Input the sharpened image and edge feature image of the lens image set into the spatial frequency dual-domain hybrid target detection model to complete the training; S5. Input the sharpened image and edge feature image of the lens under test into the corresponding trained spatial frequency dual-domain hybrid target detection model to obtain the defect detection results of the lens under test. S6. Determine whether all defect detection results of the lens under test are less than or equal to the preset defect threshold. If not, the lens is considered unqualified; otherwise, the lens is considered qualified.
2. The lens defect detection method based on the spatial-frequency dual-domain hybrid target detection model as described in claim 1, characterized in that: Each of the multi-scale enhancement feedforward modules performs the following operations: The input features of the current multi-scale enhancement feedforward module are added together before and after passing through the depthwise separable convolutional layer to form the first enhancement feature; The first enhanced feature is passed sequentially through a normalization layer, a multi-scale feature fusion module, an SE attention module, and a feedforward network to form a second enhanced feature. The multi-scale feature fusion module is used to input the first enhanced feature after the normalization layer into a parallel 3×3 convolutional layer, a dilated convolutional layer, a 1×1 convolutional layer, an identity mapping, and a depthwise separable convolutional layer for concatenation. The first and second enhancement features are added together to obtain the third enhancement feature, which is regarded as the output feature of the corresponding multi-scale enhancement feedforward module.
3. The lens defect detection method based on the spatial-frequency dual-domain hybrid target detection model as described in claim 1, characterized in that: Each of the gated dynamic feature aggregation modules performs the following operations: All input features of the current gated dynamic feature aggregation module are concatenated and fused to form composite features; The composite features are added together before and after passing through the depthwise separable convolutional layer to form a fourth enhanced feature. The fourth enhancement feature is passed sequentially through a normalization layer and a gated dynamic spatial attention module to form the fifth enhancement feature; The fourth and fifth enhancement features are added together to form the sixth enhancement feature; The sixth enhancement feature is passed through a normalization layer and a feedforward network to form the seventh enhancement feature; The sixth enhanced feature, the seventh enhanced feature, and all the input features of the current gating dynamic feature aggregation module are added together as the output features of the previous layer to form the first aggregated feature, which is regarded as the output feature of the corresponding gating dynamic feature aggregation module.
4. The lens defect detection method based on the spatial-frequency dual-domain hybrid target detection model as described in claim 3, characterized in that: The gated dynamic spatial attention module performs the following operations: The input features of the gated dynamic spatial attention module are extracted using the first branch module and the second branch module respectively, and the first spatial features and the second spatial features are obtained accordingly. The first branch module includes a context-mixed dynamic convolution and an SE attention module connected in sequence, and the second branch module includes a convolutional layer and a SILU activation function connected in sequence. The first and second spatial features are multiplied element-wise and then passed through a convolutional layer to generate dynamic attention weights, which are the fifth enhancement features.
5. The lens defect detection method based on the spatial-frequency dual-domain hybrid target detection model as described in claim 4, characterized in that: The context-mixed dynamic convolution satisfies the following formula: ; ; ; ; Where X represents the input feature of the context-mixed dynamic convolution, The query vector represents the input features of the context-mixed dynamic convolution. The key vector representing the input features of the context-mixed dynamic convolution. Represents the affinity matrix. The output features of the context-mixed dynamic convolution are represented. Representative 1 The grouped convolution operation is 1, RS represents the shape reshaping operation, and ADP represents the adaptive pooling operation. Represents the Sofmax function. Represents a linear layer. This represents element-wise multiplication. Represents matrix multiplication. This represents a convolution operation using a global awareness kernel, + represents matrix addition, and T represents transpose.
6. The lens defect detection method based on a spatial-frequency dual-domain hybrid target detection model as described in any one of claims 2 to 5, characterized in that: The feedforward network comprises a normalized layer, a convolutional layer, a depth-separable convolutional layer, and another convolutional layer connected in sequence.
7. The lens defect detection method based on the spatial-frequency dual-domain hybrid target detection model as described in claim 1, characterized in that: The cross-attention module satisfies the following formula: ; ; ; in, This represents the output characteristics of the frequency domain phase extraction module. This represents the output feature of the frequency domain amplitude extraction module. A query vector representing the phase in the frequency domain. The key vector representing the phase in the frequency domain. The value vector representing the phase in the frequency domain. The query vector representing the frequency domain amplitude. The key vector representing the amplitude and phase in the frequency domain. A vector of values representing the amplitude in the frequency domain. This represents the output characteristics of the CASF module. Represents a linear layer. LayerNorm represents a convolutional layer, and LayerNorm represents a normalization layer. Represents transpose. + represents matrix multiplication, and + represents matrix addition. This represents element-wise multiplication.
8. The lens defect detection method based on the spatial-frequency dual-domain hybrid target detection model as described in claim 1, characterized in that: The defect categories include seven types: dirt, scratches, white core, reddish discoloration, light ink, gaps, and black spots. The ROI region extraction involves cropping the lens image to extract the ROI region. The image sharpening process involves using an unsharpening mask method to sharpen the cropped lens image, resulting in a sharpened image. The unsharpening mask method is as follows: A 5×5 Gaussian kernel was used to perform low-pass filtering on the cropped lens image; The high-frequency components are obtained by subtracting the low-pass filtered lens image from the cropped lens image. The high-frequency components are multiplied by a preset enhancement factor and then superimposed onto the cropped lens image to form a sharpened image; The edge detection is specifically as follows: After converting the sharpened image to grayscale, the Scharr operator is used to extract edge features, obtaining the gradient in the x-direction and the gradient in the y-direction. The gradients in the x and y directions are converted to their absolute values, then linearly fused with equal weights and normalized to form the edge feature map.