An audio device housing unsupervised defect detection method and system

CN122928826APending Publication Date: 2026-10-16XI AN JIAOTONG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611158379.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-31
Publication Date
2026-10-16

AI Technical Summary

Technical Problem

[0013]本发明所要解决的技术问题在于针对上述现有技术中的不足,提供一种音频器件壳体无监督缺陷检测方法及系统,用于解决在缺陷样本稀缺且仅使用正常样本进行模型训练的条件下,现有无监督检测方法因音频器件壳体曲面光照不均、正常磨砂纹理干扰和缺陷尺度较小,导致微小缺陷特征在图像预处理及特征提取过程中容易丢失、正常区域容易被误判为异常,以及对丝印偏移、字符缺失等全局逻辑异常检测能力不足的技术问题

Benefits of technology

一种音频器件壳体无监督缺陷检测方法,通过依次设置图像预处理、无监督缺陷检测模型构建、正常样本训练以及异常图融合检测步骤,形成从输入图像标准化到缺陷区域输出的完整检测链路。其中,仿射校正和归一化互相关模板匹配能够减小工件姿态偏差及无效背景对正常特征学习的干扰;光照均衡、非锐化掩膜增强和面积插值降采样能够在抑制曲面光晕的同时保持微小划伤、尘点等高频异常信息;嵌入卷积块注意力模块的学生网络用于强化局部异常响应,采用均方误差—结构相似性联合损失的自编码器用于提高对丝印偏移、字符缺失等全局逻辑异常的敏感性。通过融合局部结构异常图和全局逻辑异常图,能够兼顾局部纹理异常与全局结构异常,并且仅使用正常样本即可完成模型训练,降低缺陷样本收集和标注成本。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122928826A_ABST
    Figure CN122928826A_ABST
Patent Text Reader

Abstract

The application discloses an audio device shell unsupervised defect detection method and system, belongs to the technical field of industrial machine vision and unsupervised deep learning, and the method carries out affine correction, normalization cross-correlation template matching, illumination equalization, non-sharpening enhancement and area interpolation down-sampling on the shell image; an improved EfficientAD model including a fixed teacher network, a student network embedded with a convolution block attention module and an autoencoder is constructed, only normal samples are used for training, and a mean square error-structural similarity joint loss is used to constrain the autoencoder; the local structure anomaly graph of the teacher-student network and the global logical anomaly graph of the autoencoder are fused to generate an anomaly heat map, and the defect contour, coordinates and area are extracted. The application can detect micro surface defects and silk printing logical anomalies, and reduce false positives caused by illumination and texture changes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the fields of industrial machine vision and unsupervised deep learning technology, specifically relating to an unsupervised defect detection method and system for audio device housings. It is used to learn the normal surface feature distribution based on normal audio device housing images, and to detect and locate defects such as dust spots, scratches, discoloration, silkscreen offset, missing silkscreen, and blurred silkscreen on the surface of audio device housings. Background Technology

[0002] As consumer electronics products trend towards miniaturization, precision, and integrated design, headphones, speakers, and other smart audio devices face higher demands for surface quality in their housings. Audio device housings are typically made of plastic, silicone, or metal composite materials, and undergo multiple processes including injection molding, surface coating, screen printing, assembly, and transportation. During these processes, factors such as raw material condition, fluctuations in process parameters, dust in the production environment, printing position deviations, and workpiece impacts can easily lead to defects on the housing surface, such as dust spots, scratches, discoloration, screen printing misalignment, missing characters, and blurred screen printing.

[0003] The aforementioned defects not only affect the appearance consistency of audio device housings and the clarity of product markings, but also, in some cases, scratches and coating damage, may adversely affect the housing's sealing performance, corrosion resistance, and service life. Therefore, rapid, stable, and accurate quality inspection of the housing surface is necessary during the audio device manufacturing process.

[0004] Current methods for inspecting the surface quality of audio device housings primarily rely on manual visual inspection, traditional non-destructive testing (NDT), or machine vision inspection. Manual visual inspection is susceptible to the influence of operator experience, fatigue, and subjective judgment, making it difficult to consistently identify small dust spots and shallow scratches that are close to the background color. Furthermore, its efficiency is ill-suited to the pace requirements of continuous production lines. Traditional inspection methods such as penetrant testing, eddy current testing, and X-ray inspection are typically designed for specific materials or types of structural defects, and are not readily applicable to stains, discoloration, and screen printing anomalies on non-metallic housing surfaces such as plastics and silicones. Additionally, some of these methods suffer from slow inspection speeds, high equipment costs, or inconvenience for online deployment.

[0005] Traditional machine vision inspection typically sets detection rules based on differences in grayscale, color, edges, or textures, relying on significant pixel differences between defects and the normal background for detection effectiveness. However, audio device housings often have curved structures and frosted surfaces, which are prone to center overexposure, edge underexposure, localized halos, and diffuse reflection variations under ring lighting or other industrial light sources. These lighting variations and normal frosted textures interfere with defect feature extraction, causing significant grayscale or texture differences in normal areas. Furthermore, defects such as dust spots and shallow scratches are small in size, occupy a low proportion of the overall image, and their colors are similar to the background, making them easily smoothed or lost during image cropping, scaling, and downsampling. Therefore, machine vision methods based on fixed thresholds or manually designed features are prone to missed detections and false positives.

[0006] Deep learning-based defect detection methods can automatically extract surface features from training data, reducing the difficulty of manually setting detection rules. Supervised defect detection methods typically require a large number of defect samples with accurate category labels or pixel-level annotations. However, in actual production, the number of normal products far exceeds the number of defective products, and the frequency, morphology, and location of different defects exhibit significant randomness. Some unknown defects are difficult to collect in advance, leading to difficulties in obtaining defect samples, high annotation costs, and the trained model may lack the ability to identify new types of defects not included in the training.

[0007] Unsupervised anomaly detection learns normal feature distributions using only normal samples, classifying areas deviating from the normal distribution as anomalies. This makes it more suitable for industrial inspection scenarios where defect samples are scarce. Existing unsupervised detection methods mainly include feature matching, image reconstruction, and knowledge distillation. For example, feature matching methods like PaDiM and PatchCore construct a feature library of normal samples for anomaly detection, but they typically require storing a large number of normal features, resulting in high memory consumption and computational overhead. Furthermore, their ability to detect global logical anomalies such as overall silkscreen offsets and missing characters is limited. Reconstruction methods based on autoencoders or generative models learn image reconstruction rules from normal samples, but they may reconstruct some anomalous regions along with them, or produce significant reconstruction differences due to lighting and texture variations, leading to missed weak defects or false positives for normal areas.

[0008] The EfficientAD model employs a parallel detection structure of teacher-student networks and autoencoders, enabling anomaly detection by utilizing feature differences and reconstruction differences separately, balancing detection accuracy and inference efficiency. However, directly applying the existing EfficientAD model to audio device housing detection still presents at least the following technical challenges: First, defects such as dust spots and shallow scratches on the surface of audio device housings are small in scale and similar in texture and color to the background. When the original high-resolution image is converted to the model input size, the edges and gray-scale abrupt changes of these tiny defects are easily weakened by interpolation operations. At the same time, existing student networks are not good at paying attention to local weak anomalies, and are prone to mistaking tiny defects for normal surface texture changes, resulting in missed detections.

[0009] Second, the uneven lighting, halos, shadows, and matte texture fluctuations produced by the curved surface of the shell are all normal phenomena, but these changes may manifest as significant differences in the feature space. Existing unsupervised detection models struggle to effectively distinguish between normal lighting and texture variations and real surface defects, easily generating abnormal responses in non-defect areas and increasing the false detection rate.

[0010] Third, defects such as silkscreen offset, missing characters, and incorrect pattern positioning mainly manifest as changes in global positional relationships or topology, while the texture of local pixels may still be the same as that of normal silkscreen areas. Existing teacher-student networks are limited by local receptive fields, making it difficult to make judgments based on the overall positional relationships of the silkscreen; the original autoencoder uses a single mean square error loss for training, which mainly reflects pixel-by-pixel numerical differences and is not sensitive enough to structural positional changes and spatial relationships, making it easy to miss global logical anomalies.

[0011] Fourth, existing methods typically address image illumination correction, minor defect enhancement, or model structure improvement separately, lacking a collaborative detection mechanism that integrates input image standardization, minor feature preservation, local anomaly enhancement, and global logic anomaly detection. This makes it difficult to simultaneously ensure the detection accuracy of minor surface defects and silkscreen logic anomalies when defect samples are scarce.

[0012] Therefore, there is a need to provide an unsupervised defect detection method suitable for audio device housings, which can reduce the impact of workpiece posture deviation, uneven surface illumination and normal texture changes on the detection results when trained using only normal samples, reduce the loss of minor defect information caused by image downsampling, and improve the model's comprehensive detection capability for local minor defects and global logical anomalies. Summary of the Invention

[0013] The technical problem to be solved by the present invention is to address the shortcomings of the prior art by providing an unsupervised defect detection method and system for audio device housings. This method addresses the technical problems of existing unsupervised detection methods, which, under the condition of scarce defect samples and model training using only normal samples, are prone to losing minute defect features during image preprocessing and feature extraction due to uneven lighting on the curved surface of the audio device housing, interference from normal matte textures, and small defect scale. These problems also result in normal areas being easily misjudged as abnormalities, and the method is insufficient in detecting global logical anomalies such as silkscreen offsets and missing characters.

[0014] The present invention adopts the following technical solution: An unsupervised defect detection method for audio device housings includes the following steps: S1. Obtain the original image of the audio device housing, perform geometric correction on the original image of the audio device housing, perform template matching according to the normalized cross-correlation algorithm, determine the matching coordinates corresponding to the maximum similarity, and crop the housing detection area according to the matching coordinates; perform illumination equalization, unsharpened mask enhancement and area interpolation downsampling on the housing detection area to obtain a standardized image; S2. Construct an improved EfficientAD unsupervised defect detection model, which includes a teacher-student network branch and an autoencoder branch. The teacher-student network branch includes a teacher network and a student network. The teacher network uses a pre-trained lightweight block description network (PDN) and maintains fixed weights during training. The student network uses the same PDN topology as the teacher network, and a convolutional block attention module is embedded after the fourth convolutional output of the student network. The autoencoder branch adopts an encoder-decoder structure. S3. The improved EfficientAD unsupervised defect detection model is trained using a standardized image of a normal audio device housing. The student network is updated based on the difference between the output features of the teacher network and the output features of the student network. The autoencoder branch is updated using the mean square error-structural similarity joint loss to obtain the trained improved EfficientAD unsupervised defect detection model. S4. After processing the image of the audio device housing to be detected according to step S1, input it into the trained improved EfficientAD unsupervised defect detection model. Calculate the difference between the output features of the teacher network and the output features of the student network to obtain a local structural anomaly map. Calculate the difference between the output features of the teacher network and the reconstructed features of the autoencoder branch outputs to obtain a global logical anomaly map. Perform weighted fusion and extreme value normalization on the local structural anomaly map and the global logical anomaly map to generate an anomaly heatmap, and determine the defect region based on the anomaly heatmap.

[0015] Further, in step S1, geometric correction is performed on the original image of the audio device housing, including: A draft image is obtained by performing a 5×5 median filter on the grayscale image of the original image of the audio device housing. The draft image is binarized, and morphological closing operations are performed on the binarized image using 15×15 rectangular structuring elements. Extract the outer contour of the image after morphological closing operation, filter the main contour of the shell with the largest area, and determine the image tilt angle based on the minimum bounding rectangle of the main contour of the shell. The tilt angle of the image is corrected, an affine transformation matrix is ​​constructed based on the corrected tilt angle, and the original image of the audio device housing is rotated and corrected using the affine transformation matrix.

[0016] Furthermore, template matching is performed based on the normalized cross-correlation algorithm, including: Obtain a reference template containing the complete outline of a normal audio device housing; The reference template is slid on the rotated and corrected image, and the normalized cross-correlation value between the image region corresponding to each sliding position and the reference template is calculated. Determine the matching coordinates corresponding to the maximum normalized cross-correlation value, and reserve a boundary around the area corresponding to the matching coordinates. Then, crop the housing detection area from the original image of the audio device housing after rotation correction.

[0017] Further, in step S1, illumination equalization is performed on the detection area of ​​the shell, including: The shell detection area is divided into 8×8 local sub-grids; The grayscale histograms of each local sub-grid are statistically analyzed. A truncation threshold of 1.5 is set. The frequency of grayscale levels exceeding the truncation threshold is truncated, and the remaining pixels generated by the truncation are redistributed to each grayscale level. Histogram equalization is performed on each local sub-grid, and bilinear interpolation is used to smooth the boundaries between adjacent local sub-grids to obtain the image after illumination equalization.

[0018] Further, the shell detection area is enhanced with an unsharpened mask and downsampled by area interpolation, including: A low-frequency blurred image is obtained by applying a Gaussian filter to the image after illumination equalization using a 15×15 Gaussian kernel. The image after illumination equalization is fused with the low-frequency blurred image using a weighted differential fusion method, where the weight of the image after illumination equalization is 1.5, to enhance the edge features of minor defects on the shell surface. The enhanced image was downsampled to 512×512 pixels using the INTER_AREA area interpolation method to obtain the standardized image.

[0019] Further, in step S2, the convolutional block attention module includes a channel attention submodule and a spatial attention submodule connected in sequence; The channel attention submodule is used to perform global average pooling and global max pooling on the input feature map respectively, input the pooling results into a shared multilayer perceptron, and perform element-wise summation and sigmoid activation on the features output by the shared multilayer perceptron to obtain channel attention weights; the channel attention weights are used to perform channel recalibration on the input feature map to obtain a channel-enhanced feature map; The spatial attention submodule is used to perform channel average pooling and channel max pooling on the channel enhanced feature map respectively, concatenate the pooling results, and perform convolution and sigmoid activation on the concatenated results to obtain spatial attention weights; and use the spatial attention weights to perform spatial recalibration on the channel enhanced feature map to obtain the enhanced feature map.

[0020] Furthermore, in step S2, the autoencoder branch includes an encoder and a decoder; The encoder is used to extract features and compress feature dimensions from the input standardized image through continuous stride convolution to obtain low-dimensional features. The decoder is used to decode the low-dimensional features through deconvolution to obtain reconstructed features with the same dimension as the output features of the teacher network.

[0021] Further, in step S3, the joint loss of mean square error and structural similarity is:

[0022] in, This represents the joint loss of mean square error and structural similarity. This represents the mean squared error loss between the teacher network output features and the reconstructed features. This represents the structural similarity loss between the teacher network output features and the reconstructed features. The weighting coefficient representing the structural similarity loss is λ, which is 0.1.

[0023] Further, in step S4, determining the defect region based on the abnormal thermal map includes: The abnormal heatmap is binarized and segmented using a classification threshold of 0.5 to obtain a binary map of the abnormal region. Extract the defect contour from the binary image of the abnormal region; The location coordinates and area of ​​the defect region in the image of the audio device housing to be tested are determined based on the defect contour.

[0024] Secondly, embodiments of the present invention provide an unsupervised defect detection system for audio device housings, comprising: The image preprocessing module is used to acquire the original image of the audio device housing, perform geometric correction on the original image of the audio device housing, perform template matching according to the normalized cross-correlation algorithm, crop out the housing detection area, and perform illumination equalization, unsharpened mask enhancement and area interpolation downsampling on the housing detection area to obtain a standardized image. The model building module is used to build an improved EfficientAD unsupervised defect detection model. The improved EfficientAD unsupervised defect detection model includes a teacher-student network branch and an autoencoder branch. The teacher-student network branch includes a teacher network that uses a pre-trained lightweight block description network (PDN) and a student network that uses the same PDN topology as the teacher network. The fourth convolutional output of the student network is followed by a convolutional block attention module. The autoencoder branch adopts an encoder-decoder structure. The model training module is used to train the improved EfficientAD unsupervised defect detection model using a standardized image of a normal audio device housing, update the student network based on the difference between the output features of the teacher network and the output features of the student network, and update the autoencoder branch using a mean squared error-structural similarity joint loss. The defect detection module is used to input the image of the housing of the audio device to be detected into the trained improved EfficientAD unsupervised defect detection model, generate a local structural anomaly map and a global logical anomaly map, perform weighted fusion and extreme value normalization on the local structural anomaly map and the global logical anomaly map to generate an anomaly heat map, and determine the defect region based on the anomaly heat map.

[0025] Thirdly, a computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the steps of the above-described unsupervised defect detection method for audio device housings.

[0026] Fourthly, embodiments of the present invention provide a computer-readable storage medium including a computer program, which, when executed by a processor, implements the steps of the above-described unsupervised defect detection method for audio device housings.

[0027] Fifthly, a chip includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the above-described unsupervised defect detection method for audio device housings.

[0028] In a sixth aspect, embodiments of the present invention provide an electronic device including a computer program, which, when executed by the electronic device, implements the steps of the above-described unsupervised defect detection method for audio device housings.

[0029] Compared with the prior art, the present invention has at least the following beneficial effects: An unsupervised defect detection method for audio device housings establishes a complete detection chain from input image standardization to defect region output by sequentially setting up image preprocessing, unsupervised defect detection model construction, normal sample training, and anomaly map fusion detection steps. Affine correction and normalized cross-correlation template matching reduce the interference of workpiece posture deviation and invalid background on normal feature learning; illumination equalization, unsharpened mask enhancement, and area interpolation downsampling suppress surface halos while preserving high-frequency anomaly information such as minor scratches and dust spots; a student network with embedded convolutional block attention modules enhances local anomaly responses; and an autoencoder using a mean squared error-structural similarity joint loss improves sensitivity to global logical anomalies such as silkscreen offsets and missing characters. By fusing local structural anomaly maps and global logical anomaly maps, both local texture anomalies and global structural anomalies can be considered, and model training can be completed using only normal samples, reducing the cost of defect sample collection and annotation.

[0030] Furthermore, geometric correction is performed using median filtering, binarization, morphological closing operations, principal contour extraction, minimum bounding rectangle, and affine transformation. Median filtering suppresses salt-and-pepper noise and surface texture burrs while preserving the shell contour edges; morphological closing operations fill in foreground breaks caused by screen printing, holes, etc., ensuring the continuity and integrity of the shell's principal contour; determining the tilt angle based on the minimum bounding rectangle of the maximum contour avoids the involvement of background supports and local textures in angle calculations. By performing affine rotation correction on the high-resolution original image, the shell posture in different samples can be kept consistent, providing stable input for subsequent teacher-student networks and autoencoders that rely on spatial feature alignment, and reducing the possibility of posture differences being misjudged as defects.

[0031] Furthermore, a normalized cross-correlation algorithm is employed for template matching, and the shell detection area is determined based on the maximum normalized cross-correlation value. The normalized cross-correlation algorithm normalizes the grayscale mean of the matching window and the template, offering better adaptability to overall brightness fluctuations and diffuse reflection variations on frosted surfaces compared to directly calculating the pixel squared difference. Cropping the shell detection area based on the maximum correlation position eliminates invalid background elements such as turntables, supports, and stray ambient light, reducing model computation. Reserving boundaries around the matching area prevents the cropping operation from missing defects such as scratches and dust spots located at the shell edges, thus balancing positioning accuracy and defect integrity.

[0032] Furthermore, the shell detection area is divided into 8×8 local sub-grids, and contrast-limited adaptive histogram equalization with a truncation threshold of 1.5 is applied. Independent equalization of local sub-grids adjusts the grayscale distribution according to the illumination intensity at different locations on the shell surface, improving issues such as center overexposure, edge underexposure, and localized halos. The truncation mechanism limits the mapping slope of the local histogram, preventing excessive amplification of sensor noise in solid color or matte areas. Bilinear interpolation smooths the grayscale transition between adjacent grids, avoiding blocky artifacts. This improves the local contrast between shallow scratches, discoloration, dust spots, and the background, and reduces false alarms caused by normal illumination differences.

[0033] Furthermore, a Gaussian filter is used to generate a low-frequency blurred image on the high-resolution shell detection area, and an unsharpened mask is used to enhance the high-frequency edge response of minor defects. A 15×15 Gaussian kernel can cover minute scratches or pits approximately 5 pixels wide, separating them from the low-frequency background. By assigning an enhancement weight of 1.5 to the original image, the gray-level abrupt change at the defect edges can be increased. Subsequently, the INTER_AREA area interpolation method is used to downsample to 512×512 pixels. This method can retain abnormal gray-level energy by utilizing a weighted average of the source image pixel regions. Compared to interpolation methods that only select local pixels, this reduces the risk of small defects being skipped or smoothly disappearing during large-scale scaling.

[0034] Furthermore, a channel attention submodule and a spatial attention submodule are sequentially connected in the student network. The channel attention submodule utilizes both global average pooling and global max pooling to acquire the overall distribution information of each feature channel while retaining significant response peaks caused by local defects. It also generates channel weights through a shared multilayer perceptron, thereby enhancing feature channels sensitive to edges, scratches, and surface roughness, and suppressing redundant channels that primarily respond to halos or background textures. The spatial attention submodule further identifies the key locations of anomalous features in the image space, strengthening the responses of local areas such as dust spots and fine scratches. This cascaded attention setup improves the student network's ability to represent features of minor defects with relatively few additional model parameters.

[0035] Furthermore, the spatial dimension of the input image is compressed through continuous stride convolution of the encoder, and reconstructed features consistent with the output dimension of the teacher network are generated through deconvolution of the decoder. The low-dimensional bottleneck structure forces the autoencoder to learn the macroscopic contours, silkscreen positions, and overall spatial topological relationships of a normal audio device casing, rather than simply copying local pixels. When the image to be detected has silkscreen offsets, missing characters, or incorrect pattern positions, the autoencoder tends to reconstruct features according to the spatial positions learned from normal samples, thus making the reconstructed features significantly different from the true features extracted by the teacher network. This is beneficial for identifying logical anomalies that only manifest as changes in global positional relationships.

[0036] Furthermore, the autoencoder is constrained by both mean squared error loss and structural similarity loss. Mean squared error loss maintains pixel-wise numerical consistency between the reconstructed features and the teacher network's output features, exhibiting high sensitivity to subtle grayscale differences. Structural similarity loss evaluates feature consistency from three aspects: brightness, contrast, and spatial structural relationships. It enhances the response to topological changes such as silkscreen offsets and missing characters, and reduces the impact of significant pixel differences caused by slight illumination fluctuations on the detection results. Setting the weight coefficient of structural similarity loss to 0.1 introduces structural constraints while maintaining pixel-level reconstruction accuracy, achieving a balance between local texture anomaly detection and global logical anomaly detection.

[0037] Furthermore, a classification threshold of 0.5 is used to binarize the anomaly heatmap, and defect contours, location coordinates, and areas are further extracted. Binarization converts continuous anomaly scores into clearly defined defect regions, facilitating the distinction between normal backgrounds and abnormal areas; contour extraction obtains the external boundaries of defects, reducing the dispersion of results caused by directly using pixel-level heatmaps; defect coordinates and areas provide quantitative basis for subsequent workpiece sorting, defect level judgment, and production process traceability, enabling the detection results to not only determine whether a workpiece is abnormal but also provide information on defect location and size.

[0038] It is understood that the beneficial effects of the second to sixth aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here.

[0039] In summary, this invention preserves minute defect information through affine correction, template matching, illumination equalization, and unsharpening enhancement. It utilizes a teacher-student network embedded with CBAM and MSE-SSIM joint loss to collaboratively detect local texture anomalies and global logic anomalies. It requires only normal sample training and balances detection accuracy, speed, and industrial deployment capabilities.

[0040] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description

[0041] Figure 1 This is a schematic diagram of the silkscreen defects on the housing of the audio device of the present invention, wherein (a) is a schematic diagram of silkscreen font offset, (b) is a schematic diagram of silkscreen pattern offset, and (c) is a schematic diagram of silkscreen blurring defects. Figure 2 This is a schematic diagram of surface defects of the audio device housing of the present invention, wherein (a) is a schematic diagram of scratch defects, (b) is a schematic diagram of discoloration defects, and (c) is a schematic diagram of dust spot defects; Figure 3 This is a schematic diagram illustrating the construction of the original dataset for this invention; Figure 4This is a flowchart of the image preprocessing for the audio device housing of the present invention; Figure 5 This is a schematic diagram of the morphological closing operation of the present invention; Figure 6 This is a schematic diagram of the tilt correction process of the audio device housing image of the present invention, wherein (a) is the original tilt image, (b) is the result of mid-range filtering and binarization processing in the draft image, (c) is the contour extraction result after closing operation, and (d) is the image after angle correction. Figure 7 This is a schematic diagram of template matching and shell detection area trimming of the present invention, wherein (a) is the reference template, (b) is the original template matching and positioning result, and (c) is the shell detection area trimming result; Figure 8 This is the grayscale histogram of the image after contrast-limited adaptive histogram equalization processing according to the present invention. Figure 9 The images show a comparison of the processing effects of different illumination equalization methods of the present invention. (a) is the original image, (b) is the global histogram equalization processing effect, (c) is the adaptive histogram equalization processing effect, and (d) is the contrast-limited adaptive histogram equalization processing effect. Figure 10 The image enhancement effect of the unsharpened mask of the present invention is shown in (a) and (b) is the original image of the shell detection area and the magnified image of the defect. Figure 11 This is a schematic diagram of the EfficientAD model of the present invention. Figure 12 This is a structural diagram of the convolutional block attention module of the present invention; Figure 13 This is a structural diagram of the channel attention submodule of the present invention; Figure 14 This is a structural diagram of the spatial attention submodule of the present invention; Figure 15 The structure diagram of the improved EfficientAD unsupervised defect detection model of this invention is shown below; Figure 16 This is a graph showing the decrease in training loss for different model modules of the present invention; Figure 17 The confusion matrix diagram of the improved EfficientAD unsupervised defect detection model of this invention; Figure 18 The following is a comparison of the heatmaps for defect detection in this invention: (a) is the original defect image, (b) is the abnormal heatmap of the baseline model, (c) is the abnormal heatmap of the improved EfficientAD model, and (d) is the defect detection result image. Figure 19A schematic diagram of a computer device provided in an embodiment of the present invention; Figure 20 This is a block diagram of a chip provided according to an embodiment of the present invention.

[0042] Among them, 60. Computer equipment; 61. Processor; 62. Memory; 63. Computer program; 600. Electronic device; 610. Processing unit; 620. Storage unit; 6201. Random access memory unit; 6202. Cache memory unit; 6203. Read-only memory unit; 6204. Program / utility; 6205. Program module; 630. Bus; 640. Display unit; 650. Input / output interface; 660. Network adapter; 700. External device. Detailed Implementation

[0043] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0044] In the description of this invention, it should be understood that the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.

[0045] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.

[0046] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes such combinations. For example, A and / or B can represent three cases: A alone, A and B simultaneously, and B alone. Additionally, the character " / " in this invention generally indicates that the preceding and following objects have an "or" relationship.

[0047] It should be understood that although terms such as first, second, third, etc., may be used in the embodiments of the present invention to describe the preset range, these preset ranges should not be limited to these terms. These terms are only used to distinguish the preset ranges from one another. For example, without departing from the scope of the embodiments of the present invention, the first preset range may also be referred to as the second preset range, and similarly, the second preset range may also be referred to as the first preset range.

[0048] Depending on the context, the word "if" as used here can be interpreted as "when," "when," "in response to determination," or "in response to detection." Similarly, depending on the context, the phrase "if determination" or "if detection (of the stated condition or event)" can be interpreted as "when determination," "in response to determination," "when detection (of the stated condition or event)," or "in response to detection (of the stated condition or event)."

[0049] The accompanying drawings illustrate various structural schematic diagrams according to embodiments disclosed in this invention. These drawings are not to scale, and some details have been enlarged for clarity, and some details may have been omitted. The shapes of the various regions and layers shown in the drawings, as well as their relative sizes and positional relationships, are merely exemplary and may deviate from reality due to manufacturing tolerances or technical limitations. Furthermore, those skilled in the art can design regions / layers with different shapes, sizes, and relative positions as needed.

[0050] This invention provides an unsupervised defect detection method for audio device housings. Addressing the problems of scarce defect samples, the ease with which minute defects are obscured by background textures, and the difficulty in identifying silkscreen logical anomalies, the method first achieves precise alignment of housing regions, equalized surface illumination, and preservation of minute defect features through affine correction, normalized cross-correlation template matching, contrast-limited adaptive histogram equalization, unsharpened mask enhancement, and area interpolation downsampling. This reduces false detections caused by pose, halo, and texture variations. Secondly, a convolutional block attention module is embedded in the student network to enhance responses to local anomalies such as dust spots and scratches from both channel and spatial dimensions. Simultaneously, a mean squared error-structural similarity joint loss is introduced into the autoencoder branch to improve sensitivity to global structural anomalies such as silkscreen offsets and missing characters. By fusing local structural anomaly maps and global logical anomaly maps, this invention can complete training using only normal samples, balancing detection accuracy, inference speed, and industrial deployment capabilities.

[0051] Audio device housings are mostly made of ABS plastic, silicone, and aluminum alloy composite materials, and are processed through multiple processes such as injection molding, surface spraying, screen printing, and edge grinding. Due to factors such as raw material purity, fluctuations in process parameters, interference from the production environment, human assembly errors, and transportation bumps, the housing surface is prone to four typical defects: dust spots, scratches, screen printing defects, and discoloration.

[0052] like Figure 1 As shown, screen printing defects manifest as character misalignment, blurring, or missing characters, which stem from uneven printing pressure and screen clogging, directly affecting the clarity of product markings.

[0053] like Figure 2 As shown, scratches are divided into perceptible scratches and non-perceptible scratches. The former are obvious in depth and have a rough feel, while the latter are micro-marks on the surface. Both are caused by workpiece bumps or excessive polishing, which can easily damage the protective surface coating. Discoloration refers to local color differences or stains, caused by uneven spraying thickness and color deviation, which reduces the uniformity of the product's appearance. Dust spots are tiny particles attached to the surface of the shell, mostly caused by dust in the spraying environment and impurities remaining in the mold. Although they do not affect performance, they damage the consistency of appearance.

[0054] The characteristics of various defects are shown in the table below:

[0055] To quantify the relative size of defects, the defect target percentage is defined as:

[0056] in, The percentage of defective targets. , These represent the width and height of the defect area in pixels, respectively. , This represents the total width and height of the image in pixels.

[0057] Taking a typical dust spot defect as an example, its pixel size is approximately 20×30, and the original image resolution is 4024×3036. Substituting these values ​​into the calculation, we get... The percentage is approximately 0.01%, far below the 1% threshold for small target identification. Based on the target size classification standard, over 90% of the defects in this embodiment fall into the category of small targets. The defect area has an extremely low pixel ratio, and its feature information is easily interfered with by background texture and halo.

[0058] like Figure 3 As shown, this embodiment uses a 4-station ring vision inspection hardware platform to acquire images of the audio device housing. The temperature of the image acquisition environment is 25±5℃, and the humidity is 40%~60%. An MV-CU120-10GC industrial camera, a VM1224MP12 fixed-focus lens, and an adjustable ring LED light source are used to acquire images of different key areas of the audio device housing by rotating a turntable.

[0059] In this embodiment, a total of 185 valid images were collected, including 111 images of good products and 74 images of various defects. The defect samples cover four typical defects: dust spots, scratches, silkscreen defects, and color differences. The image format is JPG, and the resolution is uniformly 4024×3036 pixels. 80% of the good product images are divided into the training set and 20% into the test set.

[0060] This invention discloses an unsupervised defect detection method for audio device housings, comprising the following steps: S1, Audio Device Housing Image Preprocessing The original image of the audio device housing is acquired, geometric correction is performed on the original image, template matching is performed according to the normalized cross-correlation algorithm, the matching coordinates corresponding to the maximum similarity are determined, and the housing detection area is cropped; illumination equalization, unsharpened mask enhancement and area interpolation downsampling are performed on the housing detection area to obtain a standardized image of 512×512 pixels.

[0061] The image preprocessing flow in this embodiment is as follows: Figure 4 As shown, it mainly includes geometric correction, shell detection area positioning, illumination equalization, defect feature enhancement, and area interpolation downsampling.

[0062] S101, Tilt Correction The original image contains invalid background elements such as the turntable, support, and ambient stray light. Furthermore, the turntable's start-stop inertia and positioning tolerances cause changes in the angle and position of the housing within the image. Since the knowledge distillation-based EfficientAD model relies on spatial feature alignment between normal samples, tilt correction is performed first.

[0063] To avoid damaging the fine scratches and dents in the high-resolution original image during contour calculations and other operations, this embodiment preserves both the draft image and the high-resolution original image. The draft image is used for median filtering, binarization, contour extraction, and tilt angle calculation, while the high-resolution original image is used for final rotation and cropping.

[0064] A 5×5 median filter is applied to the original grayscale image to obtain the draft image:

[0065] in, These are the pixel values ​​of the original grayscale image. It is a 5×5 circular neighborhood. These are the pixel values ​​of the filtered draft image.

[0066] The draft image is forward binarized using the significant grayscale difference between the white audio device casing and the black background, with the binarization threshold T set to 100.

[0067] Since screen printing and holes on the shell surface may cause fracture regions in the binary foreground, a 15×15 rectangular structuring element is used for morphological closing operations.

[0068] in, For binarized images, As a structural element, For expansion operations, For erosion calculation.

[0069] Extract the outer contour of the image after the closing operation, select the contour with the largest area as the main contour of the shell, and determine the original tilt angle based on the minimum bounding rectangle of the main contour of the shell. To ensure the corrected image is horizontally aligned, an adaptive angle correction is performed: when >45 At that time, the angle was corrected to 90 ;when < 45 At that time, the angle was corrected to +90 The remaining angles remain unchanged. Based on the corrected angles, an affine transformation matrix is ​​constructed, and rotation transformations are performed simultaneously on the high-resolution original image and the draft image to ensure geometric correction consistency. Affine transformations maintain the straightness and parallelism of lines within an image; their essence is a matrix operation combining coordinate rotation and origin translation. Let the physical coordinates of any pixel in the original acquired image be... The spatially corrected pixel coordinates of the target image are The equation of the affine inverse remapping matrix in homogeneous coordinates is shown below:

[0070] Where (x,y) represents the pixel coordinates of the original image, and (x′,y′) represents the pixel coordinates of the corrected image. To correct the rotation angle, , This represents the translation amount.

[0071] The affine transformation matrix is ​​used to simultaneously rotate the draft and the high-resolution original image. INTER_CUBIC bicubic interpolation is used for rotation interpolation to reduce jagged edges caused by rotation and maintain the continuity of defect edges. For example... Figure 6 As shown, the original tilted shell is adjusted to a horizontal orientation by means of median filtering and binarization, closing operation and contour extraction, and affine rotation.

[0072] S102, Normalized cross-correlation template matching and shell detection region trimming An image containing the complete outline of a white audio device housing was cropped from a standard good product image with uniform lighting and an absolutely horizontal orientation as a reference template. To suppress sensor thermal noise generated by long-term high-frequency triggering of the industrial camera, the reference template was first preprocessed with median filtering.

[0073] For any sliding window origin coordinate on the original image Its standard NCC response value The mathematical definition is as follows:

[0074] in, This is the rotated draft. For template image, and These are the average grayscale values ​​of the matching region and the template, respectively. ∈[0,1], the closer the value is to 1, the higher the matching degree.

[0075] The system iterates through the image to find the matching coordinates corresponding to the maximum response value, which are then used as the reference coordinates for locating the top-left corner of the audio device housing. To avoid losing edge defects during cropping, a certain number of pixels are reserved for the top, bottom, left, and right boundaries. Finally, the housing detection area is cropped from the rotated high-resolution original image.

[0076] like Figure 7 As shown, after template matching, invalid backgrounds such as turntables and supports can be removed, while minor defects and details such as scratches and dents are fully preserved.

[0077] S103, Contrast-limited adaptive histogram equalization processing The audio device housing has a non-standard freeform surface, which may cause overexposure at the center, underexposure at the edges, and localized halos when illuminated by a ring light source. Assume the total number of pixels in the image is... The kth gray level Frequency of occurrence Global histogram equalization maps the image based on the cumulative gray-level distribution function of the entire image:

[0078] Global histogram equalization may allocate too much grayscale mapping range to dark areas, causing saturation in bright areas; while adaptive histogram equalization can improve local contrast, it may amplify sensor noise in solid-color areas of the casing. Therefore, this embodiment employs a contrast-limited adaptive histogram equalization algorithm.

[0079] The shell detection area was divided into 8×8 local sub-grids. A gray-level histogram was calculated for each local sub-grid, and a truncation threshold of 1.5 was set. Gray-level frequencies exceeding the truncation threshold were truncated, and the resulting pixel counts were evenly redistributed to each gray level. After local equalization of each sub-grid, the gray-level mapping results of adjacent sub-grids were weighted using bilinear interpolation to eliminate blocky artifacts at grid boundaries.

[0080] Figure 8 The processed local grayscale histogram is shown. Figure 9 The processing effects of global histogram equalization, adaptive histogram equalization, and contrast-limited adaptive histogram equalization were compared. Figure 9 As can be seen, contrast-limited adaptive histogram equalization can make the transition between light and dark on the shell surface more uniform, suppress halo and noise amplification, and improve the contrast between shallow scratches and discolored areas and the background.

[0081] S104, Unsharpened Mask Enhancement and Area Interpolation Downsampling To prevent high-frequency information such as tiny scratches, dust spots, or dents from being smoothed when the high-resolution image is scaled to the model input size, an unsharpened mask enhancement is first performed on the high-resolution shell detection area.

[0082] Let the input original high-resolution ROI image be... First, use a standard deviation as The dimensions are Two-dimensional Gaussian smoothing kernel Spatial convolution filtering is applied to obtain a low-frequency blurred image with high-frequency details removed. :

[0083] in, The input is a high-resolution image of the shell detection region, G(x,y,σ) is a two-dimensional Gaussian smoothing kernel, and f_blur(x,y) is a low-frequency blurred image.

[0084] The high-frequency components are obtained by differentiating the original image from the low-frequency blurred image, and then the original image is enhanced.

[0085] For minute scratches that may be only about 5 pixels wide, a 15×15 Gaussian kernel is used, with α=2.5 and β= 1.5, γ=0, amplifies the defect features of the original image with high weight and suppresses low-frequency background.

[0086] After sharpening, the high-resolution image was downsampled to 512×512 pixels using INTER_AREA area interpolation. After downsampling, a slightly blurred image was generated using a 3×3 Gaussian kernel, with α=1.5 and β= A secondary light sharpening compensation of 0.5 is performed to restore the sharpness of defect edges while suppressing the amplification of salt-and-pepper noise and texture noise.

[0087] Figure 10 The image shows the original image of the shell detection area and the magnified results of the defect local area in the image after enhancement with an unsharpened mask. The preprocessing process removes more than 90% of redundant areas through affine transformation and normalized cross-correlation template matching, and uses contrast-limited adaptive histogram equalization to improve the contrast between the defect and the background by 3 times, and achieves a feature retention rate of more than 92% for 5-pixel-level micro-defects.

[0088] S2. Construction of an improved EfficientAD unsupervised defect detection model An improved EfficientAD unsupervised defect detection model is constructed. The model includes a teacher-student network branch and an autoencoder branch. The teacher-student network branch is used to detect local structural anomalies, and the autoencoder branch is used to detect global logical anomalies.

[0089] S201, EfficientAD Basic Model Supervised defect detection methods require a large number of labeled anomalous samples, making them unsuitable for production scenarios with low defect incidence and random defect types. Feature matching methods such as PaDiM and PatchCore require storing normal feature libraries, resulting in high memory consumption and slow inference speed. Reconstruction methods such as autoencoders and generative adversarial networks may reconstruct anomalous regions along with the defects, leading to missed detections of weak defects.

[0090] This embodiment uses EfficientAD as its base model, which detects anomalies in parallel through two mechanisms: knowledge distillation and feature reconstruction. For example... Figure 11 As shown, the EfficientAD model includes a teacher network, a student network, and an autoencoder.

[0091] The teacher network distills the knowledge of the pre-trained WideResNet-101 network into the lightweight block description network (PDN) in advance, and uses the PDN as the final teacher network. During the training and inference process of the audio device housing dataset, the weights of the teacher network remain fixed and do not participate in backpropagation.

[0092] The student network adopts the same lightweight PDN topology as the teacher network, with randomly initialized weight parameters, and mimics the feature output of the teacher network at the same spatial location when given a normal, high-quality image as input. The local structural anomaly score between the teacher and student networks is:

[0093] in, Output feature maps for the teacher network. Output feature maps for the student network; These represent the height and width of the feature map, respectively.

[0094] The student network is trained using only normal samples. When structural anomalies such as minor scratches or pits appear in the image to be detected, the student network cannot accurately predict the feature response at the corresponding location. A heatmap of local structural anomalies is generated by the difference between the features of the teacher network and the features of the student network.

[0095] An autoencoder consists of an encoder and a decoder. The encoder compresses the image into a low-dimensional feature vector through continuous stride convolutions, and the decoder reconstructs and maps it into a feature dimension aligned with the output of the teacher network.

[0096] The bottleneck layer of the autoencoder enables the network to learn the macroscopic global topology of the audio device casing and the absolute spatial coordinate patterns of the silkscreen. Spatial difference is then performed between the reconstructed features of the autoencoder and the true features extracted by the teacher network to obtain the global logical anomaly score.

[0097] S202, Convolutional Block Attention Module To improve the student network's ability to represent minor local defects such as dust spots and shallow scratches, a convolutional block attention module is embedded only after the fourth convolutional layer output of the student network, while the teacher network retains its original structure. For example... Figure 12 As shown, the convolutional block attention module includes a channel attention submodule and a spatial attention submodule connected in sequence.

[0098] like Figure 13 As shown, the channel attention submodule focuses on the input features. Global average pooling and global max pooling are performed separately. Global average pooling is used to characterize the overall response of each feature channel, while global max pooling is used to preserve the maximum response generated by local anomalies. The results of both pooling methods are input into a shared multilayer perceptron, and the outputs are summed element-wise before being input into a sigmoid activation function to obtain the channel attention weights.

[0099] in, This represents the Sigmoid activation function. and These are the learnable shared weight matrices for the dimensionality reduction and dimensionality increase layers in an MLP, respectively. The calculated channel weights With the original input feature tensor By performing element-wise multiplication along the channel dimension, the network can autonomously enhance key channels that are sensitive to frosted textures and edge contours, while suppressing redundant channels that only respond to halo noise, thereby obtaining transition feature maps that have undergone channel recalibration. .

[0100] like Figure 14 As shown, the transition feature map after channel recalibration by the spatial attention submodule. Average pooling and max pooling are performed along the channel direction respectively. The two 2D spatial feature maps are concatenated, and then convolutional and sigmoid activation is performed to generate spatial attention weights.

[0101] in, Indicates the filter kernel size is The convolution operation is performed. Finally, the spatial weight matrix is... With transition feature map Perform broadcast multiplication in spatial dimensions This completes the spatial dimension feature enhancement, and finally outputs the enhanced feature map:

[0102] The above processing can enhance the feature channels and spatial locations that have a high response to defect areas, and suppress redundant features that mainly respond to halos, shadows or frosted backgrounds.

[0103] Taking a medium-PDN student network as an example, such as Figure 15 As shown, a convolutional block attention module is set after the 512-channel features output by the fourth convolutional layer of the student network. After channel and spatial recalibration, the final features are output by the sixth convolutional layer. The teacher network maintains its original structure and does not embed the convolutional block attention module.

[0104] S203, Mean Squared Error - Structural Similarity Joint Loss While a single mean square error is sensitive to changes in pixel values, it has limited ability to perceive spatial structural changes such as overall silkscreen offset and may amplify numerous minute pixel differences caused by illumination fluctuations. Therefore, structural similarity loss is introduced.

[0105] An 11×11 Gaussian sliding window was used, with the standard deviation set to... =1.5 Local calculations are performed to avoid weakening of minute structural differences by global averaging. The structural similarity is:

[0106] in, , For teachers and local feature sub-blocks of the autoencoder; , The value is a Gaussian weighted average, representing brightness. , The weighted variance represents the contrast. The weighted covariance characterizes the spatial structural correlation. , SSIM is a regularization constant to prevent the denominator from being zero. SSIM takes values ​​of [0,1]. The smaller the value, the greater the structural difference. When the silkscreen offsets, the covariance drops sharply, which can accurately identify topological deviations.

[0107] Structural similarity loss is defined as:

[0108] The joint loss of the autoencoder branches is:

[0109] in, For pixel-level loss, The weighting coefficients are used to balance pixel matching and structural constraints. To scientifically determine the optimal weighting coefficients, this paper adopts a strategy of grid search combined with validation set tuning: the value range of λ is set to [0,1], the step size is 0.1, the model is trained sequentially, and its UROC and F1 scores on the validation set are recorded. Experimental results show that when λ=0.1, the model achieves the best balance in performance across various defects, with both UROC and F1 scores reaching their peak values. This coefficient retains the sensitivity of MSE to small pixel defects and enhances the perception of topological deviations through SSIM, complementing the CBAM attention mechanism and achieving collaborative detection of local texture anomalies and global logical anomalies.

[0110] Introducing joint loss significantly improves model performance. In logic anomaly detection, SSIM accurately captures structural fractures caused by silkscreen offsets, exhibiting a focused and sharp anomaly response. Under fluctuating lighting conditions, SSIM is insensitive to brightness changes, effectively suppressing false positives. The joint loss complements CBAM, constructing a detection mechanism adaptable to various types of defects in audio device housings, providing theoretical support for high-precision defect detection in industry.

[0111] S3, Model Training The EfficientAD unsupervised defect detection model is improved by training with standardized images of normal audio device housings. The student network is updated based on the difference between the output features of the teacher network and the output features of the student network, and the autoencoder branch is updated using the mean squared error-structural similarity joint loss.

[0112] The experimental hardware and software environment for this embodiment is shown in the table below.

[0113]

[0114] The training parameters are shown in the table below.

[0115]

[0116] During training, normal shell standardized images are sequentially input into the teacher network, student network, and autoencoder. The teacher network weights are fixed and do not participate in backpropagation; the student network weights are updated based on distillation loss, and the autoencoder weights are updated based on the mean squared error-structural similarity joint loss. The training process uses only normal audio device shell samples, without requiring defect category labels or defect region annotations.

[0117] The training loss function descent curve is as follows: Figure 16 As shown.

[0118] S4. Defect Detection and Post-processing of Results After processing the image of the housing of the audio device to be detected according to step S1, it is input into the trained improved EfficientAD unsupervised defect detection model to generate local structural anomaly maps and global logical anomaly maps, and an anomaly heatmap is generated.

[0119] Calculate the local structural anomaly scores for the teacher-student network branches respectively. Global logic exception score with autoencoder branch And perform weighted fusion according to the following formula:

[0120] Where α and β are the fusion weights of the local structural anomaly score and the global logical anomaly score, respectively.

[0121] The weighted fusion results are normalized to generate an anomaly heatmap; a classification threshold of 0.5 is used to perform binarization segmentation on the anomaly heatmap and mark the defect areas; the defect contours are extracted through image post-processing, and the defect coordinates and area are calculated.

[0122] In another embodiment of the present invention, an unsupervised defect detection system for audio device housings is provided. This system can be used to implement the above-mentioned unsupervised defect detection method for audio device housings. Specifically, the unsupervised defect detection system for audio device housings includes an image preprocessing module, a model building module, a model training module, and a defect detection module.

[0123] The image preprocessing module is used to acquire the original image of the audio device housing, perform geometric correction on the original image of the audio device housing, perform template matching according to the normalized cross-correlation algorithm, crop out the housing detection area, and perform illumination equalization, unsharpened mask enhancement and area interpolation downsampling on the housing detection area to obtain a standardized image. The model building module is used to build an improved EfficientAD unsupervised defect detection model. The improved EfficientAD unsupervised defect detection model includes a teacher-student network branch and an autoencoder branch. The teacher-student network branch includes a teacher network that uses a pre-trained lightweight block description network (PDN) and a student network that uses the same PDN topology as the teacher network. The fourth convolutional output of the student network is followed by a convolutional block attention module. The autoencoder branch adopts an encoder-decoder structure. The model training module is used to train the improved EfficientAD unsupervised defect detection model using a standardized image of a normal audio device housing, update the student network based on the difference between the output features of the teacher network and the output features of the student network, and update the autoencoder branch using a mean squared error-structural similarity joint loss. The defect detection module is used to input the image of the housing of the audio device to be detected into the trained improved EfficientAD unsupervised defect detection model, generate a local structural anomaly map and a global logical anomaly map, perform weighted fusion and extreme value normalization on the local structural anomaly map and the global logical anomaly map to generate an anomaly heat map, and determine the defect region based on the anomaly heat map.

[0124] This invention provides a terminal device comprising a processor and a memory. The memory stores a computer program, which includes program instructions. The processor executes the program instructions stored in the computer storage medium. The processor may be a Central Processing Unit (CPU), or other general-purpose processors, graphics processing units (GPUs), tensor processing units (TPUs), digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. It is the computing and control core of the terminal, suitable for implementing one or more instructions, specifically suitable for loading and executing one or more instructions to achieve a corresponding method flow or corresponding function. The processor described in this embodiment can be used in the operation of an unsupervised defect detection method for audio device housings, including: The process involves acquiring an original image of the audio device housing, performing geometric correction on the original image, performing template matching based on a normalized cross-correlation algorithm to determine the matching coordinates corresponding to the maximum similarity, and cropping the housing detection region based on these matching coordinates. The housing detection region is then subjected to illumination equalization, unsharpened mask enhancement, and area interpolation downsampling to obtain a standardized image. An improved EfficientAD unsupervised defect detection model is constructed, comprising a teacher-student network branch and an autoencoder branch. The teacher-student network branch includes a teacher network and a student network. The teacher network uses a pre-trained lightweight block description network (PDN) with fixed weights during training. The student network uses the same PDN topology as the teacher network, and a convolutional block attention module is embedded after the fourth convolutional layer output. The autoencoder branch employs an encoder-decoder structure. Normal audio is used. The improved EfficientAD unsupervised defect detection model is trained using a standardized image of the device housing. The student network is updated based on the difference between the output features of the teacher network and the output features of the student network, and the autoencoder branch is updated using a mean squared error-structural similarity joint loss, resulting in a trained improved EfficientAD unsupervised defect detection model. The image of the audio device housing to be detected is standardized and then input into the trained improved EfficientAD unsupervised defect detection model. The difference between the output features of the teacher network and the output features of the student network is calculated to obtain a local structural anomaly map. The difference between the output features of the teacher network and the reconstructed features output by the autoencoder branch is calculated to obtain a global logical anomaly map. The local structural anomaly map and the global logical anomaly map are weighted, fused, and normalized to generate an anomaly heatmap. Defect regions are determined based on the anomaly heatmap.

[0125] Please see Figure 19 The terminal device is a computer device. In this embodiment, the computer device 60 includes a processor 61, a memory 62, and a computer program 63 stored in the memory 62 and executable on the processor 61. When executed by the processor 61, the computer program 63 implements the unsupervised defect detection method for audio device housings in this embodiment. To avoid repetition, these details are not elaborated here. Alternatively, when executed by the processor 61, the computer program 63 implements the functions of each model / unit in the unsupervised defect detection system for audio device housings in this embodiment. To avoid repetition, these details are not elaborated here.

[0126] Computer device 60 can be a desktop computer, laptop, handheld computer, cloud server, or other computing device. Computer device 60 may include, but is not limited to, a processor 61 and a memory 62. Those skilled in the art will understand that... Figure 19This is merely an example of computer device 60 and does not constitute a limitation on computer device 60. It may include more or fewer components than shown, or combine certain components, or different components. For example, computer device may also include input / output devices, network access devices, buses, etc.

[0127] The processor 61 may be a Central Processing Unit (CPU), or other general-purpose processors, graphics processing units (GPUs), tensor processing units (TPUs), digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.

[0128] The memory 62 can be an internal storage unit of the computer device 60, such as a hard disk or memory of the computer device 60. The memory 62 can also be an external storage device of the computer device 60, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc. equipped on the computer device 60.

[0129] Furthermore, the memory 62 may include both internal storage units of the computer device 60 and external storage devices. The memory 62 is used to store computer programs and other programs and data required by the computer device. The memory 62 can also be used to temporarily store data that has been output or will be output.

[0130] Please see Figure 20 The terminal device is an electronic device 600, which is manifested in the form of a general-purpose computing device. The components of the electronic device may include, but are not limited to: at least one processing unit 610, at least one storage unit 620, a bus 630 connecting different platform components (including storage unit 620 and processing unit 610), a display unit 640, etc.

[0131] The storage unit stores program code, which can be executed by the processing unit 610 to perform the steps described in the method section of this specification according to various exemplary embodiments of the present invention. For example, the processing unit 610 can perform actions such as... Figure 1 The steps are shown in the figure.

[0132] Storage unit 620 may include readable media in the form of volatile storage units, such as random access memory (RAM) 6201 and / or cache memory 6202, and may further include read-only memory (ROM) 6203.

[0133] Storage unit 620 may also include a program / utility 6204 having a set (at least one) program module 6205, such program module 6205 including but not limited to: operating system, one or more application programs, other program modules and program data, each or some combination of these examples may include an implementation of a network environment.

[0134] Bus 630 can represent one or more of several types of bus structures, including a memory cell bus or memory cell controller, a peripheral bus, a graphics acceleration port, a processing unit, or a local bus using any of the multiple bus structures.

[0135] Electronic device 600 can also communicate with one or more external devices 700 (e.g., keyboard, pointing device, Bluetooth device, etc.), and with one or more devices that enable a user to interact with electronic device 600, and / or with any device that enables electronic device 600 to communicate with one or more other computing devices (e.g., router, modem). This communication can be performed via input / output interface 650. Furthermore, electronic device 600 can also communicate with one or more networks (e.g., local area network, wide area network, and / or public network, such as the Internet) via network adapter 660. Network adapter 660 can communicate with other modules of electronic device 600 via bus 630. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with electronic device 600, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage platforms.

[0136] This invention also provides a storage medium, specifically a computer-readable storage medium, which is a memory device in a terminal device for storing programs and data. It is understood that the computer-readable storage medium here can include both built-in storage media in the terminal device and extended storage media supported by the terminal device; it can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. The computer-readable storage medium provides storage space that stores the terminal's operating system. Furthermore, the storage space also stores one or more instructions suitable for loading and execution by a processor, which can be one or more computer programs (including program code). More specific examples of the computer-readable storage medium include: an electrical connection with one or more wires, a portable disk, a hard disk, random access memory, read-only memory, erasable programmable read-only memory, optical fiber, portable compact disk read-only memory, optical storage device, magnetic storage device, or any suitable combination thereof.

[0137] Computer-readable storage media also include data signals propagated in baseband or as part of a carrier wave, carrying readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable storage medium can also be any readable medium other than a readable storage medium that can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the readable storage medium can be transmitted using any suitable medium, including but not limited to wireless, wired, optical fiber, radio frequency, etc., or any suitable combination thereof.

[0138] Program code for performing the operations of this invention can be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java and C++, and conventional procedural programming languages ​​such as C or similar languages. The program code can execute entirely on the user's computing device, partially on the user's device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).

[0139] One or more instructions stored in a computer-readable storage medium can be loaded and executed by a processor to implement the corresponding steps of the unsupervised defect detection method for audio device housings in the above embodiments; one or more instructions in the computer-readable storage medium are loaded and executed by the processor to perform the following steps: The process involves acquiring an original image of the audio device housing, performing geometric correction on the original image, performing template matching based on a normalized cross-correlation algorithm to determine the matching coordinates corresponding to the maximum similarity, and cropping the housing detection region based on these matching coordinates. The housing detection region is then subjected to illumination equalization, unsharpened mask enhancement, and area interpolation downsampling to obtain a standardized image. An improved EfficientAD unsupervised defect detection model is constructed, comprising a teacher-student network branch and an autoencoder branch. The teacher-student network branch includes a teacher network and a student network. The teacher network uses a pre-trained lightweight block description network (PDN) with fixed weights during training. The student network uses the same PDN topology as the teacher network, and a convolutional block attention module is embedded after the fourth convolutional layer output. The autoencoder branch employs an encoder-decoder structure. Normal audio is used. The improved EfficientAD unsupervised defect detection model is trained using a standardized image of the device housing. The student network is updated based on the difference between the output features of the teacher network and the output features of the student network, and the autoencoder branch is updated using a mean squared error-structural similarity joint loss, resulting in a trained improved EfficientAD unsupervised defect detection model. The image of the audio device housing to be detected is standardized and then input into the trained improved EfficientAD unsupervised defect detection model. The difference between the output features of the teacher network and the output features of the student network is calculated to obtain a local structural anomaly map. The difference between the output features of the teacher network and the reconstructed features output by the autoencoder branch is calculated to obtain a global logical anomaly map. The local structural anomaly map and the global logical anomaly map are weighted, fused, and normalized to generate an anomaly heatmap. Defect regions are determined based on the anomaly heatmap.

[0140] 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 data processing logic devices, etc., and are not limited to these.

[0141] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without inventive effort are within the scope of protection of the present invention.

[0142] Evaluation of test results Based on the true labels and prediction results, the detected samples are divided into true positives (TP), false positives (FP), true negatives (TN), and false negatives (FN). Precision, recall, and F1 score are as follows:

[0143]

[0144]

[0145] Meanwhile, the area under the receiver operating characteristic curve (AUROC) is used to evaluate the model's ability to distinguish between normal and defective samples, and frames per second (FPS) is used to evaluate inference speed.

[0146] To verify the effects of the convolutional block attention module and structural similarity loss, four ablation experiments were set up: the original EfficientAD, only CBAM embedded, only SSIM loss introduced, and both CBAM and SSIM loss are embedded. The results are shown in the table below.

[0147]

[0148] Experimental results show that, compared with the baseline model, embedding only CBAM attention improves AUROC by 2.03%, proving that the attention mechanism can strengthen the weight of defect features and suppress background interference such as frosted texture, effectively improving the detection capability of small defects; introducing only SSIM joint loss improves AUROC by 1.91%, indicating that structural loss can capture logical anomalies such as silkscreen offset and reduce false positives caused by illumination fluctuations; when the two modules work together, AUROC is 94.99%, F1 score is 0.9289, and FPS is 22.50.

[0149] like Figure 17As shown, the vertical axis of the confusion matrix represents the true class label, the horizontal axis represents the predicted class, the main diagonal represents the number of correctly predicted samples, and the off-diagonal represents the number of misclassified and missed samples. In the test samples that were actually defective products, the model correctly identified 98 defective samples and misclassified 7 defective samples as good products.

[0150] like Figure 18 As shown, four typical defects—dust spots, discoloration, silkscreen printing, and scratches—were selected for anomaly heatmap comparison. The baseline model was found to be insufficient in detecting minute defects and easily affected by background interference. The improved model, on the other hand, provided a more comprehensive anomaly response and was able to locate the defect area.

[0151] Continuous detection experiment

[0152] Performance testing involved randomly selecting approximately 100 audio device housings for continuous inspection. Results showed that the entire inspection process for a single workpiece took 9.8 seconds, with an average system accuracy of 93.0% and a defect detection rate exceeding 90% for all types of defects. The model inference frame rate was 22.50 FPS, and the AUROC was 94.99%. The silkscreen defect detection rate was 100%, and the scratch defect detection rate was 95.5%.

[0153] To verify the application effect of this invention in the surface quality inspection of audio device housings, a 4-station ring vision inspection platform was used for image acquisition. The experimental environment temperature was controlled at 25±5℃, and the relative humidity was 40%~60%. An MV-CU120-10GC industrial camera, a VM1224MP12 fixed-focus lens, and an adjustable ring LED light source were used to acquire images of different surfaces of the audio device housing by rotating the turntable.

[0154] This example collected 185 valid images, including 111 images of normal audio device housings and 74 defect images. Defect types included dust spots, scratches, discoloration, silkscreen misalignment, missing silkscreen, and blurred silkscreen. The original image resolution was 4024×3036 pixels. 80% of the normal images were used as the training set, and the remaining normal and defect images were used for testing. During model training, only normal samples were used; defect category or defect region annotations were not employed to simulate the scarcity of defect samples in actual production.

[0155] First, the original image undergoes 5×5 median filtering, contour extraction, and affine correction. The shell detection region is then determined using normalized cross-correlation template matching. The detection region is divided into 8×8 sub-grids, and contrast-limited adaptive histogram equalization with a truncation threshold of 1.5 is used to suppress surface halos. Next, a 15×15 Gaussian kernel is used to construct an unsharpened mask, and the image is downsampled to 512×512 pixels using INTER_AREA area interpolation. After this preprocessing, the feature retention rate of 5-pixel-level micro-defects reaches over 92%, indicating that this processing procedure can reduce the loss of fine defect information caused by large-scale scaling.

[0156] Subsequently, the improved EfficientAD model was trained. The teacher network used a lightweight block description network (PDN) with fixed weights, and the student network embedded a convolutional block attention module after the output of the fourth convolutional layer. The autoencoder used a joint loss of mean squared error and structural similarity. Training was performed using the Adam optimizer with a base learning rate of 0.0001, a batch size of 1, 100 training epochs, and a weight coefficient of 0.1 for the structural similarity loss.

[0157] To verify the effectiveness of each improvement method, four ablation experiments were conducted. The original EfficientAD model achieved an AUROC of 93.05% and an F1 score of 0.9209. When only the convolutional block attention module was used, the AUROC increased to 95.08% and the recall increased to 0.9810, indicating that channel attention and spatial attention can enhance the response to small defect regions. When only structural similarity loss was used, the AUROC was 94.96% and the precision was 0.9065, indicating that structural constraints can improve the model's ability to recognize changes in silkscreen position and missing characters. When both the convolutional block attention module and structural similarity loss were used, the F1 score reached 0.9289, the precision was 0.9245, and the recall was 0.9333, demonstrating a good overall detection balance.

[0158] It should be noted that the AUROC of the experimental group with only the convolutional block attention module was 95.08%, slightly higher than the 94.99% of the fully improved model. Therefore, it is inappropriate to say that all individual metrics of the fully improved model are the highest. The advantage of the fully improved model lies in its highest F1 score and a good overall balance between precision, recall, and inference speed.

[0159] Approximately 100 audio device housings were randomly selected for continuous inspection. Test results showed that the improved model achieved an AUROC of 94.99%, an F1 score of 0.9289, a precision of 92.45%, a recall of 93.33%, a mean detection rate of 93.0%, and an inference speed of 22.50 FPS. In actual defect test samples, the model correctly detected 98 defect samples and missed 7. For defects such as dust spots, discoloration, silkscreen printing, and scratches, the generated anomaly heatmap can concentrate the abnormal response in the defect area, and the defect coordinates and area can be obtained through binarization and contour extraction.

[0160] In continuous operation testing, the full-process inspection time for a single workpiece was 9.8 seconds, which meets the inspection requirement of no more than 10 seconds per workpiece; the corresponding production line adaptability is 368 pieces / hour, exceeding the production cycle of 240 pieces / hour. The system ran continuously for 8 hours without failure, with GPU memory usage of 2.2GB and CPU utilization of 15%, indicating that the model maintains inspection accuracy without significantly increasing computational resource requirements.

[0161] The application results above show that this invention only requires normal samples to learn the normal feature distribution of audio device housings, reducing the work of defect sample collection and annotation; the composite preprocessing process can maintain weak abnormal features such as minor scratches and dust spots; the convolutional block attention module can enhance the response to local defects; the mean square error-structural similarity joint loss can improve the detection capability of global logical anomalies such as silkscreen offset and character missingness; after the two types of anomaly maps are fused, the defect judgment, location and area can be output simultaneously, which is suitable for automatic sorting and quality traceability on the production line.

[0162] In summary, this invention presents an unsupervised defect detection method and system for audio device housings. Addressing the issues of scarce defect samples, easy loss of minute defects, and difficulty in identifying silkscreen logic anomalies, it employs a collaborative technical solution of image preprocessing and dual-branch unsupervised detection. The composite preprocessing corrects housing posture, suppresses surface halos, and preserves minute defect information; the convolutional block attention module enhances responses to local scratches, dust spots, and other anomalies; and the mean squared error-structural similarity joint loss improves the structural perception capability for silkscreen offsets and missing characters. In experiments, the model achieved an AUROC of 94.99%, an F1 score of 0.9289, precision of 92.45%, and recall of 93.33%, with an inference speed of 22.50 FPS. The full-process detection time for a single workpiece is 9.8 seconds, and it runs stably for 8 hours continuously. This approach balances detection accuracy, real-time performance, and resource consumption, while reducing the cost of defect sample collection and manual annotation.

[0163] The above content is only for illustrating the technical concept of the present invention and should not be construed as limiting the scope of protection of the present invention. Any modifications made to the technical solution based on the technical concept proposed in this invention shall fall within the scope of protection of the claims of this invention.

Claims

1. A method for unsupervised defect detection in the housing of an audio device, characterized in that, Includes the following steps: S1. Obtain the original image of the audio device housing, perform geometric correction on the original image of the audio device housing, perform template matching according to the normalized cross-correlation algorithm, determine the matching coordinates corresponding to the maximum similarity, and crop the housing detection area according to the matching coordinates; perform illumination equalization, unsharpened mask enhancement and area interpolation downsampling on the housing detection area to obtain a standardized image; S2. Construct an improved EfficientAD unsupervised defect detection model, which includes a teacher-student network branch and an autoencoder branch. The teacher-student network branch includes a teacher network and a student network. The teacher network uses a pre-trained lightweight block description network (PDN) and maintains fixed weights during training. The student network uses the same PDN topology as the teacher network, and a convolutional block attention module is embedded after the fourth convolutional output of the student network. The autoencoder branch adopts an encoder-decoder structure. S3. The improved EfficientAD unsupervised defect detection model is trained using a standardized image of a normal audio device housing. The student network is updated based on the difference between the output features of the teacher network and the output features of the student network. The autoencoder branch is updated using the mean square error-structural similarity joint loss to obtain the trained improved EfficientAD unsupervised defect detection model. S4. After processing the image of the audio device housing to be detected according to step S1, input it into the trained improved EfficientAD unsupervised defect detection model. Calculate the difference between the output features of the teacher network and the output features of the student network to obtain a local structural anomaly map. Calculate the difference between the output features of the teacher network and the reconstructed features of the autoencoder branch outputs to obtain a global logical anomaly map. Perform weighted fusion and extreme value normalization on the local structural anomaly map and the global logical anomaly map to generate an anomaly heatmap, and determine the defect region based on the anomaly heatmap.

2. The unsupervised defect detection method for audio device housings according to claim 1, characterized in that, In step S1, geometric correction is performed on the original image of the audio device housing, including: A draft image is obtained by performing a 5×5 median filter on the grayscale image of the original image of the audio device housing. The draft image is binarized, and morphological closing operations are performed on the binarized image using 15×15 rectangular structuring elements. Extract the outer contour of the image after morphological closing operation, filter the main contour of the shell with the largest area, and determine the image tilt angle based on the minimum bounding rectangle of the main contour of the shell. The tilt angle of the image is corrected, an affine transformation matrix is ​​constructed based on the corrected tilt angle, and the original image of the audio device housing is rotated and corrected using the affine transformation matrix.

3. The unsupervised defect detection method for audio device housings according to claim 2, characterized in that, Template matching is performed based on the normalized cross-correlation algorithm, including: Obtain a reference template containing the complete outline of a normal audio device housing; The reference template is slid on the rotated and corrected image, and the normalized cross-correlation value between the image region corresponding to each sliding position and the reference template is calculated. Determine the matching coordinates corresponding to the maximum normalized cross-correlation value, and reserve a boundary around the area corresponding to the matching coordinates. Then, crop the housing detection area from the original image of the audio device housing after rotation correction.

4. The unsupervised defect detection method for audio device housings according to claim 1, characterized in that, In step S1, illumination equalization is performed on the detection area of ​​the shell, including: The shell detection area is divided into 8×8 local sub-grids; The grayscale histograms of each local sub-grid are statistically analyzed. A truncation threshold of 1.5 is set. The frequency of grayscale levels exceeding the truncation threshold is truncated, and the remaining pixels resulting from the truncation are redistributed to each grayscale level. Histogram equalization is performed on each local sub-grid, and bilinear interpolation is used to smooth the boundaries between adjacent local sub-grids to obtain the image after illumination equalization.

5. The unsupervised defect detection method for audio device housings according to claim 4, characterized in that, The shell detection area is subjected to unsharpened mask enhancement and area interpolation downsampling, including: A low-frequency blurred image is obtained by applying a Gaussian filter to the image after illumination equalization using a 15×15 Gaussian kernel. The image after illumination equalization is fused with the low-frequency blurred image using weighted differential fusion, where the weight of the image after illumination equalization is 1.5, to enhance the edge features of minor defects on the shell surface. The enhanced image was downsampled to 512×512 pixels using the INTER_AREA area interpolation method to obtain the standardized image.

6. The unsupervised defect detection method for audio device housings according to claim 1, characterized in that, In step S2, the convolutional block attention module includes a channel attention submodule and a spatial attention submodule connected in sequence; The channel attention submodule is used to perform global average pooling and global max pooling on the input feature map respectively, input the pooling results into a shared multilayer perceptron, and perform element-wise summation and sigmoid activation on the features output by the shared multilayer perceptron to obtain channel attention weights; the channel attention weights are used to perform channel recalibration on the input feature map to obtain a channel-enhanced feature map; The spatial attention submodule is used to perform channel average pooling and channel max pooling on the channel enhanced feature map respectively, concatenate the pooling results, and perform convolution and Sigmoid activation on the concatenated results to obtain spatial attention weights. The channel enhancement feature map is spatially recalibrated using the spatial attention weights to obtain the enhancement feature map.

7. The unsupervised defect detection method for audio device housings according to claim 1, characterized in that, In step S2, the autoencoder branch includes an encoder and a decoder; The encoder is used to extract features and compress feature dimensions from the input standardized image through continuous stride convolution to obtain low-dimensional features. The decoder is used to decode the low-dimensional features through deconvolution to obtain reconstructed features with the same dimension as the output features of the teacher network.

8. The unsupervised defect detection method for audio device housings according to claim 1, characterized in that, In step S3, the joint loss of mean square error and structural similarity is: in, This represents the joint loss of mean square error and structural similarity. This represents the mean squared error loss between the teacher network output features and the reconstructed features. This represents the structural similarity loss between the teacher network output features and the reconstructed features. The weighting coefficient representing the structural similarity loss is λ, which is 0.

1.

9. The unsupervised defect detection method for audio device housings according to claim 1, characterized in that, In step S4, determining the defect region based on the abnormal thermal map includes: The abnormal heatmap is binarized and segmented using a classification threshold of 0.5 to obtain a binary map of the abnormal region. Extract the defect contour from the binary image of the abnormal region; The location coordinates and area of ​​the defect region in the image of the audio device housing to be tested are determined based on the defect contour.

10. An unsupervised defect detection system for audio device housings, characterized in that, include: The image preprocessing module is used to acquire the original image of the audio device housing, perform geometric correction on the original image of the audio device housing, perform template matching according to the normalized cross-correlation algorithm, crop out the housing detection area, and perform illumination equalization, unsharpened mask enhancement and area interpolation downsampling on the housing detection area to obtain a standardized image. The model building module is used to build an improved EfficientAD unsupervised defect detection model. The improved EfficientAD unsupervised defect detection model includes a teacher-student network branch and an autoencoder branch. The teacher-student network branch includes a teacher network that uses a pre-trained lightweight block description network (PDN) and a student network that uses the same PDN topology as the teacher network. The fourth convolutional output of the student network is followed by a convolutional block attention module. The autoencoder branch adopts an encoder-decoder structure. The model training module is used to train the improved EfficientAD unsupervised defect detection model using a standardized image of a normal audio device housing, update the student network based on the difference between the output features of the teacher network and the output features of the student network, and update the autoencoder branch using a mean squared error-structural similarity joint loss. The defect detection module is used to input the image of the housing of the audio device to be detected into the trained improved EfficientAD unsupervised defect detection model, generate a local structural anomaly map and a global logical anomaly map, perform weighted fusion and extreme value normalization on the local structural anomaly map and the global logical anomaly map to generate an anomaly heat map, and determine the defect region based on the anomaly heat map.