Metal surface defect detection method, device and storage medium
By constructing a metal surface defect detection model of encoding network and decoding network, the deep learning method is used to solve the problem of inaccurate detection results of traditional methods, achieve accurate identification and judgment of metal surface defects, and improve detection accuracy.
Patent Information
- Application Number
- CN202410517080.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-28
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-04-28
AI Technical Summary
In the existing technology, traditional image processing methods and methods based on manual features or shallow learning technology have inaccurate detection results when detecting metal surface defects, and require manual parameter adjustment, resulting in inaccurate parameter adjustment.
By constructing a metal surface defect detection model of the encoding network and the decoding network, deep learning methods are used to identify and detect defects on the metal surface, and a prediction tensor corresponding to the metal surface image is generated, including a prediction matrix, representing the probability of different types of surface defects. value.
There is no need for manual parameter adjustment, which improves the accuracy of parameters and detection results, and can accurately and easily identify and judge defects under complex conditions.
Smart Images

Figure CN118446972B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer vision technology, and in particular to a metal surface defect detection method, device and storage medium. Background Art
[0002] Surface defects have an adverse effect on the quality and performance of industrial products. For manufacturers, a lot of efforts have been made to inspect surface defects and control the quality of products. In recent years, machine vision-based methods have gradually become a trend in surface defect detection because they can overcome many shortcomings of manual detection, including low accuracy, poor real-time performance, strong subjectivity, and high labor intensity. These machine vision-based inspection systems appear in many industrial applications, such as steel strip inspection, LCD inspection, fabric inspection, aluminum profile, rail inspection, food inspection, and optical component inspection. Compared with smooth surfaces (such as LCDs and optical components), photos of metal surfaces are prone to some problems, such as uneven lighting, strong reflections, and background noise, which increases the difficulty of inspection. At the same time, advanced defect assessment standards not only need to judge whether there are defects on the surface, but also need to obtain the exact size and type of the defects, in addition to requiring real-time detection. These scenarios are widely present in actual industrial environments, posing great challenges to the detection of metal surface defects.
[0003] In the past decade, many studies have investigated the application of machine vision technology in surface defect detection, but this is not limited to metal surfaces. These methods can be mainly divided into two categories, namely: traditional image processing methods and machine learning methods based on handcrafted features or shallow learning techniques. Traditional image processing methods use the original properties reflected by local anomalies to detect and segment defects, which can be further divided into structural methods, threshold methods, spectral methods and model-based methods. Structural methods include edge, skeleton, template matching and morphological operations. Threshold methods include iterative optimal threshold, Otsu method, contrast adjustment threshold method, Kittler method and watershed method. Spectral methods usually include Fourier transform, wavelet transform and Gabor transform. Model-based methods include Gaussian mixture entropy model and low-rank matrix model.
[0004] However, when detecting surface defects, traditional image processing methods often need to set multiple thresholds for various defects in the algorithm, and these defects are very sensitive to lighting conditions and background colors. When new problems arise, these thresholds and parameters need to be manually adjusted, which not only consumes a lot of manpower and material resources, but also easily causes inaccurate parameter adjustments, resulting in inaccurate surface defect detection results.
[0005] Moreover, when detecting surface defects through manual or shallow learning techniques, there is insufficient discrimination for complex conditions, resulting in inaccurate detection.
[0006] Currently, no effective solution has been proposed to the technical problem that, in the prior art, the detection results are inaccurate when detecting surface defects using traditional image processing methods and machine learning methods based on manual features or shallow learning techniques. Summary of the invention
[0007] The embodiments of the present application provide a metal surface defect detection method, device and storage medium to at least solve the technical problem in the prior art of inaccurate detection results when detecting surface defects through traditional image processing methods and machine learning methods based on manual features or shallow learning techniques.
[0008] According to one aspect of an embodiment of the present application, a method for detecting metal surface defects is provided, comprising: inputting a metal surface image into a coding network, and generating a first feature tensor corresponding to the metal surface image through a coding operation of at least one coding module in the coding network, wherein the metal surface image is obtained by photographing the metal surface; generating a second feature tensor based on the first feature tensor using a decoding network corresponding to the coding network; and classifying the second feature tensor using a softmax classifier to generate a prediction tensor corresponding to the metal surface image, wherein the prediction tensor includes at least one prediction matrix, wherein each prediction matrix corresponds to a different type of surface defect, and the elements of the prediction matrix are used to indicate the probability value of the surface defect corresponding to the prediction matrix existing at a corresponding position on the metal surface.
[0009] According to another aspect of an embodiment of the present application, a storage medium is further provided, the storage medium including a stored program, wherein the above-described method is executed by a processor when the program is running.
[0010] According to another aspect of an embodiment of the present application, a metal surface defect detection device is also provided, including: a first generation module, used to input a metal surface image into a coding network, and generate a first feature tensor corresponding to the metal surface image through the coding operation of at least one coding module in the coding network, wherein the metal surface image is obtained by photographing the metal surface; a second generation module, used to generate a second feature tensor based on the first feature tensor using a decoding network corresponding to the coding network; and a third generation module, used to classify the second feature tensor using a softmax classifier to generate a prediction tensor corresponding to the metal surface image, wherein the prediction tensor includes at least one prediction matrix, wherein each prediction matrix corresponds to a different type of surface defect, and the elements of the prediction matrix are used to indicate the probability value of the surface defect corresponding to the prediction matrix existing at a corresponding position on the metal surface.
[0011] According to another aspect of an embodiment of the present application, a metal surface defect detection device is also provided, including: a processor; and a memory connected to the processor, for providing the processor with instructions for processing the following processing steps: inputting a metal surface image into a coding network, and generating a first feature tensor corresponding to the metal surface image through a coding operation of at least one coding module in the coding network, wherein the metal surface image is obtained by photographing the metal surface; using a decoding network corresponding to the coding network, generating a second feature tensor based on the first feature tensor; and using a softmax classifier to classify the second feature tensor to generate a prediction tensor corresponding to the metal surface image, wherein the prediction tensor includes at least one prediction matrix, wherein each prediction matrix corresponds to a different type of surface defect, and the elements of the prediction matrix are used to indicate the probability value of the surface defect corresponding to the prediction matrix existing at a corresponding position on the metal surface.
[0012] In the embodiment of the present application, the defects on the metal surface are identified and detected by a metal surface defect detection model constructed by an encoding network and a decoding network, so that the defects under complex conditions can be accurately and easily identified and judged by using a deep learning method. Compared with the prior art, this technical solution does not require manual parameter adjustment, and uses a deep learning method to improve the accuracy of the parameters, thereby improving the accuracy of metal surface defect detection. This solves the technical problem of inaccurate detection results when detecting surface defects using traditional image processing methods and machine learning methods based on manual features or shallow learning techniques in the prior art. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0014] Figure 1 is a hardware structure block diagram of a computing device for implementing the method according to Embodiment 1 of the present application;
[0015] Figure 2 is a schematic flow chart of a metal surface defect detection method according to the first aspect of Example 1 of the present application;
[0016] Figure 3A This is a schematic diagram of the metal surface defect detection model according to Example 1 of the present application;
[0017] Figure 3B is another architecture diagram of the metal surface defect detection model according to Example 1 of the present application;
[0018] Figure 4is a schematic diagram of a process of extracting features from a first tensor to be encoded according to Embodiment 1 of the present application;
[0019] Figure 5A is a schematic diagram of image data corresponding to pixel points in a partial image area of a binary image according to Embodiment 1 of the present application;
[0020] Figure 5B is a schematic diagram of coordinates corresponding to image data in a partial image area of a binary image according to Embodiment 1 of the present application;
[0021] Figure 5C is a schematic diagram of part of tensor element data of the first tensor feature to be encoded according to Embodiment 1 of the present application;
[0022] Figure 5D is a schematic diagram of part of tensor element data of the third tensor feature to be encoded according to Embodiment 1 of the present application;
[0023] Figure 6 is a schematic diagram of the pooling module according to Example 1 of the present application;
[0024] Figure 7 is a schematic diagram of an upsampling layer of the pooling module according to Example 1 of the present application;
[0025] Figure 8 is a schematic diagram of the unified attention fusion module according to Example 1 of the present application;
[0026] Fig. 9 is a schematic diagram of a metal surface defect detection device according to Embodiment 2 of the present application; and
[0027] Fig.10 It is a schematic diagram of the metal surface defect detection device described in Example 3 of the present application. DETAILED DESCRIPTION
[0028] In order to enable those skilled in the art to better understand the technical solutions of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only embodiments of a part of the present application, not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work should fall within the scope of protection of the present application.
[0029] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0030] Example 1
[0031] According to this embodiment, a method embodiment of a metal surface defect detection method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0032] The method embodiment provided in this embodiment can be executed in a mobile terminal, a computer terminal, a server or a similar computing device. Figure 1 FIG. 1 shows a hardware structure block diagram of a computing device for implementing a metal surface defect detection method. Figure 1 As shown, the computing device may include one or more processors (the processor may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory for storing data, and a transmission device for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the I / O interface), a network interface, a power supply and / or a camera. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.
[0033] It should be noted that the one or more processors and / or other data processing circuits described above may generally be referred to herein as "data processing circuitry". The data processing circuitry may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuitry may be a single independent processing module, or may be incorporated in whole or in part into any of the other components in the computing device. As described in the embodiments of the present application, the data processing circuitry serves as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).
[0034] The memory can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the metal surface defect detection method in the embodiment of the present application. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, that is, the metal surface defect detection method of the above-mentioned application is realized. The memory may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include a memory remotely arranged relative to the processor, and these remote memories may be connected to the computing device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0035] The transmission device is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computing device. In one example, the transmission device includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device can be a radio frequency (Radio Frequency, RF) module, which is used to communicate with the Internet wirelessly.
[0036] The display may be, for example, a touch screen liquid crystal display (LCD) that may enable a user to interact with a user interface of the computing device.
[0037] It should be noted that, in some optional embodiments, the above Figure 1 The computing device shown may include hardware elements (including circuits), software elements (including computer code stored on a computer-readable medium), or a combination of both hardware elements and software elements. Figure 1 This is merely one example of a particular embodiment and is intended to illustrate the types of components that may be present in the computing devices described above.
[0038] Under the above operating environment, according to the first aspect of this embodiment, a metal surface defect detection method is provided. Figure 1 The computing device implementation shown in . Figure 2 A schematic diagram showing the process of the method is shown in FIG. Figure 2 As shown, the method includes:
[0039] S202: inputting a metal surface image into a coding network, and generating a first feature tensor corresponding to the metal surface image through a coding operation of at least one coding module in the coding network, wherein the metal surface image is obtained by photographing the metal surface;
[0040] S204: using a decoding network corresponding to the encoding network to generate a second feature tensor based on the first feature tensor; and
[0041] S206: Use a softmax classifier to classify the second feature tensor to generate a prediction tensor corresponding to the metal surface image, wherein the prediction tensor includes at least one prediction matrix, wherein each prediction matrix corresponds to a different type of surface defect, and the elements of the prediction matrix are used to indicate the probability value of the surface defect corresponding to the prediction matrix existing at the corresponding position of the metal surface.
[0042] Specifically, the staff takes a picture of the metal surface to obtain a metal surface image, and then uses a metal surface defect detection model to detect the metal surface image to determine whether there are defects on the metal surface and determine the type of defects.
[0043] refer to Figure 3A As shown, the metal surface defect detection model includes an encoding network, a decoding network, a pooling module and a softmax classifier, the encoding network includes encoding modules 1 to 2, and the decoding network includes multiple decoding modules 1 to 2.
[0044] Thus, the computing device inputs the metal surface image into the encoding network, and then the encoding module 1 in the encoding network receives the metal surface image and performs an encoding operation on the metal surface image, thereby generating a corresponding feature map 101. The computing device then inputs the feature map 101 into the encoding module 2, and the encoding module 2 performs an encoding operation on the received feature map 101, thereby outputting a corresponding feature map 102 (i.e., a first feature tensor).
[0045] Furthermore, the computing device position-encodes the feature map 102 (ie, the first feature tensor) and performs a pooling operation through a pooling unit, thereby outputting the pooled feature map 102 .
[0046] Furthermore, the computing device inputs the pooled feature map 102 output by the encoding module 2 to the pooling module. The pooling module processes the received pooled feature map 102 and outputs a corresponding feature map.
[0047] Further, the computing device inputs the feature map output by the pooling module into the decoding network, so that the deconvolution unit of the decoding module 1 in the decoding network extracts features from the feature map, thereby outputting feature map 301. The computing device then inputs feature map 301 into the unified attention fusion module 1, and the unified attention fusion module 1 extracts features from feature map 301, thereby outputting feature map 302.
[0048] Furthermore, the computing device inputs the feature map 302 to the decoding module 2 , and the decoding module 2 uses a deconvolution unit to extract features from the feature map 302 , thereby outputting a feature map 303 .
[0049] The computing device then inputs the feature map 303 to the deconvolution module in the decoding network, and the deconvolution module performs an upsampling operation on the feature map 303 to generate a feature map 304, so that the encoding network outputs the feature map 304 as a second feature tensor.
[0050] Further, the computing device inputs the feature map 304 (i.e., the second feature tensor) into a softmax classifier. The softmax classifier performs classification processing on the feature map 304 (i.e., the second feature tensor) to generate a prediction tensor corresponding to the metal surface image. The prediction tensor includes at least one prediction matrix, wherein each prediction matrix corresponds to a different type of surface defect, and the elements of the prediction matrix are used to indicate the probability value of the surface defect corresponding to the prediction matrix existing at the corresponding position of the metal surface.
[0051] For example, this embodiment includes 12 types of surface defects and 1 type of surface background, for a total of 13 surface types. Thus, the prediction tensor has a total of 13 prediction matrices. Each prediction matrix corresponds to one surface type. And the elements of each prediction matrix correspond to the pixel points at the corresponding position of the metal surface image, so that each element in each prediction matrix represents the probability value of the corresponding pixel point being the corresponding surface type. The prediction tensor order is a tensor greater than or equal to 2.
[0052] The 12 types of surface defects are: dirt, scratches, corrosion, black spots, black stripes, scratches, cracked edges, water marks, prints, stickiness, peeling and bubbles.
[0053] For example, prediction matrix 1 corresponds to a surface defect of the dirt type. Thus, in the prediction matrix 1, each element corresponds to a probability value that a pixel point of the metal surface image is a surface defect of the dirt type.
[0054] For example, the pixels of the metal surface image are 4096*1000*3, and the metal surface defect detection model outputs a defect feature map of 4096*1000*13.
[0055] In another embodiment, reference Figure 3B As shown, the metal surface defect detection model includes an encoding network, a decoding network, a pooling module and a softmax classifier, the encoding network includes encoding modules 1 to n, and the decoding network includes multiple decoding modules 1 to n.
[0056] Thus, the computing device inputs the metal surface image into the encoding network, and then the encoding module 1 in the encoding network receives the metal surface image and performs an encoding operation on the metal surface image, thereby generating a corresponding feature map 101. The computing device then inputs the feature map 101 into the encoding module 2, and the encoding module 2 performs an encoding operation on the received feature map 101, thereby outputting a corresponding feature map 102, and so on, until the encoding module n-1 outputs the corresponding feature map ( Figure 3A The feature map is input to the encoding module n, and then the encoding module n outputs the corresponding feature map according to the feature map. Fig.10 n (i.e., the first eigentensor).
[0057] Furthermore, the computing device features Fig.10 n (i.e., the first feature tensor) is positionally encoded and pooled through the pooling unit to output the pooled feature Fig.10 n.
[0058] Furthermore, the computing device performs pooling of the features output by the encoding module n Fig.10 n is input to the pooling module. The pooling module receives the pooled features Fig.10 n is processed and the corresponding feature map is output.
[0059] Further, the computing device inputs the feature map output by the pooling module into the decoding network, so that the decoding network uses the deconvolution unit of the decoding module 1 to extract features from the feature map, thereby outputting feature map 301. The computing device then inputs feature map 301 into the unified attention fusion module 1, and the unified attention fusion module 1 extracts features from feature map 301, thereby outputting feature map 302.
[0060] Furthermore, the computing device inputs the feature map 302 to the decoding module 2 , and the decoding module 2 uses a deconvolution unit to extract features from the feature map 302 , thereby outputting a feature map 303 .
[0061] And so on, until the decoding module n outputs the corresponding feature map 30m.
[0062] in Figure 3B The process of unified attention fusion module n-2, decoding module n-1, and unified attention fusion module n-1 outputting feature maps is the same as above ( Figure 3B The feature graph output by the above module is not shown in FIG, and will not be described here.
[0063] The computing device then inputs the feature map 30m into the deconvolution module in the decoding network. The deconvolution module performs an upsampling operation on the feature map 30m to generate a feature map 401, so that the encoding network outputs the feature map 401 as a second feature tensor.
[0064] Further, the computing device inputs the feature map 401 (i.e., the second feature tensor) into a softmax classifier. The softmax classifier performs classification processing on the feature map 401 (i.e., the second feature tensor) to generate a prediction tensor corresponding to the metal surface image. The prediction tensor includes at least one prediction matrix, wherein each prediction matrix corresponds to a different type of surface defect, and the elements of the prediction matrix are used to indicate the probability value of the surface defect corresponding to the prediction matrix existing at the corresponding position of the metal surface.
[0065] As described in the background technology, when detecting surface defects, traditional image processing methods often need to set multiple thresholds for various defects in the algorithm, and these defects are very sensitive to lighting conditions and background colors. When new problems arise, these thresholds and parameters need to be manually adjusted, which not only consumes a lot of manpower and material resources, but also easily causes inaccurate parameter adjustments, resulting in inaccurate surface defect detection results. In addition, when detecting surface defects through manual production or shallow learning technology, there is not enough discrimination for complex conditions, resulting in inaccurate detection.
[0066] In view of the technical problems described above, through the technical solutions of the embodiments of the present application, the defects on the metal surface are identified and detected through the metal surface defect detection model constructed by the encoding network and the decoding network, so that the defects under complex conditions can be accurately and easily identified and judged by the deep learning method. Compared with the prior art, this technical solution does not require manual parameter adjustment, and uses the deep learning method to improve the accuracy of the parameters, thereby improving the accuracy of metal surface defect detection. This solves the technical problem of inaccurate detection results when detecting surface defects through traditional image processing methods and machine learning methods based on manual features or shallow learning techniques in the prior art.
[0067] Optionally, the encoding operation of at least one encoding module in the encoding network includes: receiving an input tensor to be encoded; using at least one convolutional layer to convolve the tensor to be encoded to generate a first tensor feature to be encoded corresponding to the tensor to be encoded; using a feature extraction module based on a global attention mechanism and a local attention mechanism to generate a second tensor feature to be encoded corresponding to the first tensor feature to be encoded; and merging the first tensor feature to be encoded and the second tensor feature to be encoded to generate a coded tensor as the encoding result.
[0068] Specifically, refer to Figure 3A As shown, the encoding module 1 receives the input tensor to be encoded corresponding to the metal surface image, and uses at least one convolutional layer (such as Figure 3A The convolution unit in the encoding module 1 performs a convolution operation on the tensor to be encoded, thereby generating a first tensor feature to be encoded corresponding to the tensor to be encoded.
[0069] Furthermore, the computing device inputs the first tensor feature to be encoded into a feature extraction module, wherein the feature extraction module includes a feature extraction unit based on global attention and a feature extraction unit based on a local attention mechanism.
[0070] Therefore, the feature extraction module extracts features of the first tensor feature to be encoded through a feature extraction unit based on global attention and a feature extraction unit based on a local attention mechanism, thereby generating corresponding second tensor features to be encoded.
[0071] Furthermore, the computing device adds elements of corresponding positions of the first tensor feature to be encoded and the second tensor feature to be encoded, thereby fusing the first tensor feature to be encoded and the second tensor feature to be encoded to generate an encoded tensor as an encoding result.
[0072] In addition, other encoding modules process the received feature map (i.e., the tensor to be encoded) according to the method of processing the tensor to be encoded by the above-mentioned encoding module 1 to generate the encoding tensor, so as to generate a new feature map (i.e., the encoding tensor), which will not be repeated here.
[0073] The tensor to be encoded received by encoding module 1 is a metal surface image, and the tensors to be encoded received by other encoding modules are feature maps output by the previous encoding module.
[0074] Therefore, the traditional image processing method in the prior art only processes the image through the convolution layer and the pooling layer. On this basis, the present technical solution adds a method for extracting semantic features, thereby extracting the semantic features of the image through the feature extraction module, thereby improving the accuracy of metal surface defect detection.
[0075] Optionally, the operation of generating a second tensor feature to be encoded corresponding to the first tensor feature to be encoded using a feature extraction module based on a global attention mechanism and a local attention mechanism includes: generating a binary image corresponding to the first tensor feature to be encoded, wherein a connected domain of the binary image corresponds to a metal surface defect area of the metal surface; generating a third tensor feature to be encoded based on the binary image and the first tensor feature to be encoded, wherein the tensor element values corresponding to the connected domain in the third tensor feature to be encoded are the same as the corresponding tensor element values in the first tensor feature to be encoded, and the remaining tensor element values in the third tensor feature to be encoded are 0; performing a block embedding operation on the first tensor feature to be encoded to obtain a first sequence, and performing feature extraction on the first sequence using a feature extraction unit based on a global attention mechanism to determine a global semantic feature corresponding to the first tensor feature to be encoded; performing a block embedding operation on the third tensor feature to be encoded to obtain a second sequence, and performing feature extraction on the second sequence using a feature extraction unit based on a local attention mechanism to determine a local semantic feature corresponding to the third tensor feature to be encoded; and merging the global semantic feature and the local semantic feature to determine the second tensor feature to be encoded.
[0076] Specifically, see Figure 3A and Figure 3B As shown, the metal surface defect detection model also includes an image segmentation model, which segments and binarizes the metal surface image to generate a binary image, wherein the binary image includes a connected domain corresponding to the defect area in the metal surface image. In addition, the generated binary image is input to the feature extraction module of each encoding module. After the image segmentation model generates the binary image, the binary image can also be patch-embedding operated to generate a corresponding sequence, and then the corresponding sequence is input to the feature extraction module of each encoding module.
[0077] Figure 4 A schematic diagram of the feature extraction module of each encoding module is further shown, referring to Figure 4 As shown, the feature extraction module scales the binarized image through the image scaling module so that the generated binary image is consistent with the size of the first tensor feature to be encoded.
[0078] Further, among them Figure 5A Image data corresponding to pixel points in a partial image area of a binary image is shown. Figure 5B The coordinates corresponding to the image data in the partial image area of the binary image are shown. Figure 5A and Figure 5BAs shown, the pixel value of the defective area in the binary image is 1, and the pixel value of the background area is 0. Therefore, the computing device determines the area with a pixel value of 1 as a connected domain, where the coordinates of the area with a pixel value of 1 are x(1,1), x(1,2), x(2,1) and x(2,2), respectively. The defective area is determined based on the connected domain, that is, the area with a pixel value of 1 is a connected domain and also a defective area.
[0079] Further, Figure 5C shows part of the tensor element data of the first tensor feature to be encoded, Figure 5D Part of the tensor element data of the third tensor feature to be encoded is shown. The computing device maps the first tensor feature to be encoded to the binary image, so that each tensor element in the first tensor feature to be encoded corresponds to the pixel point at the same position of the binary image. Thus, the computing device uses the tensor element value corresponding to the connected domain in the first tensor feature to be encoded as the tensor element value corresponding to the connected domain in the third tensor feature to be encoded, and the remaining tensor element values in the third tensor feature to be encoded are 0, thereby obtaining the third tensor feature to be encoded. The tensor element value corresponding to the connected domain in the third tensor feature to be encoded is the same as the corresponding tensor element value in the first tensor feature to be encoded, and the remaining tensor element values in the third tensor feature to be encoded are 0.
[0080] by FIG. 5A to FIG. 5D For example, the tensor element values at the positions x(1,1), x(1,2), x(2,1) and x(2,2) in the third tensor feature to be encoded are determined according to the tensor element values at the positions x(1,1), x(1,2), x(2,1) and x(2,2) in the third tensor feature to be encoded. The tensor element values at the remaining positions in the third tensor feature to be encoded are determined according to the pixel values at the corresponding positions in the binary image.
[0081] For example, at the corresponding positions, the tensor element values of the first tensor feature to be encoded are multiplied by the pixel values of the binary image to obtain the tensor element values of each position of the third tensor feature to be encoded. Thus, at the positions x(1,1), x(1,2), x(2,1) and x(2,2), the tensor element values of the third tensor feature to be encoded are the same as the tensor element values of the first tensor feature to be encoded, which are x 1,1 、x 1,2 、x 2,1 and x 2,2 At other positions, the tensor element value of the third tensor feature to be encoded is 0.
[0082] Further, the computing device performs a block embedding operation on the first tensor feature to be encoded to obtain a first sequence, and the computing device performs a block embedding operation on the third tensor feature to be encoded to obtain a second sequence.
[0083] Further, the feature extraction module includes a feature extraction unit based on a global attention mechanism and a feature extraction unit based on a local attention mechanism. Thus, the computing device inputs the first sequence into the feature extraction unit based on the global attention mechanism, and inputs the second sequence into the feature extraction unit based on the local attention mechanism.
[0084] Therefore, the feature extraction unit based on the global attention mechanism calculates the weight value corresponding to each element in the first sequence, and then calculates the global semantic feature according to each element and the corresponding weight value.
[0085] The feature extraction unit based on the local attention mechanism calculates the weight value corresponding to each element in the second sequence, and then calculates the local semantic feature according to each element and the corresponding weight value, wherein the number of elements in the first sequence is the same as the number of elements in the second sequence.
[0086] Thus, the feature extraction unit based on the global attention mechanism outputs the global semantic feature corresponding to the first tensor feature to be encoded, and the feature extraction unit based on the local attention mechanism outputs the local semantic feature corresponding to the third tensor feature to be encoded. The global attention mechanism and the local attention mechanism can be a multi-head attention mechanism. In this embodiment, the number of global attention heads is the same as that of local attention heads.
[0087] Furthermore, the computing device combines the global semantic features and the local semantic features to determine the second tensor feature to be encoded.
[0088] In addition, the feature extraction unit outputs the formula for the element value of each element of the second tensor feature to be encoded as follows:
[0089] [γ1,γ2,...,γ t ] T =[x1,x2,...,x t ] T +[y1,y2,...,y t ] T ;
[0090]
[0091]
[0092] as well as
[0093]
[0094] [x1,x2,...,x t ] T Represents the global semantic features, [y1,y2,...,y t ]T Represents local semantic features, represents the first sequence corresponding to the first tensor feature to be encoded, represents the second sequence corresponding to the third tensor feature to be encoded, Vg i V parameter of the global attention mechanism, kg i represents the K parameter of the global attention mechanism, Vl i V parameter represents the local attention mechanism, kl i represents the K parameter of the local attention mechanism. d is or The vector dimension of .
[0095] Therefore, the technical solution extracts the global semantic features of the first tensor feature to be encoded through the global attention mechanism, and extracts the local semantic features of the third tensor feature to be encoded through the local attention mechanism, and then fuses the global semantic features and the local semantic features. Therefore, the technical solution not only considers the feature level of the entire feature map, but also measures the local edge features of the feature map, making the detection of metal surface defects more accurate and improving the detection accuracy.
[0096] Optionally, the operation of generating a second feature tensor based on the first feature tensor using a decoding network corresponding to the encoding network includes: inputting the first feature tensor into a pooling module, performing a downsampling operation on the first feature tensor layer by layer through the pooling module to generate a downsampled tensor; upsampling the downsampled tensor layer by layer through the pooling module to generate a third feature tensor corresponding to the first feature tensor; and inputting the third feature tensor into a decoding network, and generating a second feature tensor corresponding to the third feature tensor through a decoding operation of at least one decoding module in the decoding network.
[0097] Specifically, refer to Figure 6 As shown, the pooling module includes multiple adjacent downsampling layers and multiple adjacent upsampling layers.
[0098] After the encoding network outputs the first feature tensor, the computing device inputs the first feature tensor into the upsampling layer of the pooling module, so that multiple upsampling layers downsample the received first feature tensor layer by layer to generate a downsampled tensor.
[0099] Further, the computing device inputs the downsampled tensor into the upsampled layer of the pooling module, so that the multiple upsampled layers upsample the received downsampled tensor layer by layer, thereby outputting a third feature tensor.
[0100] Further, the computing device inputs the third feature tensor into a decoding network. The decoding network includes a plurality of decoding modules. Thus, the plurality of decoding modules perform a decoding operation on the third feature tensor to obtain a corresponding feature map, and then the feature map is upsampled by a deconvolution module in the decoding network to generate a corresponding decoding feature map, so that the encoding network outputs the decoding feature map as the second feature tensor.
[0101] Therefore, the technical solution decodes the feature map through a simplified pooling module and a decoding module, which reduces the decoding process and time and improves the decoding speed.
[0102] Optionally, the downsampled tensor is upsampled layer by layer through a pooling module to generate an operation of a third feature tensor corresponding to the first feature tensor, including: receiving an input tensor to be upsampled; performing an average pooling operation on the tensor to be upsampled through a first average pooling unit of the pooling module to generate a first pooling tensor; performing average pooling operations on the first pooling tensor through multiple second average pooling units of different sizes to generate corresponding multiple second pooling tensors; and merging the multiple second pooling tensors after convolution and upsampling operations to generate an upsampled tensor.
[0103] Specifically, refer to Figure 7 As shown, each upsampling layer includes a first average pooling unit, multiple second average pooling units, multiple first convolution units, a second convolution unit and multiple upsampling units.
[0104] For example, the computing device inputs the tensor to be upsampled into the average pooling unit 1 (ie, the first average pooling unit) of the upsampling layer, and the average pooling unit 1 performs an average pooling operation on the tensor to be upsampled to generate a corresponding feature map 201 (first pooling tensor).
[0105] Further, the computing device inputs the feature map 201 into multiple average pooling units of different sizes (i.e., second average pooling units). For example, there are 3 average pooling units (i.e., average pooling units 2 to 4), with sizes of 1×1, 2×2, and 4×4, respectively. Thus, the 3 average pooling units perform average pooling operations on the feature map 201 (first pooling tensor), thereby generating feature maps 202 to 204 (i.e., multiple second pooling tensors), respectively.
[0106] Further, the computing device inputs the feature maps 202 to 204 (i.e., multiple second pooling tensors) into the corresponding first convolution units, respectively. The convolution kernel in the first convolution unit is 1×1, and the output channel is smaller than the input channel. And one of the second average pooling units corresponds to a first convolution unit and an upsampling unit, so that when the second average pooling units include 3, the first convolution unit and the upsampling unit also include 3 respectively. Thus, the three first convolution units (i.e., first convolution units 1 to 3) generate feature maps 205 to 207, respectively.
[0107] Further, the computing device inputs the feature maps 205-207 into corresponding upsampling units respectively, so that the three upsampling units (ie, upsampling units 1-3) output feature maps 208-210. The feature maps 208-210 have the same size.
[0108] Furthermore, the computing device adds the feature elements at corresponding positions of the feature maps 208 - 210 , thereby generating a feature map 211 .
[0109] Further, the computing device inputs the feature map 211 into the second convolution unit. The convolution kernel in the second convolution unit is 1×1. Thus, the second convolution unit outputs a feature map 212 (ie, an upsampled tensor).
[0110] Furthermore, the computing device inputs the feature map 212 (i.e., the upsampled tensor) as the tensor to be upsampled into the next upsampled layer, so that the next upsampled layer (i.e., the current upsampled layer) performs an upsample operation on the received feature map 212 according to the method of generating the upsampled tensor by the previous upsampled layer, and generates a corresponding upsampled tensor.
[0111] Therefore, other upsampling layers perform upsampling processing on the upsampled tensor according to the above method to generate corresponding upsampled tensors.
[0112] Therefore, the pooling module in this technical solution reduces the number of channels through a 1×1 convolution kernel, and uses a more concise and efficient addition operation to add the feature elements of multiple feature maps, making the pooling module more efficient and ensuring the real-time performance of the model.
[0113] Optionally, the third feature tensor is input into the decoding network, and the operation of generating a second feature tensor corresponding to the third feature tensor through the decoding operation of at least one decoding module in the decoding network includes: receiving the input first tensor to be decoded through the decoding module of the decoding network; performing a deconvolution operation on the first tensor to be decoded through the decoding module using at least one deconvolution layer to generate a decoding tensor corresponding to the first tensor to be decoded as a decoding result; inputting the decoding tensor as the first tensor to be fused into the unified attention fusion module; inputting the first tensor to be encoded feature output by the corresponding encoding module as the second tensor to be fused into the unified attention fusion module; fusing the first tensor to be fused and the second tensor to be fused through the unified attention fusion module to generate a fused tensor; and inputting the fused tensor as the second tensor to be decoded into a decoding module that is shallower than the unified attention fusion module.
[0114] Specifically, refer to Figure 3A As shown, the decoding network includes multiple decoding modules. For example, decoding module 1 receives the first tensor to be decoded. Decoding module 1 is the deepest decoding module in the decoding network, and the first tensor to be decoded received by the deepest decoding module is the third feature tensor output by the pooling module.
[0115] Furthermore, the decoding module 1 includes multiple deconvolution layers (such as Figure 3A The decoding module 1 inputs the first tensor to be decoded into the deconvolution unit, and the deconvolution unit performs a deconvolution operation on the first tensor to be decoded. Then, the decoding module 1 outputs a feature map 301 (i.e., a decoding tensor) corresponding to the first tensor to be decoded.
[0116] Further, the computing device inputs the feature map 301 (ie, the decoded tensor) as the first tensor to be fused into the unified attention fusion module 1.
[0117] The encoding module 1 corresponds to the unified attention fusion module 1, so that the computing device inputs the first tensor to be encoded output by the encoding module 1 into the unified attention fusion module 1 as the second tensor to be fused.
[0118] Furthermore, the unified attention fusion module 1 calculates the weights corresponding to the first tensor to be fused and the second tensor to be fused respectively through the attention module, and merges the first tensor to be fused and the second tensor to be fused and the corresponding weights after calculating, thereby generating a feature map 302 (i.e., a fused tensor).
[0119] The computing device then sends the feature map 302 (ie, fusion tensor) to a decoding module at a shallower level than the unified attention fusion module. The decoding module at a shallower level than the unified attention fusion module 1 is decoding module 2.
[0120] Thus, the computing device sends the feature map 302 (i.e., fused tensor) output by the unified attention module 1 to the decoding module 2 as the second tensor to be decoded. In this case, relative to the decoding module 2, the feature map 302 is the first tensor to be decoded, and similar operations described above are continued. The decoding module 2 includes multiple deconvolution units. The decoding module 2 receives the second tensor to be decoded and inputs it into the deconvolution unit, and the deconvolution unit performs a deconvolution operation on the second tensor to be decoded, and then the decoding module 2 outputs a feature map 303 corresponding to the second tensor to be decoded.
[0121] Therefore, this technical solution adds a unified attention fusion module in the decoding module to strengthen the feature representation of the feature map and screens important features so that only important features can be calculated, reducing the amount of calculation and improving the decoding speed.
[0122] Therefore, in the decoding network, the process of taking the third feature tensor as input and generating the second feature tensor corresponding to the third feature tensor through the decoding operation of at least one decoding module includes a series of complex operations.
[0123] First, the decoding module receives an input first tensor to be decoded, and then uses at least one deconvolution layer to perform a deconvolution operation on the first tensor to be decoded. This process is called a decoding operation, and the purpose is to convert the first tensor to be decoded into a decoding tensor.
[0124] Then, the decoded tensor is input into the unified attention fusion module as the first tensor to be fused. At the same time, the first tensor feature to be encoded output by the corresponding encoding module is also input into the unified attention fusion module as the second tensor to be fused.
[0125] In the unified attention fusion module, the first tensor to be fused and the second tensor to be fused are fused through a specific fusion algorithm to generate a fused tensor. This step is a key link in the decoding process, because through the attention mechanism, the decoding network can selectively focus on the output of the encoding network, thereby introducing richer context information in the decoding process.
[0126] Finally, the fused tensor is input as the second tensor to be decoded into a decoding module that is shallower than the unified attention fusion module. This step further decodes the fused tensor to generate the final second feature tensor.
[0127] This decoding process allows the model to gradually introduce more contextual information during the decoding process when processing sequence data or image data, thereby generating more accurate and meaningful outputs.
[0128] Optionally, the operation of fusing the first tensor to be fused and the second tensor to be fused through a unified attention fusion module to generate a fused tensor includes: performing an upsampling operation on the first tensor to be fused through an upsampling unit of the unified attention fusion module to generate a third tensor to be fused, wherein the third tensor to be fused has the same size as the second tensor to be fused; inputting the second tensor to be fused and the third tensor to be fused into the attention unit respectively, and calculating the first weight corresponding to the second tensor to be fused and the second weight corresponding to the third tensor to be fused through the attention unit respectively; calculating the first attention weighted feature according to the second tensor to be fused and the first weight; calculating the second attention weighted feature according to the third tensor to be fused and the second weight; and fusing the first attention weighted feature and the second attention weighted feature to generate a fused tensor.
[0129] Specifically, refer to Figure 8 As shown, the unified attention fusion module includes an upsampling unit and an attention unit.
[0130] For example, the unified attention fusion module 1 receives the first tensor to be fused F output by the decoding module 1 respectively high , and the second tensor to be fused output by the convolution unit of the encoding module 1, and then the first tensor to be decoded F high Input upsampling unit, upsampling unit through bilinear interpolation operation, the first to be decoded tensor F high Upsample to the same size as the second tensor to be decoded, thereby generating the third tensor to be fused F up The third tensor to be fused has the same size as the second tensor to be fused. up The expression is:
[0131] F up =Upsample(F high ).
[0132] Furthermore, the computing device converts the third tensor to be fused F up and the second tensor to be fused F low are input to the attention unit respectively, so that the attention unit calculates and the second tensor to be fused F low The corresponding first weight and second tensor to be fused F low The corresponding second weight. The sum of the first weight and the second weight is 1, so the first weight is expressed as r, and the second weight is expressed as 1-r. The method for the attention unit to calculate the first weight and the second weight can be, for example, through a spatial attention mechanism or a channel attention mechanism. The expression for calculating the first weight r is:
[0133] r = Attention(F up ,Flow ).
[0134] Further, the computing device multiplies the tensor elements in the second tensor to be fused by the first weight respectively, so as to obtain the first attention weighted feature.
[0135] Further, the computing device multiplies the tensor elements of the third tensor to be fused by the second weights respectively, so as to obtain a second attention weighted feature.
[0136] Further, the computing device adds the tensor elements of the first attention-weighted feature and the tensor elements at the corresponding positions of the second attention-weighted feature to generate a fused tensor F out The formula for calculating the fused tensor is:
[0137] F out =F up ·r+F low ·(1-r).
[0138] Therefore, this technical solution strengthens the feature representation of the feature map through a unified attention fusion module, and screens important features, so that only important features can be calculated, reducing the amount of calculation and improving the decoding speed.
[0139] Therefore, during the decoding process, the first tensor to be fused is fused with the second tensor to be fused through the unified attention fusion module, and the operation of generating the fused tensor involves multiple steps.
[0140] First, the upsampling unit in the unified attention fusion module performs an upsampling operation on the first tensor to be fused to generate the third tensor to be fused. This upsampling process ensures that the third tensor to be fused has the same size as the second tensor to be fused, which provides the necessary conditions for subsequent attention weight calculation and feature fusion.
[0141] Subsequently, the second tensor to be fused and the third tensor to be fused are respectively input into the attention unit. In the attention unit, the model calculates the first weight corresponding to the second tensor to be fused and the second weight corresponding to the third tensor to be fused. This step utilizes the attention mechanism, so that the metal surface defect detection model can selectively focus on and weight the corresponding features according to the characteristics of the second tensor to be fused and the third tensor to be fused.
[0142] Next, based on the second tensor to be fused and the calculated first weight, the metal surface defect detection model calculates the first attention weighted feature. Similarly, based on the third tensor to be fused and the second weight, the second attention weighted feature is calculated. This step further emphasizes the importance of different features, allowing the metal surface defect detection model to more accurately extract and decode relevant information.
[0143] Finally, the first attention weighted features and the second attention weighted features are fused to generate the final fused tensor. This step ensures that features from different sources can be effectively integrated, providing richer and more comprehensive information for subsequent decoding operations.
[0144] In general, through the above series of complex operations, the decoding network can effectively fuse the first tensor to be fused and the second tensor to be fused to generate a fused tensor with rich information. This process is crucial to improving the performance and accuracy of the decoding network, especially when dealing with complex and large-scale data sets.
[0145] In addition, during the training phase of the metal surface defect detection model, the learning rate preheating scheme is used to accelerate the convergence of training and improve the training speed. In addition, three output heads are manufactured, and the imbalanced classification loss functions OhemCrossEntropyLoss, Diceloss, and CEloss are selected, and the adaptability weights are set respectively to enhance the expression of small defects (i.e., small samples) and alleviate the impact of sample imbalance.
[0146] In addition, reference Figure 1 As shown, according to the second aspect of this embodiment, a storage medium is provided, wherein the storage medium includes a stored program, wherein when the program is run, the processor executes the above method.
[0147] Therefore, according to this embodiment, the defects on the metal surface are identified and detected by the metal surface defect detection model constructed by the encoding network and the decoding network, so that the defects under complex conditions can be accurately and easily identified and judged by the deep learning method. Compared with the prior art, this technical solution does not require manual parameter adjustment, and uses the deep learning method to improve the accuracy of the parameters, thereby improving the accuracy of metal surface defect detection. This solves the technical problem of inaccurate detection results when detecting surface defects through traditional image processing methods and machine learning methods based on manual features or shallow learning technology in the prior art.
[0148] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should know that the present invention is not limited by the described action sequence, because according to the present invention, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.
[0149] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an 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, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0150] Example 2
[0151] Fig. 9 The metal surface defect detection device 900 according to this embodiment is shown, and the device 900 corresponds to the method according to the first aspect of embodiment 1. Fig. 9 As shown, the device 900 includes: a first generating module 910, which is used to input a metal surface image into a coding network, and generate a first feature tensor corresponding to the metal surface image through a coding operation of at least one coding module in the coding network, wherein the metal surface image is obtained by photographing the metal surface; a second generating module 920, which is used to generate a second feature tensor based on the first feature tensor using a decoding network corresponding to the coding network; and a third generating module 930, which is used to classify the second feature tensor using a softmax classifier to generate a prediction tensor corresponding to the metal surface image, wherein the prediction tensor includes at least one prediction matrix, wherein each prediction matrix corresponds to a different type of surface defect, and the elements of the prediction matrix are used to indicate the probability value of the surface defect corresponding to the prediction matrix existing at a corresponding position on the metal surface.
[0152] Optionally, the first generation module 910 includes: a first receiving submodule, used to receive an input tensor to be encoded; a first generating submodule, used to use at least one convolutional layer to convolve the tensor to be encoded, and generate a first tensor feature to be encoded corresponding to the tensor to be encoded; a second generating submodule, used to use a feature extraction module based on a global attention mechanism and a local attention mechanism to generate a second tensor feature to be encoded corresponding to the first tensor feature to be encoded; and a third generating submodule, used to merge the first tensor feature to be encoded and the second tensor feature to be encoded to generate a coded tensor as the encoding result.
[0153] Optionally, the second generating submodule includes: a first generating unit, which is used to generate a binary image corresponding to the first tensor feature to be encoded, wherein the connected domain of the binary image corresponds to the metal surface defect area of the metal surface; a second generating unit, which is used to generate a third tensor feature to be encoded based on the binary image and the first tensor feature to be encoded, wherein the tensor element value corresponding to the connected domain in the third tensor feature to be encoded is the same as the corresponding tensor element value in the first tensor feature to be encoded, and the remaining tensor element values in the third tensor feature to be encoded are 0; a first determining unit, which is used to perform a block embedding operation on the first tensor feature to be encoded to obtain a first sequence, and use a feature extraction unit based on a global attention mechanism to extract features from the first sequence to determine the global semantic features corresponding to the first tensor feature to be encoded; a second determining unit, which is used to perform a block embedding operation on the third tensor feature to be encoded to obtain a second sequence, and use a feature extraction unit based on a local attention mechanism to extract features from the second sequence to determine the local semantic features corresponding to the third tensor feature to be encoded; and a third determining unit, which is used to merge the global semantic features and the local semantic features to determine the second tensor feature to be encoded.
[0154] Optionally, the second generation module 920 includes: a fourth generation submodule, used to input the first feature tensor into a pooling module, and perform downsampling operations on the first feature tensor layer by layer through the pooling module to generate a downsampled tensor; a fifth generation submodule, used to upsample the downsampled tensor layer by layer through the pooling module to generate a third feature tensor corresponding to the first feature tensor; and a sixth generation submodule, used to input the third feature tensor into a decoding network, and generate a second feature tensor corresponding to the third feature tensor through a decoding operation of at least one decoding module in the decoding network.
[0155] Optionally, the fifth generating submodule includes: a first receiving unit, used to receive the input tensor to be upsampled; a third generating unit, used to perform an average pooling operation on the tensor to be upsampled through the first average pooling unit of the pooling module to generate a first pooling tensor; a fourth generating unit, used to perform an average pooling operation on the first pooling tensor through multiple second average pooling units of different sizes, respectively, to generate a corresponding multiple second pooling tensors; and a fifth generating unit, used to merge the multiple second pooling tensors after convolution and upsampling operations to generate an upsampled tensor.
[0156] Optionally, the sixth generation submodule includes: a second receiving unit, used to receive an input first tensor to be decoded through a decoding module of a decoding network; a sixth generation unit, used to perform a deconvolution operation on the first tensor to be decoded through the decoding module using at least one deconvolution layer, and generate a decoding tensor corresponding to the first tensor to be decoded as a decoding result; a first input unit, used to input the decoding tensor as the first tensor to be fused into a unified attention fusion module; a second input unit, used to input the first tensor feature to be encoded output by the corresponding encoding module as the second tensor to be fused into the unified attention fusion module; a seventh generation unit, used to fuse the first tensor to be fused and the second tensor to be fused through the unified attention fusion module to generate a fused tensor; and a third input unit, used to input the fused tensor as the second tensor to be decoded into a decoding module that is shallower than the unified attention fusion module.
[0157] Optionally, the seventh generation unit includes: performing an upsampling operation on the first tensor to be fused through the upsampling unit of the unified attention fusion module to generate a third tensor to be fused, wherein the third tensor to be fused has the same size as the second tensor to be fused; inputting the second tensor to be fused and the third tensor to be fused into the attention unit respectively, and calculating the first weight corresponding to the second tensor to be fused and the second weight corresponding to the third tensor to be fused through the attention unit respectively; calculating the first attention weighted feature according to the second tensor to be fused and the first weight; calculating the second attention weighted feature according to the third tensor to be fused and the second weight; and fusing the first attention weighted feature and the second attention weighted feature to generate a fused tensor.
[0158] Therefore, according to this embodiment, the defects on the metal surface are identified and detected by the metal surface defect detection model constructed by the encoding network and the decoding network, so that the defects under complex conditions can be accurately and easily identified and judged by the deep learning method. Compared with the prior art, this technical solution does not require manual parameter adjustment, and uses the deep learning method to improve the accuracy of the parameters, thereby improving the accuracy of metal surface defect detection. This solves the technical problem of inaccurate detection results when detecting surface defects through traditional image processing methods and machine learning methods based on manual features or shallow learning technology in the prior art.
[0159] Example 3
[0160] Fig.10 The metal surface defect detection device 1000 according to the first aspect of this embodiment is shown, and the device 1000 corresponds to the method according to the first aspect of embodiment 1. Fig.10As shown, the device 1000 includes: a processor 1010; and a memory 1020, which is connected to the processor 1010 and is used to provide the processor 1010 with instructions for processing the following processing steps: inputting a metal surface image into a coding network, and generating a first feature tensor corresponding to the metal surface image through a coding operation of at least one coding module in the coding network, wherein the metal surface image is obtained by photographing the metal surface; using a decoding network corresponding to the coding network, generating a second feature tensor based on the first feature tensor; and using a softmax classifier to classify the second feature tensor to generate a prediction tensor corresponding to the metal surface image, wherein the prediction tensor includes at least one prediction matrix, wherein each prediction matrix corresponds to a different type of surface defect, and the elements of the prediction matrix are used to indicate the probability value of the surface defect corresponding to the prediction matrix existing at a corresponding position on the metal surface.
[0161] Optionally, the encoding operation of at least one encoding module in the encoding network includes: receiving an input tensor to be encoded; using at least one convolutional layer to convolve the tensor to be encoded to generate a first tensor feature to be encoded corresponding to the tensor to be encoded; using a feature extraction module based on a global attention mechanism and a local attention mechanism to generate a second tensor feature to be encoded corresponding to the first tensor feature to be encoded; and merging the first tensor feature to be encoded and the second tensor feature to be encoded to generate a coded tensor as the encoding result.
[0162] Optionally, the operation of generating a second tensor feature to be encoded corresponding to the first tensor feature to be encoded using a feature extraction module based on a global attention mechanism and a local attention mechanism includes: generating a binary image corresponding to the first tensor feature to be encoded, wherein a connected domain of the binary image corresponds to a metal surface defect area of the metal surface; generating a third tensor feature to be encoded based on the binary image and the first tensor feature to be encoded, wherein the tensor element values corresponding to the connected domain in the third tensor feature to be encoded are the same as the corresponding tensor element values in the first tensor to be encoded, and the remaining tensor element values in the third tensor feature to be encoded are 0; performing a block embedding operation on the first tensor feature to be encoded to obtain a first sequence, and performing feature extraction on the first sequence using a feature extraction unit based on a global attention mechanism to determine a global semantic feature corresponding to the first tensor feature to be encoded; performing a block embedding operation on the third tensor feature to be encoded to obtain a second sequence, and performing feature extraction on the second sequence using a feature extraction unit based on a local attention mechanism to determine a local semantic feature corresponding to the third tensor feature to be encoded; and merging the global semantic feature and the local semantic feature to determine the second tensor feature to be encoded.
[0163] Optionally, the operation of generating a second feature tensor based on the first feature tensor using a decoding network corresponding to the encoding network includes: inputting the first feature tensor into a pooling module, performing a downsampling operation on the first feature tensor layer by layer through the pooling module to generate a downsampled tensor; upsampling the downsampled tensor layer by layer through the pooling module to generate a third feature tensor corresponding to the first feature tensor; and inputting the third feature tensor into a decoding network, and generating a second feature tensor corresponding to the third feature tensor through a decoding operation of at least one decoding module in the decoding network.
[0164] Optionally, the downsampled tensor is upsampled layer by layer through a pooling module to generate an operation of a third feature tensor corresponding to the first feature tensor, including: receiving an input tensor to be upsampled; performing an average pooling operation on the tensor to be upsampled through a first average pooling unit of the pooling module to generate a first pooling tensor; performing an average pooling operation on the first pooling tensor through multiple average pooling units of different sizes to generate corresponding multiple second pooling tensors; and merging the multiple second pooling tensors after convolution and upsampling operations to generate an upsampled tensor.
[0165] Optionally, the third feature tensor is input into the decoding network, and the operation of generating a second feature tensor corresponding to the third feature tensor through the decoding operation of at least one decoding module in the decoding network includes: receiving the input first tensor to be decoded through the decoding module of the decoding network; performing a deconvolution operation on the first tensor to be decoded through the decoding module using at least one deconvolution layer to generate a decoding tensor corresponding to the first tensor to be decoded as a decoding result; inputting the decoding tensor as the first tensor to be fused into the unified attention fusion module; inputting the first tensor to be encoded feature output by the corresponding encoding module as the second tensor to be fused into the unified attention fusion module; fusing the first tensor to be fused and the second tensor to be fused through the unified attention fusion module to generate a fused tensor; and inputting the fused tensor as the second tensor to be decoded into a decoding module that is shallower than the unified attention fusion module.
[0166] Optionally, the operation of fusing the first tensor to be fused and the second tensor to be fused through a unified attention fusion module to generate a fused tensor includes: performing an upsampling operation on the first tensor to be fused through an upsampling unit of the unified attention fusion module to generate a third tensor to be fused, wherein the third tensor to be fused has the same size as the second tensor to be fused; inputting the second tensor to be fused and the third tensor to be fused into the attention unit respectively, and calculating the first weight corresponding to the second tensor to be fused and the second weight corresponding to the third tensor to be fused through the attention unit respectively; calculating the first attention weighted feature according to the second tensor to be fused and the first weight; calculating the second attention weighted feature according to the third tensor to be fused and the second weight; and fusing the first attention weighted feature and the second attention weighted feature to generate a fused tensor.
[0167] Therefore, according to this embodiment, the defects on the metal surface are identified and detected by the metal surface defect detection model constructed by the encoding network and the decoding network, so that the defects under complex conditions can be accurately and easily identified and judged by the deep learning method. Compared with the prior art, this technical solution does not require manual parameter adjustment, and uses the deep learning method to improve the accuracy of the parameters, thereby improving the accuracy of metal surface defect detection. This solves the technical problem of inaccurate detection results when detecting surface defects through traditional image processing methods and machine learning methods based on manual features or shallow learning technology in the prior art.
[0168] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0169] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0170] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0171] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0172] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0173] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program codes.
[0174] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A method for detecting metal surface defects, It is characterized in that include: Inputting a metal surface image into a coding network, and generating a first feature tensor corresponding to the metal surface image through a coding operation of at least one coding module in the coding network, wherein the metal surface image is obtained by photographing the metal surface; Using a decoding network corresponding to the encoding network, generating a second feature tensor based on the first feature tensor; as well as The second feature tensor is classified by using a softmax classifier to generate a prediction tensor corresponding to the metal surface image, wherein the prediction tensor includes at least one prediction matrix, wherein each prediction matrix corresponds to a different type of surface defect, and the elements of the prediction matrix are used to indicate the probability value of the surface defect corresponding to the prediction matrix existing at the corresponding position of the metal surface, wherein The encoding operation of at least one encoding module in the encoding network includes: receiving an input tensor to be encoded; using at least one convolutional layer to convolve the tensor to be encoded to generate a first tensor feature to be encoded corresponding to the tensor to be encoded; using a feature extraction module based on a global attention mechanism and a local attention mechanism to generate a second tensor feature to be encoded corresponding to the first tensor feature to be encoded; and merging the first tensor feature to be encoded and the second tensor feature to be encoded to generate an encoded tensor as an encoding result, and The operation of generating a second tensor feature to be encoded corresponding to the first tensor feature to be encoded by using a feature extraction module based on a global attention mechanism and a local attention mechanism includes: generating a binary image corresponding to the first tensor feature to be encoded, wherein a connected domain of the binary image corresponds to a metal surface defect area of the metal surface; generating a third tensor feature to be encoded based on the binary image and the first tensor feature to be encoded, wherein the tensor element value corresponding to the connected domain in the third tensor feature to be encoded is the same as the corresponding tensor element value in the first tensor feature to be encoded, and the third tensor feature to be encoded has a corresponding value. The remaining tensor element values of are 0; performing a block embedding operation on the first tensor feature to be encoded to obtain a first sequence, and using a feature extraction unit based on a global attention mechanism to extract features from the first sequence to determine a global semantic feature corresponding to the first tensor feature to be encoded; performing a block embedding operation on the third tensor feature to be encoded to obtain a second sequence, and using a feature extraction unit based on a local attention mechanism to extract features from the second sequence to determine a local semantic feature corresponding to the third tensor feature to be encoded; and merging the global semantic feature and the local semantic feature to determine the second tensor feature to be encoded, and wherein The operation of generating a second feature tensor based on the first feature tensor by using a decoding network corresponding to the encoding network includes: inputting the first feature tensor into a pooling module, performing a downsampling operation on the first feature tensor layer by layer through the pooling module to generate a downsampled tensor; upsampling the downsampled tensor layer by layer through the pooling module to generate a third feature tensor corresponding to the first feature tensor; and inputting the third feature tensor into the decoding network, and generating the second feature tensor corresponding to the third feature tensor through a decoding operation of at least one decoding module in the decoding network, wherein The third feature tensor is input into the decoding network, and the second feature tensor corresponding to the third feature tensor is generated through the decoding operation of at least one decoding module in the decoding network, including: receiving the input first tensor to be decoded through the decoding module of the decoding network; performing a deconvolution operation on the first tensor to be decoded by the decoding module using at least one deconvolution layer to generate a decoding tensor corresponding to the first tensor to be decoded as a decoding result; inputting the decoding tensor as the first tensor to be fused into the unified attention fusion module; inputting the first tensor to be encoded feature output by the corresponding encoding module as the second tensor to be fused into the unified attention fusion module; fusing the first tensor to be fused and the second tensor to be fused through the unified attention fusion module to generate a fused tensor; and inputting the fused tensor as the second tensor to be decoded into a decoding module shallower than the unified attention fusion module.
2. The method according to claim 1, It is characterized in that The operation of upsampling the downsampled tensor layer by layer through the pooling module to generate a third feature tensor corresponding to the first feature tensor includes: Receive the input tensor to be upsampled; Performing an average pooling operation on the tensor to be upsampled by a first average pooling unit of the pooling module to generate a first pooling tensor; performing an average pooling operation on the first pooling tensor through a plurality of second average pooling units of different sizes, respectively, to generate a plurality of corresponding second pooling tensors; and The multiple second pooling tensors after the convolution and upsampling operations are merged to generate the upsampling tensor.
3. The method according to claim 1, It is characterized in that The operation of fusing the first tensor to be fused and the second tensor to be fused by the unified attention fusion module to generate a fused tensor includes: Performing an upsampling operation on the first tensor to be fused by an upsampling unit of the unified attention fusion module to generate a third tensor to be fused, wherein the third tensor to be fused has the same size as the second tensor to be fused; Inputting the second tensor to be fused and the third tensor to be fused into the attention unit respectively, and calculating the first weight corresponding to the second tensor to be fused and the second weight corresponding to the third tensor to be fused respectively through the attention unit; Calculate a first attention weighted feature according to the second tensor to be fused and the first weight; Calculating a second attention weighted feature according to the third tensor to be fused and the second weight; and The first attention weighted feature and the second attention weighted feature are fused to generate the fused tensor.
4. A storage medium, It is characterized in that The storage medium includes a stored program, wherein when the program is executed, the processor executes the method according to any one of claims 1 to 3.
5. A metal surface defect detection device, It is characterized in that include: A first generating module, configured to input a metal surface image into a coding network, and generate a first feature tensor corresponding to the metal surface image through a coding operation of at least one coding module in the coding network, wherein the metal surface image is obtained by photographing the metal surface; A second generating module, configured to generate a second feature tensor based on the first feature tensor by using a decoding network corresponding to the encoding network; as well as The third generating module is used to classify the second feature tensor using a softmax classifier to generate a prediction tensor corresponding to the metal surface image, wherein the prediction tensor includes at least one prediction matrix, wherein each prediction matrix corresponds to a different type of surface defect, and the elements of the prediction matrix are used to indicate the probability value of the surface defect corresponding to the prediction matrix existing at the corresponding position of the metal surface, wherein The encoding operation of at least one encoding module in the encoding network includes: receiving an input tensor to be encoded; using at least one convolutional layer to convolve the tensor to be encoded to generate a first tensor feature to be encoded corresponding to the tensor to be encoded; using a feature extraction module based on a global attention mechanism and a local attention mechanism to generate a second tensor feature to be encoded corresponding to the first tensor feature to be encoded; and merging the first tensor feature to be encoded and the second tensor feature to be encoded to generate an encoded tensor as an encoding result, and The operation of generating a second tensor feature to be encoded corresponding to the first tensor feature to be encoded by using a feature extraction module based on a global attention mechanism and a local attention mechanism includes: generating a binary image corresponding to the first tensor feature to be encoded, wherein a connected domain of the binary image corresponds to a metal surface defect area of the metal surface; generating a third tensor feature to be encoded based on the binary image and the first tensor feature to be encoded, wherein the tensor element value corresponding to the connected domain in the third tensor feature to be encoded is the same as the corresponding tensor element value in the first tensor feature to be encoded, and the third tensor feature to be encoded has a corresponding value. The remaining tensor element values of are 0; performing a block embedding operation on the first tensor feature to be encoded to obtain a first sequence, and using a feature extraction unit based on a global attention mechanism to extract features from the first sequence to determine a global semantic feature corresponding to the first tensor feature to be encoded; performing a block embedding operation on the third tensor feature to be encoded to obtain a second sequence, and using a feature extraction unit based on a local attention mechanism to extract features from the second sequence to determine a local semantic feature corresponding to the third tensor feature to be encoded; and merging the global semantic feature and the local semantic feature to determine the second tensor feature to be encoded, and wherein The operation of generating a second feature tensor based on the first feature tensor by using a decoding network corresponding to the encoding network includes: inputting the first feature tensor into a pooling module, performing a downsampling operation on the first feature tensor layer by layer through the pooling module to generate a downsampled tensor; upsampling the downsampled tensor layer by layer through the pooling module to generate a third feature tensor corresponding to the first feature tensor; and inputting the third feature tensor into the decoding network, and generating the second feature tensor corresponding to the third feature tensor through a decoding operation of at least one decoding module in the decoding network, wherein The third feature tensor is input into the decoding network, and the second feature tensor corresponding to the third feature tensor is generated through the decoding operation of at least one decoding module in the decoding network, including: receiving the input first tensor to be decoded through the decoding module of the decoding network; performing a deconvolution operation on the first tensor to be decoded by the decoding module using at least one deconvolution layer to generate a decoding tensor corresponding to the first tensor to be decoded as a decoding result; inputting the decoding tensor as the first tensor to be fused into the unified attention fusion module; inputting the first tensor to be encoded feature output by the corresponding encoding module as the second tensor to be fused into the unified attention fusion module; fusing the first tensor to be fused and the second tensor to be fused through the unified attention fusion module to generate a fused tensor; and inputting the fused tensor as the second tensor to be decoded into a decoding module shallower than the unified attention fusion module.
6. A metal surface defect detection device, It is characterized in that include: processor; as well as A memory, connected to the processor, configured to provide the processor with instructions for processing the following processing steps: Inputting a metal surface image into a coding network, and generating a first feature tensor corresponding to the metal surface image through a coding operation of at least one coding module in the coding network, wherein the metal surface image is obtained by photographing the metal surface; Using a decoding network corresponding to the encoding network, generating a second feature tensor based on the first feature tensor; as well as The second feature tensor is classified by using a softmax classifier to generate a prediction tensor corresponding to the metal surface image, wherein the prediction tensor includes at least one prediction matrix, wherein each prediction matrix corresponds to a different type of surface defect, and the elements of the prediction matrix are used to indicate the probability value of the surface defect corresponding to the prediction matrix existing at the corresponding position of the metal surface, wherein The encoding operation of at least one encoding module in the encoding network includes: receiving an input tensor to be encoded; using at least one convolutional layer to convolve the tensor to be encoded to generate a first tensor feature to be encoded corresponding to the tensor to be encoded; using a feature extraction module based on a global attention mechanism and a local attention mechanism to generate a second tensor feature to be encoded corresponding to the first tensor feature to be encoded; and merging the first tensor feature to be encoded and the second tensor feature to be encoded to generate an encoded tensor as an encoding result, and The operation of generating a second tensor feature to be encoded corresponding to the first tensor feature to be encoded by using a feature extraction module based on a global attention mechanism and a local attention mechanism includes: generating a binary image corresponding to the first tensor feature to be encoded, wherein a connected domain of the binary image corresponds to a metal surface defect area of the metal surface; generating a third tensor feature to be encoded based on the binary image and the first tensor feature to be encoded, wherein the tensor element value corresponding to the connected domain in the third tensor feature to be encoded is the same as the corresponding tensor element value in the first tensor feature to be encoded, and the third tensor feature to be encoded has a corresponding value. The remaining tensor element values of are 0; performing a block embedding operation on the first tensor feature to be encoded to obtain a first sequence, and using a feature extraction unit based on a global attention mechanism to extract features from the first sequence to determine a global semantic feature corresponding to the first tensor feature to be encoded; performing a block embedding operation on the third tensor feature to be encoded to obtain a second sequence, and using a feature extraction unit based on a local attention mechanism to extract features from the second sequence to determine a local semantic feature corresponding to the third tensor feature to be encoded; and merging the global semantic feature and the local semantic feature to determine the second tensor feature to be encoded, and wherein The operation of generating a second feature tensor based on the first feature tensor by using a decoding network corresponding to the encoding network includes: inputting the first feature tensor into a pooling module, performing a downsampling operation on the first feature tensor layer by layer through the pooling module to generate a downsampled tensor; upsampling the downsampled tensor layer by layer through the pooling module to generate a third feature tensor corresponding to the first feature tensor; and inputting the third feature tensor into the decoding network, and generating the second feature tensor corresponding to the third feature tensor through a decoding operation of at least one decoding module in the decoding network, wherein The third feature tensor is input into the decoding network, and the second feature tensor corresponding to the third feature tensor is generated through the decoding operation of at least one decoding module in the decoding network, including: receiving the input first tensor to be decoded through the decoding module of the decoding network; performing a deconvolution operation on the first tensor to be decoded by the decoding module using at least one deconvolution layer to generate a decoding tensor corresponding to the first tensor to be decoded as a decoding result; inputting the decoding tensor as the first tensor to be fused into the unified attention fusion module; inputting the first tensor to be encoded feature output by the corresponding encoding module as the second tensor to be fused into the unified attention fusion module; fusing the first tensor to be fused and the second tensor to be fused through the unified attention fusion module to generate a fused tensor; and inputting the fused tensor as the second tensor to be decoded into a decoding module shallower than the unified attention fusion module.
Citation Information
Patent Citations
Method for constructing surface defect detection model based on RecTransform
CN115578358A
Object surface defect detection method and system
CN115661097A
