CN117635585A - Texture surface defect detection method based on teacher-student network - Google Patents

Texture surface defect detection method based on teacher-student network Download PDF

Info

Publication number
CN117635585A
CN117635585A CN202311663492.8A CN202311663492A CN117635585A CN 117635585 A CN117635585 A CN 117635585A CN 202311663492 A CN202311663492 A CN 202311663492A CN 117635585 A CN117635585 A CN 117635585A
Authority
CN
China
Prior art keywords
feature
scale
image
defect
normal
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311663492.8A
Other languages
Chinese (zh)
Inventor
杨华
何源
尹周平
郑洲
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huazhong University of Science and Technology
Original Assignee
Huazhong University of Science and Technology
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huazhong University of Science and Technology filed Critical Huazhong University of Science and Technology
Priority to CN202311663492.8A priority Critical patent/CN117635585A/en
Publication of CN117635585A publication Critical patent/CN117635585A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/0002Inspection of images, e.g. flaw detection
    • G06T7/0004Industrial image inspection
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/045Combinations of networks
    • G06N3/0455Auto-encoder networks; Encoder-decoder networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/0464Convolutional networks [CNN, ConvNet]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/048Activation functions
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods
    • G06N3/096Transfer learning
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/20Image preprocessing
    • G06V10/26Segmentation of patterns in the image field; Cutting or merging of image elements to establish the pattern region, e.g. clustering-based techniques; Detection of occlusion
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/40Extraction of image or video features
    • G06V10/44Local feature extraction by analysis of parts of the pattern, e.g. by detecting edges, contours, loops, corners, strokes or intersections; Connectivity analysis, e.g. of connected components
    • G06V10/443Local feature extraction by analysis of parts of the pattern, e.g. by detecting edges, contours, loops, corners, strokes or intersections; Connectivity analysis, e.g. of connected components by matching or filtering
    • G06V10/449Biologically inspired filters, e.g. difference of Gaussians [DoG] or Gabor filters
    • G06V10/451Biologically inspired filters, e.g. difference of Gaussians [DoG] or Gabor filters with interaction between the filter responses, e.g. cortical complex cells
    • G06V10/454Integrating the filters into a hierarchical structure, e.g. convolutional neural networks [CNN]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/40Extraction of image or video features
    • G06V10/52Scale-space analysis, e.g. wavelet analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/70Arrangements for image or video recognition or understanding using pattern recognition or machine learning
    • G06V10/77Processing image or video features in feature spaces; using data integration or data reduction, e.g. principal component analysis [PCA] or independent component analysis [ICA] or self-organising maps [SOM]; Blind source separation
    • G06V10/80Fusion, i.e. combining data from various sources at the sensor level, preprocessing level, feature extraction level or classification level
    • G06V10/806Fusion, i.e. combining data from various sources at the sensor level, preprocessing level, feature extraction level or classification level of extracted features
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/70Arrangements for image or video recognition or understanding using pattern recognition or machine learning
    • G06V10/77Processing image or video features in feature spaces; using data integration or data reduction, e.g. principal component analysis [PCA] or independent component analysis [ICA] or self-organising maps [SOM]; Blind source separation
    • G06V10/80Fusion, i.e. combining data from various sources at the sensor level, preprocessing level, feature extraction level or classification level
    • G06V10/809Fusion, i.e. combining data from various sources at the sensor level, preprocessing level, feature extraction level or classification level of classification results, e.g. where the classifiers operate on the same input data
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/70Arrangements for image or video recognition or understanding using pattern recognition or machine learning
    • G06V10/82Arrangements for image or video recognition or understanding using pattern recognition or machine learning using neural networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/20Special algorithmic details
    • G06T2207/20081Training; Learning
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/20Special algorithmic details
    • G06T2207/20084Artificial neural networks [ANN]
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02PCLIMATE CHANGE MITIGATION TECHNOLOGIES IN THE PRODUCTION OR PROCESSING OF GOODS
    • Y02P90/00Enabling technologies with a potential contribution to greenhouse gas [GHG] emissions mitigation
    • Y02P90/30Computing systems specially adapted for manufacturing

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Evolutionary Computation (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • General Health & Medical Sciences (AREA)
  • Computing Systems (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Software Systems (AREA)
  • Multimedia (AREA)
  • Molecular Biology (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Biomedical Technology (AREA)
  • Mathematical Physics (AREA)
  • Computational Linguistics (AREA)
  • Biophysics (AREA)
  • Data Mining & Analysis (AREA)
  • General Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Medical Informatics (AREA)
  • Biodiversity & Conservation Biology (AREA)
  • Quality & Reliability (AREA)
  • Image Analysis (AREA)

Abstract

The invention belongs to the field of image processing, and particularly relates to a texture surface defect detection method based on a teacher-student network, which is realized by adopting a defect detection model which is trained based on texture surface defect images and comprises a student network and a double-branch decoding module, and comprises the following steps: respectively encoding images to be detected by adopting a pre-training teacher network and a student network; carrying out semantic segmentation and feature recovery on the deepest scale features in the multi-scale features obtained by the student network by adopting a double-branch decoding module, and correspondingly obtaining a defect segmentation image and pseudo normal features with the same multi-scale as the multi-scale features obtained by the teacher network; calculating cosine similarity between the pseudo-normal features under each scale and features obtained by a teacher network to construct a global anomaly score map; and fusing the defect segmentation image and the global anomaly score image to obtain a detection result image, and completing defect detection. The invention can realize accurate detection of various texture defects in complex industrial environments.

Description

一种基于教师-学生网络的纹理表面缺陷检测方法A texture surface defect detection method based on teacher-student network

技术领域Technical field

本发明属于图像处理领域,更具体地,涉及一种基于教师-学生网络的纹理表面缺陷检测方法。The invention belongs to the field of image processing, and more specifically, relates to a texture surface defect detection method based on a teacher-student network.

背景技术Background technique

现代化工业生产通常涉及高度自动化和高速生产,而且生产流程变得越来越复杂,导致许多产品表面会不可避免地产生瑕疵或缺陷,严重影响产线的良品率和生产效率。随着计算机图像处理技术的不断进步,基于机器视觉的纹理表面缺陷检测方法不断涌现。然而大部分纹理产品表面的正常区域与缺陷区域通常存在低对比度特性,具体表现为没有明显的过度区域,难以对其进行清晰成像和区分出明晰的轮廓边界,受纹理背景干扰严重,导致检测效果不佳。而且非规则纹理和规则纹理情况下的缺陷区域和纹理区域相比存在不同程度的干扰,这要求检测技术需要具备良好的泛化性。由于纹理和缺陷复杂多样性以及缺陷的不可预测、大尺度变化等特性,对纹理表面缺陷的鲁棒性检测一直以来是一项极具挑战性的任务。Modern industrial production usually involves a high degree of automation and high-speed production, and the production process is becoming more and more complex, resulting in the inevitable defects or defects on the surface of many products, seriously affecting the yield rate and production efficiency of the production line. With the continuous advancement of computer image processing technology, texture surface defect detection methods based on machine vision continue to emerge. However, the normal areas and defective areas on the surface of most textured products usually have low contrast characteristics. Specifically, there is no obvious transition area, which makes it difficult to clearly image and distinguish clear contour boundaries. The texture background is seriously interfered, resulting in detection results. Not good. Moreover, there are different degrees of interference between defect areas and texture areas in the case of irregular textures and regular textures, which requires the detection technology to have good generalization. Due to the complex diversity of textures and defects, as well as the unpredictable and large-scale changes of defects, the robust detection of textured surface defects has always been a very challenging task.

随着各大生产企业越来越重视产品表面缺陷的检测,依靠人眼观察辨别缺陷的传统方式由于存在较大主观性,不稳定且效率低,已经逐步被具有非接触、高速、精度高等优点的现代自动光学检测(Automatic Optical Inspection,AOI)设备取代,AOI技术理论基础来源于机器视觉,主要包括视觉成像、视觉定位、视觉检测、视觉分类四个部分,其中核心是视觉检测部分的检测算法。AOI设备的检测效果上限通常取决于检测算法的性能,因此研究高性能的纹理表面缺陷检测算法,实现对各类纹理表面缺陷的高精度、高鲁棒检测,对提升自动化工业生产的质量和效率有重要意义。As major manufacturing companies pay more and more attention to the detection of product surface defects, the traditional method of identifying defects by human eye observation has been gradually replaced by non-contact, high-speed, and high-precision methods due to its great subjectivity, instability, and low efficiency. It is replaced by modern automatic optical inspection (AOI) equipment. The theoretical basis of AOI technology comes from machine vision, which mainly includes four parts: visual imaging, visual positioning, visual detection, and visual classification. The core of which is the detection algorithm of the visual detection part. . The upper limit of the detection effect of AOI equipment usually depends on the performance of the detection algorithm. Therefore, high-performance texture surface defect detection algorithms are studied to achieve high-precision and highly robust detection of various texture surface defects, which is important for improving the quality and efficiency of automated industrial production. There's important meaning.

目前已有大量纹理表面缺陷检测算法被提出,但这些算法在实际生产场景下难以达到高精度且高效率的检测性能。基于图像重建的方法尝试将缺陷图像重建为正常图像,然后计算原始图像与重建图像之间的残差来检测缺陷,但是这种方法容易在重建过程中将缺陷也很好地重建出来,导致漏检。基于嵌入相似度的方法在训练过程中需要不断计算并储存正常图像的嵌入向量,然后在测试阶段计算待测图像的嵌入向量与已储存的正常嵌入向量之间的距离,距离偏远的则被判断为缺陷,这种方法的检测结果不仅粗糙而且需要额外的储存开销,储存开销会随着训练集的增长而线性增长,同时由于需要计算大量向量之间的距离,该算法的计算过程极其耗时,难以满足工业生产中的实时性需求。A large number of texture surface defect detection algorithms have been proposed, but these algorithms are difficult to achieve high-precision and efficient detection performance in actual production scenarios. Methods based on image reconstruction try to reconstruct the defective image into a normal image, and then calculate the residual between the original image and the reconstructed image to detect defects. However, this method is prone to reconstructing the defects well during the reconstruction process, resulting in leakage. Check. The method based on embedding similarity needs to continuously calculate and store the embedding vector of the normal image during the training process, and then calculate the distance between the embedding vector of the image to be tested and the stored normal embedding vector during the test phase. The distance between the embedding vector and the stored normal embedding vector is judged. As a drawback, the detection results of this method are not only rough but also require additional storage overhead. The storage overhead will increase linearly with the growth of the training set. At the same time, due to the need to calculate the distance between a large number of vectors, the calculation process of this algorithm is extremely time-consuming. , It is difficult to meet the real-time needs in industrial production.

因此,为了促进生产工艺的改善、提升良品率,需要提出一种鲁棒的纹理表面缺陷检测算法,在面对复杂多变的生产环境和纹理表面缺陷时均能实现优秀的检测效果。Therefore, in order to promote the improvement of the production process and increase the yield rate, it is necessary to propose a robust texture surface defect detection algorithm that can achieve excellent detection results in the face of complex and changeable production environments and texture surface defects.

发明内容Contents of the invention

针对现有技术的缺陷和改进需求,本发明提供了一种基于教师-学生网络的纹理表面缺陷检测方法,其目的在于提出一种鲁棒的纹理表面缺陷检测算法,针对复杂工业环境下的各类纹理缺陷都能实现精确检测。In view of the shortcomings and improvement needs of the existing technology, the present invention provides a texture surface defect detection method based on a teacher-student network. Its purpose is to propose a robust texture surface defect detection algorithm for various tasks in complex industrial environments. Texture-like defects can be accurately detected.

为实现上述目的,按照本发明的一个方面,提供了一种基于教师-学生网络的纹理表面缺陷检测方法,采用基于纹理表面缺陷图像所训练的包括学生网络和双分支解码模块的纹理表面缺陷检测模型实现,包括:In order to achieve the above object, according to one aspect of the present invention, a texture surface defect detection method based on a teacher-student network is provided, using a texture surface defect detection method including a student network and a dual-branch decoding module trained based on texture surface defect images. Model implementation, including:

采用预训练教师网络以及所述学生网络分别对待检测纹理表面图像进行编码,得到各自对应的多尺度特征;The pre-trained teacher network and the student network are used to encode the texture surface image to be detected respectively to obtain corresponding multi-scale features;

采用所述双分支解码模块,对由所述学生网络所得到的多尺度特征中最深层尺度特征进行语义分割和特征恢复,对应得到缺陷分割图像以及与由所述教师网络所得到的多尺度特征具有相同多尺度的伪正常特征;The dual-branch decoding module is used to perform semantic segmentation and feature recovery on the deepest scale features among the multi-scale features obtained by the student network, corresponding to the defect segmentation image and the multi-scale features obtained by the teacher network. Pseudo-normal features with the same multiple scales;

计算所述多尺度伪正常特征中每一尺度特征与由所述教师网络所得到的多尺度特征中对应尺度特征之间的余弦相似度,得到对应的异常分数图;将各尺度的异常分数图上采样至待检测纹理表面图像尺寸并逐像素相乘,得到全局异常分数图;Calculate the cosine similarity between each scale feature in the multi-scale pseudo-normal features and the corresponding scale feature in the multi-scale features obtained by the teacher network to obtain the corresponding abnormal score map; convert the abnormal score map of each scale Upsample to the size of the texture surface image to be detected and multiply it pixel by pixel to obtain the global anomaly score map;

将所述缺陷分割图像和所述全局异常分数图进行融合,得到检测结果图像,完成纹理表面缺陷检测。The defect segmentation image and the global anomaly score map are fused to obtain a detection result image to complete texture surface defect detection.

进一步,所述纹理表面缺陷图像在训练阶段为人工缺陷图像,其采用如下方式所构建得到:Furthermore, the texture surface defect image is an artificial defect image in the training stage, which is constructed in the following way:

对一张纹理表面正常图像进行增强处理;对由柏林噪声所生成的噪声图像进行阈值处理并二值化,得到人工缺陷掩膜图像;融合另一张纹理表面正常图像、所述增强处理后的纹理表面正常图像以及所述人工缺陷掩膜图像,得到人工缺陷图像。A normal image of a textured surface is enhanced; a noise image generated by Perlin noise is thresholded and binarized to obtain an artificial defect mask image; another normal image of a textured surface is fused with the enhanced image The normal image of the textured surface and the artificial defect mask image are used to obtain the artificial defect image.

进一步,在所述纹理表面缺陷检测模型的训练过程中所采用的损失函数包括:像素级对比解耦蒸馏损失,语义分割损失,以及特征恢复损失;Further, the loss functions used in the training process of the texture surface defect detection model include: pixel-level contrast decoupled distillation loss, semantic segmentation loss, and feature recovery loss;

其中,所述像素级对比解耦蒸馏损失用于显式引导学生网络对于图像中正常特征编码和缺陷特征编码的区分度,其构建方式为:对所述人工缺陷掩膜图像下采样,得到纹理和缺陷两类特征的语义标签;根据所述语义标签,对人工缺陷特征嵌入中的纹理和缺陷两类特征进行解耦分离,得到正常特征向量集合和缺陷特征向量集合,基于正常特征向量集合和缺陷特征向量集合,计算像素级对比解耦蒸馏损失,以提高所述正常特征向量集合与正常特征嵌入之间的相似度以及降低所述缺陷特征向量集合与正常特征嵌入之间的相似度;所述人工缺陷特征嵌入为由学生网络对人工缺陷图像进行编码所得到的多尺度人工缺陷特征中最深层尺度的人工缺陷特征;所述正常特征嵌入为:由预训练教师网络对所述另一张纹理表面正常图像进行编码,并由线性映射器对编码得到的多尺度正常特征中最深层尺度特征在空间维度上进行微调得到;Among them, the pixel-level contrast decoupling distillation loss is used to explicitly guide the student network to distinguish between normal feature encoding and defect feature encoding in the image. The construction method is: downsampling the artificial defect mask image to obtain the texture and defect features; according to the semantic labels, the texture and defect features in the artificial defect feature embedding are decoupled and separated, and a normal feature vector set and a defect feature vector set are obtained. Based on the normal feature vector set and Defect feature vector set, calculate pixel-level contrast decoupling distillation loss to improve the similarity between the normal feature vector set and normal feature embedding and reduce the similarity between the defect feature vector set and normal feature embedding; so The artificial defect feature embedding is the deepest scale artificial defect feature among the multi-scale artificial defect features obtained by encoding the artificial defect image by the student network; the normal feature embedding is: the other image is encoded by the pre-trained teacher network The texture surface normal image is encoded, and the deepest scale feature among the encoded multi-scale normal features is fine-tuned in the spatial dimension by a linear mapper;

所述语义分割损失用于监督双分支解码模块中语义分割分支所输出的缺陷分割图像接近所述人工缺陷掩膜图像;The semantic segmentation loss is used to supervise that the defect segmentation image output by the semantic segmentation branch in the dual-branch decoding module is close to the artificial defect mask image;

所述特征恢复损失用于监督双分支解码模块中特征恢复分支所述输出的多尺度伪正常特征接近所述多尺度正常特征。The feature recovery loss is used to supervise that the multi-scale pseudo-normal features output by the feature recovery branch in the dual-branch decoding module are close to the multi-scale normal features.

进一步,所述像素级对比解耦蒸馏损失表示为:Further, the pixel-level contrast decoupling distillation loss is expressed as:

式中,Lintra表示所述像素级对比解耦蒸馏损失,VN表示正常特征向量集合中正常特征向量的数量,表示第i个正常特征向量,VD表示缺陷特征向量集合中缺陷特征向量的数量,/>表示第j个缺陷特征向量,/>表示所述正常特征嵌入中与/>位于同一空间位置处的特征向量,/>表示所述正常特征嵌入中与/>位于同一空间位置处的特征向量,τ表示用来平滑数据分布的温度参数,sim(·)表示余弦相似度。In the formula, L intra represents the pixel-level contrast decoupling distillation loss, VN represents the number of normal feature vectors in the normal feature vector set, represents the i-th normal feature vector, VD represents the number of defect feature vectors in the defect feature vector set, /> Represents the jth defect feature vector,/> Represents the normal feature embedding with/> Feature vectors located at the same spatial position,/> Represents the normal feature embedding with/> Feature vectors located at the same spatial position, τ represents the temperature parameter used to smooth the data distribution, and sim(·) represents cosine similarity.

进一步,所述像素级对比解耦蒸馏损失表示为:Further, the pixel-level contrast decoupling distillation loss is expressed as:

式中,Lc表示所述像素级对比解耦蒸馏损失,表示同一批次的随机的另一正常特征嵌入中与/>位于同一空间位置处的特征向量,/>表示所述另一正常特征嵌入中与/>位于同一空间位置处的特征向量。In the formula, L c represents the pixel-level contrast decoupling distillation loss, Represents another random normal feature embedding of the same batch with/> Feature vectors located at the same spatial position,/> Represents the other normal feature embedding with/> Eigenvectors located at the same spatial location.

进一步,所述特征恢复损失具体为全局特征掩膜感知蒸馏损失,其构建方式为:Further, the feature recovery loss is specifically a global feature mask-aware distillation loss, and its construction method is:

对所述多尺度正常特征中每一尺度特征采用与检测模型一同待训练的语义标记进行掩膜感知蒸馏,生成对应尺度的第一特征级掩膜;同时对多尺度伪正常特征中每一尺度特征采用所述可训练的语义标记进行掩膜感知蒸馏,得到对应尺度的第二特征级掩膜;对每一尺度下的第一特征级掩膜和第二特征级掩膜进行融合,得到该尺度下的全局感知掩膜;For each scale feature in the multi-scale normal features, the semantic tags to be trained together with the detection model are used for mask-aware distillation to generate a first feature-level mask corresponding to the scale; at the same time, each scale of the multi-scale pseudo-normal features is The feature uses the trainable semantic mark to perform mask-aware distillation to obtain a second feature-level mask corresponding to the scale; the first feature-level mask and the second feature-level mask at each scale are fused to obtain the Global perceptual mask at scale;

采样稠密监督方式,计算每一尺度下的正常特征和伪正常特征之间在空间维度上的L2距离,用以结合该尺度下的全局感知掩膜,计算该尺度下的特征掩膜感知蒸馏损失;综合所有尺度下的特征掩膜感知蒸馏损失,得到全局特征掩膜感知蒸馏损失。Sampling dense supervision method, calculating the L2 distance in the spatial dimension between normal features and pseudo-normal features at each scale, used to combine with the global perceptual mask at that scale, and calculate the feature mask perceptual distillation loss at this scale ;Synthesize the feature mask-aware distillation loss at all scales to obtain the global feature mask-aware distillation loss.

进一步,每一尺度下的特征掩膜感知蒸馏损失表示为:Furthermore, the feature mask-aware distillation loss at each scale is expressed as:

式中,Hk表示第k尺度下的特征高度,Wk表示第k尺度下的特征宽度,Mk表示第k尺度下的全局感知掩膜,Dk表示第k尺度下的所述L2距离。In the formula, Hk represents the feature height at the kth scale, Wk represents the feature width at the kth scale, Mk represents the global sensing mask at the kth scale, and Dk represents the L2 distance at the kth scale. .

进一步,所述语义分割损失表示为:Further, the semantic segmentation loss is expressed as:

式中,表示计算期望,||·||1表示L1范数,Im表示所述人工缺陷掩膜图像,Is表示缺陷分割图像,Id表示所述人工缺陷图像。In the formula, represents the calculation expectation, ||·|| 1 represents the L1 norm, I m represents the artificial defect mask image, I s represents the defect segmentation image, and I d represents the artificial defect image.

本发明还提供一种计算机可读存储介质,所述计算机可读存储介质包括存储的计算机程序,其中,在所述计算机程序被处理器运行时控制所述存储介质所在设备执行如上所述的纹理表面缺陷检测方法。The present invention also provides a computer-readable storage medium. The computer-readable storage medium includes a stored computer program, wherein when the computer program is run by a processor, the device where the storage medium is located is controlled to execute the texture as described above. Surface defect detection methods.

总体而言,通过本发明所构思的以上技术方案,能够取得以下有益效果:Generally speaking, through the above technical solutions conceived by the present invention, the following beneficial effects can be achieved:

(1)本发明提出的纹理表面缺陷检测方法,结合预训练教师网络以及已构建的包括学生网络和双分支解码模块的纹理表面缺陷检测模型实现,其中,双分支解码模块能够实现特征恢复和语义分割。首先采用学生网络对待测图像进行编码,得到多尺度特征,双分支解码模块对该多尺度特征中最深层尺度特征分别进行语义分割和特征恢复,这期间教师网络也会对待测图像进行编码得到另一个多尺度特征,上述特征恢复所得到的伪正常特征尺度数需要与教师网络得到的特征尺度数相同,以计算每个尺度下伪特征与教师网络得到的特征之间的相似度从而构建全局异常分数图,该过程充分利用预训练教师网络的知识泛化到纹理表面缺陷检测任务中,结合教师网络的先验知识实现精细化的缺陷分割;进一步,结合语义分割得到的缺陷分割图像和全局异常分数图,作为最终的检测结果,语义分割分支得到的缺陷分割图像结果较为精细,适合检测结构性缺陷,轮廓较为清晰,而基于特征恢复分支得到的全局异常分数图,鲁棒性好,适合检测微小的逻辑性缺陷,因此本发明提出综合这两个分支的结果,可以极大提升对各类纹理表面缺陷的检测精度,应用价值高。(1) The texture surface defect detection method proposed by the present invention is implemented by combining a pre-trained teacher network and a constructed texture surface defect detection model including a student network and a dual-branch decoding module. The dual-branch decoding module can achieve feature recovery and semantics segmentation. First, the student network is used to encode the image to be tested to obtain multi-scale features. The dual-branch decoding module performs semantic segmentation and feature recovery on the deepest scale features of the multi-scale features. During this period, the teacher network will also encode the image to be tested to obtain another A multi-scale feature. The number of pseudo-normal feature scales obtained by the above feature recovery needs to be the same as the number of feature scales obtained by the teacher network, so as to calculate the similarity between the pseudo features and the features obtained by the teacher network at each scale to construct global anomalies. Score map, this process makes full use of the knowledge of the pre-trained teacher network to generalize to the texture surface defect detection task, and combines the prior knowledge of the teacher network to achieve refined defect segmentation; further, combines the defect segmentation image and global anomalies obtained by semantic segmentation Score map, as the final detection result, the defect segmentation image result obtained by the semantic segmentation branch is relatively refined, suitable for detecting structural defects, and the outline is relatively clear, while the global anomaly score map obtained based on the feature recovery branch has good robustness and is suitable for detection. Therefore, the present invention proposes to integrate the results of these two branches, which can greatly improve the detection accuracy of various texture surface defects and has high application value.

(2)本发明在训练纹理表面缺陷检测模型时,引入像素级对比解耦蒸馏损失,通过显式地驱动网络在训练过程中学习对这两类特征的差异化表征,引导学生网络对正常特征和缺陷特征进行有效的解耦分离,可以有效增强模型的判别能力,进一步提高检测性能。(2) When training the texture surface defect detection model, the present invention introduces pixel-level contrast decoupling distillation loss, explicitly drives the network to learn differentiated representations of these two types of features during the training process, and guides the student network to identify normal features. Effective decoupling and separation from defect features can effectively enhance the discriminative ability of the model and further improve detection performance.

(3)本发明在训练纹理表面缺陷检测模型时,还引入全局特征掩膜感知蒸馏损失,结合教师网络编码得到的各尺度正常特征,促进双分支解码模块中特征恢复分支对有效知识的传递,让网络在特征恢复时更加关注有价值的原型先验特征信息,全面感知多层级特征间的上下文依赖关系,进而提高检出率,降低过检率。(3) When training the texture surface defect detection model, the present invention also introduces the global feature mask perceptual distillation loss, combined with the normal features of each scale obtained by the teacher network coding, to promote the transfer of effective knowledge by the feature recovery branch in the dual-branch decoding module. This allows the network to pay more attention to valuable prototype prior feature information during feature recovery, and comprehensively perceive the contextual dependencies between multi-level features, thereby increasing the detection rate and reducing the over-detection rate.

附图说明Description of drawings

图1为本发明实施例提供的一种基于教师-学生网络的纹理表面缺陷检测方法流程框图;Figure 1 is a flow chart of a texture surface defect detection method based on a teacher-student network provided by an embodiment of the present invention;

图2为本发明实施例提供的纹理表面缺陷检测模型的训练流程示意图;Figure 2 is a schematic diagram of the training process of the textured surface defect detection model provided by an embodiment of the present invention;

图3为本发明实施例提供的感知掩膜的实现方式示意图;Figure 3 is a schematic diagram of the implementation of the sensing mask provided by the embodiment of the present invention;

图4为本发明实施例提供的特征对比解耦效果示意图;Figure 4 is a schematic diagram of the feature comparison and decoupling effect provided by the embodiment of the present invention;

图5为本发明实施例提供的缺陷检测效果示意图。Figure 5 is a schematic diagram of the defect detection effect provided by the embodiment of the present invention.

具体实施方式Detailed ways

为了使本发明的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本发明进行进一步详细说明。应当理解,此处所描述的具体实施例仅仅用以解释本发明,并不用于限定本发明。此外,下面所描述的本发明各个实施方式中所涉及到的技术特征只要彼此之间未构成冲突就可以相互组合。In order to make the purpose, technical solutions and advantages of the present invention more clear, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described here are only used to explain the present invention and are not intended to limit the present invention. In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.

实施例一Embodiment 1

一种基于教师-学生网络的纹理表面缺陷检测方法,采用基于纹理表面缺陷图像所训练的包括学生网络和双分支解码模块的纹理表面缺陷检测模型实现,如图1所示,包括:A texture surface defect detection method based on a teacher-student network is implemented using a texture surface defect detection model including a student network and a dual-branch decoding module trained based on texture surface defect images, as shown in Figure 1, including:

采用预训练教师网络以及上述学生网络分别对待检测纹理表面图像进行编码,得到各自对应的多尺度特征;The pre-trained teacher network and the above-mentioned student network are used to encode the texture surface image to be detected respectively to obtain their corresponding multi-scale features;

采用上述双分支解码模块,对由学生网络所得到的多尺度特征中最深层尺度特征进行语义分割和特征恢复,对应得到缺陷分割图像以及与由所述教师网络所得到的多尺度特征具有相同多尺度的伪正常特征;The above-mentioned dual-branch decoding module is used to perform semantic segmentation and feature recovery on the deepest scale features among the multi-scale features obtained by the student network. The corresponding defect segmentation image is obtained and has the same characteristics as the multi-scale features obtained by the teacher network. Pseudo-normal characteristics of scale;

计算多尺度伪正常特征中每一尺度特征与由教师网络所得到的多尺度特征中对应尺度特征之间的余弦相似度,得到对应的异常分数图;将各尺度的异常分数图上采样至待检测纹理表面图像尺寸并逐像素相乘,得到全局异常分数图;Calculate the cosine similarity between each scale feature in the multi-scale pseudo-normal features and the corresponding scale feature in the multi-scale features obtained by the teacher network to obtain the corresponding anomaly score map; upsample the anomaly score map at each scale to the desired Detect the texture surface image size and multiply it pixel by pixel to obtain the global anomaly score map;

将缺陷分割图像和全局异常分数图进行融合,得到检测结果图像,完成纹理表面缺陷检测。The defect segmentation image and the global anomaly score map are fused to obtain the detection result image to complete texture surface defect detection.

可作为优选的实施方式,上述纹理表面缺陷图像在训练阶段为人工缺陷图像,其采用如下方式所构建得到:As a preferred implementation, the above-mentioned texture surface defect image is an artificial defect image in the training stage, which is constructed in the following manner:

对一张纹理表面正常图像进行增强处理;对由柏林噪声所生成的噪声图像进行阈值处理并二值化,得到人工缺陷掩膜图像;融合另一张纹理表面正常图像、所述增强处理后的纹理表面正常图像以及所述人工缺陷掩膜图像,得到人工缺陷图像。A normal image of a textured surface is enhanced; a noise image generated by Perlin noise is thresholded and binarized to obtain an artificial defect mask image; another normal image of a textured surface is fused with the enhanced image The normal image of the textured surface and the artificial defect mask image are used to obtain the artificial defect image.

具体地,以单张人工缺陷图像的生成过程为例,首先,采用不放回的方式随机选取两张正常图像It和In。然后,构建数据增强变换集合:伽马矫正、亮度变换、色调变换、过曝增强、像素反转、高斯模糊、弹性变换,并可作为优选的,从该集合中随机选取三种变换来处理It,得到增强后的图像IuSpecifically, taking the generation process of a single artificial defect image as an example, first, two normal images It and In are randomly selected without replacement. Then, a data enhancement transformation set is constructed: gamma correction, brightness transformation, hue transformation, overexposure enhancement, pixel inversion, Gaussian blur, elastic transformation, and as an option, three transformations are randomly selected from this set to process I t , the enhanced image I u is obtained:

Iu=faug(It);I u = f aug (I t );

其中,Iu、It∈RW×H×C,W、H、C分别表示图像的宽度、高度、通道数,示例性地,本实施例分别选为256、256、3;faug(·)表示由三种随机变换组成的映射函数。Among them, I u , It ∈R W×H×C , W, H, and C represent the width, height, and channel number of the image respectively. For example, in this embodiment, they are selected as 256, 256, and 3 respectively; f aug ( ·) represents a mapping function composed of three random transformations.

接着,对柏林噪声生成的噪声图像Ip进行阈值处理并二值化,得到人工缺陷掩膜图像ImNext, the noise image I p generated by Perlin noise is thresholded and binarized to obtain the artificial defect mask image Im :

Im=ftb(Ip);I m = f tb (I p );

其中,Im示例性地,本实施例中Cm选为1;ftb(·)表示阈值二值化操作。Among them, I m , Illustratively, in this embodiment, C m is selected as 1; f tb (·) represents the threshold binarization operation.

最后,根据以下公式融合图像Iu、In和Im,得到人工缺陷图像IdFinally, the artificial defect image I d is obtained by merging the images I u , In and Im according to the following formula:

Id=In⊙(1-Im)+Iu⊙ImI d =I n ⊙(1-I m )+I u ⊙I m ;

其中,Id,In∈RW×H×C;⊙表示逐像素相乘操作,即Hadamard积。Among them, I d , I n ∈R W×H×C ; ⊙ represents the pixel-by-pixel multiplication operation, that is, the Hadamard product.

进一步,上述纹理表面缺陷检测模型的训练过程可为:Furthermore, the training process of the above textured surface defect detection model can be:

对人工缺陷图像采用待训练学生网络进行编码,得到多尺度人工缺陷特征,将该多尺度人工缺陷特征的最深层尺度的人工缺陷特征作为对应的人工缺陷特征嵌入;The artificial defect images are encoded using the student network to be trained to obtain multi-scale artificial defect features, and the deepest scale artificial defect features of the multi-scale artificial defect features are embedded as the corresponding artificial defect features;

采用待训练的双分支解码模块,对上述人工缺陷特征嵌入分别进行语义分割和特征恢复,对应得到缺陷分割图像以及与多尺度正常特征的尺度数相同的多尺度伪正常特征;该多尺度正常特征为由预训练教师网络对上述纹理表面正常图像In进行编码得到;Using the dual-branch decoding module to be trained, semantic segmentation and feature recovery are performed on the above-mentioned artificial defect feature embeddings, corresponding to the defect segmentation image and multi-scale pseudo-normal features with the same number of scales as the multi-scale normal features; the multi-scale normal features It is obtained by encoding the above-mentioned texture surface normal image I n by the pre-trained teacher network;

基于损失函数,对待训练学生网络和双分支解码模块的参数进行优化,重复上述过程,直至收敛,得到纹理表面缺陷检测模型。Based on the loss function, the parameters of the to-be-trained student network and the dual-branch decoding module are optimized, and the above process is repeated until convergence, and the texture surface defect detection model is obtained.

本实施例中,上述教师网络和学生网络整体可看作特征提取映射模块。如图2所示,在纹理表面缺陷检测模型的训练过程中,特征提取映射模块首先根据下式分别对纹理表面正常图像In以及对应的人工缺陷图像Id进行编码:In this embodiment, the above-mentioned teacher network and student network as a whole can be regarded as a feature extraction mapping module. As shown in Figure 2, during the training process of the texture surface defect detection model, the feature extraction mapping module first encodes the texture surface normal image I n and the corresponding artificial defect image I d according to the following formula:

其中,和/>分别表示对正常图像In和对应的人工缺陷图像Id进行编码的多尺度特征,/>表示第k层的三维特征,Nn和Nd分别表示各自特征层级数,即尺度数量,作为示例性的分别选为2、3;fT(·)和θT分别表示特征提取映射模块里教师网络的函数和参数,教师网络是预训练的且参数被冻结不更新,例如可选用ResNet18作为教师网络;fSe(·)和θSe分别表示提取映射模块里学生网络的函数和参数。in, and/> represent the multi-scale features encoding the normal image I n and the corresponding artificial defect image I d respectively, /> Represents the three-dimensional features of the kth layer. N n and N d respectively represent the number of respective feature levels, that is, the number of scales. As an example, they are selected as 2 and 3 respectively; f T (·) and θ T respectively represent the feature extraction mapping module. Functions and parameters of the teacher network. The teacher network is pre-trained and the parameters are frozen and not updated. For example, ResNet18 can be used as the teacher network; f Se (·) and θ Se respectively represent the functions and parameters of the student network in the extraction mapping module.

考虑到教师网络的预训练数据集与本发明算法的目标数据集之间存在域差异,特征提取映射模块采用一个线性映射器对多尺度正常特征中最深层尺度特征在空间维度上进行微调,得到正常特征嵌入ZnConsidering the domain differences between the pre-training data set of the teacher network and the target data set of the algorithm of the present invention, the feature extraction mapping module uses a linear mapper to map the deepest scale features among the multi-scale normal features. Fine-tuning is performed in the spatial dimension to obtain normal feature embedding Z n :

其中,作为示例性地,Wl、Hl、Cl分别为32、32、128;fpt(·)和θpt分别表示上述线性映射器的函数和参数。Zn可被视作由一系列特征向量构成的集合 in, As an example, W l , H l , and C l are 32, 32, and 128 respectively; f pt (·) and θ pt respectively represent the functions and parameters of the above linear mapper. Z n can be regarded as a set composed of a series of eigenvectors

可作为优选的实施方式,在上述纹理表面缺陷检测模型的训练过程中所采用的损失函数包括:像素级对比解耦蒸馏损失,语义分割损失,以及特征恢复损失。As a preferred implementation, the loss functions used in the training process of the above-mentioned texture surface defect detection model include: pixel-level contrast decoupling distillation loss, semantic segmentation loss, and feature recovery loss.

其中,上述像素级对比解耦蒸馏损失用于显式引导学生网络对于图像中正常特征编码和缺陷特征编码的区分度,如图2所示,其构建方式为:对上述人工缺陷掩膜图像下采样,得到纹理和缺陷两类特征的语义标签;根据上述语义标签,对人工缺陷特征嵌入中的纹理和缺陷两类特征进行解耦分离,得到正常特征向量集合和缺陷特征向量集合,基于正常特征向量集合和缺陷特征向量集合,计算像素级对比解耦蒸馏损失,以提高正常特征向量集合与上述多尺度正常特征中最深层尺度特征之间的相似度以及缩小上述缺陷特征向量集合与上述多尺度正常特征中最深层尺度特征之间的相似度;上述人工缺陷特征嵌入为由学生网络对人工缺陷图像进行编码所得到的多尺度人工缺陷特征中最深层尺度的人工缺陷特征。Among them, the above-mentioned pixel-level contrast decoupled distillation loss is used to explicitly guide the student network to distinguish between normal feature encoding and defective feature encoding in the image, as shown in Figure 2. Its construction method is: under the above artificial defect mask image Sampling, the semantic labels of texture and defect features are obtained; according to the above semantic labels, the texture and defect features in the artificial defect feature embedding are decoupled and separated, and a normal feature vector set and a defect feature vector set are obtained. Based on the normal features Vector set and defect feature vector set, calculate pixel-level contrast decoupling distillation loss to improve the similarity between the normal feature vector set and the deepest scale feature in the above-mentioned multi-scale normal features and reduce the similarity between the above-mentioned defect feature vector set and the above-mentioned multi-scale The similarity between the deepest scale features in the normal features; the above-mentioned artificial defect feature embedding is the deepest scale artificial defect feature among the multi-scale artificial defect features obtained by encoding the artificial defect image by the student network.

上述像素级对比解耦蒸馏损失的构建过程可称为对比解耦蒸馏模块,对比解耦蒸馏模块将上述的人工缺陷特征嵌入(即多尺度人工缺陷特征的最深层尺度的人工缺陷特征)在空间维度上视作由一系列向量/>构成的特征嵌入Zd,Zd与Zn在各维度(包括空间维度和通道维度上)上严格对齐,并通过正常图像的特征嵌入Zn来引导Zd中正常特征和缺陷特征之间的对比解耦蒸馏。The construction process of the above pixel-level contrast decoupling distillation loss can be called the contrast decoupling distillation module. The contrast decoupling distillation module embeds the above artificial defect features. (i.e., the deepest-scale artificial defect features of multi-scale artificial defect features) are regarded as a series of vectors in the spatial dimension/> The formed feature embedding Z d , Z d and Z n are strictly aligned in each dimension (including the spatial dimension and the channel dimension), and the feature embedding Z n of the normal image is used to guide the relationship between the normal features and defect features in Z d Contrast decoupled distillation.

首先,对人工缺陷掩膜图像Im下采样得到两类(纹理和缺陷)特征的语义标签IlFirst, the artificial defect mask image I m is downsampled to obtain the semantic labels I l of two types of features (texture and defects):

Il=fds(Im);I l = f ds (I m );

其中,fds(·)表示下采样操作。in, f ds (·) represents the downsampling operation.

然后,根据该标签对集合里的纹理特征和缺陷特征进行分类(即解耦分离):Then, according to the label, the collection Classify the texture features and defect features (i.e. decoupling and separation):

其中,和/>分别表示正常特征向量和缺陷特征向量,VN和VD分别表示两类特征在各自集合里的数量。in, and/> Represent normal feature vectors and defect feature vectors respectively, VN and VD respectively represent the number of two types of features in their respective sets.

其次,为了后续方便表示,将计算两个特征向量之间的余弦相似度,表示为符号sim(vi,vj):Secondly, for subsequent convenience of expression, the cosine similarity between the two feature vectors will be calculated, expressed as the symbol sim(v i , v j ):

其中,·表示内积,||·||2表示L2范数。Among them, · represents the inner product, ||·|| 2 represents the L2 norm.

接着,根据下式计算像素级对比解耦蒸馏损失LintraNext, the pixel-level contrast decoupling distillation loss L intra is calculated according to the following formula:

其中,τ表示用来平滑数据分布的温度参数,示例性地可设置为0.1。表示所述正常特征嵌入中与/>位于同一空间位置处的特征向量,/>表示所述正常特征嵌入中与/>位于同一空间位置处的特征向量。Among them, τ represents the temperature parameter used to smooth the data distribution, which can be set to 0.1 as an example. Represents the normal feature embedding with/> Feature vectors located at the same spatial position,/> Represents the normal feature embedding with/> Eigenvectors located at the same spatial location.

进一步可作为优选的实施方式,为了增强算法的鲁棒性,在同一批次的正常特征嵌入Zn中引入人为扰动,在批次维度上随机打乱,形成非对齐的向量集合 表示同一批次的随机的另一正常特征嵌入中的特征向量,在此基础上按照与计算Lintra相同的形式计算全局图像间的对比解耦蒸馏损失LinterAs a further preferred implementation, in order to enhance the robustness of the algorithm, artificial disturbances are introduced into the normal feature embeddings Z n of the same batch, and randomly disrupted in the batch dimension to form a non-aligned vector set. Represents the feature vector in another random normal feature embedding of the same batch. On this basis, the contrast decoupling distillation loss L inter between global images is calculated in the same form as calculating L intra :

最后,由Lintra和Linter两部分构成整体的对比解耦蒸馏损失LcFinally, the contrastive decoupling distillation loss L c composed of the two parts L intra and L inter as a whole:

在实施例中,Lc赋予Lintra和Linter两部分相等的权重,表示对二者的置信度相同。如图4所示,对比解耦蒸馏损失Lc可以为促进特征间的类可分离性提供有效约束。In the embodiment, L c gives equal weight to the two parts L intra and L inter , indicating that the confidence level for both parts is the same. As shown in Figure 4, the contrastive decoupling distillation loss L c can provide effective constraints to promote class separability between features.

双分支解码模块用于语义分割和特征恢复,语义分割表示:The dual-branch decoding module is used for semantic segmentation and feature recovery. The semantic segmentation represents:

Is=fSs(Zd;θSs);I s = f Ss (Z d ; θ Ss );

其中,Is∈RW×H×1,表示缺陷分割图像,fSs(·)和θSs分别表示语义分割分支的函数和参数。上述语义分割损失用于监督双分支解码模块中语义分割分支所输出的缺陷分割图像接近人工缺陷掩膜图像,根据下式计算分割损失LsAmong them, I s ∈R W×H×1 represents the defect segmentation image, f Ss (·) and θ Ss represent the functions and parameters of the semantic segmentation branch respectively. The above semantic segmentation loss is used to supervise the defect segmentation image output by the semantic segmentation branch in the dual-branch decoding module to be close to the artificial defect mask image. The segmentation loss L s is calculated according to the following formula:

其中,表示计算期望,||·||1表示L1范数,Im表示人工缺陷掩膜图像,Is表示缺陷分割图像,Id表示人工缺陷图像。in, represents the calculation expectation, ||·|| 1 represents the L1 norm, I m represents the artificial defect mask image, I s represents the defect segmentation image, and I d represents the artificial defect image.

上述特征恢复表示为:其中,/>表示网络恢复的多层级伪正常特征,Nr表示伪正常特征层级数,取值与Nn相同,示例性地取值为2;fSr(·)和θSr分别表示特征恢复分支的函数和参数。The above feature recovery is expressed as: Among them,/> Represents the multi-level pseudo-normal features recovered by the network, N r represents the number of pseudo-normal feature levels, the value is the same as N n , and the value is 2 for example; f Sr (·) and θ Sr respectively represent the function sum of the feature recovery branch parameter.

上述的特征恢复损失用于监督双分支解码模块中特征恢复分支输出的多尺度伪正常特征接近教师网络输出的多尺度正常特征,可作为优选的实施方式,该特征恢复损失具体为全局特征掩膜感知蒸馏损失,其构建可由掩膜感知蒸馏模块实现,如图2所示,掩膜感知蒸馏模块首先引入可训练的语义标记生成特征级掩膜,具体如图3所示,每一尺度下感知掩膜的公式化计算形式如下:The above-mentioned feature recovery loss is used to supervise the multi-scale pseudo-normal features output by the feature recovery branch in the dual-branch decoding module to be close to the multi-scale normal features output by the teacher network. It can be used as a preferred implementation. The feature recovery loss is specifically a global feature mask. Perceptual distillation loss, whose construction can be implemented by the mask-aware distillation module, as shown in Figure 2, the mask-aware distillation module first introduces trainable semantic tags Generate feature-level masks, as shown in Figure 3. The formulaic calculation form of the perceptual mask at each scale is as follows:

其中,和/>分别表示语义标记对正常特征和恢复的伪正常特征进行处理后生成的特征级掩膜,Mk表示网络学习到的全局感知掩膜;fmg(·)和θmg分别表示掩膜感知蒸馏的函数和参数。in, and/> respectively represent the feature-level masks generated after semantic labeling processes normal features and restored pseudo-normal features, M k represents the global perceptual mask learned by the network; f mg (·) and θ mg respectively represent the mask-aware distillation Functions and parameters.

然后,采用稠密监督方式计算每一尺度下正常特征和恢复的伪正常特征之间在空间维度上的L2距离:Then, a dense supervision method is used to calculate the L2 distance in the spatial dimension between the normal features and the restored pseudo-normal features at each scale:

接着,对于每一尺度的特征掩膜感知蒸馏损失,其计算方式为:Next, the feature mask-aware distillation loss for each scale is calculated as:

最后,综合多尺度的损失得到全局的掩膜感知蒸馏损失LmFinally, the global mask-aware distillation loss L m is obtained by integrating multi-scale losses:

其中,K表示在算法中用到的特征层级数量(即尺度数量),示例性的为2。Lm在训练过程中可以有效约束模型更加关注重要的上下文信息蒸馏与传递。Among them, K represents the number of feature levels (that is, the number of scales) used in the algorithm, and the example is 2. L m can effectively constrain the model to pay more attention to important contextual information distillation and transfer during the training process.

在训练纹理表面缺陷检测模型时,可根据前述得到的对比解耦蒸馏损失Lc、语义分割损失Ls、掩膜感知蒸馏损失Lm计算整体的训练损失L,依此对模型整体进行训练迭代至收敛,得到纹理表面缺陷检测模型。算法在训练阶段的整体损失计算方式如下:When training the texture surface defect detection model, the overall training loss L can be calculated based on the contrast decoupling distillation loss L c , semantic segmentation loss L s , and mask-aware distillation loss L m obtained above, and the entire model can be trained and iterated accordingly. To convergence, the texture surface defect detection model is obtained. The overall loss of the algorithm during the training phase is calculated as follows:

L=λcLcsLsmLmL=λ c L cs L sm L m ;

其中,λc、λs、λm表示用于平衡损失项的可调整的超参数,示例性的分别被设置为0.1、10、100。Among them, λ c, λ s , and λ m represent adjustable hyperparameters used to balance the loss term, and are exemplary set to 0.1, 10, and 100 respectively.

通过训练并得到纹理表面缺陷检测模型后,可在测试阶段输入一张待测图像,经过特征提取映射模块提取特征,教师网络会输出多层级的特征学生网络输出的特征会由双分支解码模块处理得到缺陷分割图像Is以及多层级的恢复特征/>示例性的Nn和Nr均为2。通过计算每一层级恢复特征与教师网络输出特征间的余弦相似度,得到每一层级的异常分数图:After training and obtaining the texture surface defect detection model, an image to be tested can be input during the testing phase, and the features will be extracted through the feature extraction mapping module. The teacher network will output multi-level features. The features output by the student network will be processed by the dual-branch decoding module to obtain the defect segmentation image I s and multi-level recovery features/> Exemplary N n and N r are both 2. By calculating the cosine similarity between the restored features at each level and the teacher network output features, the anomaly score map of each level is obtained:

将这些异常分数图上采样至输入图像尺寸,然后逐像素相乘得到全局的异常分数图IaThese anomaly score maps are upsampled to the input image size, and then multiplied pixel by pixel to obtain the global anomaly score map I a :

其中,Ia∈RW×H×1,U(·)表示插值上采样操作。Among them, I a ∈R W×H×1 , U(·) represents the interpolation upsampling operation.

最后,将缺陷分割图像Is与异常分数图Ia融合,得到检测结果图像IrFinally, the defect segmentation image I s is fused with the anomaly score map I a to obtain the detection result image I r :

Ir=G(λfIa+(1-λf)Is·max(Ia));I r =G(λ f I a +(1-λ f )I s ·max(I a ));

其中,Ir∈RW×H×1,G表示高斯去噪,0≤λf≤1用于调整两项权重占比,示例性的设置为0.5,表示对缺陷分割图像和异常分数图像的置信度相同;max(Ia)表示异常分数图Ia里的最大值。Among them, I rR W × H × 1 , G represents Gaussian denoising, 0 ≤ λ f ≤ 1 is used to adjust the weight ratio of the two items, and the exemplary setting is 0.5, which represents the defect segmentation image and the abnormal score image. The confidence level is the same; max(I a ) represents the maximum value in the anomaly score map I a .

采用本实施例所提供的检测方法,对各类纹理表面缺陷的检测效果如图5所示,其中第一行是测试图像,第二行是真值图像,第三行是检测结果在测试图像上的热力图,第四行是经过二值化处理后的检测结果图像。由图可知,本实施例所提出的纹理表面缺陷检测方法,在不使用任何真实缺陷图像的情况下,可以实现对各种不同尺度、不同形状、不同对比度且类型未知的纹理表面缺陷高精度、高效率的检测,可有效提升自动化工业生产质量和效率。Using the detection method provided in this embodiment, the detection effect of various texture surface defects is shown in Figure 5, in which the first row is the test image, the second row is the true value image, and the third row is the detection result in the test image. In the heat map above, the fourth row is the detection result image after binarization. It can be seen from the figure that the texture surface defect detection method proposed in this embodiment can achieve high-precision detection of various texture surface defects of different scales, different shapes, different contrasts and unknown types without using any real defect images. High-efficiency detection can effectively improve the quality and efficiency of automated industrial production.

实施例二Embodiment 2

一种计算机可读存储介质,所述计算机可读存储介质包括存储的计算机程序,其中,在所述计算机程序被处理器运行时控制所述存储介质所在设备执行如上实施例一所述的一种纹理表面缺陷检测方法。A computer-readable storage medium, the computer-readable storage medium includes a stored computer program, wherein when the computer program is run by a processor, the device where the storage medium is located is controlled to execute one of the methods described in Embodiment 1 above. Textured surface defect detection methods.

相关技术方案同实施例一,在此不再赘述。The relevant technical solutions are the same as those in Embodiment 1 and will not be described again here.

本领域的技术人员容易理解,以上所述仅为本发明的较佳实施例而已,并不用以限制本发明,凡在本发明的精神和原则之内所作的任何修改、等同替换和改进等,均应包含在本发明的保护范围之内。It is easy for those skilled in the art to understand that the above descriptions are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions and improvements, etc., made within the spirit and principles of the present invention, All should be included in the protection scope of the present invention.

Claims (9)

1.一种基于教师-学生网络的纹理表面缺陷检测方法,其特征在于,采用基于纹理表面缺陷图像所训练的包括学生网络和双分支解码模块的纹理表面缺陷检测模型实现,包括:1. A texture surface defect detection method based on a teacher-student network, which is characterized in that it is implemented using a texture surface defect detection model including a student network and a dual-branch decoding module trained based on texture surface defect images, including: 采用预训练教师网络以及所述学生网络分别对待检测纹理表面图像进行编码,得到各自对应的多尺度特征;The pre-trained teacher network and the student network are used to encode the texture surface image to be detected respectively to obtain corresponding multi-scale features; 采用所述双分支解码模块,对由所述学生网络所得到的多尺度特征中最深层尺度特征进行语义分割和特征恢复,对应得到缺陷分割图像以及与由所述教师网络所得到的多尺度特征具有相同多尺度的伪正常特征;The dual-branch decoding module is used to perform semantic segmentation and feature recovery on the deepest scale features among the multi-scale features obtained by the student network, corresponding to the defect segmentation image and the multi-scale features obtained by the teacher network. Pseudo-normal features with the same multiple scales; 计算所述多尺度伪正常特征中每一尺度特征与由所述教师网络所得到的多尺度特征中对应尺度特征之间的余弦相似度,得到对应的异常分数图;将各尺度的异常分数图上采样至待检测纹理表面图像尺寸并逐像素相乘,得到全局异常分数图;Calculate the cosine similarity between each scale feature in the multi-scale pseudo-normal features and the corresponding scale feature in the multi-scale features obtained by the teacher network to obtain the corresponding abnormal score map; convert the abnormal score map of each scale Upsample to the size of the texture surface image to be detected and multiply it pixel by pixel to obtain a global anomaly score map; 将所述缺陷分割图像和所述全局异常分数图进行融合,得到检测结果图像,完成纹理表面缺陷检测。The defect segmentation image and the global anomaly score map are fused to obtain a detection result image to complete texture surface defect detection. 2.根据权利要求1所述的纹理表面缺陷检测方法,其特征在于,所述纹理表面缺陷图像在训练阶段为人工缺陷图像,其采用如下方式所构建得到:2. The texture surface defect detection method according to claim 1, characterized in that the texture surface defect image is an artificial defect image in the training stage, which is constructed in the following manner: 对一张纹理表面正常图像进行增强处理;对由柏林噪声所生成的噪声图像进行阈值处理并二值化,得到人工缺陷掩膜图像;融合另一张纹理表面正常图像、所述增强处理后的纹理表面正常图像以及所述人工缺陷掩膜图像,得到人工缺陷图像。A normal image of a textured surface is enhanced; a noise image generated by Perlin noise is thresholded and binarized to obtain an artificial defect mask image; another normal image of a textured surface is fused with the enhanced image The normal image of the textured surface and the artificial defect mask image are used to obtain the artificial defect image. 3.根据权利要求2所述的纹理表面缺陷检测方法,其特征在于,在所述纹理表面缺陷检测模型的训练过程中所采用的损失函数包括:像素级对比解耦蒸馏损失,语义分割损失,以及特征恢复损失;3. The texture surface defect detection method according to claim 2, characterized in that the loss function used in the training process of the texture surface defect detection model includes: pixel-level contrast decoupling distillation loss, semantic segmentation loss, and feature recovery loss; 其中,所述像素级对比解耦蒸馏损失用于显式引导学生网络对于图像中正常特征编码和缺陷特征编码的区分度,其构建方式为:对所述人工缺陷掩膜图像下采样,得到纹理和缺陷两类特征的语义标签;根据所述语义标签,对人工缺陷特征嵌入中的纹理和缺陷两类特征进行解耦分离,得到正常特征向量集合和缺陷特征向量集合,基于正常特征向量集合和缺陷特征向量集合,计算像素级对比解耦蒸馏损失,以提高所述正常特征向量集合与正常特征嵌入之间的相似度以及降低所述缺陷特征向量集合与正常特征嵌入之间的相似度;所述人工缺陷特征嵌入为由学生网络对人工缺陷图像进行编码所得到的多尺度人工缺陷特征中最深层尺度的人工缺陷特征;所述正常特征嵌入为:由预训练教师网络对所述另一张纹理表面正常图像进行编码,并由线性映射器对编码得到的多尺度正常特征中最深层尺度特征在空间维度上进行微调得到;Among them, the pixel-level contrast decoupling distillation loss is used to explicitly guide the student network to distinguish between normal feature encoding and defect feature encoding in the image. The construction method is: downsampling the artificial defect mask image to obtain the texture and defect features; according to the semantic labels, the texture and defect features in the artificial defect feature embedding are decoupled and separated, and a normal feature vector set and a defect feature vector set are obtained. Based on the normal feature vector set and Defect feature vector set, calculate pixel-level contrast decoupling distillation loss to improve the similarity between the normal feature vector set and normal feature embedding and reduce the similarity between the defect feature vector set and normal feature embedding; so The artificial defect feature embedding is the deepest scale artificial defect feature among the multi-scale artificial defect features obtained by encoding the artificial defect image by the student network; the normal feature embedding is: the other image is encoded by the pre-trained teacher network The textured surface normal image is encoded, and the deepest scale feature among the encoded multi-scale normal features is fine-tuned in the spatial dimension by a linear mapper; 所述语义分割损失用于监督双分支解码模块中语义分割分支所输出的缺陷分割图像接近所述人工缺陷掩膜图像;The semantic segmentation loss is used to supervise that the defect segmentation image output by the semantic segmentation branch in the dual-branch decoding module is close to the artificial defect mask image; 所述特征恢复损失用于监督双分支解码模块中特征恢复分支所述输出的多尺度伪正常特征接近所述多尺度正常特征。The feature recovery loss is used to supervise that the multi-scale pseudo-normal features output by the feature recovery branch in the dual-branch decoding module are close to the multi-scale normal features. 4.根据权利要求3所述的纹理表面缺陷检测方法,其特征在于,所述像素级对比解耦蒸馏损失表示为:4. The texture surface defect detection method according to claim 3, characterized in that the pixel-level contrast decoupling distillation loss is expressed as: 式中,Lintra表示所述像素级对比解耦蒸馏损失,VN表示正常特征向量集合中正常特征向量的数量,表示第i个正常特征向量,VD表示缺陷特征向量集合中缺陷特征向量的数量,/>表示第j个缺陷特征向量,/>表示所述正常特征嵌入中与/>位于同一空间位置处的特征向量,/>表示所述正常特征嵌入中与/>位于同一空间位置处的特征向量,τ表示用来平滑数据分布的温度参数,sim(·)表示余弦相似度。In the formula, L intra represents the pixel-level contrast decoupling distillation loss, VN represents the number of normal feature vectors in the normal feature vector set, represents the i-th normal feature vector, VD represents the number of defect feature vectors in the defect feature vector set, /> Represents the jth defect feature vector,/> Represents the normal feature embedding with/> Feature vectors located at the same spatial position,/> Represents the normal feature embedding with/> Feature vectors located at the same spatial position, τ represents the temperature parameter used to smooth the data distribution, and sim(·) represents cosine similarity. 5.根据权利要求3所述的纹理表面缺陷检测方法,其特征在于,所述像素级对比解耦蒸馏损失表示为:5. The texture surface defect detection method according to claim 3, characterized in that the pixel-level contrast decoupling distillation loss is expressed as: 式中,Lc表示所述像素级对比解耦蒸馏损失,表示同一批次的随机的另一正常特征嵌入中与/>位于同一空间位置处的特征向量,/>表示所述另一正常特征嵌入中与/>位于同一空间位置处的特征向量。In the formula, L c represents the pixel-level contrast decoupling distillation loss, Represents another random normal feature embedding of the same batch with/> Feature vectors located at the same spatial position,/> Represents the other normal feature embedding with/> Eigenvectors located at the same spatial location. 6.根据权利要求3所述的纹理表面缺陷检测方法,其特征在于,所述特征恢复损失具体为全局特征掩膜感知蒸馏损失,其构建方式为:6. The texture surface defect detection method according to claim 3, characterized in that the feature recovery loss is specifically a global feature mask-aware distillation loss, and its construction method is: 对所述多尺度正常特征中每一尺度特征采用与检测模型一同待训练的语义标记进行掩膜感知蒸馏,生成对应尺度的第一特征级掩膜;同时对多尺度伪正常特征中每一尺度特征采用所述可训练的语义标记进行掩膜感知蒸馏,得到对应尺度的第二特征级掩膜;对每一尺度下的第一特征级掩膜和第二特征级掩膜进行融合,得到该尺度下的全局感知掩膜;For each scale feature in the multi-scale normal features, the semantic tags to be trained together with the detection model are used for mask-aware distillation to generate a first feature-level mask corresponding to the scale; at the same time, each scale of the multi-scale pseudo-normal features is The feature uses the trainable semantic mark to perform mask-aware distillation to obtain a second feature-level mask corresponding to the scale; the first feature-level mask and the second feature-level mask at each scale are fused to obtain the Global perceptual mask at scale; 采样稠密监督方式,计算每一尺度下的正常特征和伪正常特征之间在空间维度上的L2距离,用以结合该尺度下的全局感知掩膜,计算该尺度下的特征掩膜感知蒸馏损失;综合所有尺度下的特征掩膜感知蒸馏损失,得到全局特征掩膜感知蒸馏损失。Sampling dense supervision method, calculating the L2 distance in the spatial dimension between normal features and pseudo-normal features at each scale, used to combine with the global perceptual mask at that scale, and calculate the feature mask perceptual distillation loss at this scale ;Synthesize the feature mask-aware distillation loss at all scales to obtain the global feature mask-aware distillation loss. 7.根据权利要求6所述的纹理表面缺陷检测方法,其特征在于,每一尺度下的特征掩膜感知蒸馏损失表示为:7. The texture surface defect detection method according to claim 6, characterized in that the feature mask perceptual distillation loss at each scale is expressed as: 式中,Hk表示第k尺度下的特征高度,Wk表示第k尺度下的特征宽度,Mk表示第k尺度下的全局感知掩膜,Dk表示第k尺度下的所述L2距离。In the formula, Hk represents the feature height at the kth scale, Wk represents the feature width at the kth scale, Mk represents the global sensing mask at the kth scale, and Dk represents the L2 distance at the kth scale. . 8.根据权利要求3所述的纹理表面缺陷检测方法,其特征在于,所述语义分割损失表示为:8. The texture surface defect detection method according to claim 3, characterized in that the semantic segmentation loss is expressed as: 式中,表示计算期望,||·||1表示L1范数,Im表示所述人工缺陷掩膜图像,Is表示缺陷分割图像,Id表示所述人工缺陷图像。In the formula, represents the calculation expectation, ||·|| 1 represents the L1 norm, I m represents the artificial defect mask image, I s represents the defect segmentation image, and I d represents the artificial defect image. 9.一种计算机可读存储介质,其特征在于,所述计算机可读存储介质包括存储的计算机程序,其中,在所述计算机程序被处理器运行时控制所述存储介质所在设备执行如权利要求1至8任一项所述的纹理表面缺陷检测方法。9. A computer-readable storage medium, characterized in that the computer-readable storage medium includes a stored computer program, wherein when the computer program is run by a processor, the device where the storage medium is located is controlled to execute as claimed in claim The texture surface defect detection method described in any one of 1 to 8.
CN202311663492.8A 2023-12-06 2023-12-06 Texture surface defect detection method based on teacher-student network Pending CN117635585A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311663492.8A CN117635585A (en) 2023-12-06 2023-12-06 Texture surface defect detection method based on teacher-student network

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311663492.8A CN117635585A (en) 2023-12-06 2023-12-06 Texture surface defect detection method based on teacher-student network

Publications (1)

Publication Number Publication Date
CN117635585A true CN117635585A (en) 2024-03-01

Family

ID=90021343

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311663492.8A Pending CN117635585A (en) 2023-12-06 2023-12-06 Texture surface defect detection method based on teacher-student network

Country Status (1)

Country Link
CN (1) CN117635585A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN118154607A (en) * 2024-05-11 2024-06-07 湖南大学 Lightweight defect detection method based on mixed multiscale knowledge distillation
CN118468230A (en) * 2024-07-10 2024-08-09 苏州元瞰科技有限公司 Glass defect detection algorithm based on multi-mode teacher and student framework
CN118864454A (en) * 2024-09-25 2024-10-29 山东省计算中心(国家超级计算济南中心) An unsupervised anomaly detection method and system based on memory expert guidance

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN118154607A (en) * 2024-05-11 2024-06-07 湖南大学 Lightweight defect detection method based on mixed multiscale knowledge distillation
CN118468230A (en) * 2024-07-10 2024-08-09 苏州元瞰科技有限公司 Glass defect detection algorithm based on multi-mode teacher and student framework
CN118864454A (en) * 2024-09-25 2024-10-29 山东省计算中心(国家超级计算济南中心) An unsupervised anomaly detection method and system based on memory expert guidance

Similar Documents

Publication Publication Date Title
CN117635585A (en) Texture surface defect detection method based on teacher-student network
CN111524135A (en) Image enhancement-based method and system for detecting defects of small hardware fittings of power transmission line
CN110648310B (en) Weak supervision casting defect identification method based on attention mechanism
CN114757904B (en) A surface defect detection method based on AI deep learning algorithm
Tian et al. CASDD: Automatic surface defect detection using a complementary adversarial network
CN114565594A (en) Image Anomaly Detection Method Based on Soft Mask Contrast Loss
Wu et al. Joint specular highlight detection and removal in single images via Unet-Transformer
Jenifa et al. Classification of cotton leaf disease using multi-support vector machine
Sun et al. 3d segmentation of pulmonary nodules based on multi-view and semi-supervised
CN115527072A (en) Chip surface defect detection method based on sparse space perception and meta-learning
CN116205876A (en) Unsupervised notebook appearance defect detection method based on multi-scale standardized flow
An et al. Patch loss: A generic multi-scale perceptual loss for single image super-resolution
CN116843611A (en) A hardware surface defect detection system based on differential sum graph neural network
Qiao et al. DeepSEM-Net: Enhancing SEM defect analysis in semiconductor manufacturing with a dual-branch CNN-Transformer architecture
CN114820541A (en) Defect detection method based on reconstructed network
CN118397074B (en) Fish target length detection method based on binocular vision
CN114429461A (en) A cross-scenario strip surface defect detection method based on domain adaptation
CN111882545B (en) Fabric defect detection method based on bidirectional information transmission and feature fusion
Tao et al. Learning multiresolution features for unsupervised anomaly localization on industrial textured surfaces
CN115100451B (en) Data expansion method for monitoring oil leakage of hydraulic pump
CN114897842B (en) Infrared small target segmentation detection method based on texture enhancement network
CN114240886B (en) Steel picture defect detection method in industrial production based on self-supervision contrast characterization learning technology
CN113362347B (en) Image defect region segmentation method and system based on super-pixel feature enhancement
Zhao et al. Cross-supervised contrastive learning domain adaptation network for steel defect segmentation
Ma et al. Unsupervised prototype-wise contrastive learning for domain adaptive semantic segmentation in remote sensing image

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination