Defect detection method, electronic equipment, storage medium and computer program product

By using a lightweight backbone network enhanced in the frequency domain and a hybrid encoder, combined with a high- and low-frequency attention module and a multi-scale feature adaptive fusion module, the accuracy and efficiency problems of multi-scale and micro-defect detection on the surface of mobile phone frames in existing technologies have been solved. This has enabled high-precision and low-complexity defect detection, meeting the needs of real-time industrial inspection.

CN121861019APending Publication Date: 2026-04-14SOUTH CHINA AGRICULTURAL UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-01-27
Publication Date
2026-04-14

AI Technical Summary

Technical Problem

Existing technologies are insufficient for efficiently detecting multi-scale and micro-defects on the surface of mobile phone frames, and deep learning models are inadequate in terms of accuracy and efficiency, failing to meet the quality inspection requirements of high-end manufacturing.

Method used

A lightweight backbone network with frequency domain enhancement and a hybrid encoder are used, combined with a high- and low-frequency attention module and a multi-scale feature adaptive fusion module to construct an object detection model. The model is then optimized through a specialized training strategy and loss function to achieve high-precision and efficient defect detection.

Benefits of technology

It significantly improves the detection accuracy and robustness of subtle defects, enabling stable detection in complex reflective and multi-scale scenarios, meeting the efficiency requirements of real-time industrial detection, and reducing the computational complexity and resource requirements of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121861019A_ABST
    Figure CN121861019A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a defect detection method and device, a medium and a program product. The method comprises the steps that a backbone network, a hybrid encoder and a decoder are utilized to construct a target detection model, the backbone network adopts a frequency domain enhanced lightweight backbone network and is used for extracting multi-level feature information from a training sample, the hybrid encoder comprises a high and low frequency attention module and a multi-scale feature adaptive fusion module, and the decoder comprises a high and low frequency attention module and a multi-scale feature adaptive fusion module; the decoder is used for performing frequency-attention enhancement and space-scale fusion on the feature information to generate high-level semantic features, and the decoder is used for restoring the high-level semantic features into category and position information of defects; training and optimizing the target detection model by using the training sample set to obtain a trained target detection model; and performing defect detection on a target object by using the target detection model. According to the embodiment of the invention, the detection precision and detection efficiency of fine defects can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the field of artificial intelligence technology, and in particular to a defect detection method, device, storage medium and computer program product. Background Technology

[0002] As a crucial component of a phone's structure, the surface defects of the phone's frame directly impact the product's appearance and quality. Current traditional inspection methods rely on manual visual inspection or fixed feature extraction, which are ill-suited for detecting multi-scale, minute defects. Existing deep learning models are mostly based on spatial domain features, lacking the ability to capture subtle defects, and their complexity makes it difficult to balance accuracy and efficiency. Summary of the Invention

[0003] The purpose of this invention is to provide a defect detection method, device, electronic device, and storage medium that can improve the detection accuracy of minute defects and ensure detection efficiency.

[0004] To address the aforementioned technical problems, embodiments of the present invention provide a defect detection method, comprising: A target detection model is constructed using a backbone network, a hybrid encoder, and a decoder. The backbone network is a lightweight backbone network with frequency domain enhancement, used to extract multi-level feature information from each training sample in the training sample set. The hybrid encoder includes a high- and low-frequency attention module and a multi-scale feature adaptive fusion module, used to perform frequency-attention enhancement and spatial-scale fusion on the multi-level feature information to generate high-level semantic features. The decoder is used to restore the high-level semantic features to the category and location information of the defect. The target detection model is trained and optimized using the training sample set to obtain a trained target detection model; The trained target detection model is used to detect defects in the target object, and the detection results containing the category and location information of the defects are obtained.

[0005] Embodiments of the present invention also provide an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the defect detection method described above.

[0006] Embodiments of the present invention also provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described defect detection method.

[0007] The present invention also provides a computer program product, characterized in that the computer program product includes a computer program or instructions, which are executed by a processor using the steps of the defect detection method as described in any one of claims 1 to 7.

[0008] In addition, the step of training and optimizing the target detection model using the training sample set to obtain a trained target detection model includes: Configure the AdamW optimizer, setting its weight decay coefficient, initial learning rate, and momentum parameter; Construct a combined loss function, which is a weighted combination of the focus loss function and the Dess loss function using adjustable weighting coefficients; The target detection model is iteratively trained using the training sample set until the model converges, and the weights of the model with the best performance on the validation set are saved to obtain the trained target detection model: The target detection model is forward-propagated using the training sample set, and the combined loss function value is calculated; and The AdamW optimizer is used to perform backpropagation and update the model parameters.

[0009] In addition, the iterative training of the target detection model using the training sample set includes: The object detection model is trained using a two-stage training strategy, wherein: The first stage freezes the parameters of the frequency domain-enhanced lightweight backbone network and optimizes the parameters of the high-efficiency hybrid encoder. The second stage involves unfreezing all model parameters of the target detection model and jointly optimizing the overall network parameters.

[0010] In addition, the high- and low-frequency attention module includes a high-frequency branch, a low-frequency branch, and a high- and low-frequency feature fusion submodule, wherein: The high-frequency branch is configured to use a local window self-attention mechanism to perform attention calculation on the multi-level feature information output by the backbone network within a non-overlapping 2×2 window. The low-frequency branch is configured to perform average pooling on the multi-level feature information output by the backbone network within a 4×4 window to obtain low-frequency features, and to use a global self-attention mechanism to calculate the low-frequency features. The high- and low-frequency feature fusion submodule is configured to perform weighted fusion of the output features of the high-frequency branch and the output features of the low-frequency branch according to an adjustable weight coefficient to obtain the fused features.

[0011] In addition, the multi-scale feature adaptive fusion module is configured as follows: Receive a first feature map and a second feature map from different depths of the backbone network, wherein the spatial resolution of the first feature map is higher than that of the second feature map; The first feature map and the second feature map are respectively input into the multi-scale dual attention mechanism module for key feature enhancement, resulting in the first enhanced feature and the second enhanced feature. The first enhanced feature is split into a first preserved branch and a first fused branch; The first fusion branch is concatenated with the second enhanced feature to obtain the concatenated feature; The spliced ​​features are then input again into the multi-scale dual attention mechanism module for cross-level feature enhancement to obtain enhanced features. The enhanced feature is split into a first enhanced branch and a second enhanced branch; The first reinforcement branch and the second reinforcement branch are respectively input into the adaptive weight allocation module to generate the corresponding first weight and second weight; The first reinforcement branch and the second reinforcement branch are weighted using the first weight and the second weight respectively to obtain the first weighted feature and the second weighted feature; The first weighted feature and the second weighted feature are added together to obtain the primary fused feature; The primary fusion features are additively fused with the features of the first retained branch and the second enhanced features to obtain the first output features and the second output features. The first output features and the second output features are then concatenated with the fused features output by the high- and low-frequency attention module to generate the advanced semantic features.

[0012] In addition, the method also includes: Capture the original image of the phone's mid-frame surface; In the original image, a target area of ​​a predetermined height is cropped with the phone's frame as the center. A sliding window segmentation strategy is used to segment the target region into multiple overlapping sub-images; The sub-images are subjected to hybrid data augmentation processing to obtain enhanced sample images; Defect annotations are performed on the enhanced sample images to form a training sample set.

[0013] In addition, the sliding window segmentation strategy is used to segment the target region into multiple overlapping sub-images, including: Set the window size and sliding step size of the sliding window, wherein the sliding step size is smaller than the window size; The sliding window is moved sequentially along the horizontal and vertical directions of the target region to segment multiple sub-images; The segmented sub-images are filtered for validity, retaining those containing valid target content, and the filtered sub-images are output as the multiple overlapping sub-images. In this embodiment, the low-frequency structural information and high-frequency detail features of the image are extracted by enhancing the backbone network in the frequency domain. Based on this, the high- and low-frequency attention module performs frequency-attention enhancement on the features, with its high-frequency branch focusing on local subtle defects and its low-frequency branch modeling the global structural context. The two are weighted and fused, enabling the model to adaptively distinguish multi-scale defects. The multi-scale feature adaptive fusion module performs spatial-scale fusion, progressively interacting and adaptively weighting the features at different levels of the backbone network to strengthen cross-scale semantic association and spatial context. The two models work together to significantly improve the detection robustness and localization accuracy of the model in complex reflection and multi-scale defect scenarios. Furthermore, a lightweight backbone network and a structured encoder-decoder design are adopted to effectively control the number of model parameters and computational complexity while ensuring feature extraction capabilities. The high- and low-frequency attention mechanism reduces the computational overhead of traditional global attention through parallel processing and windowed computation. The multi-scale fusion module adopts a progressive fusion strategy to avoid redundant calculations, enabling the entire model to maintain high accuracy while having a faster inference speed, meeting the stringent efficiency requirements of industrial real-time detection scenarios. Attached Figure Description

[0014] One or more embodiments of the present invention are illustrated by way of example with the corresponding images in the accompanying drawings. These illustrations do not constitute a limitation on the embodiments. Elements with the same reference numerals in the drawings are represented as similar elements. Unless otherwise stated, the figures in the drawings do not constitute a limitation on scale.

[0015] Figure 1 This is a schematic diagram illustrating the application environment of the defect detection method provided in some embodiments of this application; Figure 2 This is a schematic flowchart of a defect detection method provided in some embodiments of this application; Figure 3 This is a schematic diagram of the structure of a defect detection device provided in some embodiments of this application; Figure 4 This is a schematic diagram of the internal structure of an electronic device provided in some embodiments of this application. Detailed Implementation

[0016] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.

[0017] The terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or apparatuses.

[0018] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0019] The following describes the relevant content, concepts, meanings, technical issues, technical solutions, and beneficial effects involved in the embodiments of this application.

[0020] As a core load-bearing and connecting component in the structural system of modern smartphones, the mid-frame not only provides mechanical support for key components such as the display screen, motherboard, and battery, but also directly shapes the side profile and structural integrity of the phone's appearance. Its surface quality directly affects the overall aesthetics, user grip experience, long-term structural stability, and brand image. In high-end manufacturing, especially in consumer electronics, tolerance for appearance defects is extremely low. Even micron-level scratches, pitting, liquid stains, or dents can lead to customer complaints, after-sales repairs, or even batch quality incidents, causing significant economic and reputational losses.

[0021] Currently, in the actual production process of mobile phone frames, common defects mainly originate from multiple precision machining processes. For example, burrs, tool marks, or micro-cracks may be generated during CNC (Computer Numerical Control) cutting; sandblasting may result in residual sand particles or differences in uniformity; anodizing may cause color differences, spots, or uneven film due to electrolyte contamination or voltage fluctuations; and subsequent handling, assembly, and inspection processes may introduce external damage such as bumps and scratches. These defects often have characteristics such as multi-scale, low contrast, varied shapes, and mixing with background textures. Especially on highly reflective metal or plating surfaces, the visual signals of defects are often masked by strong specular reflection, complex textures, or ambient light interference, posing a severe challenge to stable and reliable automated inspection.

[0022] Traditional industrial vision inspection solutions primarily rely on manual visual inspection and rule-based traditional machine vision methods. Manual visual inspection depends on operators making judgments under specific lighting conditions using the naked eye or auxiliary magnification equipment. While manual inspection offers some adaptability and flexibility, its drawbacks are significant: low efficiency, high labor intensity, inconsistent subjective inspection standards, susceptibility to fatigue and emotional influences, and difficulty in consistently identifying minute defects. It suffers from consistently high false negative and false positive rates, failing to meet the demands of modern intelligent manufacturing for efficient, zero-defect quality control. Traditional machine vision methods typically employ fixed lighting schemes combined with algorithms such as edge detection, grayscale thresholding, template matching, or morphological operations, designed for specific defect types. These methods are effective in stable environments with simple defect types and high contrast, but their feature representation relies on manual design, resulting in poor generalization ability. They struggle to adapt to the diversity of defect morphologies, scale variations, and complex background interference, and are unable to handle new defect types introduced by new products and processes. Whenever the production line changes products or processes, the vision algorithm often needs to be redesigned or adjusted, leading to high development and maintenance costs.

[0023] In recent years, with the breakthroughs in deep learning technology in computer vision, especially the outstanding performance of convolutional neural networks (CNNs) in image classification, object detection, and semantic segmentation tasks, deep learning-based surface defect detection methods have gradually become a research and application hotspot. These methods automatically learn deep feature representations of defects through models driven by large amounts of labeled data, possessing stronger generalization ability and adaptability, and have demonstrated significant advantages in various industrial quality inspection scenarios. However, directly applying deep learning to high-precision, high-requirement surface defect detection, such as that of mobile phone mid-frames, still faces a series of key technical bottlenecks: 1. The limitations of spatial domain features in representing subtle defects.

[0024] Current mainstream deep learning detection models (such as Faster R-CNN, YOLO series, SSD, etc.) and their backbone networks (such as ResNet, VGG, MobileNet) primarily perform convolutional operations in the spatial domain, extracting texture, edge, and other features layer by layer through local receptive fields. For minute defects on the surface of a mobile phone frame (such as shallow scratches or tiny pits a few micrometers wide), their proportion at the pixel level is extremely low, resulting in weak differentiation from normal textures or noise. Spatial convolution easily loses these weak local detail signals during multiple downsampling processes, leading to the annihilation of semantic information about small target defects in the feature map. Although some works have enhanced detail perception by introducing attention mechanisms or feature pyramids, they fundamentally have not overcome the limitation of spatial domain analysis's insensitivity to high-frequency detail information. Defects, especially linear scratches or point-like flaws, often manifest as high-frequency components or local frequency domain anomalies in the frequency domain, which are difficult to effectively separate and enhance in spatial domain analysis.

[0025] 2. The challenge of fusing multi-scale defect detection.

[0026] The scale of defects in mobile phone frames varies greatly, ranging from tiny point imperfections of tens of micrometers to large blocky impacts of several millimeters. This necessitates that detection models possess efficient multi-scale feature fusion capabilities. Common Feature Pyramid Networks (FPNs) and their variants integrate features from different levels through top-down or bidirectional fusion paths. However, in practical applications, shallow features are rich in detail but weak in semantics, while deep features are semantically strong but have low spatial resolution. Simple addition or splicing operations can easily lead to loss of detail or semantic confusion during the fusion process, failing to achieve truly adaptive and complementary fusion. For reflective metallic surfaces, defects of different scales are intertwined with background noise, texture, and reflective patches, requiring models that can intelligently balance local details with global structure, suppress interference, and highlight true defect signals.

[0027] 3. The contradiction between model complexity and real-time requirements.

[0028] To achieve high-precision detection, especially in capturing minute defects, deeper networks, more complex modules, or higher input image resolution are often required, directly leading to a surge in model parameters and computational load. In industrial online inspection scenarios, detection speed (typically requiring the processing of tens or even hundreds of images per second) is a critical requirement. Many existing high-performance detection models struggle to meet real-time requirements on limited embedded or edge computing devices (such as industrial PCs and GPU edge boxes). How to achieve model lightweighting while maintaining or even improving accuracy is one of the core challenges that must be addressed for industrialization.

[0029] 4. Training challenges posed by imbalanced samples and diverse defect morphologies.

[0030] Industrial defect detection is essentially an extreme class imbalance problem: the number of normal samples far exceeds the number of defect samples, and within each defect sample, the number of different categories (scratches, dents, liquid stains, etc.) can vary greatly. This imbalance easily leads to overfitting of the model to the majority class (background) and underfitting of the minority class (especially rare defect types). Furthermore, the shape, size, orientation, and contrast of defects vary infinitely, and the limited training samples cannot cover all possibilities, posing a severe challenge to the model's generalization ability and robustness. Traditional cross-entropy loss functions perform poorly on such problems, necessitating the design of more reasonable loss functions and training strategies.

[0031] 5. Interference suppression under complex imaging conditions.

[0032] The diverse materials used for mobile phone frames (aluminum alloy, stainless steel, glass, ceramic composites, etc.) and the complex surface treatment processes (polishing, brushing, sandblasting, anodizing, coating, etc.) result in significant differences in their optical properties. Uniform and stable illumination is fundamental to visual inspection, but even with diffuse lighting solutions such as dome lights, it's difficult to completely eliminate false defect signals caused by localized reflections, specular highlights, or textures. The model must be able to learn to distinguish between real physical defects and these optical interferences during training, which places higher demands on data augmentation strategies and the model's feature discrimination capabilities.

[0033] 6. Insufficient integration of prior knowledge and domain characteristics.

[0034] Existing general-purpose object detection models are typically designed for natural scenes and do not fully consider the specific domain knowledge of industrial defect detection. For example, prior information such as the characteristic distribution of defects in the frequency domain, defect patterns that may be introduced by different processing techniques, and the correlation between defects and workpiece geometry, if effectively integrated into the model design, could guide the model to learn more efficiently and accurately. Combining mature ideas from traditional signal processing and machine vision fields, such as frequency domain analysis and multi-scale analysis, with the representation learning capabilities of deep learning is a promising technical path.

[0035] In conclusion, while deep learning has brought hope to automated defect detection, achieving high-precision, high-efficiency, and high-robust detection of multi-scale minute defects on the surface of mobile phone frames still requires innovative breakthroughs in multiple areas, including feature representation, multi-scale fusion, model efficiency, training strategies, and domain knowledge integration. Therefore, to find a better solution through network structure design, it is necessary to start from the essence of the problem, explore new feature spaces (such as the frequency domain) that go beyond pure spatial domain analysis, design more intelligent feature fusion and attention mechanisms, and construct corresponding efficient training and optimization methods. Ultimately, this will form a systematic solution to meet the increasingly stringent quality inspection requirements of the consumer electronics manufacturing industry.

[0036] Based on the above background, embodiments of this application provide a defect detection method, device, storage medium, and program product, which can improve the detection accuracy of minor defects and ensure detection efficiency.

[0037] To better understand the defect detection method, apparatus, electronic device, computer-readable storage medium, and computer program product provided in the embodiments of this application, the application environment applicable to the embodiments of this application is described below.

[0038] Please see Figure 1 , Figure 1This diagram illustrates an application environment for a defect detection method provided in an embodiment of this application. As one implementation, the defect detection method provided in this embodiment can be applied to an electronic device. This electronic device can be, for example,... Figure 1 The server 110 shown can be connected to the terminal device 120 via a network. The network serves as a medium for providing a communication link between the server 110 and the terminal device 120. The network can include various connection types, such as wired communication links, wireless communication links, etc., and this embodiment is not limited thereto. Optionally, in other embodiments, the electronic device can also be a smartphone, laptop, etc.

[0039] It should be understood that Figure 1 The server 110, network, and terminal device 120 shown are merely illustrative. Depending on the implementation requirements, any number of servers, networks, and terminal devices can be included. For example, server 110 can be a physical server or a server cluster consisting of multiple servers, and terminal device 120 can be a mobile phone, tablet, desktop computer, laptop computer, smart wearable device, etc. It is understood that embodiments of this application can also allow multiple terminal devices 120 to access server 110 simultaneously.

[0040] In some embodiments, the terminal device 120 can acquire an original defect image of the object to be detected, such as the surface of a mobile phone frame. Further, the terminal device 120 sends the original defect image to the server 110 via a network, and the server 110 performs a defect detection operation after receiving the original defect image.

[0041] As another implementation, the server 110 and the terminal device 120 described in this application embodiment can be integrated, such as the server 110 or the terminal device 120 directly acquiring the original defect image and performing defect detection operations based on the original defect image.

[0042] The defect detection method, apparatus, device, storage medium, and computer program product provided in this application are described in detail below with reference to the accompanying drawings. In this embodiment, server 110 is used as the execution subject. It should be noted that the order of description in the following embodiments is not intended to limit the preferred order of the embodiments. Although a logical order is shown in the flowcharts, in some cases, the steps shown or described may be performed in a different order than that shown in the accompanying drawings.

[0043] Figure 2 This is a flowchart illustrating a defect detection method provided in an embodiment of this application. In one embodiment of this application, the defect detection method may include steps S21 to S23, wherein: S21. A target detection model is constructed using a backbone network, a hybrid encoder, and a decoder. The backbone network is a lightweight backbone network with frequency domain enhancement, used to extract multi-level feature information from each training sample in the training sample set. The hybrid encoder includes a high- and low-frequency attention module and a multi-scale feature adaptive fusion module, used to perform frequency-attention enhancement and space-scale fusion on the multi-level feature information to generate high-level semantic features. The decoder is used to restore the high-level semantic features to the category and location information of the defect. S22. The target detection model is trained and optimized using the training sample set to obtain a trained target detection model; S23. Use the trained target detection model to perform defect detection on the target object and obtain the detection results containing the category and location information of the defect.

[0044] This application embodiment constructs a detection model consisting of three parts: 1. Lightweight backbone network with frequency domain enhancement: Unlike traditional convolutional networks that operate only in the spatial domain, this network extends its operations to the frequency domain by introducing the WTConv (Wavelet Transform Convolution) module and the CSP (CrossStage Partial Network) network structure. It performs multi-level wavelet decomposition and frequency domain convolution on each training sample in the training sample set to extract multi-level feature information containing different scale structures and details, such as low-frequency (overall structure) and high-frequency (fine texture) features of the image, laying the foundation for detecting multi-scale defects.

[0045] Specifically, in the embodiments of this application, the WTConv wavelet convolution module and the CSP network structure work together to form the core engine of the frequency domain-enhanced lightweight backbone network. The two have a clear division of labor and complement each other's advantages: The core function of the WTConv module is to achieve multi-scale feature extraction in the frequency domain. Traditional convolution operates only in the spatial domain and is insensitive to subtle, directional texture changes. WTConv decomposes the input features into the frequency domain by performing a two-dimensional wavelet transform, separating subbands carrying different information: Low-frequency components: capture smooth areas and main structural information of the image, corresponding to the overall shape of large-scale defects; Horizontal, vertical, and diagonal high-frequency components: capture edges, sharp changes, and texture details in different directions, corresponding to the fine features of small-scale defects such as micron-level scratches and pits.

[0046] Through multi-level decomposition, the WTConv module can construct a feature pyramid from coarse to fine. Each level further decomposes the low-frequency components of the previous level, thereby simultaneously resolving the image at multiple scales and enabling the network to inherently perceive defects of different sizes. The following depthwise separable convolution processing is applied to each frequency band component to selectively enhance or suppress information at specific frequencies, such as strengthening high-frequency components to highlight defect edges. Finally, inverse wavelet transform is used to reconstruct the spatial domain, forming a highly information-rich and structured feature map. .

[0047] in, This represents the wavelet transform operation. These are the original input features; Indicates the current decomposition level, indicating the th decomposition level. The low-frequency components of the layer, It contains the main structural information of the image, corresponding to large-scale defect features; They represent the first The high-frequency detail components in the horizontal, vertical, and diagonal directions of the layer correspond to edge and texture information in different directions, making it particularly suitable for capturing small-scale defect features.

[0048] The core function of the CSP network architecture is to optimize feature flow and network efficiency. The CSP architecture splits the feature flow in two. One part undergoes deep feature transformation through a backbone branch containing modules such as WTConv; the other part is directly passed through a lightweight shortcut. This design diverts the gradients during backpropagation, avoiding the problems of redundant gradient calculation and vanishing / exploding gradients in traditional deep networks, making networks containing complex WTConv modules easier to train, converge faster, and be more stable. At the end of the stage, the rich semantic features processed at depth are fused (usually concatenated) with the directly passed shallow detail features. This ensures that subsequent network layers can simultaneously utilize: multi-scale high-level semantics enhanced in the frequency domain from the WTConv module branch and raw spatial details from the shortcut that have not been overly abstracted. This fusion greatly enhances the representational power of the feature maps.

[0049] Since only a portion of the features require complex WTConv modules and convolutional calculations, while the rest are "shortcutted," the CSP structure can significantly reduce the total computational cost and memory usage in this stage. This is key to achieving a "lightweight" backbone network, enabling the model to run in real time on resource-constrained industrial equipment.

[0050] In this embodiment, the WTConv module provides high-quality multi-scale frequency domain features, while CSP provides an efficient and stable feature processing and transmission pipeline. Together, they enable the backbone network in this embodiment to produce high-quality features with extremely high information content and both global structure and microscopic details, with relatively low parameter count and computational overhead. This lays a solid foundation for the subsequent "frequency-attention enhancement" and "spatial-scale fusion" modules.

[0051] 2. Hybrid encoder containing two key modules: (1) High and low frequency attention module: "Frequency-attention enhancement" is performed on the features extracted by the backbone network. It processes the high-frequency and low-frequency components of the features in parallel, and uses local and global attention mechanisms respectively, so that the model can adaptively focus on the local details of the minor flaws and the global context of the overall defect.

[0052] (2) Multi-scale feature adaptive fusion module: performs "spatial-scale fusion" on features from different depths of the network. It intelligently fuses semantic information in feature maps of different resolutions through an adaptive weight allocation mechanism, strengthens key features, and improves the ability to represent multi-scale targets.

[0053] The two modules mentioned above can be used in parallel or as complementary modules to generate information-rich "high-level semantic features".

[0054] 3. Decoder: Decodes and restores the above high-level semantic features, and outputs the specific defect category and the precise location bounding box or segmentation mask.

[0055] After the above model is constructed, the embodiments of this application use specially designed training strategies (such as combined loss functions, two-stage training, see the description below) for training and optimization, and finally obtain the object detection model.

[0056] In this embodiment, frequency domain enhancement and high / low frequency attention mechanisms are employed to make the model highly sensitive to minute defects such as micron-level scratches and pitting. Simultaneously, multi-scale feature adaptive fusion ensures accurate identification of defects of different sizes, significantly reducing false negatives and false negatives. The model constructed by the method described in this embodiment effectively suppresses background interference such as metallic reflections and complex textures common in industrial scenarios, maintaining stable detection performance under varying lighting conditions. Furthermore, the lightweight backbone network and efficient attention design control computational complexity while ensuring high accuracy, which is beneficial for meeting the real-time detection needs of industrial production lines.

[0057] In one embodiment of this application, the method includes constructing a training sample set, comprising: Capture the original image of the phone's mid-frame surface; In the original image, a target area of ​​a predetermined height is cropped with the phone's frame as the center. A sliding window segmentation strategy is used to segment the target region into multiple overlapping sub-images; The sub-images are subjected to hybrid data augmentation processing to obtain enhanced sample images; Defect annotations are performed on the enhanced sample images to form a training sample set.

[0058] This application embodiment uses a 5-megapixel industrial camera and dome light source, among other professional equipment, to acquire high-resolution raw images segmented from key areas such as the long side, short side, and rounded corners of the phone's frame. This ensures coverage of all potential defect locations and obtains high-quality raw data with uniform illumination and low reflectivity. A rectangular area of ​​fixed height (e.g., 512 pixels) is cropped centered on the phone's frame. This step removes irrelevant background, focusing computational resources on the target object itself, significantly improving subsequent processing efficiency and reducing interference. Furthermore, since the phone's frame is a long, narrow object and the raw image resolution is high, directly inputting it into the network would result in loss of detail or an excessively large model size. This step uses a fixed window (e.g., 512x512) and a step size smaller than the window (e.g., 416) for sliding segmentation, generating a series of sub-images with overlapping regions. This overlap ensures that no defect will be cut off simply because it falls on the segmentation boundary, guaranteeing data integrity. Various enhancement transformations (e.g., rotation, flipping, brightness and contrast adjustment, noise addition, etc.) are applied to the segmented sub-images. This step aims to artificially expand the diversity and scale of the dataset to simulate various imaging variations that may be encountered in actual production, thereby greatly improving the model's generalization ability and robustness and avoiding overfitting. On the enhanced images, annotation tools are used to accurately mark the location (bounding boxes) and category of various defects (such as scratches and dents), forming the "standard answers" required for model training. This is crucial for supervised learning, providing the model with learning objectives.

[0059] In this embodiment, by "cropping the target region" and "sliding window segmentation," a high-resolution large image is transformed into a series of sub-images with prominent targets and standardized sizes, significantly improving the efficiency of data loading, training, and inference while ensuring the integrity of defect details. High-quality raw data acquisition and detailed annotation provide reliable learning materials for the model, which is a fundamental prerequisite for improving detection accuracy. "Hybrid data augmentation" acts like providing the model with "mock exams" in various complex scenarios, making it more stable in actual deployments when facing challenges such as changes in lighting and slight deformations.

[0060] The method of employing a sliding window segmentation strategy to segment the target region into multiple overlapping sub-images includes: Set the window size and sliding step size of the sliding window, wherein the sliding step size is smaller than the window size; The sliding window is moved sequentially along the horizontal and vertical directions of the target region to segment multiple sub-images; The segmented sub-images are filtered for validity, and the sub-images containing valid target content are retained. The filtered sub-images are then output as the multiple overlapping sub-images.

[0061] This application achieves efficient and lossless data preprocessing of a long, high-resolution image of an industrial component through the above embodiments. Its core is to transform a large image into a series of standard small blocks suitable for input to deep learning models through a systematic cropping strategy.

[0062] The solution involves the following three steps: When setting parameters for the overlapping window, two key parameters need to be specified: Window size: Defines the size of each sub-image (e.g., 512x512 pixels), which is typically matched to the fixed input size of the subsequent neural network.

[0063] Slide step size: Defines the distance the window moves each time. The key constraint is that "the slide step size is less than the window size," which ensures that there is an overlapping area between adjacent windows.

[0064] Furthermore, in this embodiment, the sliding segmentation is performed using the window size and sliding step size of the sliding window, much like using a fixed-size "viewfinder." Starting from the upper left corner of the target area, it first moves horizontally to the right with a set step size to segment a row of sub-images. After completion, it moves downward by one step size to segment the next row. This process is repeated until the entire target area is covered. Because the step size is smaller than the window size, adjacent sub-images will partially overlap in both the horizontal and vertical directions.

[0065] Not all segmented sub-images are valuable. In this embodiment, all sub-images are filtered to remove invalid sub-images that do not contain the target object (phone frame) or whose target area is too small or severely blurred. Only those sub-images that do contain valid detection content are retained as the final output.

[0066] Because the step size is smaller than the window size, any defect, regardless of its location within the target region, will fall completely within at least one sliding window, rather than being precisely cut in half by the window boundary. This ensures that no defect information is lost during the conversion from large to small images, laying a data foundation for subsequent high-precision detection. High-resolution, large-size original images (e.g., 2448x2048) are segmented into multiple standard-sized (e.g., 512x512) smaller images, allowing them to be directly input into modern deep learning models with fixed input requirements. This avoids the severe loss of detail caused by scaling the entire large image to the model size, and also avoids the enormous computational overhead of using ultra-large models. Furthermore, the overlapping segmentation strategy allows the same defect to appear in multiple adjacent sub-images, with only slight differences in context. This naturally increases the number and diversity of training samples without increasing the number of original images, contributing to improved model robustness.

[0067] In one embodiment of this application, training and optimizing the target detection model using the training sample set to obtain a trained target detection model includes: Configure the AdamW optimizer, setting its weight decay coefficient, initial learning rate, and momentum parameter; Construct a combined loss function, which is a weighted combination of the focus loss function and the Dess loss function using adjustable weighting coefficients; The target detection model is iteratively trained using the training sample set until the model converges, and the weights of the model with the best performance on the validation set are saved to obtain the trained target detection model: The target detection model is forward-propagated using the training sample set, and the combined loss function value is calculated; and The AdamW optimizer is used to perform backpropagation and update the model parameters.

[0068] The embodiments described above in this application construct a complete and automated model training closed loop, comprising three core parts: The AdamW optimizer is configured. Building upon the Adam optimizer, AdamW modifies the weight decay process, more effectively preventing overfitting and resulting in a model with stronger generalization capabilities. By setting the optimizer's weight decay coefficient, initial learning rate, and momentum parameter, the magnitude and direction of model parameter updates can be finely controlled, ensuring smooth and efficient convergence during training.

[0069] Furthermore, this application embodiment constructs a combined loss function: Focal Loss: This function specifically addresses the problem of extreme imbalance between the number of foreground (defect) and background (normal region) samples. By reducing the contribution of a large number of simple negative samples (background) to the total loss, it forces the model to focus more on learning samples that are difficult to classify (especially small, blurry defects), significantly improving the detection recall rate for sparse targets.

[0070] Dice Loss: Directly optimizes the overlap area between the predicted bounding box and the actual defect region. It is highly sensitive to small targets and can effectively improve the accuracy of defect localization, especially excelling at optimizing the fit of bounding boxes. In this embodiment, the expression of the combined loss function is: ,in This is the loss balance factor.

[0071] In this embodiment, the focus loss function and the Desce loss function are weighted by adjustable coefficients. This combination achieves complementary advantages. It enables the model to simultaneously achieve a balance between "finding defects" (high recall, driven by Focal Loss) and "identifying defects" (high precision, driven by Dice Loss).

[0072] Furthermore, the embodiments of this application execute the following iterative training process: forward propagation calculates the predicted value and loss → backpropagation calculates the gradient → optimizer updates the model parameters. In addition, the criteria for training termination and model selection in the embodiments of this application are not simply training until the loss no longer decreases, but rather continuously monitoring the performance of an independent validation set and saving the model weights that perform best on the validation set throughout the entire training process. This effectively avoids overfitting the model on the training set, ensuring that the final model possesses the strongest generalization ability.

[0073] In this embodiment, focus loss is used to strongly address sample imbalance, ensuring that minute defects are not submerged in a large number of normal samples. Dessian loss is used to finely adjust the localization, enabling the model to accurately outline defect boundaries. The combination of these two methods can solve the challenge of detecting "small, few, and difficult" defects in industrial inspection. Furthermore, the AdamW optimizer provides stable and fast convergence. Combined with a model saving strategy based on validation set performance, the peak point of generalization ability can be automatically found, avoiding undertraining or overfitting, and systematically ensuring the highest usability performance of the final output model.

[0074] Further, the iterative training of the target detection model using the training sample set includes: The object detection model is trained using a two-stage training strategy, wherein: The first stage freezes the parameters of the frequency domain-enhanced lightweight backbone network and optimizes the parameters of the high-efficiency hybrid encoder. The second stage involves unfreezing all model parameters of the target detection model and jointly optimizing the overall network parameters.

[0075] This application embodiment divides the model training process into two stages, each with different training objectives: The first stage involves "freezing" the parameters of the frequency-domain enhanced lightweight backbone network. This means that during training, the pre-trained weights (or initialized weights) in the backbone network remain unchanged and do not participate in gradient updates. The core task of this stage is to enable the hybrid encoder in the network (containing high- and low-frequency attention modules and multi-scale feature adaptive fusion modules) to quickly and stably learn how to understand the current specific defective data. By freezing the backbone network, training resources are concentrated on optimizing these new modules, preventing them from being interfered with by unstable features output by the untuned backbone network, and also avoiding the random initialization of new modules from destroying the general feature extraction capabilities already possessed by the backbone network.

[0076] The second stage involves "unfreezing" all model parameters, including all weights of the backbone network, the efficient hybrid encoder, and the decoder. In the first stage, the hybrid encoder has already adapted to the task. This stage performs end-to-end joint fine-tuning. At this point, the backbone network no longer simply provides a static feature; instead, it can co-evolve with the encoder and decoder according to the overall task objectives, dynamically adjusting its feature extraction method to better serve the final defect localization and classification. This allows feature extraction, feature enhancement, and feature decoding to achieve globally optimal coordination.

[0077] If all parameters are trained together from the outset, the powerful new modules with random initialization may generate drastic gradients, destroying the pre-trained, valuable general features in the backbone network (i.e., "catastrophic forgetting"). The two-stage strategy effectively isolates this risk, allowing for a smooth start to training. In the first stage, because the number of parameters to be optimized is significantly reduced (only the encoder), and the optimization objective is clear (learning to utilize backbone features), the encoder can converge to a reasonable state faster and more effectively. The backbone network (especially when based on a pre-trained model) provides general visual features. The first stage teaches the encoder to "call" these general features to solve defect problems. The second stage allows the backbone network to specifically "refine" these general features according to the specific needs of defect detection, thus forming more task-specific feature representations. The entire process is smooth and controllable. Through this "local first, global later" optimization sequence, the entire model ultimately achieves a higher peak performance than direct end-to-end training, fully utilizing both the prior knowledge of the backbone network and the innovative potential of the encoder, and achieving a perfect fit between the two through joint optimization, thereby achieving higher accuracy and robustness on complex defect detection tasks.

[0078] In one embodiment of this application, the high-low frequency attention module includes a high-frequency branch, a low-frequency branch, and a high-low frequency feature fusion submodule, wherein: The high-frequency branch is configured to use a local window self-attention mechanism to perform attention calculation on the multi-level feature information output by the backbone network within a non-overlapping 2×2 window. The low-frequency branch is configured to perform average pooling on the multi-level feature information output by the backbone network within a 4×4 window to obtain low-frequency features, and to use a global self-attention mechanism to calculate the low-frequency features. The high- and low-frequency feature fusion submodule is configured to weight and fuse the output features of the high-frequency branch and the output features of the low-frequency branch using adjustable weight coefficients to obtain the fused features. In this embodiment, features from the backbone network are processed through three parallel paths: High-frequency branch: Used to focus on microscopic details and capture minute imperfections. In the high-frequency branch, the input feature map is divided into non-overlapping 2×2 small windows, and self-attention computation is performed within each window. The extremely small 2×2 windows force the attention mechanism to focus only on extremely local neighborhoods. This design makes it naturally suitable for capturing pixel-level subtle changes, such as micron-level scratches, pitted edges, and textures. It ignores long-distance correlations and concentrates all computational resources on amplifying and enhancing local detail signals.

[0079] The low-frequency branch is used to model the macroscopic structure and understand the global context. In this branch, average pooling is first performed within a 4×4 window to downsample the features, filter out high-frequency noise and details, and extract low-frequency signals representing smooth areas and the main structure of the image. Then, global self-attention is applied to the pooled low-frequency features. Average pooling acts as "information condensation" and "noise reduction," yielding an overview of defects and the background. Based on this, global attention can establish relationships between distant regions in the image, such as understanding the relationship between a dent defect and the overall frame outline, or distinguishing between real defects and large reflective areas. This acts as a "wide-angle lens" for grasping the overall structure.

[0080] High- and low-frequency feature fusion submodule: Adaptive integration to form a unified representation. This submodule weights and sums the outputs of the two paths mentioned above—detail-rich high-frequency features and structure-rich low-frequency features—using an adjustable weight coefficient. This process is not a simple concatenation, but an adaptive fusion. This adjustable weight allows the network to dynamically decide whether to emphasize local details or global structure in the final feature based on the actual task requirements. This achieves information complementarity, forming an enhanced feature that is both "clear" and "comprehensive."

[0081] In one embodiment of this application, the weighting coefficient allocation ratio can be set to α=0.35, that is, 35% of the attention head is allocated to the low-frequency branch and 65% to the high-frequency branch, which enhances the feature capture of subtle defects and balances the modeling effect of local details and global structure. The adaptive fusion formula is as follows: , in, This indicates the output characteristics of the low-frequency branch. Indicates the output characteristics of high-frequency branches. These are adjustable weighting coefficients.

[0082] The high-frequency branch specifically tackles the challenge of detecting small-scale, low-contrast defects, while the low-frequency branch ensures that large-scale defects can be accurately identified and their relationship with the background can be understood. When combined, the model does not need to choose between the two, achieving robust cross-scale perception capabilities. This application's embodiment precisely allocates computational resources through "frequency division": expensive global computation is used only for the dimensionality-reduced low-frequency signal, while efficient local computation is used for high-frequency details. This significantly reduces the computational complexity of the attention mechanism while maintaining or even improving performance, achieving a balance between efficiency and accuracy. Furthermore, the global context modeling capability of the low-frequency branch helps the model distinguish local flicker (reflection) from real defects, as reflections often lack semantic association with the overall structure. The high-frequency branch accurately delineates the edges of defects, providing sub-pixel-level localization cues. The combination of these two significantly improves the detection signal-to-noise ratio and localization accuracy in noisy industrial scenarios.

[0083] Furthermore, the adjustable weight coefficients make the high- and low-frequency attention module an adaptive system. For datasets with different materials (e.g., matte vs. glossy) and different proportions of defect types, the network can automatically learn the optimal fusion ratio through training without manual redesign. This enhances the universality and transferability of the solution.

[0084] In one embodiment of this application, the multi-scale feature adaptive fusion module is configured as follows: Receive a first feature map and a second feature map from different depths of the backbone network, wherein the spatial resolution of the first feature map is higher than that of the second feature map; The first feature map and the second feature map are respectively input into the multi-scale dual attention mechanism module for key feature enhancement, resulting in the first enhanced feature and the second enhanced feature. The first enhanced feature is split into a first preserved branch and a first fused branch; The first fusion branch is concatenated with the second enhanced feature to obtain the concatenated feature; The spliced ​​features are then input again into the multi-scale dual attention mechanism module for cross-level feature enhancement to obtain enhanced features. The enhanced feature is split into a first enhanced branch and a second enhanced branch; The first reinforcement branch and the second reinforcement branch are respectively input into the adaptive weight allocation module to generate the corresponding first weight and second weight; The first reinforcement branch and the second reinforcement branch are weighted using the first weight and the second weight respectively to obtain the first weighted feature and the second weighted feature; The first weighted feature and the second weighted feature are added together to obtain the primary fused feature; The primary fusion features are additively fused with the features of the first retained branch and the second enhanced features to obtain the first output features and the second output features. The first output features and the second output features are then concatenated with the fused features output by the high- and low-frequency attention module to generate the advanced semantic features.

[0085] In this embodiment, the multi-scale feature adaptive fusion module adopts a progressive segmented fusion strategy, which includes three stages: individual enhancement, joint analysis, and adaptive fusion. It integrates multi-scale dual attention and coordinates channel attention and spatial attention to achieve feature weighted fusion.

[0086] Phase 1: Individual Enhancement and Cross-Level Interaction.

[0087] Input: Receive two feature maps from the shallow and deep layers of the backbone network (first feature map: high resolution, rich details; second feature map: low resolution, strong semantics).

[0088] Individual key feature enhancement: Initial enhancement is performed on both features using a "multi-scale dual attention mechanism (MSDA)". MSDA filters and enhances important information (such as defect regions) in each feature map from both channel and spatial dimensions, while suppressing irrelevant background.

[0089] Cross-level feature interaction and secondary reinforcement: The enhanced shallow feature (first enhancement feature) is split into a branch (first fusion branch) and concatenated with the deep feature (second enhancement feature). This concatenated feature contains both detailed and semantic information. Then, this feature, which integrates cross-level information, is fed back into MSDA for reinforcement. This step is crucial, as it forces the attention mechanism to work in a mixed information field, thereby learning the correlations between features at different scales and further reinforcing the cross-level cues related to defects.

[0090] Phase Two: Adaptive Weight Allocation and Weighting.

[0091] Splitting and Weight Learning: Split the features (enhanced features) after the above secondary enhancement back into two branches and input them into the "Adaptive Weight Distribution (AWD) module".

[0092] Generate adaptive weights: The AWD module learns a dynamic weight for each branch. This weight is not fixed but automatically generated based on the content of the current input features, quantifying the importance of that branch's features in the current fusion. For example, if the defects of the current sample mainly depend on details, the shallow feature branches may receive higher weights.

[0093] The internal processing flow of the AWD module is as follows: First, the number of channels of the feature is adjusted by 1×1 convolution. After normalization by BatchNorm and ReLU activation, the feature is transformed by 1×1 convolution. Finally, the weights of the two branches are generated by Softmax normalization. The two feature branches after splitting are multiplied by their corresponding weights to obtain the weighted features.

[0094] Phase 3: Gradual Integration and Information Retention.

[0095] Primary weighted fusion: The two branches are weighted using the learned weights and then summed to obtain the primary fused features. This is the first fusion, which embodies the idea of ​​adaptation.

[0096] Residual refusion and information feedback: The primary fusion features are additively fused with the first retained branch (the original enhanced shallow details) and the second enhanced feature (the original enhanced deep semantics). This is a residual connection concept. It ensures that after complex interactions and weighting, the original, important single-level features are not lost or over-distorted, while "injecting" new information learned from cross-level interactions back into each level.

[0097] Output the first output feature (shallow feature that incorporates cross-level information) and the second output feature (deep feature that incorporates cross-level information).

[0098] The third stage involves primary weighted fusion, which performs additive fusion on the two weighted feature branches. The fusion result is then added to the features of the two input feature maps that have been initially enhanced by Multi-Scale Dual Attention (MSDA). Finally, the results of these two additive fusions are concatenated to obtain the output features of the multi-scale feature adaptive fusion module. This achieves adaptive weighted fusion of features at different levels and enhancement of key information.

[0099] The multi-scale dual attention includes two branches: multi-scale channel attention and multi-scale spatial attention, which refine the features from the channel and spatial dimensions, respectively.

[0100] The multi-scale channel attention branch first processes the input features through Local Pooling, Max Pooling, and Avg Pooling to extract feature statistics under different receptive fields. These three pooling results are then concatenated and input into an MLP (Multilayer Perceptron) for feature transformation, and finally, a Sigmoid activation function is used to generate channel attention weights. The multi-scale spatial attention branch first performs Mean and Max operations on the input features along the channel dimension to obtain two single-channel feature maps. These maps are then concatenated and input into a 3×3 convolutional layer for feature extraction, and finally, a Sigmoid activation function is used to generate spatial attention weights.

[0101] Simultaneously, the input features are passed to the Initial Weight module, whose output is normalized by Softmax to obtain the fused weights for channel and spatial attention. and Ultimately, the module achieves this through learnable fusion weights. and The channel and spatial attention results are adaptively weighted and fused to obtain the enhanced feature output: ; in, Let be the learnable fusion coefficient for channel attention. Let be the learnable fusion coefficient for spatial attention. This indicates the channel attention result. This represents the spatial attention result. For input features, This represents element-wise multiplication. This is the enhanced feature output.

[0102] In this embodiment, the first output feature (a shallow feature that integrates cross-level information) and the second output feature (a deep feature that integrates cross-level information) are concatenated with the fused feature output by the high- and low-frequency attention module to generate high-level semantic features that are sent to the decoder. This completes the final convergence of the two major paths: spatial-scale fusion and frequency-attention enhancement.

[0103] Traditional fusion methods (such as stitching or simple addition) are "blind." This application's embodiments, through an AWD module, achieve adaptive weight allocation based on the input image content. The model dynamically determines "whether to trust shallow details or deep semantics more" during each inference, making the fusion strategy highly adaptable to specific defect instances, greatly improving the flexibility and effectiveness of the fusion. Through "stitching..." The "MSDA Secondary Enhancement" module forces deep mixing and co-analysis early in the feature interaction process. This allows shallow, detailed features to "understand" the deep semantic context before being fused, and vice versa. This early, attention-guided interaction establishes richer cross-scale semantic associations than late-stage simple fusion, which is crucial for understanding the "local texture of large defects" or the "global background of small defects." Furthermore, through the design of bifurcation (first preserved branch) and residual re-fusion, the module encourages feature interaction while perfectly preserving the detailed information of the original high-resolution features and the pure semantics of the low-resolution features. The output features contain both the new knowledge learned from cross-level interactions and retain the original advantages of each level, achieving a "1+1>2" effect.

[0104] It should be understood that although each step in the flowcharts of the embodiments described above is shown sequentially as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages in other steps.

[0105] Based on the same inventive concept, this application also provides a defect detection device for implementing the defect detection method described above. The solution provided by this device is similar to the solution described in the above method; therefore, specific limitations in the embodiments of one or more defect detection devices provided below can be found in the limitations of the defect detection method described above, and these specific limitations will not be repeated here.

[0106] The defect detection device provided in this embodiment can be integrated into a server. For example, such as... Figure 3As shown, the defect detection device may include: a model building module 31, used to build a target detection model using a backbone network, a hybrid encoder, and a decoder. The backbone network is a frequency-domain enhanced lightweight backbone network used to perform multi-level wavelet decomposition and frequency-domain convolution on each training sample in the training sample set to extract multi-level feature information containing different scale structures and details. The hybrid encoder includes a high- and low-frequency attention module and a multi-scale feature adaptive fusion module, used to perform frequency-attention enhancement and space-scale fusion on the multi-level feature information to generate high-level semantic features. The decoder is used to restore the high-level semantic features to the category and location information of the defect. A model training module 32 is used to train and optimize the target detection model using the training sample set to obtain a trained target detection model. A defect detection module 33 is used to perform defect detection on the target object using the trained target detection model and obtain detection results containing the category and location information of the defect.

[0107] In this embodiment, a frequency-domain enhanced backbone network is used to extract low-frequency structural information and high-frequency detail features from the image. Based on this, a high- and low-frequency attention module performs frequency-attention enhancement on the features, with its high-frequency branch focusing on local subtle defects and its low-frequency branch modeling the global structural context. The two are weighted and fused, enabling the model to adaptively distinguish multi-scale defects. A multi-scale feature adaptive fusion module performs spatial-scale fusion, progressively interacting and adaptively weighting features at different levels of the backbone network to strengthen cross-scale semantic associations and spatial context. The two models work synergistically, significantly improving the model's robustness and localization accuracy in complex reflective and multi-scale defect scenarios. Furthermore, a lightweight backbone network and a structured encoder-decoder design are adopted, effectively controlling the number of model parameters and computational complexity while ensuring feature extraction capabilities. The high- and low-frequency attention mechanism reduces the computational overhead of traditional global attention through parallel processing and windowed computation. The multi-scale fusion module employs a progressive fusion strategy to avoid redundant computation, enabling the entire model to maintain high accuracy while achieving faster inference speed, meeting the stringent efficiency requirements of industrial real-time detection scenarios.

[0108] Based on the same inventive concept, this application also provides an electronic device, which can be a server or a terminal device. The electronic device includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the steps of the aforementioned defect detection method. This enables various functions, such as: A target detection model is constructed using a backbone network, a hybrid encoder, and a decoder. The backbone network is a lightweight backbone network with frequency domain enhancement, used to perform multi-level wavelet decomposition and frequency domain convolution on each training sample in the training sample set to extract multi-level feature information containing different scale structures and details. The hybrid encoder includes a high- and low-frequency attention module and a multi-scale feature adaptive fusion module, used to perform frequency-attention enhancement and space-scale fusion on the multi-level feature information to generate high-level semantic features. The decoder is used to restore the high-level semantic features to the category and location information of defects. The target detection model is trained and optimized using the training sample set to obtain a trained target detection model; The trained target detection model is used to detect defects in the target object, and the detection results containing the category and location information of the defects are obtained.

[0109] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.

[0110] In one embodiment, taking a terminal device as an example, its internal structure diagram can be as follows: Figure 4 As shown, this electronic device includes a processor, memory, input / output interface, communication interface, display unit, and input device. The processor, memory, and input / output interface are connected via a system bus, and the communication interface, display unit, and input device are also connected to the system bus via the input / output interface. The processor provides computational and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage medium. The input / output interface is used for exchanging information between the processor and external devices. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, NFC (Near Field Communication), or other technologies. When the computer program is executed by the processor, it implements a defect detection method. The display unit of the electronic device is used to form a visually visible image. It can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be an LCD screen or an e-ink screen. The input device of the electronic device can be a touch layer covering the display screen, or buttons, trackballs, or touchpads set on the casing of the electronic device, or external keyboards, touchpads, or mice, etc.

[0111] Those skilled in the art will understand that Figure 4The structure shown is only a block diagram of a part of the structure related to the present application and does not constitute a limitation on the electronic device to which the present application is applied. The specific electronic device may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements.

[0112] Based on the same inventive concept, embodiments of this application also provide a computer-readable storage medium, which may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.

[0113] Since the computer program stored in the computer-readable storage medium can execute any of the defect detection methods provided in the embodiments of this application, it can achieve the beneficial effects that any of the defect detection methods provided in the embodiments of this application can achieve, as detailed in the preceding embodiments, and will not be repeated here.

[0114] Based on the same inventive concept, embodiments of this application also provide a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the electronic device to perform the methods provided in the various optional implementations of the above embodiments.

[0115] It should be noted that the object data (including but not limited to user device information, user personal information, etc.) and dialogue data involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of relevant countries and regions. Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods.

[0116] Any reference to memory, database, or other media used in the embodiments provided in this application may include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory may include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM may be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc.

[0117] The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based defect detection logic devices, etc., but are not limited to these.

[0118] In the above embodiments of the defect detection device, computer-readable storage medium, electronic device, and computer program product, the descriptions of each embodiment have different focuses. Parts not described in detail in a particular embodiment can be referred to in the relevant descriptions of other embodiments. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes and beneficial effects of the defect detection device, computer-readable storage medium, computer program product, electronic device, and their corresponding units described above can be referred to the description of the defect detection method in the above embodiments, and will not be repeated here.

[0119] The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as the combination of these technical features does not contradict each other, it should be considered within the scope of this specification. The above provides a detailed description of a defect detection method, apparatus, electronic device, computer-readable storage medium, and computer program product provided by the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The description of the above embodiments is only for the purpose of helping to understand the method and its core ideas. Furthermore, those skilled in the art will recognize that, based on the ideas of this application, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A defect detection method, characterized in that, The method includes: A target detection model is constructed using a backbone network, a hybrid encoder, and a decoder. The backbone network is a lightweight backbone network with frequency domain enhancement, used to perform multi-level wavelet decomposition and frequency domain convolution on each training sample in the training sample set to extract multi-level feature information containing different scale structures and details. The hybrid encoder includes a high- and low-frequency attention module and a multi-scale feature adaptive fusion module, used to perform frequency-attention enhancement and space-scale fusion on the multi-level feature information to generate high-level semantic features. The decoder is used to restore the high-level semantic features to the category and location information of defects. The target detection model is trained and optimized using the training sample set to obtain a trained target detection model; The trained target detection model is used to detect defects in the target object, and the detection results containing the category and location information of the defects are obtained.

2. The defect detection method according to claim 1, characterized in that, The step of training and optimizing the target detection model using the training sample set to obtain a trained target detection model includes: Configure the AdamW optimizer, setting its weight decay coefficient, initial learning rate, and momentum parameter; Construct a combined loss function, which is a weighted combination of the focus loss function and the Dess loss function using adjustable weighting coefficients; The target detection model is iteratively trained using the training sample set until the model converges, and the weights of the model with the best performance on the validation set are saved to obtain the trained target detection model: The target detection model is forward-propagated using the training sample set, and the combined loss function value is calculated; and The AdamW optimizer is used to perform backpropagation and update the model parameters.

3. The defect detection method according to claim 2, characterized in that, The iterative training of the target detection model using the training sample set includes: The object detection model is trained using a two-stage training strategy, wherein: The first stage freezes the parameters of the frequency domain-enhanced lightweight backbone network and optimizes the parameters of the high-efficiency hybrid encoder. The second stage involves unfreezing all model parameters of the target detection model and jointly optimizing the overall network parameters.

4. The defect detection method according to claim 1, characterized in that, The high- and low-frequency attention module includes a high-frequency branch, a low-frequency branch, and a high- and low-frequency feature fusion submodule, wherein: The high-frequency branch is configured to use a local window self-attention mechanism to perform attention calculation on the multi-level feature information output by the backbone network within a non-overlapping 2×2 window. The low-frequency branch is configured to perform average pooling on the multi-level feature information output by the backbone network within a 4×4 window to obtain low-frequency features, and to use a global self-attention mechanism to calculate the low-frequency features. The high- and low-frequency feature fusion submodule is configured to perform weighted fusion of the output features of the high-frequency branch and the output features of the low-frequency branch according to an adjustable weight coefficient to obtain the fused features.

5. The defect detection method according to claim 1, characterized in that, The multi-scale feature adaptive fusion module is configured as follows: Receive a first feature map and a second feature map from different depths of the backbone network, wherein the spatial resolution of the first feature map is higher than that of the second feature map; The first feature map and the second feature map are respectively input into the multi-scale dual attention mechanism module for key feature enhancement, resulting in the first enhanced feature and the second enhanced feature. The first enhanced feature is split into a first preserved branch and a first fused branch; The first fusion branch is concatenated with the second enhanced feature to obtain the concatenated feature; The spliced ​​features are then input again into the multi-scale dual attention mechanism module for cross-level feature enhancement to obtain enhanced features. The enhanced feature is split into a first enhanced branch and a second enhanced branch; The first reinforcement branch and the second reinforcement branch are respectively input into the adaptive weight allocation module to generate the corresponding first weight and second weight; The first reinforcement branch and the second reinforcement branch are weighted using the first weight and the second weight respectively to obtain the first weighted feature and the second weighted feature; The first weighted feature and the second weighted feature are added together to obtain the primary fused feature; The primary fusion features are additively fused with the features of the first retained branch and the second enhanced features to obtain the first output features and the second output features. The first output features and the second output features are then concatenated with the fused features output by the high- and low-frequency attention module to generate the advanced semantic features.

6. The defect detection method according to claim 1, characterized in that, The method further includes: Capture the original image of the phone's mid-frame surface; In the original image, a target area of ​​a predetermined height is cropped with the phone's frame as the center. A sliding window segmentation strategy is used to segment the target region into multiple overlapping sub-images; The sub-images are subjected to hybrid data augmentation processing to obtain enhanced sample images; Defect annotations are performed on the enhanced sample images to form a training sample set.

7. The defect detection method according to claim 6, characterized in that, The sliding window segmentation strategy is used to segment the target region into multiple overlapping sub-images, including: Set the window size and sliding step size of the sliding window, wherein the sliding step size is smaller than the window size; The sliding window is moved sequentially along the horizontal and vertical directions of the target region to segment multiple sub-images; The segmented sub-images are filtered for validity, and the sub-images containing valid target content are retained. The filtered sub-images are then output as the multiple overlapping sub-images.

8. An electronic device, characterized in that, include: At least one processor; as well as, A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the defect detection method as described in any one of claims 1 to 7.

9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the defect detection method according to any one of claims 1 to 7.

10. A computer program product, characterized in that, The computer program product includes a computer program or instructions, which are executed by a processor using the steps of the defect detection method as described in any one of claims 1 to 7.