Defect detection methods, devices, equipment and storage media
By combining a feature extraction network module and a bidirectional weighted feature network module with a weighted bidirectional feature pyramid architecture, defect detection of images is performed, which solves the problem of ignoring contextual information in existing technologies and achieves higher detection accuracy and speed.
Patent Information
- Application Number
- CN202311148035.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-06
- Publication Date
- 2025-10-31
- Estimated Expiration
- 2043-09-06
AI Technical Summary
Existing defect detection methods ignore contextual and conditional information, resulting in low detection accuracy and speed.
A feature extraction network module and a bidirectional weighted feature network module are combined with a weighted bidirectional feature pyramid architecture to perform defect detection on images. By combining preprocessing, adversarial neural network model and detection model, the contextual information association of the image is enhanced.
It improves the accuracy and speed of defect detection, reduces costs, and enhances the connection with contextual information.
Smart Images

Figure CN117252824B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image detection, and more particularly to a defect detection method, apparatus, device, and storage medium. Background Technology
[0002] Product quality and reliability are crucial to a company's success. Currently, image defect detection methods have been applied to product inspection. This refers to the process of using computer vision technology to automatically identify and locate defects, abnormalities, or undesirable parts in an image. Existing defect detection methods are generally trained based on a large amount of effective labeled data and usually focus on the extraction of local features.
[0003] This method ignores contextual and conditional information, resulting in low detection accuracy and speed. Summary of the Invention
[0004] The main objective of this invention is to provide a defect detection method, apparatus, device, and storage medium, aiming to solve the problem of how to improve both detection accuracy and speed.
[0005] To achieve the above objectives, the present invention provides a defect detection method, the defect detection method comprising the following steps:
[0006] Get the first image;
[0007] The first image is input into the detection model, and the first image is subjected to defect detection through the feature extraction network module and the bidirectional weighted feature network module in the detection model to obtain the defect detection result;
[0008] Output the results of the defect detection.
[0009] Optionally, before acquiring the first image, the process further includes:
[0010] The image to be detected is preprocessed to obtain a preprocessed image. The preprocessing includes at least mosaic data augmentation and adaptive anchor box calculation.
[0011] The preprocessed image is input into the adversarial neural network model to obtain the first image.
[0012] Optionally, before inputting the preprocessed image into the adversarial neural network model, the method further includes:
[0013] The preprocessed image is input into the generative model in the adversarial neural network algorithm to obtain a fake high-resolution image. Content loss and adversarial loss are obtained based on the fake high-resolution image and the real high-resolution image.
[0014] Construct a loss function based on the content loss and adversarial loss;
[0015] The model is trained based on the loss function to obtain the adversarial neural network model.
[0016] Optionally, obtaining content loss and adversarial loss based on the fake high-resolution image and the real high-resolution image includes:
[0017] The fake high-resolution image and the real high-resolution image are input into the VGG network for feature extraction to obtain feature maps and feature vectors corresponding to the fake high-resolution image and the real high-resolution image, respectively.
[0018] Content loss is obtained based on the feature map using the root mean square error (MSE), and the feature vectors corresponding to the fake high-resolution image and the real high-resolution image are compared to obtain the adversarial loss.
[0019] Optionally, the step of inputting the first image into the detection model and performing defect detection on the first image through the feature extraction network module and the bidirectional weighted feature network module in the detection model to obtain the defect detection result includes:
[0020] The first image is input into the detection model, and the feature extraction network module in the detection model calls a preset high-efficiency long-range aggregation network layer to process the first image to obtain the second image;
[0021] The second image is processed by calling the weighted bidirectional feature pyramid architecture through the bidirectional weighted feature network module in the detection model to obtain the defect detection result.
[0022] Optionally, the step of using the second image to call the weighted bidirectional feature pyramid architecture through the bidirectional weighted feature network module in the detection model to obtain the defect detection result includes:
[0023] The second image is processed by calling the weighted bidirectional feature pyramid architecture through the bidirectional weighted feature network module in the detection model;
[0024] The second image is weighted using the weighted bidirectional feature pyramid architecture, and the weights corresponding to the second image are automatically adjusted using an efficient feature fusion method to obtain the defect detection result.
[0025] Optionally, the weighted bidirectional feature pyramid architecture is obtained by performing tensor concatenation on the ends of the two branches responsible for feature information fusion in the feature extraction network module, and combining it with a weighted bidirectional feature pyramid.
[0026] Furthermore, to achieve the above objectives, the present invention also proposes a defect detection device, the defect detection device comprising:
[0027] The acquisition module is used to acquire the first image;
[0028] The detection module is used to input the first image into the detection model, and perform defect detection on the first image through the feature extraction network module and the bidirectional weighted feature network module in the detection model to obtain the defect detection result;
[0029] The output module is used to output the results of the defect detection.
[0030] Furthermore, to achieve the above objectives, the present invention also proposes a defect detection device, the device comprising: a memory, a processor, and a detection program stored in the memory and executable on the processor, the detection program being configured to implement the steps of the defect detection method described above.
[0031] Furthermore, to achieve the above objectives, the present invention also proposes a storage medium storing a detection program, which, when executed by a processor, implements the steps of the defect detection method as described above.
[0032] This invention acquires a first image; inputs the first image into a detection model; performs defect detection on the first image through a feature extraction network module and a bidirectional weighted feature network module in the detection model; and outputs the defect detection result. This process involves calling a preset high-efficiency long-range aggregation network layer and a weighted bidirectional feature pyramid architecture to process the image. This achieves the effects of reducing costs, better connecting contextual and conditional information, and improving detection accuracy and speed. Attached Figure Description
[0033] Figure 1 This is a schematic diagram of the structure of a defect detection device for the hardware operating environment involved in the embodiments of the present invention;
[0034] Figure 2 This is a flowchart illustrating the first embodiment of the defect detection method of the present invention;
[0035] Figure 3 This is a diagram of the generative network model structure of the defect detection method of the present invention;
[0036] Figure 4 This is a diagram of the discriminant network model structure of the defect detection method of the present invention;
[0037] Figure 5 This is a diagram of the efficient long-range aggregation network layer structure of the defect detection method of the present invention;
[0038] Figure 6 This is a diagram of the weighted bidirectional feature pyramid architecture of the defect detection method of the present invention;
[0039] Figure 7 This is a network architecture diagram of the defect detection method of the present invention, which combines the ELAN-T network with the weighted bidirectional feature pyramid architecture.
[0040] Figure 8 This is a flowchart illustrating the second embodiment of the defect detection method of the present invention;
[0041] Figure 9 This is a diagram of the algorithm network structure of the defect detection method of the present invention;
[0042] Figure 10 This is a structural block diagram of the first embodiment of the defect detection device of the present invention.
[0043] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0044] It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
[0045] Reference Figure 1 , Figure 1 This is a schematic diagram of the defect detection device structure of the hardware operating environment involved in the embodiment of the present invention.
[0046] like Figure 1 As shown, the defect detection device may include: a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. The communication bus 1002 is used to enable communication between these components. The user interface 1003 may include a display screen or an input unit such as a keyboard; optionally, the user interface 1003 may also include a standard wired interface or a wireless interface. The network interface 1004 may optionally include a standard wired interface or a wireless interface (such as a Wireless-Fidelity (Wi-Fi) interface). The memory 1005 may be a high-speed random access memory (RAM) or a stable non-volatile memory (NVM), such as a disk drive. The memory 1005 may also optionally be a storage device independent of the aforementioned processor 1001.
[0047] Those skilled in the art will understand that Figure 1 The structure shown does not constitute a limitation on the defect detection equipment and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0048] like Figure 1 As shown, the memory 1005, which serves as a storage medium, may include an operating system, a data storage module, a network communication module, a user interface module, and a detection program.
[0049] exist Figure 1 In the defect detection device shown, the network interface 1004 is mainly used for data communication with other devices; the user interface 1003 is mainly used for data interaction with the user; the processor 1001 and the memory 1005 in the defect detection device of the present invention can be set in the defect detection device, and the defect detection device calls the detection program stored in the memory 1005 through the processor 1001 and executes the defect detection method provided in the embodiment of the present invention.
[0050] This invention provides a defect detection method, referring to... Figure 2 , Figure 2 This is a flowchart illustrating the first embodiment of a defect detection method according to the present invention.
[0051] In this embodiment, the defect detection method includes:
[0052] Step S10: Obtain the first image.
[0053] The pre-processed image is fed as input into the adversarial neural network model. This step produces a first image, which may have been creatively processed and differs from the original image. The adversarial neural network model includes a generative network model and a discriminative network model, and the adversarial neural network model is trained.
[0054] It should be noted that the executing entity of this embodiment can be a defect detection method device, or other devices that can achieve the same or similar functions. This embodiment does not limit this; this embodiment uses a defect detection method device as an example for explanation.
[0055] Further, in one feasible embodiment, step S10 includes:
[0056] Step S101: Preprocess the image to be detected to obtain a preprocessed image. The preprocessing includes at least mosaic data augmentation and adaptive anchor box calculation.
[0057] It should be understood that an image to be inspected refers to a digital representation of visual information that needs to be analyzed, identified, detected, or evaluated. Such images may be obtained through methods such as photography, scanning, or generation, and are typically stored as an array of pixels, with each pixel containing information about color, brightness, and other visual attributes. Images to be inspected can cover a wide range of fields, including computer vision, medical imaging, remote sensing images, industrial quality inspection, and security monitoring.
[0058] It's important to note that Mosaic data augmentation is a commonly used image augmentation technique in computer vision and deep learning, designed to enhance the diversity and robustness of training data. This technique creates a more challenging training sample by merging multiple distinct images into a large synthetic image. Mosaic data augmentation generally includes the following steps:
[0059] Image Collection: Four distinct images are randomly selected from the training dataset; Random Cropping and Scaling: The four selected images are randomly cropped and scaled to fit them for stitching in the composite image. This helps simulate real-world scenes at different distances and scales; Composite Image Creation: The four cropped and scaled images are stitched together into a large composite image. Typically, these images are arranged in a 2x2 grid, creating a "mosaic" effect; Label Adjustment: The labels corresponding to each sub-image in the composite image also need to be adjusted accordingly. This involves updating the object positions and bounding box information to the coordinate system of the composite image.
[0060] Adaptive anchor box computation is a technique in object detection algorithms used to generate anchor boxes (also called anchor points or prior boxes) suitable for targets of different scales and aspect ratios. An anchor box is a predefined rectangular box on an image, used to attempt to match targets in the image at different locations, scales, and aspect ratios. Traditional anchor box generation methods generate a set of anchor boxes at fixed scales and aspect ratios, but real-world targets are diverse, thus requiring a more flexible method to adapt to various target shapes and sizes. This is the purpose of adaptive anchor box computation. Adaptive anchor box computation typically involves the following steps:
[0061] Feature Map Generation: Object detection algorithms typically use Convolutional Neural Networks (CNNs) to generate feature maps. These feature maps capture information at different levels in the image, such as high-level features of edges, textures, and objects. Initial Anchor Box Setup: For each location on a feature map, a set of initial anchor boxes with different scales and aspect ratios are set. Prediction on Feature Maps: On each feature map, the trained model is used to predict the target. These predictions include the target's category and location. Anchor Box Adjustment: Based on the predictions on the feature maps, the scale and aspect ratio of the anchor boxes are dynamically adjusted to better fit the actual size and shape of the target. This can be done based on the predicted target location and its position on the feature map. Target Matching: Based on the adjusted anchor boxes and the predicted target location, target matching is performed, associating the anchor boxes with the actual target. Training and Optimization: The object detection model is trained using the adjusted anchor boxes, while simultaneously optimizing the model's parameters to more accurately predict the target's location and category.
[0062] Before performing the object detection task, the images to be detected are preprocessed. Mosaic data augmentation is applied to the images, fusing four different images into a single synthetic image. This allows various scenes and objects in the images to interweave, providing the model with richer training samples. This augmentation helps the model better handle diversity and complexity, thus improving its performance in real-world environments. Furthermore, adaptive anchor box computation is introduced to adapt to the diverse sizes and shapes of the targets. Traditional anchor box setting methods often struggle to cover all possible targets; therefore, adaptive anchor box computation adjusts the scale and proportion of the anchor boxes to better match the targets. This computation considers predictions on the feature map to dynamically adjust the anchor box at each location, thereby capturing targets more accurately at different scales. The resulting preprocessed image is then obtained.
[0063] Step S102: Input the preprocessed image into the adversarial neural network model to obtain the first image.
[0064] The pre-processed image is fed into the adversarial neural network model. This step produces a first image, which may have been creatively processed and differs from the original image.
[0065] The adversarial neural network model includes a generative network model and a discriminative network model. For example, refer to... Figure 3 , Figure 3 To generate the network model structure diagram, where Input represents the input, LR represents the image to be detected, and SR represents the output, n represents the number of output channels, s represents the stride, conv represents the convolutional layer, and ReLU represents the function, it can be represented as:
[0066] f(x) = max(0,x);
[0067] Here, x is the input value, and f(x) is the output value. BN refers to Batch Normalization, a commonly used technique in deep learning to accelerate the training of neural networks and improve model stability. Elementwise Sum represents the additive structure in the residual structure. PixelShuffler is a technique used in image super-resolution and generative models, typically for converting low-resolution images into high-resolution images.
[0068] Depend on Figure 3 It can be seen that after a low-resolution image enters the generative network model of an adversarial neural network, it first passes through a convolutional network and a ReLU function, and then through B residual networks. Each residual network contains...
[0069] It contains two convolutional layers, two normalization layers, two ReLU functions, and residual edges. Finally, it enters the upsampling part, which enlarges the length and width to four times the original size, thereby improving the resolution.
[0070] Reference Figure 4 , Figure 4 To determine the network model structure diagram, where Input represents the input, Leaky ReLU is an activation function, an extension of the traditional ReLU activation function. It can be represented as:
[0071]
[0072] Here, x is the input, and α is a small positive number, usually close to 0. When x is greater than zero, the function behaves the same as ReLU; when x is less than or equal to zero, the function allows a small negative slope α. BN refers to batch normalization, and Dense refers to a fully connected layer, also known as a dense layer. A fully connected layer is a basic layer type in neural networks, where each neuron is connected to every neuron in the previous layer, forming a dense connection structure. For example, dense(1024) refers to the configuration of a neural network layer, where 1024 represents the number of neurons in that layer. Sigmoid represents an activation function. It has an S-shaped curve, and its mathematical representation is as follows:
[0073]
[0074] Where x represents the input, f(x) represents the output, and e is the natural base.
[0075] The training of the discriminative network model involves feeding real high-resolution images and fake low-resolution images into the discriminative network, comparing them with 1 and 0 respectively to obtain the loss function, and then using the loss function to discriminate the model.
[0076] Step S20: Input the first image into the detection model, and perform defect detection on the first image through the feature extraction network module and the bidirectional weighted feature network module in the detection model to obtain the defect detection result;
[0077] It should be understood that the detection model includes a feature extraction network module and a bidirectional weighted feature network module. The feature extraction network module is obtained by concatenating different features using tensors from CBL convolutional blocks, a pre-defined efficient long-range aggregation network layer (ELAN-T), and an MPConv convolutional layer. The bidirectional weighted feature network module is obtained by performing tensor concatenation operations on the ends of the two branches responsible for feature information fusion in the feature extraction network module, combined with a weighted bidirectional feature pyramid (BiFPN). By inputting the first image into the detection model, the feature extraction network module and the bidirectional weighted feature network module in the detection model perform defect detection on the first image, obtaining the defect detection result, which is represented in image form and carries image information. This information may include the location of the defect, i.e., the specific coordinates or region in the image, and the nature of the defect, such as its type. In addition, it may also include the number, size, and shape of the defects.
[0078] It's important to note that Convolutional Block Layers (CBLs) are a common module in convolutional neural networks (CNNs) used to extract features in image processing and computer vision tasks. A CBL typically consists of multiple convolutional layers, normalization layers, and activation function layers to enhance the network's feature extraction capabilities. Efficient Long-range Aggregation Networks (ELANs) are neural network layers used in image processing and computer vision tasks to introduce long-range dependencies into the network, improving feature perception and information aggregation capabilities. ELAN-T layers are a variant of ELAN networks; their primary goal is to capture a broader range of contextual information in images, leading to a better understanding of the structure and semantics within them. To achieve this, ELAN-T layers typically employ various strategies. MPConv convolutional layers are one of the core components of convolutional neural networks (CNNs). Convolutional layers are used to extract features from input data. They extract various features such as edges, textures, and shapes by applying a set of convolutional kernels (or filters) to the input data (usually an image) and sliding them across different locations. These feature extractions are achieved by calculating and summing the element-wise products between the input data and the convolutional kernels. Tensor concatenation refers to connecting or concatenating multiple tensors (multidimensional arrays) along a certain dimension to create a larger tensor. In deep learning, this is often used to combine multiple tensors together when the model processes data for further computation and analysis.
[0079] Further, in one feasible embodiment, step S20 includes:
[0080] Step S201: Input the first image into the detection model, and use the feature extraction network module in the detection model to call the preset high-efficiency long-range aggregation network layer to process the first image to obtain the second image;
[0081] The first image is imported into the detection model. Inside the model, a feature extraction network module extracts multi-level features from the image. These features capture low-level texture, mid-level object shape, and high-level semantic information. The feature maps are then processed using a pre-defined efficient long-range aggregation network layer (ELAN-T). These layers are designed to incorporate long-range correlations and contextual information between different regions within the image, thereby enhancing the image's expressiveness and perceptual range. This helps capture global information and relationships across long distances, improving the quality of image processing. This results in a more deeply processed feature map containing richer information and contextual relationships. These features are then used to generate a second image, which may differ from the original image in quality, content, or for a specific task.
[0082] Reference Figure 5 , Figure 5 This is a structure diagram of a pre-defined high-efficiency long-range aggregation network layer, where CBS represents a convolutional block used to process input data and extract features from it, and concat refers to the connection operation.
[0083] Step S202: The second image is processed by calling the weighted bidirectional feature pyramid architecture through the bidirectional weighted feature network module in the detection model to obtain the defect detection result.
[0084] Further, in one feasible embodiment, step S202 includes:
[0085] Step S2021: The second image is processed by calling the weighted bidirectional feature pyramid architecture through the bidirectional weighted feature network module in the detection model;
[0086] The second image, obtained after processing by a pre-defined efficient long-range aggregation network layer, is then processed by the bidirectional weighted feature network module in the detection model. This module employs a weighted bidirectional feature pyramid architecture, which combines features from different scales and directions to construct richer feature representations. This helps improve the accuracy and robustness of the features, enabling the model to better understand the structure and semantics in the image. Furthermore, based on bidirectional feature propagation, a pyramid structure is introduced, allowing the feature layers to interact with information at different scales.
[0087] Step S2022: The second image is weighted using the weighted bidirectional feature pyramid architecture, and the weights corresponding to the second image are automatically adjusted using an efficient feature fusion method to obtain the result of the defect detection.
[0088] It's important to note that the weighted bidirectional feature pyramid architecture functions similarly to an attention mechanism, possessing a complex bidirectional fusion structure. The second input image is weighted according to the contribution of its input features, and these weights are automatically adjusted. This is because it employs a weighted and efficient feature fusion method: fast normalization fusion, as shown in the following formula:
[0089]
[0090] Where O represents the automatically adjusted weights, w is the parameter ratio of the weights, i and j are the number of layers input to the feature fusion node (i = j), and ε is a value of 0.0001 to avoid numerical instability. i The value of each normalized weight is between 0 and 1.
[0091] The weighting mechanism allows features at different levels to be effectively combined according to their importance, thereby enhancing the expressive power of the features. This further improves the feature representation and visual information of the second image, ultimately leading to the defect detection result.
[0092] Reference Figure 6 , Figure 6 This is a weighted bidirectional feature pyramid structure diagram, where P3 to P7 are the input features. (Refer to...) Figure 7 , Figure 7 This is a network structure diagram of the ELAN-T network combined with a weighted bidirectional feature pyramid architecture, where CBS represents a convolutional block and concat refers to a connection operation.
[0093] Step S30: Output the result of the defect detection.
[0094] In the output stage, the output image passes through three Rep (Representation Layers). The Rep layers extract and transform features from the input image to obtain representations at different levels of abstraction. Each Rep layer internally extracts features to capture various features and structures within the image. Each Rep layer produces a feature representation, which is then fed into a CBM (Contextual Bi-directional Message Passing Layer) after a series of operations. The CBM layer employs a bi-directional message passing mechanism to introduce long-range dependencies between different regions within the image. This helps to better understand the global contextual information in the image.
[0095] It's important to note that Rep (Representation Layers) are neural network layers used in image processing and computer vision tasks. Their primary purpose is to extract and represent features or representations of the input data. These layers are typically used in deep learning models to transform raw data into higher-level representations, enabling subsequent tasks such as classification, detection, or segmentation to be performed more effectively. CBM (Contextual Bi-directional Message Passing Layer) is a neural network layer used in deep learning to introduce bi-directional message passing with contextual information. This layer is designed to allow each data point to communicate with its surrounding data points during data processing, thereby better capturing local and global relationships and enhancing the model's representational capabilities.
[0096] The processed feature representation is passed from the Rep layer to the CBM layer to produce predictions at three different scales. Each scale's prediction is based on the feature representation at that scale, enabling the model to predict targets at different levels. The combination of the Rep and CBM layers achieves the goal of generating predictions at different scales. This contributes to obtaining more diverse and comprehensive outputs in image analysis and computer vision tasks. By introducing image features into the prediction process from different levels, we are able to better capture details, structure, and contextual information in the image.
[0097] This embodiment, through the above-described scheme, specifically involves acquiring a first image; inputting the first image into a detection model; performing defect detection on the first image using the feature extraction network module and the bidirectional weighted feature network module in the detection model; and outputting the defect detection result. By calling a preset high-efficiency long-range aggregation network layer and a weighted bidirectional feature pyramid architecture to process the image, the contextual and conditional information is better considered, thereby improving detection accuracy and speed.
[0098] Reference Figure 8 Based on the above embodiments, in the second embodiment, before step S102, the following steps are further included:
[0099] Step S1021: Input the preprocessed image into the generative model in the adversarial neural network algorithm to obtain a fake high-resolution image, and obtain content loss and adversarial loss based on the fake high-resolution image and the real high-resolution image;
[0100] It's important to note that adversarial neural networks (ANNs) are a type of machine learning algorithm consisting of a generator and a discriminator. They are used to generate realistic data samples, such as images and audio. The core idea of ANNs is to pit the generator and discriminator against each other, allowing the generator to continuously improve the realism of the generated data. Fake high-resolution images refer to images that appear high-resolution through image processing, image generation, or other techniques, but in reality, these images lack genuine high-quality detail. These techniques may use algorithms and methods to make images look clearer and more detailed, but they are not actually generated based on the true details of the original image. Genuine high-resolution images are images obtained through high-quality equipment or acquisition methods, possessing more detail and higher image resolution. Such images typically clearly display subtle textures, edges, and details, allowing observers to more accurately identify and understand the content within the image.
[0101] Furthermore, in a feasible embodiment, the steps described above for obtaining content loss and adversarial loss based on the fake high-resolution image and the real high-resolution image include:
[0102] The fake high-resolution image and the real high-resolution image are input into the VGG network for feature extraction to obtain feature maps and feature vectors corresponding to the fake high-resolution image and the real high-resolution image, respectively.
[0103] It's important to note that the VGG network is a deep convolutional neural network model. Renowned for its simple architecture and excellent performance, the VGG network laid the foundation for convolutional neural networks in deep learning. Feature extraction refers to the process of extracting useful information or important features from raw data. In computer vision and image processing, feature extraction typically refers to extracting visual features important to the task from images, videos, or other visual data for subsequent analysis, recognition, classification, or other tasks. In deep learning, feature extraction plays a crucial role in models such as convolutional neural networks (CNNs). Convolutional layers in CNNs can automatically learn image features that capture visual information such as edges, textures, and shapes at different levels. By stacking multiple convolutional and pooling layers, the model can extract higher-level abstract features from the original image, which are very useful in subsequent tasks. Feature maps are a form used in deep learning to represent useful information or features extracted from raw data (such as images). In models such as convolutional neural networks (CNNs), feature maps are the results obtained after convolutional operations on convolutional layers. Each convolutional kernel slides across the image, and the numerical value at the corresponding position represents the degree of response of a specific feature at that position. Eigenvectors are an important concept used in linear algebra and multivariate statistics to represent a vector in a vector space. In fields such as data analysis, machine learning, and pattern recognition, eigenvectors are a commonly used tool to express important information and features in data.
[0104] Specifically, fake high-resolution images and real high-resolution images are input into a trained VGG network. The VGG network captures low-level features such as edges and textures in its earlier convolutional layers, while capturing higher-level semantic features in its deeper convolutional layers. By extracting features at different levels to understand image content, the extracted representations of various abstract features are integrated to obtain feature maps of these features across different convolutional layers. Furthermore, by performing dimensionality reduction and transformation on these features, feature vectors corresponding to each image can be obtained. These vectors can be used to quantify the content and features of the image.
[0105] Content loss is obtained based on the feature map using the root mean square error (MSE), and the feature vectors corresponding to the fake high-resolution image and the real high-resolution image are compared to obtain the adversarial loss.
[0106] It's important to note that MSE (Mean Squared Error) is a commonly used metric to measure the difference between predicted and true values, often used in regression problems. It calculates the average of the squared differences between predicted and true values, used to measure the model's prediction accuracy. Content loss involves feeding both the generator-generated fake high-resolution image and the real high-resolution image into the VGG19 network, using the output of the first 16 layers of the VGG19 network. The VGG19 network is a deep convolutional neural network, a member of the VGG network family, and it incorporates more convolutional layers.
[0107] For example, the content loss obtained from the root mean square error of MSE can be expressed as:
[0108]
[0109] The content loss is the Euclidean distance between the fake high-resolution image and the real high-resolution image. The fake high-resolution image and the real high-resolution image obtained by the generator are input into the VGG19 network in the VGG network, and the Euclidean distance is calculated for the feature map of each layer. This refers to the feature map of the j-th convolution before the i-th maxpooling layer. Maxpooling is a common pooling operation in convolutional neural networks used to reduce the size of the feature map while preserving key features. It extracts features by selecting the maximum value within a local region, thereby reducing the dimensionality of the feature map, lowering computational cost, and preventing overfitting to some extent. The Euclidean distance is the square root of the sum of squared cardinal differences. LR represents the image to be detected, and HR represents the true high-resolution image. G is the generator. H is the height, and W is the width.
[0110] Adversarial loss measures the difference between data generated by a generative model and real data. A Generative Adversarial Network (GAN) is an architecture consisting of a generator and a discriminator. The generator attempts to generate fake data that resembles real data, while the discriminator tries to distinguish between real and fake data. The goal of adversarial loss is to make the data generated by the generator as close as possible to real data in appearance and distribution, thereby improving the generator's generative ability.
[0111] For example, the formula for calculating adversarial loss is as follows:
[0112]
[0113] Among them This represents the probability that the discriminator determines the generated image to be a real high-resolution image.
[0114] Step S1022: Construct a loss function based on the content loss and adversarial loss;
[0115] Based on the above, a comprehensive loss function can be constructed by combining content loss and adversarial loss. This is applicable to generative adversarial networks (GANs), where the generator aims to generate fake data similar to real data, and the discriminator attempts to distinguish between real and fake data.
[0116] The constructed loss function is as follows:
[0117]
[0118] Step S1023: Train the model based on the loss function to obtain the adversarial neural network model.
[0119] It should be noted that the basic steps for training a model based on a loss function include:
[0120] Generator: A generator is a neural network model that takes random noise as input and attempts to generate new samples that are similar to real data samples. By continuously learning and adjusting network weights, the generator gradually improves the realism of the generated data. The goal of the generator is to deceive the discriminator, making it unable to distinguish between the generated samples and real samples.
[0121] Discriminator: The discriminator is also a neural network model that takes real data samples and samples generated by the generator as input, and then predicts whether the input is real data or generated data. The discriminator is trained to identify the differences between generated and real data, striving to accurately distinguish between these two types of input.
[0122] Training Process: The training process is an iterative one. In each iteration, the generator produces new samples, the discriminator evaluates these samples, and assigns them a truth score. Then, by comparing the discriminator's predictions with the actual results, the weights of the generator and discriminator are adjusted to make the samples generated by the generator more realistic and the discriminator more accurate.
[0123] The game process: The game between the generator and the discriminator continues until the generator can produce sufficiently realistic samples, making it difficult for the discriminator to distinguish between real and generated data. In this case, the generator can be considered successful.
[0124] The training process of an adversarial neural network is similar to a "race," where the generator continuously strives to improve the quality of the generated data, while the discriminator constantly adapts to the samples generated by the generator. This competitive and cooperative relationship ultimately enables the generator to produce very realistic data, even to the point of being difficult to distinguish from real data.
[0125] This leads to the adversarial neural network model.
[0126] Optionally, the weighted bidirectional feature pyramid architecture is obtained by performing tensor concatenation on the ends of the two branches responsible for feature information fusion in the feature extraction network module, and combining it with a weighted bidirectional feature pyramid.
[0127] It should be noted that, referring to Figure 9 , Figure 9 This is a diagram of the algorithm network structure of the present invention. It consists of four parts: an input terminal, a feature extraction network, a feature fusion network, and an output terminal.
[0128] This embodiment, through the above-described scheme, specifically involves inputting the preprocessed image into the generative model of an adversarial neural network algorithm to obtain a fake high-resolution image. Content loss and adversarial loss are then calculated based on the fake and real high-resolution images. A loss function is constructed based on the content and adversarial losses. The model is then trained using the loss function to obtain the adversarial neural network model. This improves credibility, ensures dataset quality, enhances data diversity and richness, thereby reducing data dependency and lowering costs.
[0129] In addition, to achieve the above objectives, such as Figure 10 As shown, the present invention also proposes a defect detection device, the defect detection device comprising:
[0130] Acquisition module 10 is used to acquire the first image;
[0131] The detection module 20 is used to input the first image into the detection model, and perform defect detection on the first image through the feature extraction network module and the bidirectional weighted feature network module in the detection model to obtain the result of the defect detection;
[0132] Output module 30 is used to output the results of the defect detection.
[0133] The technical solution provided in this embodiment involves acquiring a first image; inputting the first image into a detection model; performing defect detection on the first image through a feature extraction network module and a bidirectional weighted feature network module in the detection model; and outputting the defect detection result. This process processes the image by calling a preset high-efficiency long-range aggregation network layer and a weighted bidirectional feature pyramid architecture. This achieves the effects of reducing costs, better connecting contextual and conditional information, and improving detection accuracy and speed.
[0134] Since this defect detection device adopts all the technical solutions of all the above embodiments, it has at least all the beneficial effects brought about by the technical solutions of the above embodiments, which will not be repeated here.
[0135] Optionally, the acquisition module 10 is further configured to preprocess the image to be detected to obtain a preprocessed image, wherein the preprocessing includes at least mosaic data augmentation and adaptive anchor box calculation;
[0136] The preprocessed image is input into the adversarial neural network model to obtain the first image.
[0137] Optionally, the acquisition module 10 is further configured to input the preprocessed image into the generative model in the adversarial neural network algorithm to obtain a fake high-resolution image;
[0138] Content loss and adversarial loss are derived from the fake high-resolution image and the real high-resolution image;
[0139] Construct a loss function based on the content loss and adversarial loss;
[0140] The model is trained based on the loss function to obtain the adversarial neural network model.
[0141] Optionally, the acquisition module 10 is further configured to input the fake high-resolution image and the real high-resolution image into the VGG network for feature extraction, to obtain feature maps and feature vectors corresponding to the fake high-resolution image and the real high-resolution image respectively;
[0142] Content loss is obtained based on the feature map using the root mean square error (MSE), and the feature vectors corresponding to the fake high-resolution image and the real high-resolution image are compared to obtain the adversarial loss.
[0143] Optionally, the detection module 20 is further configured to input the first image into the detection model, and process the first image by calling a preset high-efficiency long-range aggregation network layer through the feature extraction network module in the detection model to obtain the second image;
[0144] The second image is processed by calling the weighted bidirectional feature pyramid architecture through the bidirectional weighted feature network module in the detection model to obtain the defect detection result.
[0145] Optionally, the detection module 20 is further configured to call the weighted bidirectional feature pyramid architecture through the bidirectional weighted feature network module in the detection model to display the second image.
[0146] The second image is weighted using the weighted bidirectional feature pyramid architecture, and the weights corresponding to the second image are automatically adjusted using an efficient feature fusion method to obtain the defect detection result.
[0147] Optionally, the detection module 20 is further configured to obtain the weighted bidirectional feature pyramid architecture by performing tensor splicing operations on the ends of the two branches responsible for feature information fusion in the feature extraction network module, and combining them with the weighted bidirectional feature pyramid.
[0148] Furthermore, to achieve the above objectives, the present invention also proposes a defect detection device, which includes: a memory, a processor, and a defect detection program stored in the memory and executable on the processor, the defect detection program being configured to implement the steps of the defect detection method described above.
[0149] Since this defect detection device adopts all the technical solutions of all the above embodiments, it has at least all the beneficial effects brought about by the technical solutions of the above embodiments, which will not be repeated here.
[0150] Furthermore, embodiments of the present invention also propose a storage medium storing a defect detection program, wherein the defect detection program, when executed by a processor, implements the steps of the defect detection method described above.
[0151] Since this storage medium adopts all the technical solutions of all the above embodiments, it has at least all the beneficial effects brought about by the technical solutions of the above embodiments, which will not be repeated here.
[0152] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or system. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or system that includes that element.
[0153] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0154] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0155] The above are merely preferred embodiments of the present invention and do not limit the scope of the patent. Any equivalent structural or procedural transformations made based on the description and drawings of the present invention, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of the present invention.
Claims
1. A defect detection method, characterized in that, The defect detection method includes the following steps: Get the first image; The first image is input into the detection model, and the first image is subjected to defect detection through the feature extraction network module and the bidirectional weighted feature network module in the detection model to obtain the defect detection result; Output the results of the defect detection; The step of inputting the first image into the detection model, and performing defect detection on the first image through the feature extraction network module and the bidirectional weighted feature network module in the detection model to obtain the defect detection result includes: The first image is input into the detection model, and the feature extraction network module in the detection model calls a preset high-efficiency long-range aggregation network layer to process the first image to obtain the second image; The second image is processed by calling the weighted bidirectional feature pyramid architecture through the bidirectional weighted feature network module in the detection model to obtain the defect detection result; The step of obtaining the defect detection result by calling the weighted bidirectional feature pyramid architecture through the bidirectional weighted feature network module in the detection model using the second image includes: The second image is processed by calling the weighted bidirectional feature pyramid architecture through the bidirectional weighted feature network module in the detection model; The second image is weighted using the weighted bidirectional feature pyramid architecture, and the weights corresponding to the second image are automatically adjusted using an efficient feature fusion method to obtain the defect detection result.
2. The defect detection method as described in claim 1, characterized in that, Before acquiring the first image, the process also includes: The image to be detected is preprocessed to obtain a preprocessed image. The preprocessing includes at least mosaic data augmentation and adaptive anchor box calculation. The preprocessed image is input into the adversarial neural network model to obtain the first image.
3. The defect detection method as described in claim 2, characterized in that, Before inputting the preprocessed image into the adversarial neural network model, the method further includes: The preprocessed image is input into the generative model in the adversarial neural network algorithm to obtain a fake high-resolution image; Content loss and adversarial loss are derived from the fake high-resolution image and the real high-resolution image; Construct a loss function based on the content loss and adversarial loss; The model is trained based on the loss function to obtain the adversarial neural network model.
4. The defect detection method as described in claim 3, characterized in that, The content loss and adversarial loss obtained based on the fake high-resolution image and the real high-resolution image include: The fake high-resolution image and the real high-resolution image are input into the VGG network for feature extraction to obtain feature maps and feature vectors corresponding to the fake high-resolution image and the real high-resolution image, respectively. Content loss is obtained based on the feature map using the root mean square error (MSE), and the feature vectors corresponding to the fake high-resolution image and the real high-resolution image are compared to obtain the adversarial loss.
5. The defect detection method as described in claim 1, characterized in that, The weighted bidirectional feature pyramid architecture is obtained by performing tensor concatenation on the ends of the two branches responsible for feature information fusion in the feature extraction network module, and then combining it with a weighted bidirectional feature pyramid.
6. A defect detection device, characterized in that, The device includes: The acquisition module is used to acquire the first image; The detection module is used to input the first image into the detection model, and perform defect detection on the first image through the feature extraction network module and the bidirectional weighted feature network module in the detection model to obtain the defect detection result; The output module is used to output the results of the defect detection; The step of inputting the first image into the detection model, and performing defect detection on the first image through the feature extraction network module and the bidirectional weighted feature network module in the detection model to obtain the defect detection result includes: The first image is input into the detection model, and the feature extraction network module in the detection model calls a preset high-efficiency long-range aggregation network layer to process the first image to obtain the second image; The second image is processed by calling the weighted bidirectional feature pyramid architecture through the bidirectional weighted feature network module in the detection model to obtain the defect detection result; The step of obtaining the defect detection result by calling the weighted bidirectional feature pyramid architecture through the bidirectional weighted feature network module in the detection model using the second image includes: The second image is processed by calling the weighted bidirectional feature pyramid architecture through the bidirectional weighted feature network module in the detection model; The second image is weighted using the weighted bidirectional feature pyramid architecture, and the weights corresponding to the second image are automatically adjusted using an efficient feature fusion method to obtain the defect detection result.
7. A defect detection device, characterized in that, The device includes: a memory, a processor, and a detection program stored in the memory and executable on the processor, the detection program being configured to implement the defect detection method as described in any one of claims 1 to 5.
8. A storage medium, characterized in that, The storage medium stores a detection program, which, when executed by a processor, implements the defect detection method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Defect inspection device, defect inspection method, and program
EP3540688A1
Surface defect detection method, apparatus, system, storage medium, and program product
WO2022127919A1