Image reconstruction method for robust industrial defect detection
By combining parametric affine transformations and fundamental patterns with manifold constraints and mutual information penalties, this method addresses the poor robustness and identity mapping issues of existing methods when facing unknown or extreme defects, achieving efficient industrial defect detection and rapid category expansion.
Patent Information
- Application Number
- CN202511917453.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-18
- Publication Date
- 2026-03-20
AI Technical Summary
Existing reconstruction-based industrial defect detection methods are not robust to unknown or extreme defects, are prone to identity mapping, and are difficult to adapt to non-independent and identically distributed industrial defect datasets.
Using a parametric affine transformation module and a basic mode, a defect-free reconstructed image is generated through a feature extraction encoder and decoder. Manifold constraints and mutual information penalty mechanisms are introduced to ensure that the reconstruction result is within the normal sample manifold and to avoid identity mapping.
It significantly improves robustness to unknown and extreme defects, avoids identity mapping, achieves efficient industrial defect detection, and has lightweight network and rapid class expansion capabilities.
Smart Images

Figure CN121708140A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the fields of computer vision and industrial intelligent inspection technology, specifically to an image reconstruction method for robust industrial defect detection. Background Technology
[0002] Industrial defect detection is a crucial aspect of quality control in modern manufacturing. Because it is difficult to collect a large number of real-world defect samples covering all types in actual production environments, current defect detection methods typically employ unsupervised or semi-supervised training paradigms, meaning they are trained using only normal samples. Among these, reconstruction-based methods are one of the mainstream technical approaches.
[0003] Traditional reconstruction-based defect detection methods typically employ autoencoders or their variants. The core idea is to compress the input image to be detected into a latent space and then decode and reconstruct it. Since the network is trained only on normal samples, it theoretically cannot reconstruct unseen defect patterns; therefore, the reconstructed image should be a defect-free "repaired" version. Defects can be located by comparing the differences between the input image and the reconstructed image.
[0004] However, existing technologies have significant limitations. First, existing methods typically assume that the input image is directly mapped to the reconstructed image (Ii). A →I R This is an end-to-end mapping. When the input defect samples deviate significantly from the normal sample distribution (i.e., unseen, extreme defect patterns appear), this direct mapping is often unstable, leading to poor robustness. Secondly, due to the powerful generalization ability of neural networks, the model is prone to the "identical shortcut" phenomenon, where the network directly copies the defect portion from the input image to the output image, resulting in the inability to detect defects. Furthermore, industrial defect detection datasets typically exhibit non-independent identically distributed (non-IID) characteristics, meaning that synthetic defect samples differ in distribution from real defect samples, causing existing methods to degrade in performance when faced with real, complex defects.
[0005] Therefore, there is an urgent need for a new image reconstruction method that can, in principle, constrain the reconstruction result to fall within the manifold space of normal samples, thereby significantly improving the robustness to various unknown and extreme defect patterns while ensuring detection accuracy. Summary of the Invention
[0006] The purpose of this application is to provide an image reconstruction method, computer device, readable storage medium, and computer program product for robust industrial defect detection, in order to solve the problems of poor robustness and easy occurrence of identity mapping in existing reconstruction-based methods when facing unknown or extreme defects.
[0007] This application provides an image reconstruction method for robust industrial defect detection, including the following steps: Step S1: Obtain an image of the industrial workpiece to be detected, and extract the feature vector of the industrial workpiece image through a feature extraction encoder. Step S2: Obtain a pre-constructed learnable basic pattern representing the center of the normal sample manifold. Using the feature vector of the industrial workpiece image as a condition, transform the basic pattern through the parameterized affine transformation module to obtain the mapped features. Step S3: Input the mapping features into the decoder for image decoding to generate a defect-free reconstructed image corresponding to the industrial workpiece image; Step S4: Compare the industrial workpiece image with the defect-free reconstructed image, and output a mask image indicating the defect location through the segmentation module.
[0008] As an example, the parameterized affine transformation module employs an attention mechanism structure; the mapped features are input to the decoder for image decoding to generate a defect-free reconstructed image corresponding to the industrial workpiece image, including: The parametric affine transformation module uses the feature vector of the industrial workpiece image as the query condition and the basic pattern as the key and value; by calculating the correlation between the query condition and the key, it adaptively retrieves information from the basic pattern and performs weighted recombination, thereby transforming the basic pattern into the reconstructed features aligned with the structure of the industrial workpiece image. The reconstructed features are decoded into the defect-free reconstructed image.
[0009] As an example, the underlying pattern is an explicitly stored learnable tensor, specifically: The dimension of the base pattern matches the dimension of the feature map output by the feature extraction encoder; During training, the base pattern is jointly optimized with network parameters to learn and memorize the common feature centers of various normal samples; during inference, the base pattern serves as a fixed reference anchor point, and the input workpiece image only provides guidance on the offset to that reference anchor point.
[0010] As an example, the method introduces a manifold constraint mechanism during the training phase, specifically: Calculate the feature distance between the feature vector of the normal sample image and the base pattern; By constraining the feature distance through a loss function, the features of normal samples are forced to be compactly distributed around the base pattern to construct a compact normal sample manifold space and prevent confusion in the latent space representation.
[0011] As an example, the method introduces a mutual information penalty mechanism during the training phase to prevent identity mapping: Artificial defect regions are synthesized in the training samples to obtain synthetic defect images, and the correlation gradient between the reconstructed image and the input synthetic defect image in the defect region is calculated. The correlation gradient is penalized, cutting off the direct information path from the input defect region to the corresponding output region, forcing the network to use the information of the base pattern to repair the defect region instead of directly copying the texture of the input image.
[0012] As an example, the training of the method employs a two-stage strategy that decouples generation and segmentation: Phase 1: Jointly train the encoder, decoder, base pattern and parameterized affine transformation module, using reconstruction loss, manifold constraint loss and mutual information penalty loss, focusing on learning the ability to map any input back to the normal sample manifold; The second stage involves freezing some generated parameters and training only the segmentation module, using multi-scale feature differences to learn pixel-level defect localization.
[0013] As an example, the method also includes a new category extension based on parameter freezing: When expanding to detect new types of workpieces, the encoder and decoder parameters are frozen; only the parameters of the basic mode, parametric affine transformation module, and segmentation module are fine-tuned during training; and the defect detection capability for new types of workpieces is transferred using a small number of parameter updates.
[0014] This application also provides a computer device including a memory and a processor, wherein the memory stores a computer program and the processor is configured to, when executing the computer program, implement the steps of the method as described in any of the preceding claims.
[0015] This application also provides a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method as described in any of the preceding claims.
[0016] This application also provides a computer program product stored in a storage medium, the program product being executed by at least one processor to perform the steps of the method as described in any of the preceding claims.
[0017] The beneficial effects of this invention are as follows: 1. Significantly Improved Robustness: By introducing a "base pattern" as an anchor point and modeling the reconstruction process as a conditional transformation starting from the anchor point, the reconstruction result is guaranteed in principle to be strongly constrained by the normal sample manifold. No matter how extreme the input defects are, the output tends to regress to the distribution range of normal samples, effectively solving the problem of poor robustness of traditional methods.
[0018] 2. Avoid identity mapping: The introduction of mutual information penalty loss explicitly cuts off the direct information path between the input defect region and the output region, preventing the model from "lazily" copying defects and improving the reliability of detection.
[0019] 3. High efficiency: This method achieves excellent performance while using an extremely lightweight backbone network. It has fast inference speed, low computational cost, and is suitable for deployment in industrial settings.
[0020] 4. Flexible class extension capability: By only fine-tuning a few parameters such as the parameterized affine transformation module and the basic mode, it can quickly adapt to the inspection of new types of workpieces, which has good practical application value. Attached Figure Description
[0021] Figure 1 This application discloses a network model structure and data flow for robust industrial defect detection. Figure 2 This application discloses a flowchart of an image reconstruction method for robust industrial defect detection. Figure 3 This is a schematic diagram of the structure of a computer device disclosed in an embodiment of this application. Detailed Implementation
[0022] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0023] This application proposes an image reconstruction method and system for robust industrial defect detection, aiming to solve the problems of poor robustness and easy generation of identity mapping in existing reconstruction-based defect detection methods when facing non-independent and identically distributed data (i.e., unknown or extreme defects not covered by the training set).
[0024] Figure 1 This demonstrates the network model structure and data flow proposed in this application for robust industrial defect detection. For example... Figure 1 As shown, the network model mainly consists of two parts: a reconstruction generation network and a defect segmentation network.
[0025] (1) Reconstruction Generator Network: Used to generate a defect-free reconstructed image corresponding to the input image.
[0026] Feature extraction encoder (Encoder): Used to receive images of industrial workpieces to be inspected (I... A The encoder maps the image to a low-dimensional latent space and extracts feature vectors containing latent image semantics as conditional parameters ({param}). Preferably, the encoder employs a ResNet18 structure pre-trained on ImageNet to leverage its powerful feature extraction capabilities.
[0027] Base Pattern: This is an explicitly stored learnable tensor with dimensions consistent with the feature dimensions of the encoder bottleneck layer (e.g., C×H×W). It represents the central anchor point of the normal sample manifold distribution in the latent space.
[0028] Parametric Affine Transformation Module ( / PAT): Connects the encoder and decoder. It uses the feature vectors output by the encoder to drive an adaptive transformation of a fixed base pattern, generating mapped features that are structurally aligned with the input image but have a defect-free content.
[0029] Decoder: Its structure is symmetrical to the encoder. It is used to upsample and nonlinearly map the transformed mapping features to restore a defect-free reconstructed image with the same size as the input image. R ).
[0030] (2) Segmentation Network: Used for precise defect localization. It receives the input image (I... A ), reconstructed image (I) R ) and from the teacher encoder (Enc T Using multi-scale difference features as input, and through feature fusion and pixel-level classification, the output is a binarized mask image (M) indicating the location of defects.
[0031] Figure 2 This is a flowchart illustrating an image reconstruction method for robust industrial defect detection provided in this application. Figure 2 As shown, the method includes the following steps: Step S1: Obtain an image of the industrial workpiece to be detected, and extract the feature vector of the industrial workpiece image through a feature extraction encoder. In this step, the image I of the workpiece to be inspected, acquired from an industrial production scene, is received. APreprocessing operations such as normalization and resolution adjustment (e.g., uniformly scaling to 256×256 pixels) are performed to eliminate interference caused by differences in shooting environment and equipment parameters.
[0032] The preprocessed image is input into a feature extraction encoder, which preferably uses a pre-trained lightweight backbone network such as ResNet18. Through multi-layer convolution and pooling operations, the two-dimensional image is mapped to a low-dimensional latent space, outputting a feature vector E(I) that represents the deep semantic information of the image. A The eigenvector E(I) A This will serve as the core condition parameter for subsequent adjustments to the basic model.
[0033] Step S2: Obtain a pre-constructed learnable basic pattern representing the center of the normal sample manifold. Using the feature vector of the industrial workpiece image as a condition, transform the basic pattern through the parameterized affine transformation module to obtain the mapped features. In this step, this application abandons the traditional end-to-end direct mapping mode (I A –I R Instead, it adopts a reconstruction logic of "anchor point + conditional transformation". The pre-built base pattern (BP) is an explicitly stored learnable tensor whose dimension is consistent with the dimension of the feature map output by the encoder, and is used to represent the center position of the normal sample manifold in the latent space.
[0034] Parametric Affine Transformation Module ( The feature vector E(I) extracted in step S1 A Given the condition, the basic pattern is transformed through an adaptive adjustment strategy. Specifically, by calculating the correlation between the input feature vector and the basic pattern, the direction and magnitude of the transformation are determined, and finally, a mapping feature that is aligned with the structure of the input workpiece image but whose content conforms to the features of normal samples is generated. In principle, this ensures that the reconstruction result will not deviate from the normal sample distribution.
[0035] Step S3: Input the mapping features into the decoder for image decoding to generate a defect-free reconstructed image corresponding to the industrial workpiece image; This step aims to restore the mapped features of the latent space into a visualized, defect-free image. Specifically, the decoder employs a network structure symmetrical to the feature extraction encoder, progressively increasing the resolution of the feature map through operations such as deconvolution and upsampling, while simultaneously performing non-linear mapping to transform the mapped features obtained in step S2... Reconstructed into a defect-free image I with the same dimensions as the original image to be detected R .
[0036] Understandably, the reconstructed image strictly follows the feature constraints of the normal sample manifold, and can output repair results that conform to the normal workpiece shape even if the input image contains extremely unknown defects.
[0037] Step S4: Compare the industrial workpiece image with the defect-free reconstructed image, and output a mask image indicating the defect location through the segmentation module.
[0038] This step achieves precise defect localization through difference comparison. Specifically, the original image to be inspected (I) is... A Compared with the defect-free reconstructed image I generated in step S3 R Simultaneously, the input is fed into the segmentation module. This module extracts and fuses the differences between the two images in pixel space and feature space, using a pixel-level classification algorithm to identify regions in the original image that do not conform to normal shapes. Finally, it outputs a binarized mask image M. The regions marked as defects in the mask image M (e.g., regions with a pixel value of 1) represent the actual defect locations of the workpiece to be inspected, achieving visualized defect localization.
[0039] As an example, the parameterized affine transformation module employs an attention mechanism structure; the mapped features are input to the decoder for image decoding to generate a defect-free reconstructed image corresponding to the industrial workpiece image, including: The parametric affine transformation module uses the feature vector of the industrial workpiece image as the query condition and the basic pattern as the key and value; by calculating the correlation between the query condition and the key, it adaptively retrieves information from the basic pattern and performs weighted recombination, thereby transforming the basic pattern into the reconstructed features aligned with the structure of the industrial workpiece image. The reconstructed features are decoded into the defect-free reconstructed image.
[0040] This implementation method achieves adaptive adjustment and precise reconstruction of the basic pattern through a low-inductive bias attention mechanism, as detailed below: The parameterized affine transformation module employs an attention mechanism structure, which features low inductive bias and can efficiently handle nonlinear feature mappings in high-dimensional latent spaces. Its specific workflow is as follows: First, the feature vector extracted in step S1 is converted into a query vector Q using a multilayer perceptron (MLP) or a linear layer. Simultaneously, the base pattern is converted into a key vector K and a value vector V (here, the value vector V directly uses the base pattern itself). , , .
[0041] Subsequently, the dot product correlation between the query vector Q and the key vector K is calculated and then divided by the square root of the number of feature channels C. The scaling factor (i.e., scaling factor) is used to avoid the gradient vanishing due to excessively large dot product results. Then, the result is normalized using the Softmax function to obtain the attention weight map. Finally, this attention weight map is used to weight and aggregate the value vector V (base pattern), and residual connections are introduced to preserve the core features of the base pattern. The specific calculation formula is as follows: , where i represents the sample index in the batch, and T represents the matrix transpose operation.
[0042] The final generated features are reconstructed and aligned with the structure of the input industrial workpiece image.
[0043] It is understandable that the above process is essentially a parametric affine transformation model that adaptively retrieves relevant information from the basic pattern and reconstructs it based on the features of the input image, ensuring that the reconstructed features not only conform to the manifold constraints of the normal samples, but also match the structural features of the input image.
[0044] The decoder takes reconstructed features as input and gradually restores the image through a network structure symmetrical to the feature extraction encoder. The decoder employs deconvolution or interpolation upsampling techniques to progressively increase the spatial resolution of the feature maps, while simultaneously optimizing feature representation through nonlinear activation functions. Ultimately, it maps the reconstructed features in the latent space to a defect-free reconstructed image (I) with the same size as the original image to be detected. R It should be noted that the core features of this defect-free reconstructed image are strictly derived from the basic pattern of the normal sample manifold, rather than directly copying the content of the input image, thus avoiding the interference of input defects on the reconstruction result.
[0045] As an example, the underlying pattern is an explicitly stored learnable tensor, specifically: The dimension of the base pattern matches the dimension of the feature map output by the feature extraction encoder; During training, the base pattern is jointly optimized with network parameters to learn and memorize the common feature centers of various normal samples; during inference, the base pattern serves as a fixed reference anchor point, and the input workpiece image only provides guidance on the offset to that reference anchor point.
[0046] In this implementation, the base pattern is essentially an explicitly stored learnable tensor. Its dimensional design must strictly match the dimension of the feature map output by the feature extraction encoder (for example, when the feature map dimension is C×H×W, the base pattern dimension should also be set to C×H×W) to ensure that the two can perform effective feature calculation and mapping. This dimension matching principle is a prerequisite for realizing the interaction between the base pattern and the input feature vector, avoiding feature mapping distortion caused by dimension incompatibility.
[0047] During model training, the base pattern is not fixed but participates in joint optimization along with the network parameters of the encoder, decoder, and parametric affine transformation module. During training, the base pattern learns the common features of a large number of normal samples and gradually converges to the central anchor point of the normal sample manifold in the latent space. In other words, the base pattern can memorize the common feature patterns of various normal samples and form an accurate representation of the distribution of normal samples.
[0048] During the model inference phase (i.e., in a real-world industrial defect detection scenario), the parameters of the base model are fixed at the optimal values obtained after convergence during the training phase, serving as fixed reference anchors for the normal sample manifold. At this point, the input image of the industrial workpiece to be detected only needs to provide the feature vector E(I... A The core function of this feature vector is to provide offset guidance for the basic pattern of the parametric affine transformation module. That is, the model, based on the structural features of the input image, through... By adjusting the local details of the base pattern, a reconstruction result is generated that matches the structure of the input image but conforms to the characteristics of normal samples, rather than directly mapping the reconstruction map from the input image, thus ensuring the robustness of the reconstruction result.
[0049] As an example, the method introduces a manifold constraint mechanism during the training phase, specifically: Calculate the feature distance between the feature vector of the normal sample image and the base pattern; By constraining the feature distance through a loss function, the features of normal samples are forced to be compactly distributed around the base pattern to construct a compact normal sample manifold space and prevent confusion in the latent space representation.
[0050] This implementation constrains the distribution of normal sample features through a loss function, constructing a compact and regular normal sample manifold space, thus avoiding feature confusion in the latent space. Specifically: The implementation steps of the manifold constraint mechanism are as follows: First, during the training process, for each normal sample image I... N The feature vector E(I) is obtained through the feature extraction encoder. N Then, calculate the feature distance (using L1 distance) between the feature vector and the base pattern BP (normal sample manifold center). (equal measurement method); then through a specially designed manifold constraint loss function (L MC The feature distance is subject to specific constraints, and the specific calculation formula is as follows:
[0051] Where th is a preset threshold (e.g., 0.2).
[0052] When the distance between the feature vector of a normal sample and the base pattern exceeds the preset threshold, the loss function will apply a gradient penalty, forcing the model to adjust the network parameters and the base pattern to reduce the feature distance; if the distance does not exceed the threshold, no penalty will be applied to avoid excessive constraints that could lead to feature distortion.
[0053] Understandably, the core purpose of this mechanism is to construct a compact and regular manifold space for normal samples. By penalizing the features of normal samples that deviate too far from the base pattern, the feature vectors of all normal samples are compactly distributed around the base pattern in the latent space, forming a manifold structure with clear boundaries and a dense interior. This structure effectively avoids the dispersion and confusion of normal sample features in the latent space, ensuring that the model can accurately identify the feature distribution patterns of normal samples. This provides a clear reference for the normal distribution for subsequent reconstruction of defective samples, thereby improving the model's robustness to unknown defects.
[0054] As an example, the method introduces a mutual information penalty mechanism during the training phase to prevent identity mapping: Artificial defect regions are synthesized in the training samples to obtain synthetic defect images, and the correlation gradient between the reconstructed image and the input synthetic defect image in the defect region is calculated. The correlation gradient is penalized, cutting off the direct information path from the input defect region to the corresponding output region, forcing the network to use the information of the base pattern to repair the defect region instead of directly copying the texture of the input image.
[0055] This implementation avoids the "identity mapping" phenomenon in the model by severing the direct information path between the input defect region and the output reconstruction region, ensuring that the reconstruction of the defect region is based on the normal sample manifold. Specifically: The mutual information penalty mechanism is implemented on the premise of synthesizing artificial defect regions in the training samples. Specifically, it uses Perlin noise to generate a binary mask M with a random shape. P (Where 0 represents a defect area and 1 represents a normal background area), and the texture image I from the texture dataset (such as the DTD dataset) dtd Fill into normal sample I N The masked area is used to generate synthetic defect sample I. A The specific calculation formula is as follows: , where ⊙ denotes element-wise multiplication. It can be understood that this synthesized defect sample retains some structure of the normal sample while also containing clearly defined artificial defect regions, used to simulate defect samples in actual industrial scenarios. It should be noted that the method in this application has strong robustness to defect synthesis strategies; in addition to the above method, other methods such as CutPaste, geometric occlusion, or Poisson fusion can also be used to generate synthetic defect samples.
[0056] Next, the reconstructed image I is calculated. R Synthetic defect sample I with input A In the defect area (i.e., 1-M) p The correlation gradient of the region (indicated by the image) reflects the degree of information association between the defect region in the reconstructed image and the defect region in the input synthesized defect image. This is achieved through the Mutual Information Penalty Loss (LIB) function. MIP A penalty is applied to the correlation gradient and incorporated into the loss function, forcing the gradient to approach 0. The specific calculation formula is as follows:
[0057] Wherein: (1-Mp) indicates the defect region of the synthesis; This represents the difference measurement function. In this preferred embodiment, Using L1 distance (i.e. However, in other implementations, L2 distance or perceptual loss can also be used.
[0058] Understandably, based on the above formula, it is required that in the area of the input image that has been tampered with (the defect area), the pixel changes should not affect the final reconstruction result (i.e., the gradient approaches 0). This forces the reconstruction result to be generated entirely by the basic pattern and normal features, explicitly cutting off the direct information path from the input defect area to the corresponding output area, avoiding the model from "lazily" copying the defect texture, and ensuring that the reconstruction of the defect area is based on the normal sample manifold.
[0059] As an example, the training of the method employs a two-stage strategy that decouples generation and segmentation: Phase 1: Jointly train the encoder, decoder, base pattern and parameterized affine transformation module, using reconstruction loss, manifold constraint loss and mutual information penalty loss, focusing on learning the ability to map any input back to the normal sample manifold; The second stage involves freezing some generated parameters and training only the segmentation module, using multi-scale feature differences to learn pixel-level defect localization.
[0060] This implementation decouples the learning of reconstruction capability from the learning of defect localization capability. Through phased optimization, it improves the robust reconstruction performance and accurate segmentation performance of the model, as detailed below: The first stage is the generative network training stage, whose core objective is to learn the robust reconstruction ability to map arbitrary inputs (including normal samples and synthetically defective samples) back to the normal sample manifold. The training objects in this stage include the encoder, decoder, parametric affine transformation module (PAT), and learnable base patterns (BP), focusing on learning the ability to map arbitrary inputs back to the normal sample manifold. The loss function used in this stage consists of the reconstruction loss L... recon Manifold constraint loss L MC And mutual information penalty loss L MIP Its composition is as follows: ,in, and Hyperparameters are used to balance the weights of various losses.
[0061] The reconstruction loss is jointly constrained by pixel-level (L2 distance) and feature-level (intermediate feature differences between the decoder and the pre-trained teacher encoder) to ensure the quality of the reconstructed image. The specific calculation formula is as follows:
[0062] in This represents the intermediate features of the i-th layer of the decoder. This represents the intermediate features of the i-th layer of the pre-trained teacher encoder (frozen parameters).
[0063] Manifold constraint loss ensures a compact distribution of features from normal samples; mutual information penalty loss avoids identity mapping. Through training in this stage, the generative network can stably output defect-free reconstructed images that conform to the manifold of normal samples.
[0064] The second stage is the segmentation network training stage, whose core objective is to learn the ability to accurately locate defects from reconstruction differences. This stage first freezes all parameters of the generator network (including the encoder, decoder, base pattern, and parametric affine transformation modules) trained in the first stage to ensure the stability of the reconstruction capability; subsequently, only the segmentation network is trained. The input to the segmentation network includes the original image to be detected, I. A Reconstructing Image I R The difference in multi-scale features between the two in the encoder is used to output a predicted mask M. Focal Loss is employed as the loss function, and the supervised output predicted mask M is compared with the real synthetic mask 1-M. p The difference between (ensuring 1 represents a defect) is calculated using the following formula: Through this training phase, the model learns how to accurately segment defect regions from reconstruction differences and remove structural noise interference generated during the reconstruction process.
[0065] As an example, the method also includes a new category extension based on parameter freezing: When expanding to detect new types of workpieces, the encoder and decoder parameters are frozen; only the parameters of the basic mode, parametric affine transformation module, and segmentation module are fine-tuned during training; and the defect detection capability for new types of workpieces is transferred using a small number of parameter updates.
[0066] This implementation method uses a parameter freezing strategy to fine-tune only a few key parameters, enabling rapid transfer of the model's defect detection capabilities to new types of workpieces. The specific explanation is as follows: When it is necessary to extend the model to defect detection of new types of workpieces, a parameter-freezing transfer learning strategy is adopted: First, all parameters of the encoder and decoder trained in the first stage are frozen. This is because the encoder's feature extraction capability (such as E(I)) is limited. A The extraction logic of the decoder and the image reconstruction capabilities of the decoder (such as I) R The generation logic has a certain degree of universality, capable of adapting to the basic feature extraction and image restoration needs of different types of workpieces, without the need for repeated training; subsequently, only the parameters of three key parts are fine-tuned during training, including: the basic pattern BP (which needs to be updated to the center anchor point of the normal sample manifold of the new category), the parameterized affine transformation module, and the parameterized affine transformation module. (It is necessary to adapt to the feature mapping rules of the new type of workpiece and adjust accordingly) The transformation logic) and the segmentation module (which needs to learn the differences between the defect features and normal features of new types of workpieces and optimize the output accuracy of M). This implementation method freezes a large number of parameters in the encoder and decoder, fine-tuning only a few key parameters, enabling rapid model adaptation using a small number of new category normal samples. This approach avoids large-scale data collection and full network retraining for new categories of workpieces, significantly reducing the time and data costs of expanding to new categories. It allows the model to quickly adapt to the defect detection needs of different types of industrial workpieces, enhancing the model's practical application value.
[0067] like Figure 3 As shown, this application also provides a computer device including a processor and a memory, the memory storing a program or instructions executable on the processor, the program or instructions being executed by the processor to implement the steps of the method as described in any of the foregoing embodiments.
[0068] This application also provides a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method as described in any of the foregoing embodiments.
[0069] This application also provides a computer program product stored in a storage medium, which is executed by at least one processor to implement the steps of the method as described in any of the foregoing embodiments.
[0070] In summary, this application proposes an image reconstruction scheme based on parametric affine transformation and anchor point driven methods. By explicitly learning the center (basic pattern) of the normal sample manifold and modeling the reconstruction process as a conditional transformation starting from the center, combined with manifold constraint loss and mutual information penalty loss, this effectively solves the problem of poor robustness of traditional methods when facing non-independent and identically distributed data (i.e., unseen extreme defects), while avoiding the identity mapping phenomenon, thus achieving high-precision industrial defect detection.
[0071] Those skilled in the art will understand that, without departing from the core concept of this invention, various equivalent substitutions or modifications made to the initialization method of the basic mode, the specific network structure of the PAT module (such as using convolution or linear transformation to replace the attention mechanism), the weight settings of the loss function, etc., are all within the protection scope of this invention.
Claims
1. An image reconstruction method for robust industrial defect detection, characterized in that, The methods and steps include the following: Step S1: Obtain an image of the industrial workpiece to be detected, and extract the feature vector of the industrial workpiece image through a feature extraction encoder. Step S2: Obtain a pre-constructed learnable basic pattern representing the center of the normal sample manifold. Using the feature vector of the industrial workpiece image as a condition, transform the basic pattern through the parameterized affine transformation module to obtain the mapped features. Step S3: Input the mapping features into the decoder for image decoding to generate a defect-free reconstructed image corresponding to the industrial workpiece image; Step S4: Compare the industrial workpiece image with the defect-free reconstructed image, and output a mask image indicating the defect location through the segmentation module.
2. The image reconstruction method for robust industrial defect detection as described in claim 1, characterized in that, The parameterized affine transformation module employs an attention mechanism structure; it inputs the mapped features into the decoder for image decoding to generate a defect-free reconstructed image corresponding to the industrial workpiece image, including: The parametric affine transformation module uses the feature vector of the industrial workpiece image as the query condition and the basic pattern as the key and value; by calculating the correlation between the query condition and the key, it adaptively retrieves information from the basic pattern and performs weighted recombination, thereby transforming the basic pattern into the reconstructed features aligned with the structure of the industrial workpiece image. The reconstructed features are decoded into the defect-free reconstructed image.
3. The image reconstruction method for robust industrial defect detection as described in claim 2, characterized in that, The basic pattern is an explicitly stored learnable tensor, specifically: The dimension of the base pattern matches the dimension of the feature map output by the feature extraction encoder; During training, the basic pattern and network parameters are jointly optimized to learn and memorize the common feature centers of various normal samples. During the inference process, the base pattern serves as a fixed reference anchor point, and the input workpiece image only provides guidance on the offset to that reference anchor point.
4. The image reconstruction method for robust industrial defect detection as described in claim 3, characterized in that, The method introduces a manifold constraint mechanism during the training phase, specifically: Calculate the feature distance between the feature vector of the normal sample image and the base pattern; By constraining the feature distance through a loss function, the features of normal samples are forced to be compactly distributed around the base pattern to construct a compact normal sample manifold space and prevent confusion in the latent space representation.
5. The image reconstruction method for robust industrial defect detection as described in claim 4, characterized in that, The method introduces a mutual information penalty mechanism during the training phase to prevent identity mapping: Artificial defect regions are synthesized in the training samples to obtain synthetic defect images, and the correlation gradient between the reconstructed image and the input synthetic defect image in the defect region is calculated. The correlation gradient is penalized, cutting off the direct information path from the input defect region to the corresponding output region, forcing the network to use the information of the base pattern to repair the defect region instead of directly copying the texture of the input image.
6. The image reconstruction method for robust industrial defect detection as described in claim 5, characterized in that, The training of the method employs a two-stage strategy that decouples generation and segmentation: Phase 1: Jointly train the encoder, decoder, base pattern and parameterized affine transformation module, using reconstruction loss, manifold constraint loss and mutual information penalty loss, focusing on learning the ability to map any input back to the normal sample manifold; The second stage involves freezing some generated parameters and training only the segmentation module, using multi-scale feature differences to learn pixel-level defect localization.
7. The image reconstruction method for robust industrial defect detection as described in claim 6, characterized in that, The method also includes a new category extension based on parameter freezing: When expanding to detect new types of workpieces, the encoder and decoder parameters are frozen; only the parameters of the basic mode, parametric affine transformation module, and segmentation module are fine-tuned during training; and the defect detection capability for new types of workpieces is transferred using a small number of parameter updates.
8. A computer device, characterized in that, The system includes a memory and a processor, wherein the memory stores a computer program and the processor is configured to implement the image reconstruction method as described in any one of claims 1 to 7 when executing the computer program.
9. A computer-readable storage medium, characterized in that, The storage medium stores a computer program that, when run on a computer device, causes the computer device to perform the image reconstruction method as described in any one of claims 1 to 7.
10. A computer program product, characterized in that, The program product is stored in a storage medium, and the program product is executed by at least one processor to implement the steps of the method as described in any one of claims 1 to 7.