Target detection method, device, computer equipment, storage medium and program product
By segmenting the image to be detected and extracting pixel points and contextual features, the problem of low detection accuracy of high-resolution images in the existing technology is solved, and high-accuracy detection and applicability improvement of images of any resolution are achieved.
Patent Information
- Application Number
- CN202111154945.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-29
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2041-09-29
AI Technical Summary
Existing target detection methods have low accuracy and applicability when processing high-resolution images, especially due to the downsampling and cropping of images by neural networks, which results in the loss of small-size defect areas, affecting the detection effect.
By dividing the image to be detected into multiple slices, and using the feature extraction layer of the target model to extract pixel features and context features, the feature map is obtained, the resolution limit is lifted, and it is suitable for images of any resolution, and the feature extraction layer is omitted. It eliminates the downsampling operation, retains the detailed features of the original image, and improves the detection robustness of targets of different sizes.
It achieves high-accuracy detection of images with any resolution, especially accurate detection of small targets, improves the accuracy and applicability of target detection, and is suitable for low-configuration hardware scenarios.
Smart Images

Figure CN114332473B
Abstract
Description
Technical Field
[0001] The present application relates to technical fields such as computer vision, image processing, and artificial intelligence, and the present application relates to a target detection method, device, computer equipment, storage medium, and program product. Background Art
[0002] With the development of science and technology, computer vision technology is increasingly being used in industrial scenarios. For example, in modern industrial manufacturing, defects are inevitable in products such as mechanical parts and electronic components produced by industrial assembly lines. Therefore, in the quality control process, product images are usually used for target detection to identify product defects.
[0003] In the related art, the process of object detection may include: inputting the image of the product into a neural network for detection, so as to output the location of possible defects in the image. However, neural networks are usually unable to meet the detection requirements of images with larger resolutions, resulting in low accuracy and applicability of object detection. Summary of the invention
[0004] The present application provides a target detection method, device, computer equipment, storage medium and program product, which can solve the problem of low accuracy and applicability of target detection in related technologies. The technical solution is as follows:
[0005] In one aspect, a target detection method is provided, the method comprising:
[0006] Determine an image to be detected that includes a target object, and determine at least two slices of the image to be detected;
[0007] Performing pixel feature extraction and pixel context feature extraction on the at least two slices through a feature extraction layer of a target model to obtain at least two feature maps, wherein any feature point of the feature map is used to indicate features and context features of corresponding pixels in the slice, and the size of the intermediate feature map output by a target network layer of the feature extraction layer is the same as the size of the slice, and the target network layer is used to perform pixel feature extraction on the slice;
[0008] The feature map corresponding to each slice is detected to obtain defect information of each slice, where the defect information is used to indicate defects of the target object included in the slice.
[0009] In another aspect, a target detection device is provided, comprising:
[0010] A determination module, used to determine an image to be detected including a target object, and to determine at least two slices of the image to be detected;
[0011] A feature extraction module, used to perform pixel feature extraction and pixel context feature extraction on the at least two slices through a feature extraction layer of a target model to obtain at least two feature maps, wherein any feature point of the feature map is used to indicate a feature and a context feature of a corresponding pixel in the slice, wherein a size of an intermediate feature map output by a target network layer of the feature extraction layer is the same as a size of the slice, and the target network layer is used to perform pixel feature extraction on the slice;
[0012] The detection module is used to detect the feature map corresponding to each slice to obtain defect information of each slice, where the defect information is used to indicate the defects of the target object included in the slice.
[0013] On the other hand, a computer device is provided, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the above-mentioned target detection method.
[0014] On the other hand, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the above-mentioned target detection method is implemented.
[0015] On the other hand, a computer program product is provided, comprising a computer program, wherein when the computer program is executed by a processor, the above-mentioned target detection method is implemented.
[0016] The beneficial effects of the technical solution provided by this application are:
[0017] The image to be detected is first divided into at least two slices, and then pixel features and pixel context features are extracted from each slice through the feature extraction layer of the target model to obtain at least two feature maps; the feature map is detected to obtain defect information of the slice; the resolution restriction is removed, and it is applicable to images of any resolution; the feature extraction layer includes a target network layer for extracting pixel features of the slice, and the intermediate feature map output by the target network layer is the same size as the slice, that is, the downsampling when extracting the pixel features of the slice is omitted, thereby retaining the detailed features of the original image, and the feature extraction layer is also designed to extract pixel features and pixel context features, thereby improving the robustness of detection of targets of different sizes, even small targets in a smaller area can be accurately detected, thereby improving the accuracy of target detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in describing the embodiments of the present application.
[0019] Figure 1A schematic diagram of an implementation environment of a target detection method provided in an embodiment of the present application;
[0020] Figure 2 A schematic diagram of a target detection method provided in an embodiment of the present application;
[0021] Figure 3 A schematic diagram of a method for calculating an overlap ratio provided in an embodiment of the present application;
[0022] Figure 4 A schematic diagram of an offset parameter provided in an embodiment of the present application;
[0023] Figure 5 A data processing diagram of a regression branch network training process provided in an embodiment of the present application;
[0024] Figure 6 A visual schematic diagram of a defect detected in an embodiment of the present application;
[0025] Figure 7 A schematic diagram of target detection based on various network layers provided in an embodiment of the present application;
[0026] Figure 8 A schematic diagram of the structure of a target detection device provided in an embodiment of the present application;
[0027] Fig. 9 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0028] The embodiments of the present application are described below in conjunction with the drawings in the present application. It should be understood that the implementation methods described below in conjunction with the drawings are exemplary descriptions for explaining the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions of the embodiments of the present application.
[0029] It will be understood by those skilled in the art that, unless specifically stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the terms "including" and "comprising" used in the embodiments of the present application refer to that the corresponding features can be implemented as the presented features, information, data, steps, operations, elements and / or components, but do not exclude the implementation as other features, information, data, steps, operations, elements, components and / or combinations thereof supported by the technical field. It should be understood that when we say that an element is "connected" or "coupled" to another element, the one element may be directly connected or coupled to the other element, or it may refer to that the one element and the other element establish a connection relationship through an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein indicates at least one of the items defined by the term, for example, "A and / or B" indicates that it is implemented as "A", or is implemented as "A", or is implemented as "A and B".
[0030] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0031] Artificial Intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology in computer science that attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines so that machines have the functions of perception, reasoning and decision-making.
[0032] Artificial intelligence technology is a comprehensive discipline that covers a wide range of fields, including both hardware-level and software-level technologies. The basic technologies of artificial intelligence generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, blockchain and other technologies. Artificial intelligence software technology mainly includes computer vision technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0033] Among them, Computer Vision (CV) is a science that studies how to make machines "see". To put it more specifically, it refers to machine vision such as using cameras and computers to replace human eyes to identify and measure targets, and further processing graphics to make computer processing into images that are more suitable for human eye observation or transmission to instruments for detection. As a scientific discipline, computer vision studies related theories and technologies, and attempts to establish an artificial intelligence system that can obtain information from images or multi-dimensional data. Computer vision technology usually includes image processing, image recognition, image semantic understanding, image retrieval, OCR, video processing, video semantic understanding, video content / behavior recognition, three-dimensional object reconstruction, 3D technology, virtual reality, augmented reality, simultaneous positioning and map construction, and other technologies, as well as common biometric recognition technologies such as face recognition and fingerprint recognition.
[0034] Machine Learning (ML) is a multi-disciplinary subject that involves probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory and other disciplines. It specializes in studying how computers simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications are spread across all areas of artificial intelligence. Machine learning and deep learning usually include artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and self-learning.
[0035] The target detection method provided in this application relates to the above-mentioned technical fields such as artificial intelligence and machine learning. Exemplarily, the machine simulation, cloud computing and other technologies in artificial intelligence technology can be used to realize target detection of the image to be detected based on the trained model. For example, the image to be detected is divided into multiple slices using the target model; and the pixel features and context features of each slice are extracted using the feature extraction layer of the target model; the feature map of the obtained slice is used to realize the detection of small targets in the high-resolution image. Of course, the above-mentioned machine learning technology can also be used to perform reinforcement learning on the initial model using a sample set to obtain a more robust target model.
[0036] In modern industrial manufacturing, production efficiency has been improved by introducing assembly lines. However, complex processes inevitably lead to product defects. These defects mostly depend on environmental conditions and occur probabilistically, so statistical analysis of the defects is required in the later stage. Therefore, defect detection and diagnosis of finished products is an indispensable part of modern production processes.
[0037] In traditional methods, enterprises often use manual observation to detect defects in products. In this case, for enterprises, there is the problem of high detection costs (personnel costs); for employees, due to the small defect area (difficult to detect), there are problems of high work intensity and single work content, resulting in a high employee turnover rate; for algorithms, defects vary in size, and defects that are too large or too small may lead to a certain degree of missed detection, thereby affecting the actual production line yield.
[0038] At present, Faster RCNN (Faster Region Convolutional Neural Networks) is usually used to detect defects in object images. When using Faster RCNN, the image must be cropped by resizing before entering the neural network, and the image will be downsampled in the Faster RCNN network. Cropping and downsampling will cause the loss of small defect areas in the image, resulting in low accuracy of target detection, which cannot meet the needs of high-resolution detection and has low practicality.
[0039] Figure 1 A schematic diagram of an implementation environment of a target detection method provided in this application. Figure 1 As shown, the implementation environment may include: a computer device 101. Exemplarily, the computer device may be pre-configured with a trained target model, and use the target model to perform target detection on the image to be detected; or, the computer device 101 may also use a large number of samples to train the target model, so as to use the target model to perform target detection on the image to be detected.
[0040] In one possible scenario, Figure 1 As shown, the implementation environment may also include: a computer device 101 and an image acquisition device 102, the image acquisition device 102 may acquire an image to be detected of a target object to be detected, and send the image to be detected to the computer device 101, the computer device 101 is pre-configured with a trained target model, the computer device 101 uses the target model to perform target detection on the image to be detected, and sends the detection result to the image acquisition device 102. For example, the terminal 102 may be installed with an application with a target detection function, and the server 101 may be a background server of the application. The terminal 102 and the server 102 may exchange data based on the application to realize real-time data transmission of the image to be detected and the detection result.
[0041] Figure 1In the scenario shown, the above target detection method can be performed in any device such as a server, a terminal, a server cluster or a cloud computing service cluster. For example, a server or a terminal can have both image acquisition and target detection functions. For example, the server acquires the image to be detected and performs target detection based on the image to be detected and the target model.
[0042] The server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server or server cluster that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The above-mentioned network may include but is not limited to: wired network, wireless network, wherein the wired network includes: local area network, metropolitan area network and wide area network, and the wireless network includes: Bluetooth, Wi-Fi and other networks that realize wireless communication. The terminal can be a smart phone (such as Android mobile phone, iOS mobile phone, etc.), tablet computer, laptop computer, digital broadcast receiver, MID (Mobile Internet Devices), PDA (personal digital assistant), desktop computer, vehicle terminal (such as vehicle navigation terminal, vehicle computer, etc.), smart speaker, smart watch, etc. The terminal and the server can be directly or indirectly connected by wired or wireless communication, but it is not limited to this. The specific can also be determined based on the actual application scenario requirements, and is not limited here.
[0043] Figure 2 The flowchart of a target detection method provided in the embodiment of the present application is shown in FIG. The execution subject of the method may be a computer device, which may be a server, a terminal, or any electronic device with a target detection function, etc. The embodiment of the present application does not specifically limit this. The server is used as an example for explanation in the embodiment of the present application. Figure 2 As shown, the method includes the following steps.
[0044] Step 201: The server determines an image to be detected that includes a target object.
[0045] The target detection method provided in the embodiment of the present application can be a detection performed with defects that may exist on the target object as the target. The image to be detected may include defects of the target object. Exemplarily, the server can obtain the image to be detected from an image acquisition device. Alternatively, the server can also pre-store the image to be detected. For example, the image to be detected can be an image obtained by an image acquisition device or a server taking a picture of the target object to be detected.
[0046] The target detection process of the embodiment of the present application may refer to: small target detection targeting defects in a small range. The small target detection may refer to the detection of defects that are small in size or relative size. In one possible example, small target detection may refer to detection within a range where the size is less than a certain threshold. For example, detection is performed targeting defects that are smaller than 32×32 in size. In another possible example, the small target detection may also refer to defect detection within a range where the relative size is less than a certain threshold; for example, detection is performed targeting defects whose width and height are respectively less than one tenth of the width and height of the image to be detected.
[0047] It should be noted that the image to be detected can be an image with a higher resolution; that is, the image to be detected can be an image with a resolution exceeding the target resolution threshold and a size exceeding the target size threshold. For example, it can be a high-resolution, large-size original image of the target object captured by a high-definition camera; unlike ordinary neural network-based target detection methods, the target detection method of the embodiment of the present application has a better detection effect for high-resolution, large-size images. Of course, the image to be detected can also be a low-resolution image, and the target detection method of the embodiment of the present application is also applicable to low-resolution images.
[0048] In a possible example, the target object may be 3C (Computer, Communication, Consumer Electronic) or accessories of 3C products, such as computers, tablet computers, mobile phones or digital audio players, mobile phone cameras, mobile phone camera stands, etc. For example, in the embodiment of the present application, defects in the 3C product accessories can be detected based on the image data of the 3C product accessories collected by the camera.
[0049] Step 202: The server determines at least two slices of the image to be detected.
[0050] The server slices the original image to be detected based on a sliding window slicing method. The server can slice the image to be detected into multiple slices according to a certain size. Then this step may include: the server slices the image to be detected in a sliding window manner based on a sliding window of a target step size and a target size, and obtains at least two slices of the image to be detected. Exemplarily, the size of the target step size can be configured in association with the target size, for example, the target step size can be 0.7 times the target size. For example, in actual operation, the image to be detected can be sliced into a certain number of slices based on needs, and the data level of the slices can be dozens, hundreds or thousands, etc. For example, the higher the resolution of the image to be detected or the higher the accuracy requirement of the target detection to be performed, the smaller the step size of the slice can be set, and the more slices are cut, thereby improving the detection accuracy and further improving the accuracy of the detection.
[0051] Exemplarily, the image to be detected may be an original image, and the server may split the original image (PatchSplit). For example, the server sets a fixed step size stride, and configures a sliding window of a certain window size window-size, and autonomously splits the high-resolution original image into multiple slice patches through the sliding window method; for example, the relationship between the fixed step size and the window size may be: stride=(0.7~0.8)*window-size.
[0052] By dividing the image to be inspected into multiple slices of fixed size, defect target detection is performed based on the slices. In this way, the target detection method of the present application can be applied to images to be inspected of any resolution, eliminating the restrictions on the resolution of the original image to be inspected and other conditions, thereby increasing the scope of application of the present application and further improving the applicability. Subsequent detection can be performed based on high-resolution images, thereby increasing the possibility of accurate detection.
[0053] Step 203: The server performs pixel feature extraction and pixel context feature extraction on the at least two slices through the feature extraction layer of the target model to obtain at least two feature maps.
[0054] The pixel feature extraction may include extracting semantic features of the pixels of the slice, and the features extracted in this process may include primary semantic features of the pixels. The server extracts semantic features and context features of the slice through the feature extraction layer of the target model to obtain a multi-channel feature map. The pixel context feature extraction may include the features of the pixels themselves and the extraction process of the context features of the pixels, and the features extracted in this process may include high-level semantic features of the pixels.
[0055] Any feature point of the feature map is used to indicate the features and context features of the corresponding pixel in the slice. The size of the intermediate feature map output by the target network layer of the feature extraction layer is the same as the size of the slice. The target network layer is used to perform pixel feature extraction on the slice; each slice corresponds to a multi-channel feature map. The server can first perform pixel feature extraction on the slice through the feature extraction layer to obtain at least two slice feature maps; then perform pixel context feature extraction on the at least two slice feature maps to obtain the at least two feature maps. For example, the server can first perform pixel feature extraction on the slice through the feature extraction layer to obtain a primary semantic feature map; then perform context feature extraction on the primary semantic feature map to obtain the high-level semantic feature map.
[0056] In one possible implementation, the feature extraction layer includes a micro backbone network and an attention network; this step 203 can be implemented by the following steps 2031-2033.
[0057] Step 2031: The server extracts pixel features of the slice through the micro backbone network to obtain a slice feature map.
[0058] The slice feature map may include primary semantic features of pixels. Any feature point of the slice feature map is used to indicate the features of the corresponding pixel in the slice. The number of network layers included in the micro backbone network does not exceed the first threshold, and the number of convolution kernels included in each network layer does not exceed the second threshold. The target network layer may be located in the micro backbone network, and the size of the intermediate slice feature map output by the target network layer is the same as the size of the slice. The target network layer may be a convolution layer for extracting pixel features from the original slice image. Exemplarily, the micro backbone network includes multiple network layers, and the server inputs at least two slices into the first network layer in sequence according to the data propagation order of the multiple network layers, and then inputs the output result of the first network layer into the second network layer, and so on, until the output result of the last network layer of the micro backbone network is used as the slice feature map.
[0059] The target network layer may be the first network layer of the plurality of network layers. In the first network layer in the micro backbone network, the downsampling operation of the slice is omitted. That is, the size of the intermediate slice feature map output by the first network layer is the same as the size of the slice input by the first network layer.
[0060] Exemplarily, the micro-backbone network may be TBNet (Tiny-Backbone-Net), and the TBNet network may be a lightweight residual network with fewer network layers, fewer convolution kernels, and fewer parameters. As shown in Table 1 below, the structure of the TBNet network is as follows:
[0061] Table 1
[0062]
[0063] The size of the slice can be 640×640. As shown in Table 1, the target network layer can be Conv-1 (convolutional layer-1), the size of the slice input to Conv-1 can be 640×640, and the output size of Conv-1 can also be 640×640. The downsampling operation is omitted in Conv-1 to ensure the detection performance of small targets and improve accuracy. The network structure column shows the structure of each network layer. For example, in Conv-1, the network structure is , indicating that there are 2 groups of convolution kernels in Conv-1, each group includes 12 3×3 convolution kernels. Of course, the micro backbone network can also use other lightweight networks to achieve the same function, such as pruning, compressing or other optimization operations on MobileNet and shuffleNet to generate the micro backbone network for achieving the same function. The embodiment of the present application does not make specific limitations on this.
[0064] It should be noted that the existing basic network structures such as VGG (Visual Geometry Group Network, super-resolution test sequence network), Inception network or ResNet (Residual Neural Network, residual network) have a large number of parameters, resulting in low real-time efficiency; and the existing basic network structure has a large number of parameters and is prone to overfitting, especially when the samples are limited; while the micro backbone network of the present application as shown in Table 1 has a small number of parameters and does not require pre-training, thus avoiding the domain gap between the pre-training data set and the target data set, and further improving the accuracy of the model.
[0065] By inputting the slice of the original resolution into the first network layer, the output result of the first network layer is still the intermediate slice feature map of the same size as the slice, so that the detailed features of the original image are retained, and the possible targets within a small range will not be lost, thereby improving the accuracy of target detection; and the number of network layers of the micro backbone network and the number of convolution kernels included in each network layer are within a certain threshold range. By using this lightweight network result, the slice feature map of the slice can be quickly extracted, thereby improving the detection efficiency. Moreover, compared with the commonly used ResNet, MobileNet, ShuffleNet and other networks including a large number of parameters, the micro backbone network of the present application has fewer parameters and is not prone to overfitting. Therefore, it is not limited by the scale of the data set and is applicable to data set scenarios of various sizes. On the premise of meeting the small target detection and ensuring the detection accuracy, the amount of calculation is reduced, the detection efficiency is greatly improved, and it is applicable to various low-configuration hardware scenarios, which expands the scope of application of the present application and improves the applicability.
[0066] Step 2032: For each slice, the server extracts the context features of each feature point in the slice feature map of the slice through the pooling layer of the attention network to obtain the context feature map of the slice.
[0067] The pooling layer may be a multi-scale pooling layer. For each slice feature map of a slice, the server may perform context feature extraction on the slice feature map through a plurality of convolution kernels of different sizes of the pooling layer, and obtain the context feature map of the slice based on the obtained intermediate context feature map. In one possible implementation, step 2032 may include: the server extracts the context features of each feature point in the slice feature map through each of the at least two convolution kernels included in the pooling layer, respectively, to obtain at least two first context feature maps of the slice feature map, and the sizes of the at least two first context feature maps are different. Exemplarily, the server may extract the context features of each slice feature map through each convolution kernel; for each slice feature map, at least two first context feature maps corresponding to at least two convolution kernels are obtained. For example, for slice feature map A, three convolution kernels 1*1, 2*2, and 4*4 may be used to extract context feature maps of A, respectively, to obtain three context feature maps A1, A2, and A3 of A.
[0068] It should be noted that the attention network can be a GAM (Global Attention Module) configured in the target model. After the GAM module is connected to TBNet, it can be implemented by a feature pyramid pooling module; the feature pyramid pooling module can include different pyramid layers. For example, the slice feature map is pooled through three different pyramid layers with convolution kernels of 1*1, 2*2, and 4*4. Through the pooling layer of the attention network, the context feature of the slice feature is extracted, so that each feature point in the context feature map can represent the pixel feature of the corresponding pixel point, and can also represent the feature of the pixel point in the surrounding area of the corresponding pixel point, thereby integrating the context features of the pixel point corresponding to each feature point and its surrounding area, improving the feature expression ability of each feature point in the context feature map, and at the same time, it can also suppress some non-target information, further improving the accuracy of target detection.
[0069] Step 2033: The server performs feature fusion on the at least one context feature map to obtain a feature map of the slice.
[0070] In a possible implementation, when the server uses at least two convolution kernels to extract context features and obtains at least two first context feature maps of different sizes, in this step, the server may first perform size transformation and then perform feature fusion. Then this step may include: the server upsamples the at least two first context feature maps to obtain at least two second context feature maps, the sizes of the at least two second context feature maps are the same as the size of the slice feature map; the server performs feature fusion on the at least two second context feature maps to obtain the feature map of the slice.
[0071] It should be noted that the server can use the bilinear interpolation method to implement the upsampling process through the GAM module, thereby restoring the size of the context feature map to the same size as the slice feature map.
[0072] Lightweight operations are performed through the micro-backbone network in the feature extraction layer, and the downsampling process is omitted in the target network layer of the micro-backbone network to quickly extract slice features to obtain a slice feature map; and context feature extraction is performed on the slice feature map through the attention network, and the global context information is integrated based on the features of the pixel points corresponding to the feature points and their surrounding feature points, so as to further enhance the feature representation capability based on each feature point in the context feature map, and at the same time, some non-target information can be suppressed; then the context feature map after upsampling and re-pooling is restored to the size of the slice feature map, and then feature fusion is performed, so that the feature map can obtain more context information, and the receptive field can also be expanded to the entire image, which is beneficial to the subsequent target model for the detection of targets of different sizes, improves the accuracy of target detection, and further improves the accuracy of small target detection.
[0073] Moreover, the basic network structure in the prior art is usually used for image classification tasks, and the features obtained in the prior art are not suitable for detection tasks. Unlike the prior art, the present application can not only extract the features of the pixels themselves, but also fuse the features of the surrounding pixels, thereby realizing the fusion of global context features and obtaining fused features with stronger expressiveness that are more suitable for detection tasks, thereby further matching business needs and improving the accuracy of target detection.
[0074] Step 204: The server detects the feature map corresponding to each slice to obtain defect information of each slice.
[0075] The defect information is used to indicate the defects of the target object included in the slice. The target model may include a detector for target detection, and the server may detect the feature map through the detector to obtain the defect information of the slice. Exemplarily, the detector is used to perform target detection based on the input feature map and output the defect information of the target object. In this step, for each slice, the server may determine the target box based on the candidate boxes corresponding to each feature point in the feature map corresponding to the slice through the detector included in the target model, and output the defect position and defect classification result of the slice based on the target box. The target box is used to indicate the defect area of the target object; wherein the defect classification result includes a defect category and a category probability, the defect category refers to the defect category to which the defect belongs, and the category probability refers to the probability that the defect belongs to the defect category. For example, the defect category may include at least one of crushing, sticking, missing material and dirt, for example, it may be one or more of them. The defect position can be represented by the upper left corner coordinates and the lower right corner coordinates of the rectangular box; of course, the lower left corner coordinates and the upper right corner coordinates can also be used to represent it. The embodiment of the present application does not specifically limit the representation method of the defect position.
[0076] Exemplarily, the server can generate at least two candidate frames corresponding to the pixel area of each feature point in the slice through the detector, and further regress the multiple candidate frames into a target frame based on the confidence of the at least two candidate frames corresponding to the multiple feature points. Then this step may include: the server generates at least two candidate frames corresponding to each feature point in the feature map based on the offset parameter through the regression branch network of the detector; the server determines the contribution of each candidate frame other than the current maximum candidate frame based on the current maximum candidate frame with the highest confidence among the at least two candidate frames, deletes the first candidate frame whose contribution does not meet the target condition among the other candidate frames, and performs the operation of determining the contribution and deleting the first candidate frame again based on the candidate frames remaining after each deletion, until each candidate frame is traversed, and the target frame is determined based on at least one second candidate frame remaining after the deletion operation; the server classifies the area included in the target frame through the classification branch network of the detector, and outputs the defect classification result. Among them, the offset parameter is used to indicate the distance between the boundaries of the candidate frame and the positive sample pixel point in the corresponding slice of the feature map. The positive sample pixel point can be the pixel point included in the defect area in the slice. Exemplarily, the contribution of the candidate box refers to the value of the candidate box in the process of determining the target box based on multiple candidate boxes. Exemplarily, in this step, the server can determine the target box in a multiple-iteration manner, and the iterative process can include the following steps (1)-(4).
[0077] Step (1): The server sorts the multiple candidate boxes in descending order based on their confidences, and selects the current maximum value candidate box with the highest confidence;
[0078] Step (2): for each candidate box other than the current maximum candidate box, the server sequentially determines the overlap ratio between each candidate box and the current maximum candidate box;
[0079] Step (3): when the overlap ratio between the other candidate boxes and the current maximum value candidate box exceeds the target threshold, the other candidate boxes are deleted;
[0080] Step (4): The server repeats steps (1) to (3) based on the currently remaining candidate frames, that is, the current maximum candidate frame with the highest confidence among the currently remaining candidate frames is screened out, and based on its overlap ratio with each other candidate frame, each other candidate frame is deleted; until all candidate frames are traversed. The server can determine the target frame based on at least one second candidate frame currently remaining after traversing all candidate frames. For example, the at least one second candidate frame is merged to obtain the target frame.
[0081] In one possible example, the overlap ratio between the candidate box and the current maximum candidate box can be used to represent the contribution of the candidate box; the greater the overlap ratio between the candidate box and the current maximum candidate box, the smaller the contribution of the candidate box. The overlap ratio is expressed as IoU (Intersection-over-Union), which refers to the overlap ratio between the candidate box and the original marked box, that is, Figure 3 As shown, the ratio between the intersection and union of the candidate box and the original marked box is Figure 3 The numerator may be the black area of the intersection, and the denominator may be the black area of the union. In this step, in the process of determining the target frame based on the candidate frame, the original marked frame may be the current maximum candidate frame, and the overlap ratio between the candidate frame and the current maximum candidate frame is the ratio between the intersection and the union of the candidate frame and the current maximum candidate frame.
[0082] In one possible example, the confidence is used to indicate the probability that the area within the candidate box is the defect area. Each feature point in the feature map corresponds to a pixel area in the slice, and the pixel area includes multiple pixels. For example, a feature point corresponds to a pixel area composed of 16x16 pixels in the slice. The server can use the detector to generate at least one candidate box for each pixel area corresponding to each feature point, and calculate the confidence of each candidate box. The offset parameter is used to indicate the offset distance between each boundary of the target box and the positive sample pixel point in the corresponding slice of the feature map. The positive sample pixel point can be a pixel point in the target area of the slice corresponding to the feature point. Figure 4As shown, the offset parameter may include four parameters l, t, r, and b in the horizontal and vertical directions, where l represents the offset distance between the positive sample pixel and the left boundary of the target frame, t represents the offset distance between the positive sample pixel and the top boundary of the target frame, r represents the offset distance between the positive sample pixel and the right boundary of the target frame, and b represents the offset distance between the positive sample pixel and the bottom boundary of the target frame.
[0083] In a possible example, the server uses the positive sample pixel point as a reference, predicts the offset between the output and the four boundaries of the target box, and fine-tunes the positive sample pixel point based on the offset parameter;
[0084] In a possible example, the regression branch network may be a network of the regression type; the classification branch network may be a network of the classification type, and the classification branch network may include a classification function for determining the defect category. For example, the classification branch network may also use the candidate box to determine the category, for example, the classification branch network may determine the defect category and category probability corresponding to each candidate box. For candidate boxes belonging to the same defect category, the above steps (1)-(4) are performed. For example, the remaining at least one second candidate box may be used to obtain the defect category and category probability of the final target box; for example, the category probability of the target box may be calculated by averaging or merging at least one second candidate box. Among them, the classification branch network may include 2 convolutional layers and 1 classification layer. The detector Detector may be implemented using an anchor free detector, thereby using an anchor free detector with a smaller computational amount, which can be used without prior knowledge of preset anchor hyperparameters, and can output results quickly and accurately with a small amount of computation, thereby improving the efficiency of detection.
[0085] In a possible implementation, the target model may further include a classifier, which is used to output defect indication information of the slice. The process may include: for each slice, the server outputs the defect indication information of the slice based on the feature map of the slice through the classifier of the target model, and the defect indication information is used to indicate whether the local target object included in the slice has defects. Exemplarily, the defect indication information may include the defect probability of whether the slice has defects. In a possible example, the classifier may be a network of Classifier type, and the classification branch network may include a classification function for determining the defect category, for example, a binary classification function. Exemplarily, the classifier may include two convolution modules (conv-bn-relu) and a global average pooling (GAP) network. The feature map may pass through the two convolution modules included in the classifier, and after global average pooling processing by the GAP, pass through a binary classification classifier to output the defect probability of whether there is a defect.
[0086] In a possible implementation, the target model is finally obtained by jointly training the classifier and the detector; the training process of the target model includes: the server inputs the sample set into the initial model, the sample set refers to a set of sample images of the target object and the true value labels of the sample images, and the initial model includes an initial detector and an initial classifier; the server determines the joint difference between the joint result output by the initial model and the true value label based on the sample detection position and sample detection classification output by the initial detector, the sample indication information output by the initial classifier, and the true value label of the sample set through a joint loss function, and the joint result includes the sample detection position, the sample detection classification and the sample indication information; the server adjusts the model parameters of the initial model based on the joint difference until the target condition is met, and the target model is obtained. The model parameters include at least the initial offset parameters of the initial detector. The server can optimize the parameters of each initial network layer of the initial model through the joint difference, and re-execute the above-mentioned sample set input process and the process of calculating the joint difference based on the input result and the sample true value based on the optimized parameters, and optimize the parameters again based on the latest joint difference, and repeatedly optimize the model in this iterative manner until the target condition is met and the optimization is stopped. Among them, the target condition can be that the joint difference is less than the target difference threshold or the number of iterative adjustments exceeds the target number threshold, etc.
[0087] In one possible example, the process by which the server calculates the joint difference based on the joint loss function may include: the server determines a first difference between the sample candidate box and the true value box based on the sample candidate box predicted by the initial regression branch network of the initial detector, the true value box of the sample set, and a first loss function; the server determines a second difference between the predicted category probability and the overlap ratio based on the overlap ratio between the true value box and the predicted box of the sample set, the predicted category probability predicted by the initial classification branch network of the initial detector, and a second loss function, the predicted box being the area where the defect is located based on the sample candidate box prediction; the server determines a third difference between the sample indication information and the true value probability based on the sample indication information predicted by the classifier, the true value probability of the sample set, and a third loss function; the server determines the joint difference through the joint loss function based on the first difference, the second difference, the third difference, and the supervisory signal of the classifier. The server can predict the defect area based on multiple sample candidate boxes to obtain a predicted box; for example, the same iterative process as the above steps (1)-(4) can be used to obtain the predicted box based on multiple sample candidate boxes, which will not be described here one by one. The sample indication information can be the probability of whether the sample image includes a defect predicted by the classifier of the initial model; when the sample image includes a defect, the true value probability is 1, otherwise it is 0. The true value box can be the actual area where the defect of the sample image is located, indicating the true value of the location of the defect.
[0088] In one possible example, the server may predict the prediction box of the sample based on the initial detector and calculate the first difference based on the prediction box and the true value box. The process may include: for each sample image, the server predicts at least two sample candidate boxes of the sample image through the initial regression branch network based on the initial offset parameter of the initial regression branch network; the server reorganizes the boundaries of the at least two sample candidate boxes based on the deviation between the boundaries of the at least two sample candidate boxes and the boundaries of the true value box to obtain at least two reorganized boxes; the server determines the first difference between each reorganized box and the true value box based on the overlap ratio of each reorganized box and the true value box, the number of pixels of the true value box and the first loss function. Among them, the initial offset parameter can be the initial value of the offset parameter, for example, it can be the initial value of the four parameters of l, t, r, and b. The confidence of the reorganized box is used to indicate the probability that the reorganized box is the true value box, and the confidence of the sample candidate box is used to indicate the probability that the sample candidate box is the true value box. Exemplarily, the overlap ratio between the reorganized box (sample candidate box) and the true value box can be used as the confidence of the reorganized box (confidence of the sample candidate box). The deviation between the boundary of the sample candidate box and the boundary of the true value box can be: the deviation between the two boundaries at the same relative position of the candidate box and the true value box, for example, the deviation can be a distance difference. The relative position can be the position of the boundary relative to the box, for example, the left boundary of the positive sample pixel point relative to the box on the left side of the box, the top boundary at the top of the box, etc. The same relative position can be the left boundary of the candidate box and the left boundary of the true value box, and the top boundary of the candidate box and the top boundary of the true value box.
[0089] Exemplarily, the process of the server reorganizing the sample candidate frame to obtain the reorganized frame may include: the server decomposes and divides the boundaries of the at least two sample candidate frames into at least two boundary sets based on the confidence of each sample candidate frame, and each boundary set includes at least two boundaries of the at least two sample candidate frames at the same relative position; the server calculates the deviation between each boundary in the boundary set and the true boundary of the corresponding true value frame for each boundary set, and sorts the at least two boundaries in the boundary set based on the deviation corresponding to each boundary; the service reorganizes the boundaries with the same arrangement order in each boundary set into a reorganized frame based on the arrangement order of each boundary in each boundary set, and calculates the overlap ratio between the reorganized frame and the true value frame. Exemplarily, the candidate frame, the predicted frame, and the true value frame can be rectangular frames. In a possible example, the process of the server predicting the sample candidate frame of the sample based on the initial detector and calculating the first difference may include: decomposition, sorting, reorganization, allocation, and calculation of differences, which specifically correspond to the following steps ae.
[0090] Step a: Decomposition: The server uses the confidence of the four boundaries based on the confidence of the predicted candidate bounding boxes, and then divides the boundaries at the four relative positions into four groups to establish four boundary sets:
[0091]
[0092] ;
[0093] Among them, left is the set of confidences of the left border of each candidate box; right is the set of confidences of the right border of each candidate box; top is the set of confidences of the top border of each candidate box; bottom is the set of confidences of the bottom border of each candidate box; Figure 5 As shown, step a decomposes the boundaries of the three candidate boxes S0, S1, and S2 to obtain four boundary sets. Figure 5 As shown in (a), the right1 set includes the right boundaries of three candidate boxes S0, S1, and S2.
[0094] Step b: Ranking: The server calculates four boundaries based on the target instance boundaries. The deviation of each edge in the ground-truth box to the corresponding ground-truth boundary with the same relative position, and the four boundary sets are sorted based on the deviation;
[0095] like Figure 5 As shown in (b), in the right boundary set, the relative positions between the right boundaries of the three candidate boxes S0, S1, and S2 and the right boundary of the true value box are as follows: Figure 5 As shown in Figure 1, it is obvious that the right boundary of S2 is closest to the right boundary of the true value box, followed by the right boundary of S0, and the right boundary of S1 is farthest from the right boundary of the true value box. Among them, the deviation between the right boundary of S2 and the right boundary of the true value box is , the deviation between the right boundary of S0 and the right boundary of the true value box is , the deviation between the right boundary of S1 and the right boundary of the true value box is Obviously, based on the deviation, the right boundaries of S0, S1, and S2 are arranged in ascending order to obtain the Rank: the right boundary of S2 is the first, the right boundary of S0 is the second, and the right boundary of S1 is the last. Therefore, step b obtains the arrangement order of each boundary in each boundary set by sorting (ranking).
[0096] Step c: Recombination: after sorting, that is, recombining the boundaries with the same arrangement order in each boundary set into a recombined frame, calculating the overlap ratio between the recombined frame and the target frame after recombining, and taking it as the recombination confidence of the four boundaries of the recombined frame.
[0097] like Figure 5 As shown in (c), the boundary sets with the same level are reassembled into new boxes, and the overlap ratio between the reorganized boxes and the true value boxes is calculated. The confidence of the reorganized boxes of the three candidate boxes S0, S1, and S2 is S0 ' 、S1 ' 、S2 ' .
[0098] Step d: Assignment: Based on the confidence of the reorganized box and the confidence of the candidate box, the confidence of each boundary in the reorganized box is reallocated.
[0099] For example, for each bounding box in the reorganized frame, the larger value between the confidence of the candidate frame where the bounding box is located and the confidence of the reorganized frame where the bounding box is located can be used as the confidence of the bounding box. Figure 5 As shown in (d), we now have two sets of boundary scores for the original candidate box and the reorganized reorganized box, for example, S0 ' The value is max (S1, S0 ' ), that is, take the original sample candidate box S1 and the reorganized box S0 ' The final confidence for each boundary is assigned using the higher of the two sets of boundary scores, rather than using exactly one set.
[0100] It should be noted that if the confidence of the reorganized box after reorganization is low, that is, the included boundary is far away from the boundary of the true value box ground truth, this will cause the confidence of the four boundaries after reorganization to be much lower than their original boundaries. These severely drifted confidence scores will cause the gradient back propagation instability during the training phase, so a group with higher scores is selected to ensure the accuracy of training.
[0101] Step e: Calculating the difference, the first loss function may be in the form of the following formula 1. Then the step of the server determining the first difference between each reorganized frame and the true value frame based on the overlap ratio between the reorganized frame and the true value frame, the number of pixels of the true value frame and the first loss function includes: the server determines the first difference between each reorganized frame and the true value frame through the following formula 1 based on the overlap ratio between the reorganized frame and the true value frame, the overlap ratio between the candidate frame and the true value frame, and the number of pixels of the true value frame.
[0102] Formula 1: ;
[0103] in, The number of pixels representing the true value frame, that is, the number of pixels included in the corresponding pixel area of the sample image corresponding to the true value frame. is the indicator function, Represents the score of the I-th recombinant frame among multiple recombinant frames (that is, the confidence, that is, the overlap ratio between the I-th recombinant frame and the true value frame), Represents the score of the I-th sample candidate box before reorganization (that is, the confidence, that is, the overlap ratio between the I-th sample candidate box and the true value box). If the confidence of the reorganized box is higher than the confidence of the sample candidate box, the indicator function value is 1, otherwise it is 0; Recombination box With the truth box The overlap ratio between them is the confidence of the reorganized frame; Represents the sample candidate box With the truth box The overlap ratio between them is also the confidence of the sample candidate box.
[0104] In one possible implementation, the second loss function may be a QFL (Quality Focal Loss) function, and the QFL function may be in the form of the following formula 2. The server determines the second difference between the predicted category probability and the overlap ratio based on the overlap ratio between the true value box and the predicted box of the sample set, the predicted category probability predicted by the initial classification branch network, and the second loss function. The step may include: the server calculates the second difference based on the overlap ratio between the true value box and the predicted box and the predicted category probability by the following formula 2:
[0105] Formula 2: ;
[0106] in, is the predicted output, that is, the predicted category probability of a certain category; y is the overlap ratio of the predicted prediction box and the true value box, ;
[0107] In one possible implementation, the three loss functions may be the loss functions of the classifier, and the loss function may be represented by a softmax loss function, that is, the server may calculate the third difference based on the sample indication information predicted by the classifier, the true value probability of the sample, and the softmax loss function. In one possible example, the server may use the above formula 1, formula 2, and the softmax loss function to represent the joint loss function, and the server may determine the joint difference based on the first difference, the second difference, the third difference, and the supervisory signal of the classifier through the joint loss function, which may include: the server calculates the joint difference based on the first difference, the second difference, the third difference, and the supervisory signal of the classifier through the following formula 3 corresponding to the joint loss function:
[0108] Formula 3: ;
[0109] in, is the joint difference; n is the supervisory signal corresponding to the classifier, which can represent the true value probability, n={0,1}, n=1 means that the current input slice contains the defect to be detected, and n=0 means that the current input slice does not contain the defect; Represents the loss function of the classification branch network of the detector, which is also the second loss function; , represents the loss function of the regression branch network of the detector, which is also the first loss function; is the indicator function. If n=1 (indicating that the currently input slice contains the defect to be detected), the indicator function value is 1, otherwise it is 0; is a hyperparameter that can be configured based on needs, for example, Set to 0.25.
[0110] The server can use the joint loss function shown in the above formula three to calculate the joint difference, and based on the joint difference, optimize the parameters of each network layer such as the micro-backbone network of the feature extraction layer of the target model, the attention network, the regression network score and classification network branch included in the detector, and the classifier. For example, the gradient descent algorithm can be used to optimize the parameters of each network layer. For example, the offset parameters of the detector can be optimized so that the detector can output more accurate defect information using the optimized parameters.
[0111] The output results of the combined classifier and detector are used to jointly train and optimize the parameters of each network layer in the model, and a joint loss function is used to allow the detector and classifier to mutually reinforce the training optimization, reduce the probability of false detection, improve the accuracy of detection, and enhance the detection performance. In addition, the first difference and the second difference can be combined through the loss functions of the regression branch and the classification branch of the detector to further strengthen the optimization and improve the accuracy of the target model obtained through training.
[0112] like Figure 6 As shown, Figure 6 FIG. 1 is a visual diagram of a defect detected using the method of the present application. Figure 7 As shown, Figure 7 A schematic diagram of the target detection process based on each network layer in the target model. Figure 7 In the example of a mobile phone camera holder accessory, the image to be inspected may contain defects such as crushing, sticking, missing material, or dirt on the mobile phone camera holder accessory. Figure 7 (a) After the image to be detected is segmented, multiple small slices are obtained. Figure 7(a) shows two small slices. The two small slices are input into the micro backbone network TBNet of the target model, and pass through the target network layer conv-1 of the micro backbone network, omitting the downsampling operation, outputting an intermediate feature map of the same size as the slice, and passing through the other network layers of the TBNet network in turn to obtain a slice feature map. The slice feature map is then input into the attention module GAM, and is respectively pooled through the pyramid layer in GAM, for example, respectively through Figure 7 The three convolution kernels 1×1, 2×2, and 4×4 shown in (c) are pooled to obtain three context feature maps of different scales, which are then upsampled to restore three context feature maps of the same scale; for example, three context feature maps of the size of slice feature maps are fused into one feature map through the feature fusion layer Eltwise. The feature maps are respectively input into the detector (d) Detector and the classifier (e) Classifier. In (d), the regression branch network Regression 4 convolution layers and D&R (Decomposition & Recombination, decomposition and recombination module) are respectively passed; the feature map output by the feature fusion layer Eltwise is N×128×H×W data, where N is the number of slices, H is the slice height, W is the slice width, and 128 refers to the number of channels. After the D&R module, the feature vector N×4A×H×W is finally output, where 4A is the coordinate position of the target box where the defect is located. In (d), after passing through 2 convolutional layers and 1 classification layer of the classification branch network Classification, the data is N×128×H×W. Then, the N×A×H×W Objectness (target probability) data of the regression branch network Regression is multiplied with the N×128×H×W data output by 2 convolutional layers and 1 classification layer of the classification branch network Classification, and a feature vector of N×KA×H×W is output. K represents K defect categories, and the feature vector of N×KA×H×W can represent the category probabilities corresponding to the K defect categories. In the classifier (e), after passing through two convolution modules, the data changes from N×128×H×W to N×128×(H / 2)×(W / 2), and then passes through the global average pooling layer Ave Pool (averagepool) to output N×256 data. After passing through a classifier, such as a binary classifier, it finally outputs an N×2 matrix, which can represent Defect y / n (defect yes / no), that is, whether there is a defect.
[0113] Depend on Figure 7It can be seen that in the target model of the present application, the network structure is clear, and each network layer and module has good generalization ability; by segmenting the high-resolution image to be detected, it can support input monitoring of images of any resolution; the pixel features and pixel context features are extracted by the feature extraction layer to obtain a feature map with greatly improved feature representation ability, which enhances the robustness of the model and further improves the accuracy of detection using the model. Especially for small target detection, the model is required to be extremely robust to size, and the target detection method of the present application can utilize the above segmentation of the target model, the features of the global context, and the omission of upsampling through the target network layer, so that the feature map obtains more and more detailed features, and the receptive field can also be expanded to the entire image, improving the robustness of the model for target detection of different scales.
[0114] Exemplarily, the following is experimental data of target detection using the method of the embodiment of the present application, and the experimental result data is as follows:
[0115] The model was trained on a self-built training set containing 7545 images and tested using 3458 images. The results are shown in Table 2 below:
[0116] Table 2
[0117]
[0118] In Table 2, the indicators include: mAP (mean average precision) and APs (Smalltarget average accuracy). As shown in Table 2, the number of parameters in other methods (such as FasterRCNN) is more than doubled. For images of the same size, the indicators of other methods are also significantly lower and the time consumption is also longer. In comparison, this application can use a smaller number of parameters to achieve higher indicators, and it also takes less time and is more efficient. Figure 6 As shown, Figure 6 It is a visualization diagram of the test. Obviously, when the target detection method of the present application is used for detection, even if Figure 6 Even smaller, microscopic defects can be detected, thereby improving the accuracy and precision of detection.
[0119] The target detection method provided by the present application first divides the image to be detected into at least two slices, and then extracts pixel features and pixel context features of each slice through the feature extraction layer of the target model to obtain at least two feature maps; the feature map is detected to obtain defect information of the slice; the restriction on resolution is removed and it is applicable to the case of images of any resolution; the feature extraction layer includes a target network layer for extracting pixel features of the slice, and the intermediate feature map output by the target network layer is the same size as the slice, that is, the downsampling when extracting the pixel features of the slice is omitted, thereby retaining the detailed features of the original image, and the feature extraction layer is also designed to extract pixel features and pixel context features, thereby improving the robustness of detection of targets of different sizes, and even small targets in a smaller area can be accurately detected, thereby improving the accuracy of target detection.
[0120] By using a joint loss function and the output results of the combined classifier and detector to jointly train and optimize the parameters of each network layer in the model, the detector and classifier reinforce each other's training optimization, reduce the probability of false detection, improve detection accuracy, and enhance detection performance.
[0121] The micro backbone network has fewer parameters such as the number of network layers and the number of convolution kernels. While meeting the requirements of small target detection and ensuring detection accuracy, it reduces the amount of computation and greatly improves detection efficiency. It is suitable for implementation in various low-configuration hardware scenarios, thus improving applicability.
[0122] Figure 8 A schematic diagram of the structure of a target detection device provided in an embodiment of the present application. Figure 8 As shown, the device comprises:
[0123] A determination module 801 is used to determine an image to be detected including a target object, and to determine at least two slices of the image to be detected;
[0124] A feature extraction module 802 is used to perform pixel feature extraction and pixel context feature extraction on the at least two slices through the feature extraction layer of the target model to obtain at least two feature maps, wherein any feature point of the feature map is used to indicate the feature and context feature of the corresponding pixel in the slice, and the size of the intermediate feature map output by the target network layer of the feature extraction layer is the same as the size of the slice, and the target network layer is used to perform pixel feature extraction on the slice;
[0125] The detection module 803 is used to detect the feature map corresponding to each slice to obtain the defect information of each slice, and the defect information is used to indicate the defects of the target object included in the slice.
[0126] In one possible implementation, the feature extraction layer includes a micro backbone network and an attention network; the feature extraction module 802 includes:
[0127] A pixel feature extraction unit is used to extract pixel features of the at least two slices through the micro backbone network to obtain at least two slice feature maps, wherein any feature point of the slice feature map is used to indicate a feature of a corresponding pixel in the slice;
[0128] A context feature extraction unit, configured to extract, for each slice, context features of each feature point in a slice feature map of the slice through a pooling layer of the attention network to obtain at least one context feature map of the slice, and perform feature fusion on the at least one context feature map to obtain a feature map of the slice;
[0129] Among them, the number of network layers included in the micro backbone network does not exceed the first threshold, and the number of convolution kernels included in each network layer does not exceed the second threshold.
[0130] In a possible implementation, the context feature extraction unit is used to extract the context features of each feature point in the slice feature map through each of the at least two convolution kernels included in the pooling layer, so as to obtain at least two first context feature maps of the slice feature map, and the at least two first context feature maps have different sizes;
[0131] Correspondingly, the context feature extraction unit is also used to upsample the at least two first context feature maps to obtain at least two second context feature maps, and the sizes of the at least two second context feature maps are the same as the size of the slice feature map; and perform feature fusion on the at least two second context feature maps to obtain the feature map of the slice.
[0132] In a possible implementation, the detection module 803 is used to determine, for each slice, a target frame based on candidate frames corresponding to each feature point in a feature map corresponding to the slice by using a detector included in the target model, and output a defect position and a defect classification result of the slice based on the target frame, where the target frame is used to indicate a defect area of the target object;
[0133] The defect classification result includes a defect category and a category probability. The defect category refers to the defect category to which the defect belongs, and the category probability refers to the probability that the defect belongs to the defect category.
[0134] In one possible implementation, the detection module 803 is used to generate at least two candidate boxes corresponding to each feature point in the feature map based on an offset parameter through the regression branch network of the detector, and the offset parameter is used to indicate the distance by which each boundary of the candidate box is offset from the positive sample pixel point in the corresponding slice of the feature map; based on the current maximum candidate box with the highest confidence among the at least two candidate boxes, determine the contribution of each other candidate box except the current maximum candidate box, delete the first candidate box whose contribution does not meet the target condition among the other candidate boxes, and perform the operation of determining the contribution and deleting the first candidate box again based on the candidate boxes remaining after each deletion, until each candidate box is traversed, and the target box is determined based on at least one second candidate box remaining after the deletion operation; through the classification branch network of the detector, classify the area included in the target box, and output the defect classification result.
[0135] In one possible implementation, the device further includes:
[0136] A classification module, configured to output defect indication information of each slice based on a feature map of the slice through a classifier of the target model, wherein the defect indication information is used to indicate whether a local target object included in the slice has a defect;
[0137] The target model is obtained by training the output result of the classifier and the output result of the detector; accordingly, the device also includes a model training module, and the module training module includes:
[0138] An input unit, used to input a sample set into an initial model, where the sample set refers to a set of sample images of target objects and true value labels of the sample images, and the initial model includes an initial detector and an initial classifier;
[0139] A joint difference determination unit, configured to determine a joint difference between a joint result output by the initial model and the true value label based on the sample detection position and the sample detection classification output by the initial detector, the sample indication information output by the initial classifier, and the true value label of the sample set, through a joint loss function, wherein the joint result includes the sample detection position, the sample detection classification, and the sample indication information;
[0140] The optimization unit is used to adjust the model parameters of the initial model based on the joint difference until the adjustment is stopped when the target condition is met, so as to obtain the target model, wherein the model parameters at least include the initial offset parameters of the initial detector.
[0141] In a possible implementation, the joint difference determination unit is used to include:
[0142] A first difference determination subunit, configured to determine a first difference between the sample candidate frame and the true value frame based on the sample candidate frame predicted by the initial regression branch network of the initial detector, the true value frame of the sample set, and a first loss function;
[0143] A second difference determination subunit is used to determine a second difference between the predicted category probability and the overlap ratio based on the overlap ratio between the true value box and the predicted box of the sample set, the predicted category probability predicted by the initial classification branch network of the initial detector, and a second loss function, wherein the predicted box is a defect area predicted based on the sample candidate box;
[0144] a third difference determination subunit, configured to determine a third difference between the sample indication information and the true value probability based on the sample indication information predicted by the classifier, the true value probability of the sample set, and a third loss function;
[0145] The joint difference determination subunit is used to determine the joint difference degree based on the first difference, the second difference, the third difference and the supervision signal of the classifier through the joint loss function.
[0146] In one possible implementation, the first difference determination subunit is used to predict, for each sample image, at least two sample candidate frames of the sample image based on the initial offset parameters of the initial regression branch network through the initial regression branch network; based on the deviations between the boundaries of the at least two sample candidate frames and the boundaries of the true value frame, reorganize the boundaries of the at least two sample candidate frames to obtain at least two reorganized frames; and determine the first difference between each reorganized frame and the true value frame based on the overlap ratio of each reorganized frame and the true value frame, the number of pixels of the true value frame and the first loss function.
[0147] In one possible implementation, the first difference determination subunit is used to decompose and divide the boundaries of the at least two sample candidate boxes into at least two boundary sets based on the confidence of each sample candidate box, each boundary set including at least two boundaries of the at least two sample candidate boxes at the same relative position; for each boundary set, calculate the deviation between each boundary in the boundary set and the true boundary of the corresponding true value box, and sort the at least two boundaries in the boundary set based on the deviation corresponding to each boundary; based on the arrangement order of each boundary in each boundary set, reorganize the boundaries with the same arrangement order in each boundary set to obtain a reorganized frame, and calculate the overlap ratio between the reorganized frame and the true value frame.
[0148] In a possible implementation, the determination module 801 is further configured to segment the image to be detected by using a sliding window method based on a target step size and a sliding window of a target size to obtain at least two slices of the image to be detected.
[0149] The target detection device provided by the present application first divides the image to be detected into at least two slices, and then extracts pixel features and pixel context features of each slice through the feature extraction layer of the target model to obtain at least two feature maps; the feature map is detected to obtain defect information of the slice; the restriction on resolution is removed, and it is applicable to the case of images of any resolution; the feature extraction layer includes a target network layer for extracting pixel features of the slice, and the intermediate feature map output by the target network layer is the same size as the slice, that is, the downsampling when extracting the pixel features of the slice is omitted, thereby retaining the detailed features of the original image, and the feature extraction layer is also designed to extract pixel features and pixel context features, thereby improving the robustness of detection of targets of different sizes, and even small targets in a smaller area can be accurately detected, thereby improving the accuracy of target detection.
[0150] By using a joint loss function and the output results of the combined classifier and detector to jointly train and optimize the parameters of each network layer in the model, the detector and classifier reinforce each other's training optimization, reduce the probability of false detection, improve detection accuracy, and enhance detection performance.
[0151] The micro backbone network has relatively small parameters and the number of convolution kernels. While meeting the requirements of small target detection and ensuring detection accuracy, it reduces the amount of computation and greatly improves detection efficiency. It is suitable for implementation in various low-configuration hardware scenarios, thus improving applicability.
[0152] The target detection device of this embodiment can execute the target detection method shown in the above embodiments of the present application. The implementation principle is similar and will not be repeated here.
[0153] Fig. 9 1 is a schematic diagram of the structure of a computer device provided in an embodiment of the present application. Fig. 9 As shown, the computer device includes: a memory and a processor; at least one program stored in the memory, which, when executed by the processor, can achieve the following compared with the prior art:
[0154] The image to be detected is divided into at least two slices, and pixel features and pixel context features are extracted from each slice through the feature extraction layer of the target model to obtain at least two feature maps; the feature map is detected to obtain defect information of the slice; the restriction on resolution is removed, and it is applicable to the case of images of any resolution; the feature extraction layer includes a target network layer for extracting pixel features of the slice, and the intermediate feature map output by the target network layer is the same as the size of the slice, that is, the downsampling when extracting the pixel features of the slice is omitted, thereby retaining the detailed features of the original image, and the feature extraction layer is also designed to extract pixel features and pixel context features, thereby improving the robustness of detection of targets of different sizes, and even small targets in a smaller area can be accurately detected, thereby improving the accuracy of target detection.
[0155] In an alternative embodiment, a computer device is provided, such as Fig. 9 As shown, Fig. 9 The computer device 900 shown includes: a processor 901 and a memory 903. The processor 901 and the memory 903 are connected, such as through a bus 902. Optionally, the computer device 900 may also include a transceiver 904, which may be used for data interaction between the computer device and other computer devices, such as data transmission and / or data reception. It should be noted that in actual applications, the transceiver 904 is not limited to one, and the structure of the computer device 900 does not constitute a limitation on the embodiments of the present application.
[0156] The processor 901 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It may implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. The processor 901 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, and the like.
[0157] The bus 902 may include a path to transmit information between the above components. The bus 902 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 902 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 8 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0158] The memory 903 may be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto.
[0159] The memory 903 is used to store the application code (computer program) for executing the solution of the present application, and the execution is controlled by the processor 901. The processor 901 is used to execute the application code stored in the memory 903 to implement the contents shown in the above method embodiment.
[0160] Computer equipment includes but is not limited to servers, terminals or service clusters.
[0161] An embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer-readable storage medium is run on a computer, the computer can execute the corresponding contents of the target detection method in the aforementioned method embodiment.
[0162] The embodiment of the present application provides a computer program product or a computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the above-mentioned target detection method.
[0163] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0164] The above descriptions are only some embodiments 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 principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A target detection method, It is characterized in that The method comprises: Determine an image to be detected that includes a target object, and determine at least two slices of the image to be detected; Performing pixel feature extraction and pixel context feature extraction on the at least two slices through a feature extraction layer of a target model to obtain at least two feature maps, wherein any feature point of the feature map is used to indicate features and context features of corresponding pixels in the slice, and the size of the intermediate feature map output by a target network layer of the feature extraction layer is the same as the size of the slice, and the target network layer is used to perform pixel feature extraction on the slice; For each slice, a target frame is determined based on candidate frames corresponding to each feature point in a feature map corresponding to the slice by a detector included in the target model, and a defect position and a defect classification result of the slice are output based on the target frame; defect indication information of the slice is output based on the feature map of the slice by a classifier of the target model; the target frame is used to indicate the defect area of the target object, and the defect indication information is used to indicate whether a local target object included in the slice has a defect; The target model is obtained by training the joint difference between the joint result output by the initial model for the sample set and the true value label of the sample set; the initial model includes an initial detector and an initial classifier, and the joint result includes the sample detection position and sample detection classification output by the initial detector, and the sample indication information output by the initial classifier; The method for determining the joint difference degree includes: Determine a first difference between the sample candidate frame and the true value frame based on the sample candidate frame predicted by the initial regression branch network of the initial detector, the true value frame of the sample set, and a first loss function; Determine a second difference between the predicted category probability and the overlap ratio based on an overlap ratio between a true value box and a predicted box of the sample set, a predicted category probability predicted by an initial classification branch network of the initial detector, and a second loss function, wherein the predicted box is a defect region predicted based on the sample candidate box; Determining a third difference between the sample indication information and the true value probability based on the sample indication information predicted by the initial classifier, the true value probability of the sample set, and a third loss function; Based on the first difference, the second difference, the third difference and the supervisory signal of the initial classifier, the joint difference degree is determined by a joint loss function.
2. The target detection method according to claim 1, It is characterized in that The feature extraction layer includes a micro backbone network and an attention network; the feature extraction layer of the target model performs pixel feature extraction and pixel context feature extraction on the at least two slices to obtain at least two feature maps, including: By means of the micro backbone network, pixel feature extraction is performed on the at least two slices to obtain at least two slice feature maps, wherein any feature point of the slice feature map is used to indicate a feature of a corresponding pixel point in the slice; For each slice, extracting context features of each feature point in a slice feature map of the slice through a pooling layer of the attention network to obtain at least one context feature map of the slice, and performing feature fusion on the at least one context feature map to obtain a feature map of the slice; The number of network layers included in the micro backbone network does not exceed a first threshold, and the number of convolution kernels included in each network layer does not exceed a second threshold.
3. The target detection method according to claim 2, It is characterized in that The step of extracting context features of each feature point in the slice feature map of the slice through the pooling layer of the attention network to obtain at least one context feature map of the slice includes: Extracting context features of each feature point in the slice feature map through each of the at least two convolution kernels included in the pooling layer, respectively, to obtain at least two first context feature maps of the slice feature map, wherein the at least two first context feature maps have different sizes; Accordingly, the performing feature fusion on the at least one context feature map to obtain the feature map of the slice includes: Upsampling the at least two first context feature maps to obtain at least two second context feature maps, wherein the sizes of the at least two second context feature maps are the same as the size of the slice feature map; Feature fusion is performed on the at least two second context feature maps to obtain a feature map of the slice.
4. The target detection method according to claim 1, It is characterized in that in, The defect classification result includes a defect category and a category probability, the defect category refers to the defect category to which the defect belongs, and the category probability refers to the probability that the defect belongs to the defect category.
5. The target detection method according to claim 1, It is characterized in that The detector included in the target model determines the target frame where the defect is located based on the candidate frames corresponding to each feature point in the feature map corresponding to the slice, and outputs the defect position and defect classification result of the slice based on the target frame, including: Generate, by means of a regression branch network of the detector, at least two candidate boxes corresponding to each feature point in the feature map based on an offset parameter, wherein the offset parameter is used to indicate the offset distance between each boundary of the candidate box and the positive sample pixel point in the corresponding slice of the feature map; Based on the current maximum candidate frame with the highest confidence among the at least two candidate frames, determining the contribution of each other candidate frame except the current maximum candidate frame, deleting the first candidate frame whose contribution does not meet the target condition among the other candidate frames, and performing the operation of determining the contribution and deleting the first candidate frame again based on the candidate frames remaining after each deletion, until each candidate frame is traversed, and determining the target frame based on at least one second candidate frame remaining after the deletion operation; The area included in the target frame is classified through the classification branch network of the detector, and the defect classification result is output.
6. The target detection method according to claim 1, It is characterized in that The target model is obtained by training by combining the output result of the classifier with the output result of the detector; accordingly, the training process of the target model includes: Inputting a sample set into an initial model, wherein the sample set refers to a set of sample images of target objects and true value labels of the sample images, and the initial model includes an initial detector and an initial classifier; Based on the sample detection position and sample detection classification output by the initial detector, the sample indication information output by the initial classifier, and the true value label of the sample set, determining the joint difference between the joint result output by the initial model and the true value label through a joint loss function, wherein the joint result includes the sample detection position, the sample detection classification, and the sample indication information; Based on the joint difference, the model parameters of the initial model are adjusted until the target condition is met, and the adjustment is stopped to obtain the target model, wherein the model parameters at least include the initial offset parameters of the initial detector.
7. The target detection method according to claim 1, It is characterized in that The determining of a first difference between the sample candidate frame and the true value frame based on the sample candidate frame predicted by the initial regression branch network of the initial detector, the true value frame of the sample set, and the first loss function comprises: For each sample image, predicting at least two sample candidate frames of the sample image through the initial regression branch network based on an initial offset parameter of the initial regression branch network; Based on the deviations between the boundaries of the at least two sample candidate frames and the boundaries of the true value frame, reorganizing the boundaries of the at least two sample candidate frames to obtain at least two reorganized frames; Based on the overlap ratio between each reorganized frame and the true value frame, the number of pixels of the true value frame, and the first loss function, a first difference between each reorganized frame and the true value frame is determined.
8. The target detection method according to claim 7, It is characterized in that The step of reorganizing the boundaries of the at least two sample candidate frames to obtain at least two reorganized frames based on the deviations between the boundaries of the at least two sample candidate frames and the boundaries of the true value frame comprises: Based on the confidence of each sample candidate box, decompose and divide the boundaries of the at least two sample candidate boxes into at least two boundary sets, each boundary set including at least two boundaries of the at least two sample candidate boxes at the same relative position; For each boundary set, calculating the deviation between each boundary in the boundary set and the true boundary of the corresponding true value box, and sorting at least two boundaries in the boundary set based on the deviation corresponding to each boundary; Based on the arrangement order of each boundary in each boundary set, each boundary with the same arrangement order in each boundary set is reorganized to obtain a reorganized frame, and the overlap ratio between the reorganized frame and the true value frame is calculated.
9. The target detection method according to claim 1, It is characterized in that The determining of at least two slices of the image to be detected comprises: Based on a sliding window of a target step length and a target size, the image to be detected is segmented in a sliding window manner to obtain at least two slices of the image to be detected.
10. A target detection device, It is characterized in that include: A determination module, used to determine an image to be detected including a target object, and to determine at least two slices of the image to be detected; A feature extraction module, used to perform pixel feature extraction and pixel context feature extraction on the at least two slices through a feature extraction layer of a target model to obtain at least two feature maps, wherein any feature point of the feature map is used to indicate a feature and a context feature of a corresponding pixel in the slice, wherein a size of an intermediate feature map output by a target network layer of the feature extraction layer is the same as a size of the slice, and the target network layer is used to perform pixel feature extraction on the slice; A detection module, configured to determine, for each slice, a target frame based on candidate frames corresponding to each feature point in a feature map corresponding to the slice by using a detector included in the target model, and output a defect position and a defect classification result of the slice based on the target frame; Outputting defect indication information of the slice based on the feature map of the slice through the classifier of the target model; the target frame is used to indicate the defect area of the target object, and the defect indication information is used to indicate whether the local target object included in the slice has defects; The target model is obtained by training the joint difference between the joint result output by the initial model for the sample set and the true value label of the sample set; the initial model includes an initial detector and an initial classifier, and the joint result includes the sample detection position and sample detection classification output by the initial detector, and the sample indication information output by the initial classifier; The method for determining the joint difference degree includes: Determine a first difference between the sample candidate frame and the true value frame based on the sample candidate frame predicted by the initial regression branch network of the initial detector, the true value frame of the sample set, and a first loss function; Determine a second difference between the predicted category probability and the overlap ratio based on an overlap ratio between a true value box and a predicted box of the sample set, a predicted category probability predicted by an initial classification branch network of the initial detector, and a second loss function, wherein the predicted box is a defect region predicted based on the sample candidate box; Determining a third difference between the sample indication information and the true value probability based on the sample indication information predicted by the initial classifier, the true value probability of the sample set, and a third loss function; Based on the first difference, the second difference, the third difference and the supervisory signal of the initial classifier, the joint difference degree is determined by a joint loss function.
11. The target detection device according to claim 10, It is characterized in that The feature extraction layer includes a micro backbone network and an attention network; The feature extraction module comprises: A pixel feature extraction unit, used to extract pixel features from the at least two slices through the micro backbone network to obtain at least two slice feature maps, wherein any feature point of the slice feature map is used to indicate a feature of a corresponding pixel in the slice; A context feature extraction unit, configured to extract, for each slice, context features of each feature point in a slice feature map of the slice through a pooling layer of the attention network to obtain at least one context feature map of the slice, and perform feature fusion on the at least one context feature map to obtain a feature map of the slice; The number of network layers included in the micro backbone network does not exceed a first threshold, and the number of convolution kernels included in each network layer does not exceed a second threshold.
12. A computer device comprising a memory, a processor and a computer program stored in the memory, It is characterized in that The processor executes the computer program to implement the target detection method according to any one of claims 1 to 9.
13. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the target detection method according to any one of claims 1 to 9 is implemented.
14. A computer program product comprising a computer program, It is characterized in that When the computer program is executed by a processor, the target detection method according to any one of claims 1 to 9 is implemented.
Citation Information
Patent Citations
An aluminum material surface defect detection algorithm based on deep learning
CN109711474A
Lithium battery defect detection method based on yolov3 network embedded with self-attention gate module
CN111598860A
Hoisting area dynamic monitoring method based on target detection algorithm
CN111753682A
SAR image target detection method based on context information
CN112766108A
Pipeline defect detection method based on multi-scale features of convolutional neural network
CN113052834A
