Part defect detection and character recognition method and device based on segmentation network
Through a method based on segmentation network, using the parallel reverse attention PraNet network and OCR text detection algorithm, the problem of difficult identification of characters and defects on industrial parts is solved, achieving high-accuracy detection and identification, improving production efficiency and product quality.
Patent Information
- Application Number
- CN202210553478.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-20
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2042-05-20
AI Technical Summary
Existing part defect detection methods are difficult to accurately identify characters and defects on industrial parts, especially in scenarios where the character color is similar to the background color, which can easily lead to misjudgment and low accuracy.
A segmentation network-based method is used to construct a segmentation model through the PraNet network of parallel reverse attention. The Softmax activation function, AdamW optimization function and LookAhead mechanism are used, combined with the OCR text detection and recognition algorithm, to perform classification annotation and defect detection of part images.
It achieves the accurate positioning and identification of characters and defects on industrial parts, improves detection accuracy and efficiency, can replace some manual inspections, and improves production efficiency and product quality.
Smart Images

Figure CN114841981B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image recognition technology, and more specifically, to a method and device for part defect detection and character recognition based on a segmentation network. Background Art
[0002] With the development of modern industry, part defect detection technology has been widely used, especially in flaw detection, workpiece surface quality inspection, etc. However, the existing part defect detection methods mainly study the impact of the complexity of natural scenes on the detection results. They cannot solve the problem that the characters on industrial parts are almost the same color as the background, or that the characters are mixed with industrial part defects. That is, 1) when the color of the characters on the industrial parts is similar to the color of the industrial parts as a whole, it is difficult to accurately identify the characters on the industrial parts, let alone detect whether the characters have defects; 2) when defects such as scratches appear near the characters on the industrial parts, it is easy to misjudge the scratches as characters, or misjudge the characters as scratches, and the character area and the part defect area cannot be accurately identified. Take the sealing ring of an industrial component as an example (such as Figure 3 As shown, in actual industrial photos, both the characters and the background are dark green), and the color of the characters is similar to the overall color of the parts. The existing OCR algorithm has a low recognition accuracy and may even be unable to detect the character area on the industrial parts.
[0003] The traditional manual visual method can be applied to various complex scenarios, but long-term visual inspection will cause eye fatigue of the inspection employees. In addition, due to individual differences, each employee has different control over standards, which can easily lead to false detection and missed detection of defects, resulting in low detection accuracy and low detection efficiency for part defects. Summary of the invention
[0004] In order to solve the above problems, the present invention provides a method and device for part defect detection and character recognition based on a segmentation network.
[0005] The present invention provides a method for part defect detection and character recognition based on a segmentation network, which comprises:
[0006] A certain number of defective part images are obtained and the obtained part images are classified and labeled to obtain a classification and labeling training data set, wherein the classification types of the classification and labeling include: defect contour type and character contour type;
[0007] The segmentation model is constructed based on the parallel reverse attention PraNet network, in which the sigmoid activation function is improved to the Softmax activation function as the activation function of the PraNet network output. For the PraNet algorithm, the AdamW optimization function replaces the original Adam optimization function, and the LookAhead mechanism is added to the AdamW optimization function, and the original ReLU activation function is replaced by the Mish activation function;
[0008] Training the segmentation model;
[0009] The trained segmentation model is used to perform defect detection on the part image.
[0010] Among them, when classifying and annotating the obtained part images, continuous closed dot lines are used to annotate the defect contour area and the character contour area in the part image. After annotation, a corresponding annotation file with a Json extension is generated, and annotation tags are used to annotate the defect contour area and the character contour area.
[0011] Among them, when the character contour area and the defect contour area are intertwined and cannot be distinguished, the classification type is only marked as the defect contour type, and the character contour type is no longer marked.
[0012] In the process of using the trained segmentation model to perform defect detection on the part image, for the part image containing characters output by the segmentation model, an OCR text detection and recognition algorithm is used to recognize the characters in the part image.
[0013] The defect contour types include but are not limited to: scratch contour type and incomplete contour type.
[0014] The present invention provides a device for part defect detection and character recognition based on a segmentation network, which comprises:
[0015] An image acquisition and classification annotation module is used to acquire a certain number of defective part images and classify and annotate the acquired part images to obtain a classification annotation training data set, wherein the classification types of the classification annotation include: defect contour type and character contour type;
[0016] The segmentation model construction module is used to build a segmentation model based on the PraNet network with parallel reverse attention. The sigmoid activation function is improved to the Softmax activation function as the activation function at the output of the PraNet network. For the PraNet algorithm, the AdamW optimization function replaces the original Adam optimization function, and the LookAhead mechanism is added to the AdamW optimization function, and the Mish activation function replaces the original ReLU activation function.
[0017] A model training module, used for training the segmentation model;
[0018] The detection module is used to perform defect detection on the part image using the trained segmentation model.
[0019] Among them, when the image acquisition and classification annotation module classifies and annotates the obtained part image, it uses continuous closed dot lines to annotate the defect contour area and the character contour area in the part image, and generates a corresponding annotation file with a Json extension after annotation, and uses annotation tags to annotate the defect contour area and the character contour area.
[0020] Among them, when the character contour area and the defect contour area are intertwined and cannot be distinguished, the classification type is only marked as the defect contour type, and the character contour type is no longer marked.
[0021] In the process of using the trained segmentation model to perform defect detection on the part image, the detection module uses an OCR text detection and recognition algorithm to identify the characters in the part image containing characters output by the segmentation model.
[0022] The defect profile types include but are not limited to scratch profile types and incomplete profile types.
[0023] Compared with the prior art, the present invention has the following beneficial effects:
[0024] The method and device provided by the present invention can accurately locate defects and the exact position of characters on industrial parts that are difficult to detect (when the background color and the character color are almost the same), and are not affected by the defects. They can also effectively identify characters that cannot be recognized by existing OCR methods, and can replace the work of some workers, thereby improving production efficiency and product quality control. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 It is a flow chart of a method for part defect detection and character recognition based on a segmentation network provided by the present invention;
[0026] Figure 2 It is a structural schematic diagram of the segmentation model provided by the present invention;
[0027] Figure 3 It is an industrial photo of the sealing ring of industrial parts;
[0028] Figure 4 It is a schematic diagram of parts marking provided by the present invention;
[0029] Figure 5 It is a defect contour area map after the part segmentation provided by the present invention;
[0030] Figure 6 Character outline area diagram after part segmentation provided by the present invention;
[0031] Figure 7 It is a schematic block diagram of a part defect detection and character recognition device based on a segmentation network provided by the present invention. DETAILED DESCRIPTION
[0032] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0033] like Figure 1 As shown, the first embodiment of the present invention provides a method for part defect detection and character recognition based on a segmentation network, which includes:
[0034] S1: Obtain a certain number of defective part images and classify and annotate the obtained part images. Use the labelimg annotation tool for annotation. The generated annotation format is selected as the VOC format. The classification annotation here is to draw a contour line along the outline of characters, scratches and defects with dotted lines. Different contour lines correspond to different classification labels. Taking the industrial parts seal as an example, the part annotation diagram is as follows Figure 3 As shown; then a classification and annotation training data set is obtained, and the classification types of the classification and annotation include: defect contour type and character contour type, and the defect contour type includes but is not limited to: scratch contour type and incomplete contour type. The characters can be numbers, letters, symbols, etc., and the character contour is the outline of the specific shape of the characters such as numbers, letters and symbols. The scratches can be lines or grooves formed on the surface of the part that should not exist; the scratch contour is the outline of the specific shape of the scratch. The incompleteness refers to the incompleteness of the part itself, such as the presence of holes in the sealing ring in the sealing ring image; the defect contour is the outline of the specific shape of the defect.
[0035] Among them: when classifying and annotating the obtained part image, the defect contour area and the character contour area are annotated with continuous closed dot lines in the part image, and the corresponding annotation file with the extension Json is generated after annotation, and the defect contour area and the character contour area are annotated with annotation labels. For example, in the Json annotation file, "label" can be used as the contour classification label to record the classification type: defect contour and character contour; "point" is used to record the coordinate point of the annotated contour, that is, the defect contour area and the character contour area are recorded with the coordinate point.
[0036] Among them: when the character contour area and the defect contour area are intertwined and cannot be distinguished, the classification type is only marked as the defect contour type, and the character contour type is no longer marked.
[0037] S2: A segmentation model is constructed based on the PraNet network with parallel reverse attention, in which the sigmoid activation function is improved to the Softmax activation function, that is, the Softmax activation function is used as the activation function at the output of the PraNet network. For the PraNet algorithm, the AdamW optimization function is used to replace the original Adam optimization function, and the LookAhead mechanism is added to the AdamW optimization function, and the original ReLU activation function is replaced by the Mish activation function.
[0038] The Softmax activation function can be used to perform multiple classifications, and when applied in the technical solution of the invention, it can realize the identification of multiple defect types.
[0039] S3: Training the segmentation model.
[0040] In the process of training algorithm models, the activation function is usually used in the combination of momentum optimization function + learning rate adjustment strategy. However, this method is more likely to fall into the local optimal solution of momentum, resulting in poor algorithm effect.
[0041] Usually, optimization algorithms such as Adam and AdaGrad improve the algorithm by adding adaptive momentum to make the model converge, which is ultimately equivalent to optimizing on a gradient descent route. The LookAhead mechanism added to the algorithm of the segmentation model of the present invention will continue to record the momentum results of several cycles, which is set to 7 cycles here. If it is found that the momentum falls into a local optimal solution, momentum replacement can be performed. LookAhead is different from Adam, AdaGrad, etc. The LookAhead mechanism will maintain two sets of momentum weights and interpolate between the two, which is equivalent to optimizing on two gradient descent routes. It allows the weight of one route to drop faster, while the weight of the slower route can be left behind, which can cross the local minimum point of the gradient, bringing better long-term stability, thereby obtaining a better gradient descent direction, and then obtaining a better algorithm model effect, which can improve the algorithm effect.
[0042] Wherein: in the process of training the segmentation model, firstly, 80% of the samples in the training data set are randomly selected for training, 10% of the samples are randomly selected for verification, and the remaining samples are used for testing; then the training is performed as described below.
[0043] The part images with classification annotations in the training data set and the annotation files corresponding to each part image are simultaneously input into the segmentation model. The function of the part images and the annotation files is to divide the pixels on the image into multiple closed pixel areas according to the position coordinates of the annotation files. The pixels in each area correspond to the classification type identified by the label in the annotation file. In this way, all pixels on the part image can be divided into: background pixels, character outline pixels, and defect outline pixels.
[0044] After inputting the image and annotation file into the neural network, the image features and structural features of different regions can be extracted, which is described in detail below.
[0045] The input data first enters the Res2Net network structure known in the art, which is hierarchical. Figure 2 The dotted box in the figure shows the 5-layer structure of the Res2Net network, where the layers f1 to f5 are getting deeper and deeper. Based on the multi-scale backbone network structure, the Res2Net network extracts five levels of features {f i , i=1,2,3,4,5}, the resolution is [h / 2 i-1 , w / 2 i-1 ]. The underlying features of an image refer to: contours, edges, colors, textures, and shape features. Edges and contours can reflect the content of an image; if edges and key points can be reliably extracted, many visual problems can be solved. The low-level features of an image have relatively little semantic information, but their target positions are accurate. The high-level semantic features of an image refer to things that people can see. For example, if low-level features are extracted from a face, the contour, nose, eyes, and the like of the face are extracted, and then the extracted high-level features appear as a face. The semantic information of high-level features is relatively rich, but the target position is relatively rough. The deeper the features, the stronger the high-level semantics and the stronger the resolution. Based on this principle, f i Features are divided into low-level features {f i ,i=1,2} and high-level features {f i , i=3,4,5}. The high-level features are aggregated using the partial decoder module Pd(·), where the partial decoder features are composed of PD=P d (f3,f4,f5) to calculate and generate the global mapping graph S g , where P d (·) indicates a multi-level feature aggregation algorithm. The reason is that, as shown in the attached Figure 2 As shown in , S3-S5 are all small images. When aggregating, we need to generate an image as large as the original one. We need to perform image mapping before this to generate a global mapping image S g The aggregation process of the multi-level feature aggregation algorithm is as follows: Because the sizes of S3-S5 are different, through the convolution layer {fi ,i=3,4,5} features are upsampled and combined with BasicConv2d function and relu activation function to enlarge the size of S3 to S5 to be consistent with Sg, and then torch.cat() is used for splicing and aggregation. The aggregation process using torch.cat() can be completed using existing technology.
[0046] In mathematical optimization and decision theory, a loss function or cost function (sometimes also called an error function) is a function that maps the value of an event or one or more variables to a real number that intuitively represents some "cost" associated with the event. Optimization problems aim to minimize the loss function. In statistics, loss functions are often used for parameter estimation, and the event in question is some function of the difference between the estimated value and the true value of a data instance. Here we use a mixing function L.
[0047] Mixed loss function Where ω is the weight constant, represents the weighted intersection-over-union (IoU) loss based on global constraints and local (pixel-level) constraints, represents the binary cross entropy (BCE) loss, for {f i , i=3,4,5} as the three input items, the corresponding outputs S3, S4, S5 and the global map Sg are supervised learning, where input f3 corresponds to output S3, input f4 corresponds to output S4, and input f5 corresponds to output S5. The maps are upsampled one by one (e.g. ) to the same size as the true value graph G, the overall loss is expressed as:
[0048]
[0049] Where G represents the real part image feature, Represents the final prediction output of the part image; It means that when {f i , i=3,4,5}, the corresponding prediction output of each layer; Represents the input part image and predicted output The loss function result of ; Represents the input part image and predicted output The loss function result.
[0050] When the overall loss L is reached during training total The convergence state is reached and the training of the segmentation model is completed. The overall loss L total The convergence state is shown as L on the test set. totalIf the value no longer decreases, the training is considered complete, and the segmentation model learns the contour edge features of the contour areas of different categories marked, and then distinguishes the defect contour area and the character contour area to be detected. Figure 3 Taking the seal ring of an industrial component as an example, the segmentation model obtained after training can segment the defect contour area on the industrial part (such as Figure 5 as shown) and the character outline area (as Figure 6 As shown in Figure 2, the defective areas of industrial parts can be better detected and distinguished.
[0051] S4: Use the trained segmentation model to perform defect detection on the part image.
[0052] Wherein: in the process of using the trained segmentation model to perform defect detection on the part image, for the part image containing characters output by the segmentation model, an OCR text detection and recognition algorithm is used to recognize the characters in the part image.
[0053] In the segmentation network-based part defect detection and character recognition method provided in this embodiment, only about 200 part images need to be labeled in the classification and labeling training data set to achieve ideal defect recognition and character recognition effects.
[0054] After inputting the image and annotation file into the neural network, the image features and structural features of different regions can be extracted. The features output by the neural network are classified by the softmax activation function, and finally the classification results of each pixel are obtained, and finally the regional classification results are obtained. Usually in the process of OCR recognition, it is necessary to identify the character area, but in the industrial parts image scene, the character area is difficult to distinguish. This solution masks the character area to make the character outline features very obvious, so that the OCR recognition task can be better performed, and even if a general OCR algorithm model is used, good results can be obtained.
[0055] like Figure 7 As shown, the second embodiment of the present invention provides a part defect detection device based on a segmentation network, which includes:
[0056] An image acquisition and classification annotation module is used to acquire a certain number of defective part images and classify and annotate the acquired part images to obtain a classification annotation training data set, wherein the classification types of the classification annotation include: defect contour type and character contour type;
[0057] The segmentation model construction module is used to build a segmentation model based on the PraNet network with parallel reverse attention. The sigmoid activation function is improved to the Softmax activation function as the activation function at the output of the PraNet network. For the PraNet algorithm, the AdamW optimization function replaces the original Adam optimization function, and the LookAhead mechanism is added to the AdamW optimization function, and the Mish activation function replaces the original ReLU activation function.
[0058] A model training module, used for training the segmentation model;
[0059] The detection module is used to perform defect detection on the part image using the trained segmentation model.
[0060] Among them, when the image acquisition and classification annotation module classifies and annotates the obtained part image, it uses continuous closed dot lines to annotate the defect contour area and the character contour area in the part image, and generates a corresponding annotation file with a Json extension after annotation, and uses annotation tags to annotate the defect contour area and the character contour area.
[0061] Among them, when the character contour area and the defect contour area are intertwined and cannot be distinguished, the classification type is only marked as the defect contour type, and the character contour type is no longer marked.
[0062] In the process of using the trained segmentation model to perform defect detection on the part image, the detection module uses an OCR text detection and recognition algorithm to identify the characters in the part image containing characters output by the segmentation model.
[0063] The defect profile types include but are not limited to scratch profile types and incomplete profile types.
[0064] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the part defect detection device described in the above-mentioned second embodiment can refer to the corresponding process in the above-mentioned first embodiment. The examples and related descriptions listed in the above-mentioned first embodiment and the corresponding preferred embodiments are also applicable to explaining the working process of the part defect detection device described in the second embodiment, and will not be repeated here.
[0065] The segmentation network-based part defect detection and character recognition method and device provided by the present invention can accurately locate the character position for industrial part characters that are difficult to detect (when the background color and the character color are almost the same) and is not affected by defects. It can replace the work of some workers and improve production efficiency and product quality control.
[0066] Using the existing technology, if an OCR algorithm model is used for annotation and training for special scenes (such as stainless steel, sealing rings, etc., where the text area is similar to the background area in color), a large amount of data sets are required, which consumes a huge amount of annotation and training costs. The present invention can achieve good recognition results by annotating hundreds or even dozens of segmented images, and does not require special processing or retraining of the OCR algorithm, so the implementation cost is relatively low.
[0067] The above content is a further detailed description of the present invention in combination with specific implementation methods. It cannot be determined that the specific implementation of the present invention is limited to these descriptions. For ordinary technicians in the technical field to which the present invention belongs, some simple deductions or substitutions can be made without departing from the concept of the present invention, which should be regarded as belonging to the scope of protection determined by the claims submitted for the present invention.
Claims
1. A method for part defect detection and character recognition based on a segmentation network, characterized in that: include: A certain number of defective part images are obtained and the obtained part images are classified and labeled to obtain a classification and labeling training data set, wherein the classification types of the classification and labeling include: defect contour type and character contour type; The segmentation model is constructed based on the parallel reverse attention Pra Net network, in which the sigmoid activation function is improved to the Softmax activation function as the activation function of the PraNet network output. For the PraNet algorithm, the AdamW optimization function replaces the original Adam optimization function, and the LookAhead mechanism is added to the AdamW optimization function, and the original ReLU activation function is replaced by the Mish activation function; Training the segmentation model; The part images with classification annotations in the training data set and the annotation files corresponding to each part image are simultaneously input into the segmentation model. The function of the part images and the annotation files is to divide the pixels on the image into multiple closed pixel areas according to the position coordinates of the annotation files. The pixel points of each area correspond to the classification type identified by the label in the annotation file. Mixed loss function Where ω is the weight constant, represents the weighted intersection-over-union (IoU) loss based on global and local constraints. represents the binary cross entropy BCE loss, for {f i , i=3,4,5} as the three input items, the corresponding outputs S3, S4, S5 and the global mapping map Sg are respectively obtained for supervised learning, where input f3 corresponds to output S3, input f4 corresponds to output S4, and input f5 corresponds to output S5. The mapping maps are upsampled one by one to the same size as the true value map G. After inputting the image and annotation file into the neural network, the image features and structural features of different regions can be extracted. i Features are divided into low-level features {f i ,i=1,2} and high-level features {f i , i=3,4,5}; using partial decoder module P d (·) Aggregate high-level features, partial decoder features are given by PD = P d (f3,f4,f5) to calculate, thereby generating a global mapping graph S, where P d (·) indicates a multi-level feature aggregation algorithm; The trained segmentation model is used to perform defect detection on the part image.
2. The method for part defect detection and character recognition based on segmentation network according to claim 1, characterized in that: When classifying and labeling the obtained part images, continuous closed dot lines are used to label the defect contour areas and character contour areas in the part images. After labeling, a corresponding labeling file with a Json extension is generated, and the defect contour areas and character contour areas are annotated with labeling tags.
3. The method for part defect detection and character recognition based on segmentation network according to claim 2 is characterized in that: When the character contour area and the defect contour area are intertwined and cannot be distinguished, the classification type is marked only as the defect contour type, and the character contour type is no longer marked.
4. The method for part defect detection and character recognition based on segmentation network according to claim 1, characterized in that: In the process of using the trained segmentation model to perform defect detection on the part image, for the part image containing characters output by the segmentation model, an OCR text detection and recognition algorithm is used to recognize the characters in the part image.
5. The method for part defect detection and character recognition based on segmentation network according to claim 1, characterized in that: The defect profile types include but are not limited to scratch profile types and incomplete profile types.
6. A device for part defect detection and character recognition based on a segmentation network, characterized in that: include: An image acquisition and classification annotation module is used to acquire a certain number of defective part images and classify and annotate the acquired part images to obtain a classification annotation training data set, wherein the classification types of the classification annotation include: defect contour type and character contour type; The segmentation model construction module is used to build a segmentation model based on the PraNet network with parallel reverse attention. The sigmoid activation function is improved to the Softmax activation function as the activation function at the output of the PraNet network. For the PraNet algorithm, the AdamW optimization function replaces the original Adam optimization function, and the LookAhead mechanism is added to the AdamW optimization function, and the Mish activation function replaces the original ReLU activation function. A model training module, used for training the segmentation model; The part images with classification annotations in the training data set and the annotation files corresponding to each part image are simultaneously input into the segmentation model. The function of the part images and the annotation files is to divide the pixels on the image into multiple closed pixel areas according to the position coordinates of the annotation files. The pixel points of each area correspond to the classification type identified by the label in the annotation file. Mixed loss function Where ω is the weight constant, represents the weighted intersection-over-union (IoU) loss based on global and local constraints. represents the binary cross entropy BCE loss, for {f i , i=3,4,5} as the three input items, the corresponding outputs S3, S4, S5 and the global mapping map Sg are respectively obtained for supervised learning, where input f3 corresponds to output S3, input f4 corresponds to output S4, and input f5 corresponds to output S5. The mapping maps are upsampled one by one to the same size as the true value map G. After inputting the image and annotation file into the neural network, the image features and structural features of different regions can be extracted. i Features are divided into low-level features {f i ,i=1,2} and high-level features {f i , i=3,4,5}; using partial decoder module P d (·) Aggregate high-level features, partial decoder features are given by PD = P d (f3,f4,f5) to calculate, thereby generating a global mapping graph S, where P d (·) indicates a multi-level feature aggregation algorithm; The detection module is used to perform defect detection on the part image using the trained segmentation model.
7. The device for part defect detection and character recognition based on segmentation network according to claim 6, characterized in that: When the image acquisition and classification annotation module classifies and annotates the acquired part image, it uses continuous closed dot lines to annotate the defect contour area and the character contour area in the part image, and after annotation, generates a corresponding annotation file with a Json extension, and uses annotation tags to annotate the defect contour area and the character contour area.
8. The device for part defect detection and character recognition based on segmentation network according to claim 7, characterized in that: When the character contour area and the defect contour area are intertwined and cannot be distinguished, the classification type is marked only as the defect contour type, and the character contour type is no longer marked.
9. The device for part defect detection and character recognition based on segmentation network according to claim 6, characterized in that: In the process of using the trained segmentation model to perform defect detection on the part image, the detection module uses an OCR text detection and recognition algorithm to identify the characters in the part image output by the segmentation model containing characters.
10. The device for part defect detection and character recognition based on segmentation network according to claim 6, characterized in that: The defect profile types include but are not limited to scratch profile types and incomplete profile types.
