ViT-based unsupervised grey cloth defect detection method, system, device and medium
By using an unsupervised method based on ViT, we can extract features from fabric images and locate defect regions using ViT and Fastflow network models. This solves the problems of difficult sample collection and low recognition accuracy in fabric defect detection in traditional methods, and achieves efficient defect detection.
Patent Information
- Application Number
- CN202310312114.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-27
- Publication Date
- 2025-12-09
- Estimated Expiration
- 2043-03-27
AI Technical Summary
Traditional machine vision algorithms struggle to fully model and transfer the defect features of raw fabrics. Supervised learning methods rely on defect datasets, and collecting defect samples in raw fabric scenarios is difficult, leading to challenges in identification and detection.
An unsupervised method based on ViT is adopted, which uses the ViT network model to extract multi-scale feature maps of the fabric image, combines them with the Fastflow network model to transform them into probability value heat maps, and uses bilinear interpolation to unify the scale and calculate the probability value of each pixel to locate the defect area.
It solved the problem of collecting raw fabric samples, improved the accuracy of defect detection, and enabled accurate location of defective areas.
Smart Images

Figure CN116503329B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of gray cloth defect detection, more particularly, it relates to a ViT-based unsupervised gray cloth defect detection method, system, device and medium. BACKGROUND
[0002] Defect detection is a very important application in industry. Due to the diversity of defects, it is difficult for traditional machine vision algorithms to completely model and transfer defect features, and it is difficult to scale and reuse. It is usually required to distinguish different scenes, which will waste a lot of manpower cost.
[0003] However, the deep learning method using supervised training is very dependent on the defect data set. For some gray cloth scenes, due to the low frequency of defects, the good and defective data usually shows a serious long-tail distribution, and even in some cases there is no defect sample. This real scene makes it difficult to collect a large amount of defect data for supervised learning in practice, thereby affecting the identification and detection of defects. SUMMARY
[0004] In view of the defects existing in the prior art, the purpose of the present application is to provide a ViT-based unsupervised gray cloth defect detection method, system, device and medium, which has the problems of solving the difficulty of collecting gray cloth samples, and can better extract the features of the gray cloth image to improve the function of improving the recognition accuracy.
[0005] The above technical purpose of the present application is realized by the following technical scheme:
[0006] A ViT-based unsupervised gray cloth defect detection method comprises:
[0007] Obtaining a gray cloth image;
[0008] Using a trained ViT network model to extract features of the gray cloth image to obtain a multi-scale feature map;
[0009] Using a trained Fastflow network model to convert the multi-scale feature map to obtain a probability value hotspot map of each scale feature;
[0010] Using a bilinear interpolation method to unify the scales of each probability value hotspot map to obtain a corresponding unified probability hotspot map;
[0011] According to all unified probability hotspot maps, the mean value of each pixel point is calculated to obtain the probability value of each pixel point;
[0012] Based on the probability values of all pixel points, the defect area is located.
[0013] Optionally, the ViT network model adopts a Swin Transformer network model.
[0014] Optionally, the training method of the Fastflow network model comprises:
[0015] obtaining a training sample set, wherein each sample in the training sample set is a normal feature map obtained by inputting a normal gray fabric image into the ViT network model;
[0016] inputting each sample in the training sample set into the Fastflow network to obtain an output result, and obtaining a loss function by using a maximum likelihood estimation method;
[0017] performing back propagation on the loss function in the Fastflow network, updating parameters of the Fastflow network, and obtaining a trained Fastflow network model after multiple iterations.
[0018] Optionally, the maximum likelihood estimation method comprises:
[0019] using a preset formula as a likelihood function, wherein the preset formula is:
[0020]
[0021] X is an output result of the ViT network model, and Z is an output result of the Fastflow network;
[0022] taking a logarithm of the likelihood function, replacing z with f(x), wherein f(x) represents the loss function, and deriving the loss function.
[0023] Optionally, the Fastflow network comprises a convolution layer, an activation layer, and a normalization layer.
[0024] the convolution layer and the activation layer are used for bijective mapping of the multi-channel feature map to obtain a single-channel feature map;
[0025] the normalization layer is used for forward calculation of the single-channel feature map to obtain a normalized two-dimensional matrix.
[0026] Optionally, the obtaining of the probability value of each pixel point according to the mean value of all uniform probability hotspot maps comprises:
[0027] calculating the mean value of each pixel point in all uniform probability hotspot maps to obtain the mean value of each pixel point, wherein the mean value of each pixel point is the probability value of the corresponding pixel point.
[0028] Optionally, the positioning of the defect region based on the probability values of all pixel points comprises:
[0029] Select the pixel point with a probability value less than a preset threshold from all pixel points as an abnormal pixel point;
[0030] All abnormal pixel points form at least one connected domain, and the contour of each connected domain is extracted to obtain a corresponding defect region.
[0031] An unsupervised gray fabric defect detection system based on ViT, comprising:
[0032] An acquisition module is configured to acquire a gray fabric image.
[0033] An extraction module is configured to extract a multi-scale feature map from the gray fabric image by using a trained ViT network model.
[0034] A conversion module is configured to convert the multi-scale feature map to obtain a probability value hotspot map of each scale feature by using a trained Fastflow network model.
[0035] A unification module is configured to unify the scales of the probability value hotspot maps to obtain a corresponding unified probability hotspot map by using a bilinear interpolation method.
[0036] A calculation module is configured to calculate the mean value of each pixel point to obtain the probability value of each pixel point according to all unified probability hotspot maps.
[0037] A positioning module is configured to locate a defect region based on the probability values of all pixel points.
[0038] A computer device, comprising a memory and a processor, the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.
[0039] A computer-readable storage medium, which stores a computer program, the computer program is executed by a processor to implement the steps of the above method.
[0040] In summary, the present application has the following advantages: it can solve the problem of gray fabric sample collection, and can better extract the features of the gray fabric image to obtain a multi-scale feature map, which is convenient for obtaining a probability value hotspot map under different scales to improve the recognition accuracy, and the scales of the probability value hotspot maps are unified by using a bilinear interpolation method to obtain a corresponding unified probability hotspot map, which is convenient for calculating the mean value of each pixel point under the unified scale to obtain the probability value of each pixel point, and it is convenient to determine the abnormal pixel points according to the probability values to determine the defect region, and the positioning of the defect region is realized. BRIEF DESCRIPTION OF DRAWINGS
[0041] Figure 1 is a flowchart of the unsupervised gray fabric defect detection method based on ViT provided by the present application;
[0042] Figure 2 is a structural block diagram of a ViT-based unsupervised gray fabric defect detection system provided by the present application;
[0043] Figure 3 is an internal structure diagram of a computer device in an embodiment of the present application. DETAILED DESCRIPTION
[0044] In order to make the objectives, characteristics and advantages of the present application more obvious and easy to understand, the specific embodiments of the present application are described in detail below with reference to the drawings. Several embodiments of the present application are given in the drawings. However, the present application can be realized in many different forms, and is not limited to the embodiments described herein.
[0045] In the present application, unless otherwise explicitly specified and limited, the terms "mounting", "connection", "connecting", "fixing" and the like should be understood in a broad sense, for example, can be fixedly connected, or can be detachably connected, or integrally connected; can be mechanically connected, or can be electrically connected; can be directly connected, or can be indirectly connected through an intermediate medium, or can be the internal communication of two elements. For those skilled in the art, the specific meanings of the above terms in the present application can be understood according to the specific circumstances. The terms "first", "second" are only for the purpose of description, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features limited by "first", "second" can explicitly or implicitly include one or more of the features.
[0046] The present application will be described in detail below with reference to the drawings and embodiments.
[0047] The present application provides a ViT-based unsupervised gray fabric defect detection method, as shown in Figure 1 the figure, comprising: acquiring a gray fabric image;
[0048] extracting features from the gray fabric image using a trained ViT network model to obtain a multi-scale feature map;
[0049] transforming the multi-scale feature map using a trained Fastflow network model to obtain a probability value hotspot map of each scale feature;
[0050] unifying the scales of the probability value hotspot maps using a bilinear interpolation method to obtain corresponding unified probability hotspot maps;
[0051] calculating the mean values of all unified probability hotspot maps to obtain the probability values of each pixel point;
[0052] locating a defect area based on the probability values of all pixel points.
[0053] In practical applications, the obtained cloth image can be a normal cloth image or an abnormal cloth image, and the abnormal cloth image is a cloth image with defects. The ViT (Vision transformer) network model can better learn the relationship between global features and local features. After the cloth image is input into the ViT network model, the cloth image can be accurately extracted to obtain a multi-scale feature map. The multi-scale feature map is input into the Fastflow network model to obtain a probability value hotspot map of each scale feature, so as to obtain the probability value hotspot map under different scales and improve the recognition accuracy. After obtaining the probability value hotspot map of each scale feature, in order to obtain the probability value hotspot map under a unified scale feature, the scales of each probability value hotspot map are unified by using a bilinear interpolation method to obtain a corresponding unified probability hotspot map. The scale of the unified probability hotspot map can be the same as the scale of the cloth image. After the scale is unified, the mean value of each pixel point under the scale is calculated to obtain the probability value of each pixel point, so as to determine the abnormal pixel point according to the probability value, determine the defect region, and realize the positioning of the defect region.
[0054] Further, the ViT network model adopts a Swin Transformer network model. After the cloth image is input into the Swin Transformer network model, the Swin Transformer network model first segments the cloth image to obtain a plurality of patches. The projected feature dimension is applied to a linear embedding layer through Linear Embeddin. The Swin Transformer network model adopts a sliding window operation, including a non-overlapping local window and an overlapping cross-window. The attention calculation is limited in a window, which can perform local convolution operation and save calculation amount. In the present application, the Swin Transformer parameters pre-trained by an ImageNet data set are adopted, and the parameters are frozen during training and inference, which are used for image semantic and spatial feature information extraction. The ImageNet data set is one of the most commonly used data sets for image classification, detection and positioning in the field of deep learning.
[0055] Further, the training method of the Fastflow network model comprises:
[0056] obtaining a training sample set, wherein the samples in the training sample set are normal feature maps after normal cloth images pass through the ViT network model;
[0057] inputting each sample in the training sample set into the Fastflow network to obtain an output result, and obtaining a loss function by using a maximum likelihood estimation method;
[0058] The loss function is back-propagated in the Fastflow network to update the parameters of the Fastflow network, and a trained Fastflow network model is obtained after multiple iterations of training.
[0059] In actual application, since the defects of the gray cloth are detected and located, the frequency of the defects in the gray cloth is low, and the defect samples are few. In the case of training the Fastflow network model, the normal gray cloth image is obtained, and then the normal gray cloth image is input into the SwinTransformer network model to obtain the normal feature map of the normal gray cloth. Then the normal feature map is input into the Fastflow network model for training. Since all the input is normal gray cloth image, the maximum likelihood estimation method is used. After the pixel point surrounding and global feature mapping in the normal gray cloth image are extracted, the probability value of the pixel point should be close to 1. In other embodiments, it can also be set to close to 0. Thus, the loss function can be obtained. The loss function is used to back-propagate the gradient of each layer parameter of the Fastflow network to update each parameter and obtain the trained Fastflow network model.
[0060] Further, the loss function obtained by the maximum likelihood estimation method comprises:
[0061] The preset formula is used as the likelihood function, wherein the preset formula is:
[0062]
[0063] X is the output result of the ViT network model, and Z is the output result of the Fastflow network.
[0064] The likelihood function is taken as a logarithm, z is replaced by f(x), f(x) represents the loss function, and the loss function is obtained by derivation.
[0065] Specifically, the output result of the Fastflow network is a standardized two-dimensional matrix, and the preset formula is used to obtain the standard deviation of each element in the standardized two-dimensional matrix by using the Jacobian matrix, so as to equivalently obtain the normal distribution estimation of each feature pixel. Since the input sample is a normal gray cloth image, the probability value of each feature pixel of the normal gray cloth image is close to the mean value of the normal distribution. The expectation is converted into maximum likelihood estimation, and the loss function can be obtained. The logarithm of both sides of the preset formula is taken to obtain After z is replaced by f(x), the loss function is obtained. After derivation, the loss function can be obtained, so as to realize the update of each layer parameter of the Fastflow network by using the loss function and improve the recognition accuracy.
[0066] Further, the Fastflow network comprises a convolution layer, an activation layer and a standardization layer.
[0067] The single-channel feature map is obtained by bijective mapping of the multi-channel feature map through a convolution layer and an activation layer;
[0068] The normalized two-dimensional matrix is obtained by forward calculation of the single-channel feature map through a normalization layer.
[0069] Specifically, the convolution layer can be a 3*3 or 1*1 convolution kernel, the activation layer adopts a relu function, and bijective mapping of the multi-channel feature map to the single-channel feature map can be achieved, such as compressing 64-channel feature information into single-channel flow information. The relu function makes the actual convergence speed of the Fastflow network faster, and there is no complex exponential operation, so the calculation is simple and efficient. The normalization layer performs forward calculation on the single-channel feature map, that is, normalization processing, converts high-dimensional feature information of each scale into a normalized two-dimensional matrix, and expects to obtain output values conforming to the normal distribution.
[0070] Further, the probability value of each pixel point is obtained according to the mean value of each pixel point calculated from all uniform probability hotspot maps, comprising:
[0071] The mean value of each pixel point is obtained by calculating the mean value of the same pixel point in all uniform probability hotspot maps, and the mean value of each pixel point is the probability value of the corresponding pixel point.
[0072] In actual application, after the probability value hotspot maps of each scale are unified to the same scale to obtain the corresponding uniform probability hotspot map through bilinear interpolation, the present application can combine the pixel point values under each scale, calculate the mean value of each pixel point after unification of the scale, and more accurately obtain the probability value of each pixel point to obtain an accurate detection result.
[0073] Further, the defect region is located based on the probability values of all pixel points, comprising:
[0074] The pixel points with probability values less than a preset threshold are selected from all pixel points as abnormal pixel points.
[0075] All abnormal pixel points form at least one connected domain, and the contour of each connected domain is extracted to obtain the corresponding defect region.
[0076] In practical applications, the preset threshold can be adjusted according to actual conditions, and the pixel points with probability values less than the preset threshold are regarded as abnormal pixel points, and the pixel points with probability values not less than the preset threshold are regarded as normal pixel points, that is, binary processing is performed, all abnormal pixel points can form at least one connected domain, and the outer contour of the connected domain is obtained through opencv connectedComponents and / or findContours, so as to realize positioning of the defect region, opencv is a cross-platform computer vision and machine learning software library based on Apache2.0 license (open source) and can run on Linux, Windows, Android and Mac OS operating systems, connectedComponents is used for detecting the connected domain of pixels, and findContours is used for detecting the contour of the input image, so as to complete the grey cloth defect detection and positioning.
[0077] The unsupervised grey cloth defect detection based on the ViT can solve the problem of difficult grey cloth sample collection, and can better accurately extract features of the grey cloth image to obtain a multi-scale feature map, so as to facilitate obtaining a probability value hotspot map under different scales, improve the recognition accuracy, unify the scales of the probability value hotspot maps by using a bilinear interpolation method, obtain a corresponding unified probability hotspot map, facilitate calculating the mean values of all pixel points under the unified scale, and thus obtain the probability values of the pixel points, facilitate determining abnormal pixel points according to the probability values, and thus determine the defect region, and realize positioning of the defect region.
[0078] As shown in Figure 2 The application further provides a ViT-based unsupervised grey cloth defect detection system, which comprises:
[0079] The acquisition module 10 is used for acquiring a grey cloth image.
[0080] The extraction module 20 is used for extracting a multi-scale feature map from the grey cloth image by using the trained ViT network model.
[0081] The conversion module 30 is used for converting the multi-scale feature map to obtain a probability value hotspot map of each scale feature by using the trained Fastflow network model.
[0082] The unification module 40 is used for unifying the scales of the probability value hotspot maps to obtain a corresponding unified probability hotspot map by using a bilinear interpolation method.
[0083] The calculation module 50 is used for calculating the mean values of all pixel points to obtain the probability values of the pixel points according to all unified probability hotspot maps.
[0084] The positioning module 60 is used for positioning a defect region based on the probability values of all pixel points.
[0085] The specific limitations of the ViT-based unsupervised fabric defect detection system can refer to the limitations of the ViT-based unsupervised fabric defect detection method described above, which will not be repeated here. Each module of the above-mentioned ViT-based unsupervised fabric defect detection system can be realized by software, hardware and their combination. The above-mentioned modules can be embedded in or independent of the processor in the computer device in hardware form, or can be stored in the memory in the computer device in software form, so that the processor calls and executes the operations corresponding to each of the above-mentioned modules.
[0086] In one embodiment, a computer device, which can be a server, is provided, and an internal structure diagram of the computer device can be as shown in Figure 3 The computer device includes a processor, a memory, a network interface and a database connected by a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with external terminals through network connection. The computer program is executed by the processor to implement a ViT-based unsupervised fabric defect detection method.
[0087] Those skilled in the art can understand that Figure 3 The structure shown in the figure is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. The specific computer device can include more or fewer components than those shown in the figure, or combine certain components, or have a different component arrangement.
[0088] In one embodiment, a computer device is provided, including a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the following steps:
[0089] Obtaining a fabric image;
[0090] Using the trained ViT network model to perform feature extraction on the fabric image to obtain a multi-scale feature map;
[0091] Using the trained Fastflow network model to transform the multi-scale feature map to obtain a probability value hotspot map of each scale feature;
[0092] Using a bilinear interpolation method to unify the scales of each probability value hotspot map to obtain a corresponding unified probability hotspot map;
[0093] The mean value of each pixel point is calculated according to all unified probability heat maps to obtain the probability value of each pixel point.
[0094] The defect region is located based on the probability value of all pixel points.
[0095] In an embodiment, the ViT network model adopts a SwinTransformer network model.
[0096] In an embodiment, the training method of the Fastflow network model comprises:
[0097] A training sample set is obtained, and the sample in the training sample set is a normal feature map after a normal gray cloth image is subjected to a ViT network model.
[0098] Each sample in the training sample set is input into the Fastflow network to obtain an output result, and a loss function is obtained by using a maximum likelihood estimation method.
[0099] The loss function is back propagated in the Fastflow network, the parameters of the Fastflow network are updated, and a trained Fastflow network model is obtained after multiple iterations.
[0100] In an embodiment, the loss function is obtained by using the maximum likelihood estimation method, comprising:
[0101] A preset formula is used as a likelihood function, wherein the preset formula is:
[0102]
[0103] X is an output result of the ViT network model, and Z is an output result of the Fastflow network.
[0104] The likelihood function is taken as a logarithm, z is replaced by f(x), f(x) represents the loss function, and the loss function is obtained by derivation.
[0105] In an embodiment, the Fastflow network comprises a convolution layer, an activation layer and a standardization layer.
[0106] The convolution layer and the activation layer are used for bijective mapping of the multi-channel feature map to obtain a single-channel feature map.
[0107] The standardization layer is used for forward calculation of the single-channel feature map to obtain a standardized two-dimensional matrix.
[0108] In an embodiment, the probability value of each pixel point is calculated according to all unified probability heat maps to obtain the probability value of each pixel point, comprising:
[0109] Calculate the mean value of the same pixel point in all uniform probability heat maps to obtain the mean value of each pixel point, and the mean value of each pixel point is the probability value of the corresponding pixel point.
[0110] In an embodiment, the positioning of the defect region based on the probability values of all pixel points comprises:
[0111] Selecting, from all pixel points, pixel points with probability values less than a preset threshold as abnormal pixel points.
[0112] All abnormal pixel points form at least one connected domain, and the contour of each connected domain is extracted to obtain the corresponding defect region.
[0113] In one embodiment, a computer readable storage medium is provided, and a computer program is stored on the computer readable storage medium, and the computer program is executed by a processor to implement the following steps:
[0114] Obtaining a gray cloth image;
[0115] Performing feature extraction on the gray cloth image by using a trained ViT network model to obtain a multi-scale feature map;
[0116] Converting the multi-scale feature map by using a trained Fastflow network model to obtain a probability value heat map of each scale feature;
[0117] Uniformizing the scales of the probability value heat maps by using a bilinear interpolation method to obtain corresponding uniform probability heat maps;
[0118] Calculating the mean value of each pixel point from all uniform probability heat maps to obtain the probability value of each pixel point;
[0119] Positioning the defect region based on the probability values of all pixel points.
[0120] In an embodiment, the ViT network model adopts a Swin Transformer network model.
[0121] In an embodiment, the training method of the Fastflow network model comprises:
[0122] Obtaining a training sample set, and the sample in the training sample set is a normal feature map after a normal gray cloth image is subjected to a ViT network model;
[0123] Inputting each sample in the training sample set into a Fastflow network to obtain an output result, and obtaining a loss function by using a maximum likelihood estimation method;
[0124] Performing back propagation of the loss function on the Fastflow network, updating the parameters of the Fastflow network, and obtaining a trained Fastflow network model after multiple iterations of training.
[0125] In an embodiment, the loss function obtained by using the maximum likelihood estimation method comprises:
[0126] The preset formula is taken as the likelihood function, wherein the preset formula is:
[0127]
[0128] X is an output result of the ViT network model, and Z is an output result of the Fastflow network.
[0129] The likelihood function is taken as a logarithm, z is replaced by f(x), f(x) represents the loss function, and the loss function is obtained by derivation.
[0130] In an embodiment, the Fastflow network comprises a convolution layer, an activation layer, and a normalization layer.
[0131] The convolution layer and the activation layer are used for bijective mapping of the multi-channel feature map to obtain a single-channel feature map.
[0132] The normalization layer is used for forward calculation of the single-channel feature map to obtain a normalized two-dimensional matrix.
[0133] In an embodiment, the probability value of each pixel point is obtained according to the mean value of each pixel point in all unified probability hotspot maps, comprising:
[0134] The mean value of each pixel point in all unified probability hotspot maps is calculated to obtain the mean value of each pixel point, and the mean value of each pixel point is the probability value of the corresponding pixel point.
[0135] In an embodiment, the defect region is located based on the probability value of all pixel points, comprising:
[0136] The pixel points with a probability value less than a preset threshold are selected from all pixel points as abnormal pixel points.
[0137] All abnormal pixel points form at least one connected domain, and the contour of each connected domain is extracted to obtain a corresponding defect region.
[0138] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer readable storage medium, and when the computer program is executed, the processes of the above-mentioned embodiments of the methods can be included. Any reference to memory, storage, database or other medium used in the embodiments provided in the present application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration but not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0139] The technical features of the above embodiments can be combined in any manner. In order to make the description simple, not all possible combinations of the technical features in the above embodiments are described, however, as long as the combinations of the technical features do not contradict, they should be considered as the scope of the present disclosure.
Claims
1. A ViT-based unsupervised grey cloth defect detection method, characterized in that, The method comprises the following steps: obtaining a gray cloth image; extracting multi-scale feature maps from the gray cloth image by using a trained ViT network model; transforming the multi-scale feature maps to obtain probability value hotspot maps of features of each scale by using a trained Fastflow network model; unifying the scales of the probability value hotspot maps to obtain corresponding unified probability hotspot maps by using a bilinear interpolation method; calculating the mean values of all pixel points to obtain probability values of the pixel points according to all the unified probability hotspot maps; locating a defect region based on the probability values of all the pixel points. The training method of the Fastflow network model comprises the following steps: obtaining a training sample set, wherein the samples in the training sample set are normal feature maps obtained by inputting normal gray cloth images into the ViT network model; inputting each sample in the training sample set into the Fastflow network to obtain an output result, and obtaining a loss function by using a maximum likelihood estimation method; performing back propagation on the loss function in the Fastflow network to update the parameters of the Fastflow network, and obtaining a trained Fastflow network model after multiple iterations. The method for obtaining the loss function by using the maximum likelihood estimation method comprises the following steps: The preset formula is taken as a likelihood function, wherein the preset formula is: X is an output result of the ViT network model, and Z is an output result of the Fastflow network. Taking the logarithm of the likelihood function, replacing z with , denotes the loss function, and the derivative is taken to obtain the loss function; The Fastflow network comprises a convolution layer, an activation layer and a standardization layer. The convolution layer and the activation layer are used to perform bijective mapping on multi-channel feature maps to obtain single-channel feature maps. The standardization layer is used to perform forward calculation on the single-channel feature maps to obtain a standardized two-dimensional matrix. The method for calculating the mean values of all pixel points to obtain the probability values of the pixel points according to all the unified probability hotspot maps comprises the following steps: calculating the mean values of the same pixel points in all the unified probability hotspot maps to obtain the mean values of the pixel points, wherein the mean value of each pixel point is the probability value of the corresponding pixel point. The method for locating a defect region based on the probability values of all the pixel points comprises the following steps: selecting pixel points with probability values less than a preset threshold from all the pixel points as abnormal pixel points; forming at least one connected domain from all the abnormal pixel points, and extracting the contours of each connected domain to obtain corresponding defect regions.
2. The ViT-based unsupervised grey cloth defect detection method according to claim 1, wherein, The ViT network model adopts a Swin Transformer network model.
3. A ViT-based unsupervised grey cloth defect detection system, characterized in that, The method comprises the following steps: an obtaining module, configured to obtain a gray cloth image; an extracting module, configured to extract multi-scale feature maps from the gray cloth image by using a trained ViT network model; a transforming module, configured to transform the multi-scale feature maps to obtain probability value hotspot maps of features of each scale by using a trained Fastflow network model; a unifying module, configured to unify the scales of the probability value hotspot maps to obtain corresponding unified probability hotspot maps by using a bilinear interpolation method; a calculating module, configured to calculate the mean values of all pixel points to obtain probability values of the pixel points according to all the unified probability hotspot maps; a locating module, configured to locate a defect region based on the probability values of all the pixel points. The processor executes the computer program to realize the steps of the method of claim 1 or 2.
4. A computer device comprising a memory and a processor, wherein the memory stores a computer program, and the computer device is characterized in that, The processor executes the computer program to realize the steps of the method of claim 1 or 2.
5. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program, which is executed by a processor, implements the steps of the method as claimed in claim 1 or 2.
Citation Information
Patent Citations
Industrial defect detection method and device, electronic equipment and storage medium
CN115496892A