A Method for Detecting Surface Anomalies in Industrial Products Based on Image Patch Classification
By using an image patch-based classification method and training a lightweight detector with a feature extractor and a binary classifier, the problems of strong data dependence and inaccurate detection in existing technologies are solved, and rapid and low-cost surface anomaly detection of industrial products is achieved.
Patent Information
- Application Number
- CN202411250236.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-06
- Publication Date
- 2026-01-06
- Estimated Expiration
- 2044-09-06
AI Technical Summary
Existing methods for detecting surface anomalies in industrial products rely on large datasets, making it difficult to distinguish minute defects. The complexity of the models leads to high deployment and update costs, and the detection is inaccurate.
A method based on image patch classification is adopted. By using a trained feature extractor and a binary classifier, a lightweight patch classification detector is trained by acquiring a small number of abnormal and normal samples, and abnormal regions are detected and located by patch blocks.
It reduces data collection and annotation costs, shortens training time, lowers model deployment and update costs, and improves detection speed and accuracy.
Smart Images

Figure CN119205660B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of surface detection, and particularly relates to an industrial product surface anomaly detection method based on image patch classification. BACKGROUND
[0002] It has become a general trend that artificial intelligence is applied to practical production practices, and it is an important practice to use deep learning technology for industrial product surface anomaly detection, and some industrial product surface anomaly detection methods based on deep learning technology have emerged as the times require.
[0003] However, the existing industrial product surface anomaly detection methods mainly have the following pain points: first, the existing algorithm needs a large number of normal samples and abnormal samples for model training, but it is very difficult to obtain sufficient data sets in the actual production environment, so the existing algorithm using deep learning technology for industrial product surface anomaly detection is too dependent on the data set; second, the existing algorithm often cannot distinguish the tiny defect areas that are extremely similar in vision between the abnormal samples and the normal samples, so it cannot accurately detect and locate the defects, causing missed detection, and cannot meet the needs of the actual production environment; third, the structure of the existing deep learning model is mostly extremely large and complex. In the actual production environment, the deployment and application of such models correspondingly require a certain time and money cost; in addition, the updating and adjustment of the model are closely related to the complexity of the original model structure, and with the addition of new training data, the adjustment of the structure complex model also needs to consume a large amount of time cost.
[0004] Therefore, it is imperative to find an effective deep learning industrial product surface anomaly detection method that can both escape from the dependence on the data set and conveniently and quickly train the model. SUMMARY
[0005] In order to solve the above problems in the prior art, the application provides an industrial product surface anomaly detection method based on image patch classification. The technical problems to be solved by the application are solved by the following technical scheme:
[0006] The embodiment of the application provides an industrial product surface anomaly detection method based on image patch classification, including the following steps:
[0007] An industrial product surface image is obtained;
[0008] A trained feature extractor is used to extract and cut features of the industrial product surface image to obtain a plurality of patch blocks;
[0009] The trained binary classifier is used to detect the patch blocks and obtain the anomaly score of each patch block; wherein, the trained binary classifier is trained by using a number of abnormal patch blocks containing abnormal regions of abnormal samples and a number of normal patch blocks of normal samples, and the number of patch blocks of abnormal regions covers the surface anomaly types of industrial products.
[0010] The patch blocks with the anomaly scores are rearranged and adjusted back to the shape and size of the industrial product surface image to obtain an anomaly score map. The presence of anomalies in the industrial product surface image is determined based on the anomaly score map.
[0011] In one embodiment of the present invention, the training method for the feature extractor and the binary classifier includes the following steps:
[0012] Obtain a training dataset containing images of industrial product surfaces and corresponding mask images of abnormal regions in the industrial product surface images;
[0013] Initialize the parameters of the feature extractor and the binary classifier;
[0014] Feature extraction and segmentation are performed on the images in the training dataset to obtain abnormal patch blocks for several abnormal samples and normal patch blocks for several normal samples.
[0015] Based on the abnormal regions marked in the abnormal region mask diagram, select several abnormal patch blocks that actually contain abnormalities from several abnormal patch blocks as abnormal data, and randomly select several normal patch blocks as normal data according to the number of abnormal patch blocks.
[0016] The binary classifier is trained using the abnormal data and the normal data to optimize the classification loss function of the binary classifier, and the abnormal score of each abnormal patch and each normal patch is output.
[0017] The patch blocks with the anomaly scores are rearranged and adjusted back to the shape and size of the industrial product surface image to obtain an anomaly score map;
[0018] Calculate the image loss function between the anomaly score map and the anomaly region mask map;
[0019] The network parameters of the feature extractor and the binary classifier are updated using the classification loss function and the image loss function;
[0020] When the iteration conditions are met, a trained feature extractor and a trained binary classifier are obtained.
[0021] In one embodiment of the present invention, a training dataset comprising an image of an industrial product surface and a mask image of an abnormal region corresponding to the industrial product surface image is obtained, including:
[0022] Collect image data of industrial product surfaces;
[0023] All abnormal regions of abnormal samples in the industrial product surface image data are labeled to obtain an abnormal region mask map, wherein all abnormal regions cover the abnormal types of industrial product surfaces;
[0024] The abnormal samples corresponding to the abnormal region mask map and the same number of normal samples are used as the training dataset.
[0025] In one embodiment of the present invention, feature extraction and segmentation are performed on images in the training dataset to obtain a number of abnormal patch blocks for abnormal samples and a number of normal patch blocks for normal samples, including:
[0026] The images in the training dataset are scaled and cropped to obtain several images of the same size;
[0027] Feature extraction is performed on the several images of the same size to obtain several feature maps;
[0028] The aforementioned feature maps are segmented to obtain abnormal patch blocks for several abnormal samples and normal patch blocks for several normal samples.
[0029] In one embodiment of the present invention, feature extraction is performed on the plurality of images of the same size to obtain a plurality of feature maps, including:
[0030] Feature extraction is performed on the several images of the same size using a pre-trained residual network to obtain several feature maps.
[0031] In one embodiment of the present invention, the number of normal patch blocks is 90%-110% of the number of abnormal patch blocks.
[0032] In one embodiment of the present invention, the binary classifier includes a fully connected neural network model.
[0033] In one embodiment of the present invention, the fully connected neural network model includes a first fully connected layer, a second fully connected layer, and a third fully connected layer, wherein the first fully connected layer, the second fully connected layer, and the third fully connected layer are connected sequentially, the first fully connected layer uses the ReLU activation function, the second fully connected layer uses the ReLU activation function, and the third fully connected layer uses the Sigmoid activation function.
[0034] In one embodiment of the present invention, the classification loss function includes a binary cross-entropy loss function, the expression of which is:
[0035]
[0036] Where, N batchThe number of patch blocks in a batch, x i It is the feature vector of the i-th patch block. It is a collection of exception patch blocks. Indicator functions, f(x) represents a value of 1 when the i-th patch block is abnormal, and a value of 0 when it is normal. i ;θ) is the output of the fully connected neural network model for the i-th patch block, This represents the predicted probability of the output of the i-th patch block obtained by the Sigmoid activation function of the fully connected neural network model.
[0037] In one embodiment of the present invention, determining whether there are anomalies in the surface image of the industrial product based on the anomaly score map includes:
[0038] When the anomaly score map contains a patch block with an anomaly score greater than or equal to a preset threshold, the surface image of the industrial product is considered to have an anomaly, and the anomaly location is identified.
[0039] When the abnormal score map contains patch blocks with abnormal scores below a preset threshold, the surface image of the industrial product is considered to be free of abnormalities.
[0040] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0041] The method of this invention trains a binary classifier using a number of abnormal patch blocks that truly contain abnormal regions in abnormal samples and a number of normal patch blocks in normal samples. The patch blocks in the abnormal regions only need to cover the abnormal types on the industrial product surface. Therefore, only a small number of normal and abnormal samples are needed to train the binary classifier, which not only greatly reduces training time but also saves significant data acquisition and labeling costs. Furthermore, this invention forms a patch classification detector with a feature extractor and a binary classifier, resulting in an extremely lightweight and effective structure. This significantly reduces the deployment time and operating costs of the model in actual production environments. Moreover, subsequent model updates are extremely convenient and quick, requiring only a small number of samples for updates, avoiding the shortcomings of models that are too large and complex to update in a timely and effective manner. Therefore, the industrial product surface anomaly detection method of this invention has the advantages of being independent of dataset dependencies and being able to train the model conveniently and quickly, improving the speed and accuracy of industrial product surface anomaly detection. Attached Figure Description
[0042] Figure 1 A schematic flowchart of an industrial product surface anomaly detection method based on image patch classification provided in an embodiment of the present invention;
[0043] Figure 2 A flowchart illustrating a training method for a patch classification detector provided in an embodiment of the present invention;
[0044] Figure 3 This is a test flowchart for anomaly detection of a trained patch classification detector provided in an embodiment of the present invention. Detailed Implementation
[0045] The present invention will be further described in detail below with reference to specific embodiments, but the implementation of the present invention is not limited thereto.
[0046] Example 1
[0047] Please see Figure 1 , Figure 1 This is a flowchart illustrating a method for detecting surface anomalies in industrial products based on image patch classification, provided in an embodiment of the present invention. The method includes the following steps:
[0048] S1. Obtain an image of the surface of an industrial product.
[0049] Specifically, an industrial camera is used to capture high-quality, complete images of the surface of industrial products, and the images are stored to obtain surface images of the industrial products.
[0050] S2. Using a trained feature extractor, the surface image of the industrial product is used to extract and cut features to obtain several patch blocks. Then, a trained binary classifier is used to detect the patch blocks and obtain the anomaly score of each patch block. The trained binary classifier is trained using several abnormal patch blocks containing abnormal regions of abnormal samples and several normal patch blocks of normal samples. The patch blocks of abnormal regions cover the abnormal types of the industrial product surface.
[0051] In this embodiment of the invention, a patch classification detection method is generated by combining a deep learning algorithm (deep neural network) and a binary classifier. This method comprises three parts: feature patch extraction and segmentation, training of the patch-based binary classifier, and anomaly detection and localization. The patch classification detection method consists of image input, feature map extraction, feature block segmentation, anomaly detection using the binary classifier, and localization. Specifically, feature map extraction is performed using a feature extractor, and anomaly detection is performed using a binary classifier. The feature extractor and the binary classifier together constitute the patch classification detector.
[0052] In one specific embodiment, the feature extractor includes, but is not limited to, a pre-trained residual network, for example, a pre-trained 50-layer residual network.
[0053] In one specific embodiment, the binary classifier includes a fully connected neural network model. The fully connected neural network model includes a first fully connected layer, a second fully connected layer, and a third fully connected layer, wherein the first, second, and third fully connected layers are connected sequentially. The first and second fully connected layers use the ReLU activation function, and the third fully connected layer uses the Sigmoid activation function. The loss function for the fully connected neural network model is the binary cross-entropy loss function. The optimizer is the Adam optimizer.
[0054] It should be noted that binary classifiers can also use other neural network models, and are not limited to fully connected neural network models. When a binary classifier uses a fully connected neural network model, the number of fully connected layers in the fully connected neural network model is not limited to three layers; it can also have one, two, or more layers.
[0055] Please see Figure 2 , Figure 2 This is a flowchart illustrating a training method for a feature extractor and a binary classifier provided in an embodiment of the present invention. During the training process, a small number of normal and abnormal samples are input. A pre-trained residual network is used to extract feature maps. The feature maps are then segmented and partitioned. Next, patch blocks that truly contain abnormal regions are selected from all patch blocks of abnormal samples. Finally, a number of normal patch blocks approximately equal to the number of patch blocks containing abnormal regions in the former are randomly selected from the patch blocks of normal samples. These two groups of patch blocks are then used to train a binary classifier. The parameters of the feature extractor are updated during each training iteration. The specific steps of the training method for the feature extractor and binary classifier include:
[0056] S21. Obtain a training dataset containing images of industrial product surfaces and corresponding anomaly region masks. Specifically, this includes:
[0057] S211. Collect image data of industrial product surfaces.
[0058] Specifically, industrial cameras are used to create high-quality, comprehensive images of industrial product surfaces, and these images are stored as raw image data for detecting anomalies on industrial product surfaces.
[0059] S212. Label all abnormal regions of abnormal samples in the industrial product surface image data to obtain an abnormal region mask map, wherein all abnormal regions cover the abnormal types of industrial product surfaces.
[0060] Specifically, the ImageJ dataset annotation tool was used to manually annotate all abnormal regions in a small number of abnormal samples using polygonal bounding boxes. The annotation result was a mask image, whose name corresponded one-to-one with the name of the abnormal sample.
[0061] It should be noted that a small number of anomalous samples refers to samples that can cover all types of surface anomalies on industrial products. For example, if there are 5 types of surface anomalies for a certain type of industrial product, then a small number of anomalous samples can be 50 samples. In other words, for this type of industrial product, regardless of whether the number of surface image data collected is 200 or 1000, if 50 samples can cover all surface anomaly types, then the number of a small number of anomalous samples is always 50 anomalous samples.
[0062] S213. Use the abnormal samples corresponding to the abnormal region mask map and the same number of normal samples as the training set of industrial product surface images.
[0063] Specifically, all the abnormal region mask images obtained in step S212 are stored in the `ground_truth` folder, and the abnormal samples corresponding to the mask images and an equal number of normal samples are stored in the `train` folder as the training set for industrial product surface images. Further, all remaining abnormal and normal sample images are stored in the `test` folder as the test set for industrial product surface images. This step ultimately generates an industrial product surface image dataset containing three folders (`ground_truth`, `train`, and `test`).
[0064] S22. Train the feature extractor and the binary classifier.
[0065] S221. Initialize the parameters of the feature extractor and the binary classifier.
[0066] In this embodiment, the initialization parameters mainly include three parts: First, the parameters of the feature extractor are initialized. For example, a pre-trained 50-layer residual network is used as the feature extraction network. This deep neural network is widely used for the extraction of image data features. The initialization parameters are the parameters of its pre-trained model trained on a public dataset. Second, the parameters of the binary classifier are initialized. For example, a three-layer fully connected neural network model is used as the binary classifier. The initialization parameters are the number of neurons in the three layers and the learning rate parameter of the optimizer (for example, the Adam optimizer is used). Third, the parameters of the input data preprocessing are initialized, including the scaling and cropping parameters of the training set and test set data.
[0067] S222. Perform feature extraction and segmentation on the images in the training dataset to obtain abnormal patch blocks for several abnormal samples and normal patch blocks for several normal samples.
[0068] First, obtain image data masks, image names, and category names from the training dataset according to batch size.
[0069] Then, the images in the training dataset are scaled and cropped to obtain several images of the same size.
[0070] Next, feature extraction is performed on several images of the same size to obtain several feature maps. For example, several images of the same size are input into a pre-trained residual network for feature extraction to obtain several feature maps.
[0071] Finally, several feature maps are segmented to obtain abnormal patch blocks for some abnormal samples and normal patch blocks for some normal samples, which are used as raw data for subsequent training of binary classifiers.
[0072] S223. Based on the abnormal regions marked in the abnormal region mask map, select several abnormal patch blocks that truly contain anomalies from a number of abnormal patch blocks as abnormal data for training the binary classifier, and randomly select several normal patch blocks as normal data for training the binary classifier based on the number of abnormal patch blocks. Specifically, the number of normal patch blocks is 90%-110% of the number of abnormal patch blocks.
[0073] This embodiment uses normal and abnormal patch blocks obtained from the segmentation to train the binary classifier. Moreover, it uses patch blocks that actually contain abnormal regions, rather than using the entire feature map or all normal and abnormal patch blocks for training. This can more effectively amplify the difference between normal and abnormal, because compared with the entire feature map, the segmented patch blocks have higher resolution and more obvious details. In addition, using patch blocks that actually contain defect regions is equivalent to pre-screening out those regions that do not contain defects from the feature map corresponding to the abnormal samples. This makes subsequent training and detection more accurate and effective.
[0074] In this embodiment, the number of normal and abnormal patch blocks is approximately equal and of the same order of magnitude. Since the number of abnormal patch blocks is small, the number of normal patch blocks is also small. Therefore, only a small number of normal and abnormal samples are needed to train the binary classifier, saving a lot of data collection and data labeling costs and greatly reducing training time.
[0075] S224. Train a binary classifier using abnormal and normal data to optimize the classification loss function of the binary classifier, and output the abnormal score for each abnormal patch and each normal patch.
[0076] Specifically, training a three-layer fully connected neural network model to obtain a binary classifier can be viewed as an optimization process of a loss function. The classification loss function includes the binary cross-entropy loss function, the formula of which is as follows:
[0077]
[0078] Where, N batch This represents the number of patch blocks in a batch, indicating the number of patch blocks involved in a single loss calculation; x iIt is the feature vector of the i-th patch block. It is a collection of exception patch blocks. Indicator functions; f(x) represents a value of 1 when the i-th patch block is abnormal, and a value of 0 when it is normal; i ;θ) is the output of the fully connected neural network model for the i-th patch block, This represents the predicted probability of the output of the i-th patch block obtained by the Sigmoid activation function of the fully connected neural network model.
[0079] The above formula means that for each patch block x i The cross-entropy loss consists of two parts, if x i It is an abnormal patch block, and the loss is If x i It's a normal patch block, the loss is In summary, the loss function sums and averages the losses of all patch blocks in a batch.
[0080] This embodiment chooses the binary cross-entropy loss function to update the binary classifier. The binary cross-entropy loss function converts the output of the binary classifier model into a probability value between 0.0 and 1.0 through the sigmoid function. This probabilistic interpretation makes the output value intuitive and easy to understand, and the model's output can be directly interpreted as the probability that a patch is predicted as an anomaly. Simultaneously, the binary cross-entropy loss function accurately reflects the difference between the predicted and true values. When the model's predicted value is close to the true label, the loss value is small; when the model's predicted value differs significantly from the true label, the loss value is large. This design allows the binary cross-entropy loss function to effectively reward correct classification while penalizing misclassification, thereby guiding the parameter updates of the three-layer fully connected neural network model towards improving the correct classification.
[0081] S225. Rearrange and adjust the patch blocks with anomaly scores back to the shape and size of the industrial product surface image to obtain an anomaly score map.
[0082] S226. Calculate the image loss function between the anomaly score map and the anomaly samples.
[0083] Specifically, the loss function between the anomaly score map and the anomaly samples is obtained by calculating the similarity between them. This calculation process is existing technology and will not be described in detail in this embodiment.
[0084] S227. Update the network parameters of the binary classifier and feature extractor using the classification loss function and the image loss function.
[0085] Specifically, the network parameters of the binary classifier are updated using the classification loss function, and the network parameters of the feature extractor are updated using the image loss function.
[0086] S228. When the iteration conditions are met, the trained feature extractor and the trained binary classifier are obtained.
[0087] Specifically, when the preset number of iterations is reached, the iteration stops, and a trained feature extractor and a trained binary classifier are obtained. The trained feature extractor and the trained binary classifier constitute a trained patch classification detector.
[0088] Furthermore, the trained patch classification detector was tested for anomaly detection using an industrial product surface image test set. Please refer to [link to relevant documentation]. Figure 3 , Figure 3 This is a flowchart illustrating the testing process for anomaly detection using a trained patch classification detector, as provided in this embodiment of the invention. During the testing process, a large number of remaining normal and abnormal samples are input. A pre-trained residual network is used to extract feature maps, which are then segmented and partitioned. All patch blocks are then input into a trained binary classifier. The binary classifier generates an anomaly score for each patch block within the interval [0.0, 1.0]. The patch blocks with the anomaly scores are then rearranged and adjusted back to the original image shape and size. Finally, the system determines whether the test image contains anomalies and locates the anomalies.
[0089] The testing process includes the following steps:
[0090] S231. Data Acquisition. Obtain image data, mask images, image names, and category names from the industrial product surface image test set, categorized by batch size.
[0091] S232. Scale and crop the images in the industrial product surface image test set to obtain several images of the same size; use a pre-trained residual network to extract features from the several images of the same size to obtain several feature maps; then, cut the several feature maps to obtain patch blocks of the test image.
[0092] S233. Use the trained binary classifier to detect the patch blocks of the test image and generate anomaly scores between [0.0, 1.0], thereby determining whether there are anomalies in the test image and generating the corresponding heatmap.
[0093] S3. Rearrange and adjust the patch blocks with abnormal scores back to the shape and size of the industrial product surface image to obtain an abnormal score map. Determine whether there are abnormalities in the industrial product surface image based on the abnormal score map.
[0094] Specifically, when the anomaly score map contains patch blocks with anomaly scores greater than or equal to a preset threshold, the industrial product surface image is considered to have anomalies, and the anomaly location is identified; when the anomaly score map contains patch blocks with anomaly scores less than the preset threshold, the industrial product surface image is considered to have no anomalies. For example, the anomaly score is set to [0.0, 1.0], and the preset threshold is set to 0.5.
[0095] Furthermore, when using the industrial product surface anomaly detection method based on image patch classification in this embodiment for detection in an actual production environment, for products of the same type, the trained feature extraction can be used directly to detect the surface image of the industrial product; for products of different types, the surface image data of the product of that type is used to train the patch classification detector before detection. Since the number of abnormal and normal samples required for training is small, the training time is short and the training efficiency is high.
[0096] To address the technical challenge of improving the detection speed and accuracy of existing deep learning-based methods for detecting surface anomalies in industrial products, this embodiment proposes an image patch classification-based method for detecting surface anomalies in industrial products. This method segments optical images of a small number of normal and abnormal samples into patch blocks. From these large numbers of segmented patch blocks, normal and abnormal patch blocks are selected to construct a dataset for training a deep learning model. Using a patch-based classification deep learning model (i.e., ResNet) and a multilayer perceptron (MLP) (i.e., a binary classifier), the trained patch classification detector effectively detects subtle abnormal regions and provides anomaly detection results, thereby improving the speed and accuracy of surface anomaly detection in industrial products.
[0097] This embodiment only requires a small number of normal and abnormal samples to train a patch classification detector, which not only greatly reduces training time but also saves significant data collection and annotation costs. Furthermore, the patch classification detector in this embodiment has an extremely lightweight and efficient structure, which significantly reduces the deployment time and operating costs of the model in actual production environments. Moreover, subsequent model updates are extremely convenient and quick, requiring only a small number of samples for updates, avoiding the shortcomings of models that are too large and complex to update in a timely and effective manner. Therefore, the industrial product surface anomaly detection method in this embodiment has the advantages of being independent of datasets and allowing for convenient and quick model training, thus improving the speed and accuracy of industrial product surface anomaly detection.
[0098] The above description, in conjunction with specific preferred embodiments, provides a further detailed explanation of the present invention. It should not be construed that the specific implementation of the present invention is limited to these descriptions. For those skilled in the art, various simple deductions or substitutions can be made without departing from the concept of the present invention, and all such modifications and substitutions should be considered within the scope of protection of the present invention.
Claims
1. An industrial product surface anomaly detection method based on image patch classification, characterized by, The method comprises the steps of: obtaining an industrial product surface image; performing feature extraction and cutting on the industrial product surface image by using a trained feature extractor to obtain a plurality of patch blocks, and performing detection on the plurality of patch blocks by using a trained binary classifier to obtain an anomaly score of each patch block; wherein the trained binary classifier is obtained by training the binary classifier by using a plurality of abnormal patch blocks containing abnormal regions of abnormal samples and a plurality of normal patch blocks of normal samples, and the plurality of abnormal patch blocks cover industrial product surface abnormal types; wherein the training method of the feature extractor and the binary classifier comprises the steps of: obtaining a training data set containing an industrial product surface image and an abnormal region mask image corresponding to the industrial product surface image; initializing parameters of the feature extractor and the binary classifier; performing feature extraction and cutting on the images in the training data set to obtain a plurality of abnormal patch blocks of abnormal samples and a plurality of normal patch blocks of normal samples; selecting a plurality of abnormal patch blocks actually containing abnormalities from the plurality of abnormal patch blocks as abnormal data according to the abnormal regions marked in the abnormal region mask image, and randomly selecting a plurality of normal patch blocks as normal data according to the number of abnormal patch blocks; training the binary classifier by using the abnormal data and the normal data to optimize the classification loss function of the binary classifier, and outputting an anomaly score of each abnormal patch block and each normal patch block; rearranging and adjusting the patch blocks with the anomaly scores back to the shape and size of the industrial product surface image to obtain an anomaly score image; calculating an image loss function between the anomaly score image and the abnormal region mask image; updating the network parameters of the binary classifier and the feature extractor by using the classification loss function and the image loss function; when the iteration condition is met, obtaining the trained feature extractor and the trained binary classifier; rearranging and adjusting the patch blocks with the anomaly scores back to the shape and size of the industrial product surface image to obtain an anomaly score image, and judging whether the industrial product surface image has an anomaly according to the anomaly score image.
2. The industrial surface anomaly detection method based on image patch classification according to claim 1, characterized in that, obtaining a training data set containing an industrial product surface image and an abnormal region mask image corresponding to the industrial product surface image, comprising: collecting industrial product surface image data; labeling all abnormal regions of abnormal samples in the industrial product surface image data to obtain an abnormal region mask image, wherein the all abnormal regions cover industrial product surface abnormal types; using the abnormal samples corresponding to the abnormal region mask image and the same number of normal samples as the training data set.
3. The industrial surface anomaly detection method based on image patch classification according to claim 1, characterized in that, performing feature extraction and cutting on the images in the training data set to obtain a plurality of abnormal patch blocks of abnormal samples and a plurality of normal patch blocks of normal samples, comprising: scaling and cropping the images in the training data set to obtain a plurality of images of the same size; performing feature extraction on the plurality of images of the same size to obtain a plurality of feature maps; performing cutting processing on the plurality of feature maps to obtain a plurality of abnormal patch blocks of abnormal samples and a plurality of normal patch blocks of normal samples.
4. The industrial surface anomaly detection method based on image patch classification according to claim 3, characterized in that, performing feature extraction on the plurality of images of the same size to obtain a plurality of feature maps, comprising: The pre-trained residual network is used for feature extraction on the plurality of images of the same size to obtain a plurality of feature maps.
5. The industrial surface anomaly detection method based on image patch classification according to claim 1, wherein, The number of the normal patch blocks is 90%-110% of the number of the abnormal patch blocks.
6. The industrial surface anomaly detection method based on image patch classification according to claim 1, wherein, The binary classifier comprises a fully connected neural network model.
7. The industrial surface anomaly detection method based on image patch classification according to claim 6, characterized in that, The fully connected neural network model comprises a first fully connected layer, a second fully connected layer and a third fully connected layer, wherein, The first fully connected layer, the second fully connected layer and the third fully connected layer are sequentially connected, the first fully connected layer adopts a ReLU activation function, the second fully connected layer adopts a ReLU activation function, and the third fully connected layer adopts a Sigmoid activation function.
8. The industrial surface anomaly detection method based on image patch classification according to claim 7, characterized in that, The classification loss function comprises a binary cross-entropy loss function, and an expression is as follows: where N batch is the number of batches of patches, x i is the feature vector of the i-th patch, is the set of abnormal patches, is the indicator function, represents 1 when the i-th patch is abnormal, otherwise 0, f(x i ; θ) is the output of the fully connected neural network model for the i-th patch, represents the prediction probability obtained by applying the Sigmoid activation function to the output of the fully connected neural network model for the i-th patch. 9.The industrial surface anomaly detection method based on image patch classification according to claim 1, wherein, According to the abnormal score map, whether the industrial product surface image is abnormal is determined, comprising: When the abnormal score map has a patch block with an abnormal score greater than or equal to a preset threshold, the industrial product surface image is abnormal, and an abnormal position is located; When the abnormal score map has a patch block with an abnormal score less than the preset threshold, the industrial product surface image is not abnormal.
Citation Information
Patent Citations
Block-based metal surface defect detection method and system
CN113808104A