Methods, devices, and printing systems for detecting printing defects
By using an autoencoder model and contrastive learning methods, the inherent structure and features of printed characters are automatically learned. The cosine distance of the feature vectors is used to determine printing defects, which solves the problem of time-consuming and labor-intensive printing defect detection in existing technologies and achieves efficient detection of defects in different types and styles of printed characters.
Patent Information
- Application Number
- CN202311253997.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-26
- Publication Date
- 2025-12-02
- Estimated Expiration
- 2043-09-26
AI Technical Summary
Existing printing defect detection methods are time-consuming and labor-intensive, and are difficult to adapt to the detection of defects in different types and styles of printed characters.
An autoencoder model is used for iterative training, and an optimized encoder is built through a contrastive learning method. The cosine distance of the feature vectors is used to judge printing defects, reducing the reliance on manual feature engineering.
It enables automatic learning of data structures and feature representations on unlabeled printed character images, effectively distinguishing character defects and adapting to the detection of printed character defects of different types, styles and sizes.
Smart Images

Figure CN117314856B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of printing technology, and more specifically, to a method, apparatus, computer-readable storage medium, and printing system for detecting printing defects. Background Technology
[0002] In the printing process, character defects can lead to errors in information delivery, reduced readability, or quality problems. Therefore, automated methods for detecting character defects in printed materials are crucial for ensuring print quality.
[0003] Traditional character defect detection methods are typically based on rules or manually designed feature engineering. These methods rely on expert knowledge and large amounts of manually annotated data. However, the process of manually designing features or rules is time-consuming and dependent on specific tasks and application scenarios, making it difficult to adapt to the detection of different types and styles of printed character defects.
[0004] To address these issues, an unsupervised learning method is employed to automatically learn the inherent structure and patterns of the data. Based on the defects of printed character labels, datasets of positive samples, simple negative samples, and difficult negative samples are constructed to train a contrastive learning model, enabling the model to distinguish defects in printed characters. Summary of the Invention
[0005] The main objective of this application is to provide a method, apparatus, computer-readable storage medium, and printing system for detecting printing defects, so as to at least solve the problem that the existing methods for detecting printing defects are time-consuming and labor-intensive.
[0006] To achieve the above objectives, according to one aspect of this application, a method for detecting printing defects is provided, comprising: establishing an autoencoder model, the autoencoder model including an encoder and a decoder, the encoder being used to convert a character image into a feature vector, and the decoder being used to convert the feature vector into the character image; iteratively training the autoencoder model using multiple character images until the loss function value of the autoencoder model in the current iteration is less than the loss function value of the autoencoder model in the previous iteration is less than a first predetermined threshold, and determining the encoder of the autoencoder model in the current iteration as a first-order optimized encoder; performing comparative learning on the first-order optimized encoder to obtain a second-order optimized encoder, such that the feature vector output by the second-order optimized encoder contains information about printing defects in the character image; inputting a test image and a template image into the second-order optimized encoder respectively to obtain a first feature vector and a second feature vector, the test image being a printed image of the template image; and determining that the test image has printing defects when the cosine distance between the first feature vector and the second feature vector is less than a second predetermined threshold.
[0007] Optionally, the autoencoder model is iteratively trained using multiple character images until the loss function value of the autoencoder model in the current iteration is less than a first predetermined threshold compared to the loss function value of the autoencoder model in the previous iteration. The encoder of the autoencoder model in the current iteration is then determined as the first-order optimized encoder. This includes: a first adjustment step, adjusting the parameters of the autoencoder model to obtain an updated autoencoder model; an input step, inputting multiple character images into the updated autoencoder model to obtain multiple printed character images; a calculation step, calculating the mean square error between the pixel data corresponding to the multiple printed character images and the corresponding pixel data of the multiple character images to obtain the loss function value of the autoencoder model, thus completing one iteration; repeating the first adjustment step, the input step, and the calculation step at least once until the difference between the loss function value of the current iteration and the loss function value of the previous iteration is less than the first predetermined threshold, thus obtaining the first-order optimized encoder, which is the encoder in the current autoencoder model.
[0008] Optionally, the primary optimized encoder is subjected to comparative learning to obtain a secondary optimized encoder, including: establishing a comparative learning model based on the primary optimized encoder, wherein the output of the comparative learning model is a printing defect difference degree, which is used to characterize the difference caused by printing defects before and after printing of multiple character images; a second adjustment step, adjusting the parameters of the optimized encoder in the comparative learning model to obtain an updated comparative learning model; an output step, using a comparative sample set as input to the updated comparative learning model to obtain the printing defect difference degree, completing one iteration, wherein the comparative learning model is used to determine that the comparative sample set includes multiple first character images and corresponding second character images, wherein the first character images are the character images used as printing templates, and the second character images are the character images obtained by printing the first character images; repeating the adjustment step and the output step at least once until the difference between the printing defect difference degree of the current iteration and the printing defect difference degree of the previous iteration is less than a third predetermined threshold, thereby obtaining the secondary optimized encoder, which is the encoder in the current comparative learning model.
[0009] Optionally, the comparison sample set includes positive samples, simple negative samples, and difficult negative samples. The character position of the second character image x' in the positive sample differs from the character position of the first character image x in the positive sample. The character content of the second character image x” in the simple negative sample differs from the character content of the first character image x in the simple negative sample. The character shape of the second character image x”' in the difficult negative sample differs from the character shape of the first character image x in the difficult negative sample. The comparison sample set is used as input to the updated comparison learning model to obtain the printing defect difference degree, including: obtaining the objective function of the updated comparison learning model to obtain the printing defect difference degree function, wherein the printing defect difference degree function is... Where, N p N is the number of positive samples. n N is the number of simple negative samples. h Let a1 be the number of the difficult negative samples, a2 be the weight of the positive samples, a3 be the weight of the simple negative samples, and a3 be the weight of the difficult negative samples, where a3 > a1; substitute the comparison sample set into the printing defect difference function to obtain the printing defect difference.
[0010] Optionally, before determining that the image to be tested has a printing defect when the cosine distance between the first feature vector and the second feature vector is less than a second predetermined threshold, the method further includes: inputting the comparison sample set into the secondary optimization encoder to obtain multiple feature vector pairs, each feature vector pair including a first feature vector and a second feature vector, a positive sample corresponding to a feature vector pair, a simple negative sample corresponding to a feature vector pair, and a difficult negative sample corresponding to a feature vector pair; calculating the cosine distance of each feature vector pair to obtain multiple cosine distances; a determination step, whereby, if the cosine distance is greater than or equal to the second predetermined threshold, the sample corresponding to the cosine distance is determined as a predicted positive sample, and if the cosine distance is less than the second predetermined threshold, the sample corresponding to the cosine distance is determined as a predicted negative sample; a calculation step, whereby an evaluation score of the second predetermined threshold is calculated, the evaluation score being used to characterize the judgment accuracy of the predicted positive sample and the predicted negative sample; repeating the determination step and the calculation step at least once to obtain multiple evaluation scores of the second predetermined threshold; and determining the second predetermined threshold corresponding to the largest evaluation score as the second predetermined threshold.
[0011] Optionally, calculating the evaluation score for the second predetermined threshold includes: calculating the ratio of a first quantity to a second quantity to obtain a first proportion; calculating the ratio of the first quantity to a third quantity to obtain a second proportion, where the first quantity is the number of predicted positive samples of the positive samples, the second quantity is the number of predicted positive samples, and the third quantity is the number of positive samples; calculating the product of the first proportion and the second proportion to obtain a predetermined product; calculating the sum of the first proportion and the second proportion to obtain a predetermined sum; and calculating twice the ratio of the predetermined product to the predetermined sum to obtain the evaluation score.
[0012] Optionally, before determining that the image under test has a printing defect when the cosine distance between the first feature vector and the second feature vector is less than a second predetermined threshold, the method further includes: substituting the first feature vector and the second feature vector into the cosine distance formula to obtain the cosine distance, wherein the cosine distance formula is d = dot(a,b) / (norm(a)*norm(b)), where dot(a,b) is the dot product of the first feature vector and the second feature vector, norm(a) is the L2 norm of the first feature vector, and norm(b) is the L2 norm of the second feature vector.
[0013] According to another aspect of this application, a printing defect detection apparatus is provided, comprising: an establishment unit for establishing an autoencoder model, the autoencoder model including an encoder and a decoder, the encoder being used to convert a character image into a feature vector, and the decoder being used to convert the feature vector into the character image; a training unit for iteratively training the autoencoder model using multiple character images until the loss function value of the autoencoder model in the current iteration is less than the loss function value of the autoencoder model in the previous iteration is less than a first predetermined threshold, and determining the encoder of the autoencoder model in the current iteration as a first-order optimized encoder; an optimization unit for comparative learning of the first-order optimized encoder to obtain a second-order optimized encoder, such that the feature vector output by the second-order optimized encoder contains information about printing defects in the character image; an extraction unit for inputting a test image and a template image into the second-order optimized encoder respectively to obtain a first feature vector and a second feature vector, the test image being a printed image of the template image; and a first determination unit for determining that the test image has printing defects when the cosine distance between the first feature vector and the second feature vector is less than a second predetermined threshold.
[0014] According to another aspect of this application, a computer-readable storage medium is provided, the computer-readable storage medium including a stored program, wherein, when the program is executed, it controls the device on which the computer-readable storage medium is located to perform any of the methods described.
[0015] According to another aspect of this application, a printing system is provided, comprising: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs including methods for performing any one of the methods described.
[0016] By applying the technical solution of this application, an autoencoder model structure is trained on a large number of unlabeled printed character images to obtain a first-order optimized encoder. This encoder learns the inherent structure and feature representation of the data, enabling the model to express the structure and features of characters, i.e., feature vectors, without relying on manually designed feature engineering. The model is trained by comparing sample sets and uses contrastive learning to effectively distinguish character defects, resulting in a second-order optimized encoder. The feature vectors of the test image and the template image are then extracted based on the second-order optimized encoder, i.e., the first feature vector and the second feature vector. The cosine distance between the first feature vector and the second feature vector determines whether there are printing defects in the test image, thus solving the problem of time-consuming and labor-intensive printing defect detection methods. Attached Figure Description
[0017] Figure 1 A hardware structure block diagram of a mobile terminal for performing a method for detecting printing defects according to an embodiment of this application is shown.
[0018] Figure 2 A schematic flowchart of a method for detecting printing defects according to an embodiment of this application is shown;
[0019] Figure 3 A schematic diagram of a sample distribution provided according to an embodiment of this application is shown;
[0020] Figure 4 A flowchart illustrating the defect detection process after training is completed, according to an embodiment of this application, is shown.
[0021] Figure 5 A schematic flowchart of another method for detecting printing defects according to an embodiment of this application is shown;
[0022] Figure 6 A structural block diagram of a printing defect detection device provided according to an embodiment of this application is shown.
[0023] The above figures include the following reference numerals:
[0024] 102. Processor; 104. Memory; 106. Transmission device; 108. Input / output device. Detailed Implementation
[0025] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.
[0026] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0027] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this application described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0028] As described in the background section, existing methods for detecting printing defects are time-consuming and labor-intensive. To address this problem, embodiments of this application provide a method, apparatus, computer-readable storage medium, and printing system for detecting printing defects.
[0029] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.
[0030] The methods and embodiments provided in this application can be executed on a mobile terminal, computer terminal, or similar computing device. Taking running on a mobile terminal as an example, Figure 1 This is a hardware structure block diagram of a mobile terminal for a printing defect detection method according to an embodiment of the present invention. Figure 1 As shown, a mobile terminal may include one or more ( Figure 1Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing data are also shown. The mobile terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the mobile terminal described above. For example, the mobile terminal may also include components that are more... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0031] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the device information display method in this embodiment of the invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, thereby implementing the above-described method. The memory 104 may include high-speed random access memory and non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the mobile terminal via a network. Examples of the aforementioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. The transmission device 106 is used to receive or send data via a network. Specific examples of the aforementioned networks may include wireless networks provided by the mobile terminal's communication provider. In one example, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to communicate with the Internet. In one example, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0032] This embodiment provides a method for detecting printing defects that runs on a mobile terminal, computer terminal, or similar computing device. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Also, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0033] Figure 2 This is a flowchart of a printing defect detection method according to an embodiment of this application. Figure 2 As shown, the method includes the following steps:
[0034] Step S201: Establish an autoencoder model, which includes an encoder and a decoder. The encoder is used to convert a character image into a feature vector, and the decoder is used to convert the feature vector into a character image.
[0035] Specifically, using deep learning frameworks such as TensorFlow or PyTorch, a fully convolutional network autoencoder model is constructed, enabling the autoencoder model to adapt to images of arbitrary sizes. The autoencoder model consists of two parts: an encoder and a decoder. The encoder converts the input image into feature vectors, such as latent feature vectors, and the decoder restores the latent feature vectors back to the image. After inputting the image, certain translation, rotation, and scaling image processing is applied, allowing the encoder to extract translation, rotation, and scaling invariant features of the printed characters.
[0036] Step S202: The autoencoder model is iteratively trained using multiple character images until the loss function value of the autoencoder model in the current iteration is less than the loss function value of the autoencoder model in the previous iteration, and the encoder of the autoencoder model in the current iteration is determined as an optimized encoder.
[0037] Specifically, printed character image samples are used as training data to optimize the parameters of the autoencoder model in order to minimize the reconstruction error, i.e., the loss function value of the autoencoder model. If the loss function value of the autoencoder model in this iteration is less than the loss function value of the autoencoder model in the previous iteration, the reconstruction error is considered to have reached its minimum, thereby improving the autoencoder model's ability to represent and reconstruct the input data and learn the latent features of the character image. At this time, the encoder of the autoencoder model is the first-order optimized encoder.
[0038] Step S203: Compare and learn the first-order optimized encoder to obtain the second-order optimized encoder, so that the feature vector output by the second-order optimized encoder contains information about the printing defects of the character image.
[0039] Specifically, the first-order optimized encoder is compared and learned to obtain the second-order optimized encoder. The feature vector output by the second-order optimized encoder contains information about the printing defects of the character image, so as to effectively distinguish the character defects.
[0040] Step S204: Input the image to be tested and the template image into the above-mentioned secondary optimization encoder to obtain the first feature vector and the second feature vector. The image to be tested is the printed image of the template image.
[0041] Specifically, the image to be tested is the character image of the printing defect to be detected. By inputting it and the corresponding template image into the above-mentioned secondary optimization encoder, the first feature vector and the second feature vector corresponding to the two images can be obtained, so that the first feature vector carries information about the printing defects that may exist in the image to be tested.
[0042] Step S205: If the cosine distance between the first feature vector and the second feature vector is less than a second predetermined threshold, it is determined that the image to be tested has a printing defect.
[0043] Specifically, if the first feature vector carries information about printing defects in the image under test, the difference between the first feature vector and the second feature vector will be large, and the cosine distance between them will be small, satisfying the condition of being less than the second predetermined threshold, then it can be determined that the image under test has printing defects.
[0044] In the above-mentioned method for detecting printing defects, firstly, an autoencoder model is established, which includes an encoder and a decoder. The encoder is used to convert a character image into a feature vector, and the decoder is used to convert the feature vector back into a character image. Then, the autoencoder model is iteratively trained using multiple character images until the loss function value of the autoencoder model in the current iteration is less than the loss function value of the autoencoder model in the previous iteration, which is then determined as a first-order optimized encoder. Next, the first-order optimized encoder is compared and learned to obtain a second-order optimized encoder, such that the feature vector output by the second-order optimized encoder contains information about the printing defects in the character image. Then, the image to be tested and the template image are respectively input into the second-order optimized encoder to obtain a first feature vector and a second feature vector, where the image to be tested is the printed image of the template image. Finally, if the cosine distance between the first feature vector and the second feature vector is less than a second predetermined threshold, it is determined that the image to be tested has a printing defect. By employing an autoencoder model structure and training it on a large number of unlabeled printed character images, a first-order optimized encoder is obtained. This encoder learns the inherent structure and feature representation of the data, enabling the model to express the structure and features of characters, i.e., feature vectors, without relying on manually designed feature engineering. The model is trained by comparing sample sets and uses contrastive learning to effectively distinguish character defects, resulting in a second-order optimized encoder. The second-order optimized encoder then extracts feature vectors from the test image and the template image, i.e., the first feature vector and the second feature vector. The cosine distance between the first and second feature vectors determines whether the test image has printing defects, thus solving the problem of time-consuming and labor-intensive printing defect detection methods. This method has broad adaptability and can be adapted to printing character defect detection tasks of different types, styles, and sizes.
[0045] To reduce reconstruction errors, in one optional implementation, step S202 includes:
[0046] Step S2021, the first adjustment step, adjusts the parameters of the above autoencoder model to obtain the updated autoencoder model;
[0047] Step S2022, Input step, input multiple of the above character images into the updated autoencoder model to obtain multiple printed character images;
[0048] Step S2023, calculation step: calculate the mean square error between the pixel data corresponding to the multiple printed character images and the corresponding pixel data of the multiple printed character images, obtain the loss function value of the autoencoder model, and complete one iteration;
[0049] Step S2024: Repeat the first adjustment step, the input step, and the calculation step at least once until the difference between the loss function value of the current iteration and the loss function value of the previous iteration is less than the first predetermined threshold, and obtain the first optimized encoder. The first optimized encoder is the encoder in the current autoencoder model.
[0050] In the above embodiments, a large number of printed character images are used for training. The parameters of the autoencoder model are optimized once by calculating the mean square error between the pixel data corresponding to multiple printed character images and the corresponding pixel data of multiple printed character images, which is the loss function value of the autoencoder model. This process continues until the difference between the loss function value of the current iteration and the loss function value of the previous iteration is less than the first predetermined threshold. The reconstruction error is then considered to have reached its minimum, and the optimized encoder is obtained. This improves the autoencoder model's ability to represent and reconstruct input image data and learns the latent features of character images.
[0051] The instruction manual specifies that the Mean Squared Error (MSE) is used as the loss function for the autoencoder model, and its calculation formula is as follows: MSE=1 / n*Σ(xx′) 2 In this equation, n represents the number of samples, x represents the original input character image data, and x' represents the output character image data reconstructed by the autoencoder model. MSE is the average of the sum of squared reconstruction errors for each sample in each dimension. It measures the degree of difference between the reconstructed output of the autoencoder model and the original input; a smaller value indicates better performance of the autoencoder model in the reconstruction process.
[0052] In order to effectively distinguish character defects, in one optional implementation, step S203 above includes:
[0053] Step S2031: Establish a contrastive learning model based on the above-mentioned first-order optimized encoder. The output of the contrastive learning model is the printing defect difference degree, which is used to characterize the difference caused by printing defects before and after printing of multiple character images.
[0054] Step S2032, the second adjustment step, adjusts the parameters of the optimized encoder in the contrastive learning model to obtain the updated contrastive learning model;
[0055] Step S2033, Output step, using the comparison sample set as input to the updated comparison learning model, obtain the printing defect difference degree, and complete one iteration. The comparison learning model is used to determine that the comparison sample set includes multiple first character images and corresponding second character images. The first character image is the character image used as a printing template, and the second character image is the character image obtained by printing the first character image.
[0056] Step S2034: Repeat the above adjustment step and the above output step at least once until the difference between the printing defect difference degree of the current iteration and the printing defect difference degree of the previous iteration is less than the third predetermined threshold, and obtain the above-mentioned secondary optimized encoder. The above-mentioned secondary optimized encoder is the encoder in the current above-mentioned contrastive learning model.
[0057] In the above implementation, a contrastive learning network model is constructed using a primary optimized encoder as the backbone network and a pre-trained model. The model is iterated multiple times to reduce the difference in printing defects, making the contrastive learning model increasingly sensitive to the printing defects that need to be detected, so as to effectively distinguish character defects.
[0058] To improve the accuracy of defect detection, in one optional implementation, the comparison sample set includes positive samples, simple negative samples, and difficult negative samples. The character position of the second character image x' in the positive sample differs from the character position of the first character image x in the positive sample. The character content of the second character image x” in the simple negative sample differs from the character content of the first character image x in the simple negative sample. The character shape of the second character image x”' in the difficult negative sample differs from the character shape of the first character image x in the difficult negative sample. Step S2033 includes:
[0059] Step S20331: Obtain the updated objective function of the above contrastive learning model to obtain the printing defect difference function, which is: Where, N p N represents the number of positive samples mentioned above. nLet N be the number of simple negative samples mentioned above. h a1 is the number of negative samples in the above difficult examples, a2 is the weight of the above positive samples, a3 is the weight of the above simple negative samples, and a3 > a1.
[0060] Step S20332: Substitute the above-mentioned comparison sample set into the above-mentioned printing defect difference function to obtain the above-mentioned printing defect difference.
[0061] In the above embodiments, such as Figure 3 As shown, positive samples are created for labels with identical character content but different printing positions. These are then used to generate corresponding positive samples based on image transformation methods, such as translation, rotation, and scaling. A trained autoencoder model is used to extract the feature representations of these positive samples as positive sample features. Simple negative samples are created for issues like incomplete printing or errors in printing content, using random cropping and labels with other character content. Difficult negative samples are created for issues like uneven ink distribution or other printing quality problems, using random partial or complete dilation and erosion image operations. The trained autoencoder model is used to extract the feature representations of these difficult negative samples as negative sample features. The ratio of positive samples, simple negative samples, and difficult negative samples is 5:3:2. Only the defect type needs to be classified into different samples; manual annotation of each sample is not required. The feature representations of positive and negative sample pairs are compared and learned, and the loss function is optimized to further obtain the expression of character defects. For each positive sample pair (x, x') and each negative sample pair (x, x”), calculate their distances in the embedding space, denoted as d(x, x') and d(x, x”), respectively. Define a margin to represent a reference value for the distance between sample pairs, where m is a pre-set margin value, which can be set to 0.5. Use the hinge loss function to enable the contrastive learning model to better distinguish the similarity and difference between positive and negative sample pairs, i.e. Where, N p N represents the number of positive samples mentioned above. n Let N be the number of simple negative samples mentioned above. h Let a1 be the number of difficult negative samples, a2 be the weight of the simple negative samples, and a3 be the weight of the difficult negative samples. The loss function is decomposed into positive sample loss, simple negative sample loss, and difficult negative sample loss, so that the model can increase the similarity of positive sample pairs to ignore positional changes, decrease the similarity of negative sample pairs, and increase the sensitivity to defects with different content and different shapes. Since a3 > a1, the detection capability of difficult negative samples is improved to achieve accurate defect detection.
[0062] To improve the accuracy of printing defect detection, in an optional embodiment, before step S205, the method further includes:
[0063] Step S301: Input the above comparison sample set into the above secondary optimization encoder to obtain multiple feature vector pairs. The feature vector pair includes a first feature vector and a second feature vector. A positive sample corresponds to a feature vector pair, a simple negative sample corresponds to a feature vector pair, and a difficult negative sample corresponds to a feature vector pair.
[0064] Step S302: Calculate the cosine distance of each of the above feature vector pairs to obtain multiple cosine distances;
[0065] Step S303, determination step: when the cosine distance is greater than or equal to the pre-set second predetermined threshold, the sample corresponding to the cosine distance is determined as a predicted positive sample; when the cosine distance is less than the pre-set second predetermined threshold, the sample corresponding to the cosine distance is determined as a predicted negative sample.
[0066] Step S304, calculation step, calculate the evaluation score of the above-mentioned second predetermined threshold, the evaluation score is used to characterize the judgment accuracy of the above-mentioned predicted positive sample and the above-mentioned predicted negative sample;
[0067] Step S305: Repeat the above determination step and the above calculation step at least once to obtain multiple evaluation scores of the above-mentioned second predetermined threshold.
[0068] Step S306: The preliminary second predetermined threshold corresponding to the highest of the above evaluation scores is determined as the second predetermined threshold.
[0069] In the above implementation, an appropriate threshold is set according to the distribution of training samples and actual needs to determine whether there are character defects. The threshold is adjusted and optimized using a test set, and the F1 score, i.e., the evaluation score, is calculated. The evaluation score F1-score is used to evaluate the accuracy of printing defect detection. The detection threshold T is determined based on the optimal F1 score to improve the accuracy of printing defect detection.
[0070] To ensure the accuracy of printing defect detection, in one optional implementation, step S304 includes:
[0071] Step S3041: Calculate the ratio of the first quantity to the second quantity to obtain the first ratio; calculate the ratio of the first quantity to the third quantity to obtain the second ratio; the first quantity is the number of predicted positive samples of the positive samples; the second quantity is the number of predicted positive samples; and the third quantity is the number of positive samples.
[0072] Step S3042: Calculate the product of the first ratio and the second ratio to obtain a predetermined product; calculate the sum of the first ratio and the second ratio to obtain a predetermined sum.
[0073] Step S3043: Calculate twice the ratio of the predetermined product to the predetermined sum to obtain the evaluation score.
[0074] In the above implementation, the evaluation score F1-score = 2*(Precision*Recall) / (Precision+Recall), where Precision represents the proportion of samples predicted as positive that are actually positive, defined as: Precision = TP / (TP+FP), and Recall represents the proportion of samples that are actually positive that are correctly predicted as positive, defined as: Recall = TP / (TP+FN), where TP (True Positive) represents the number of true positives, FP (False Positive) represents the number of false positives, and FN (False Negative) represents the number of false negatives, so that the evaluation score F1-score can be used to evaluate the accuracy of printing defect detection.
[0075] To facilitate the identification of printing defects, in an optional embodiment, before step S205, the method further includes:
[0076] Step S401: Substitute the first eigenvector and the second eigenvector into the cosine distance formula to obtain the cosine distance, which is d = dot(a,b) / (norm(a)*norm(b)), where dot(a,b) is the dot product of the first eigenvector and the second eigenvector, norm(a) is the L2 norm of the first eigenvector, and norm(b) is the L2 norm of the second eigenvector.
[0077] Specifically, such as Figure 4 As shown, the encoder is the above-mentioned second-order optimized encoder obtained after training. The image to be tested and the template image are respectively input into the above-mentioned second-order optimized encoder to obtain the first feature vector and the second feature vector. The similarity module uses the cosine distance between the two feature vectors to represent the difference between the two feature vectors. The larger the difference, the more likely there may be printing defects. The cosine distance is simple to calculate. It can be compared with the corresponding threshold T to determine whether there are printing defects, which is convenient for judging printing defects.
[0078] To enable those skilled in the art to better understand the technical solution of this application, the implementation process of the printing defect detection method of this application will be described in detail below with reference to specific embodiments.
[0079] This embodiment relates to a specific method for detecting printing defects, such as... Figure 5 As shown, it includes the following steps:
[0080] Step S1: Data Preparation Stage
[0081] Collect a dataset of printed character images, including character images of different fonts, sizes, and colors.
[0082] Step S2: Construct the autoencoder model:
[0083] Using deep learning frameworks such as TensorFlow or PyTorch, a fully convolutional network autoencoder model is constructed to adapt the network to images of arbitrary sizes. The autoencoder model consists of two parts: an encoder and a decoder. The encoder converts the input image into a latent feature vector, and the decoder reconstructs the image from the latent feature vector. After inputting the image, certain translation, rotation, and scaling operations are performed on the image, enabling the encoder to extract translation, rotation, and scaling-invariant features of the printed characters. Printed character label samples are used as training data to optimize the parameters of the autoencoder model to minimize the reconstruction error. Mean Squared Error (MSE) is used as the reconstruction error loss function, calculated as follows:
[0084] MSE = 1 / n * Σ[(x-x')] 2
[0085] Where n represents the number of samples, x represents the original input data, and x' represents the output data reconstructed by the autoencoder model. MSE is the average of the sum of squared reconstruction errors for each sample in each dimension. It measures the difference between the autoencoder model's reconstructed output and the original input; a smaller value indicates better performance of the autoencoder model during reconstruction. The goal is to minimize MSE, thereby reducing the reconstruction error as much as possible, improving the autoencoder model's ability to represent and reconstruct input data, and learning the latent features of character labels.
[0086] Step S3: Comparison Sample Pair Construction Stage:
[0087] Positive sample pairs are created. Labels with the same character content but different character printing positions are considered positive samples. Based on the image transformation method, corresponding positive samples are generated. Transformation methods such as translation, rotation, and scaling are used. The feature representation of the positive samples is used as the feature of the positive sample pair using the trained autoencoder model.
[0088] To create negative sample pairs: 1. Create simple negative sample pairs. For problems such as incomplete printing or errors in printed content, use random cropping and tags with other character content to form simple negative sample pairs; 2. Create difficult negative sample pairs. For problems such as uneven printing ink or other printing quality issues, use random partial or complete dilation and erosion image operations to generate negative sample pairs. Use a trained autoencoder model to use the feature representation of the negative samples as the features of the negative sample pairs.
[0089] The ratio of positive sample pairs, simple negative sample pairs, and difficult negative sample pairs is 5:3:2.
[0090] Step S4: Comparative learning model training phase:
[0091] Using the encoder trained in step S2 as the backbone network and pre-trained model, a contrastive learning network model is constructed, and the similarity of the inputs is measured by connecting a similarity measurement module.
[0092] Contrastive learning is performed using the feature representations of positive and negative sample pairs, and the character defect representation is further obtained by optimizing the loss function. For each positive sample pair (x,x') and each negative sample pair (x,x”), their distances in the embedding space are calculated as d(x,x') and d(x,x”), respectively.
[0093] Define a margin to represent a reference value for the distance between sample pairs, where m is a preset margin value, which can be set to 0.5.
[0094] Using the hinge loss function allows the model to better distinguish the similarity and difference between positive and negative sample pairs; that is, the printing defect difference function mentioned above is... Where, N p N represents the number of positive samples mentioned above. n Let N be the number of simple negative samples mentioned above. h Let a1 be the number of the difficult negative samples, a2 be the weight of the simple negative samples, and a3 be the weight of the difficult negative samples. Since a3 > a1, the model focuses more on learning the difficult examples.
[0095] The distance d between the embedding spaces of samples can be measured using cosine distance:
[0096] d = dot(a,b) / (norm(a)*norm(b)), where dot(a,b) represents the dot product of eigenvectors a and b, and norm(a) represents the L2 norm of vector a.
[0097] Step S5: Determine the judgment threshold T:
[0098] According to the distribution of training samples and actual requirements, set an appropriate threshold to determine whether there are character defects. Use the test set to adjust and optimize the threshold, and calculate the accuracy, recall rate, and F1-score of the model. Determine the detection threshold T in the case of the best F1-score.
[0099] F1-score = 2 * (Precision * Recall) / (Precision + Recall)
[0100] Among them, Precision represents the proportion of samples predicted as positive examples that are truly positive, and is defined as:
[0101] Precision = TP / (TP + FP)
[0102] Recall represents the proportion of samples that are truly positive and are correctly predicted as positive, and is defined as:
[0103] Recall = TP / (TP + FN)
[0104] Among them, TP (True Positive) represents the number of true positive examples, FP (False Positive) represents the number of false positive examples, and FN (False Negative) represents the number of false negative examples.
[0105] Step S6: Defect detection stage:
[0106] Input the template image and the image to be detected into the trained contrast learning to obtain an evaluation score, and determine whether there are character defects based on the preset threshold. If it is higher than T, it indicates that the待测 target is qualified; if it is lower than T, it indicates that the待测 target is unqualified.
[0107] It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. And although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than here.
[0108] The embodiment of the present application also provides a detection device for printing defects. It should be noted that the detection device for printing defects in the embodiment of the present application can be used to execute the detection method for printing defects provided in the embodiment of the present application. The device is used to implement the above embodiments and preferred implementation manners, and those that have been described will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that can achieve a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation in hardware, or a combination of software and hardware is also possible and contemplated.
[0109] The following describes the printing defect detection device provided in the embodiments of this application.
[0110] Figure 6 This is a structural block diagram of a printing defect detection device according to an embodiment of this application. Figure 6 As shown, the device includes:
[0111] Establishment unit 10 is used to establish an autoencoder model, which includes an encoder and a decoder. The encoder is used to convert a character image into a feature vector, and the decoder is used to convert the feature vector into a character image.
[0112] Specifically, using deep learning frameworks such as TensorFlow or PyTorch, a fully convolutional network autoencoder model is constructed, enabling the autoencoder model to adapt to images of arbitrary sizes. The autoencoder model consists of two parts: an encoder and a decoder. The encoder converts the input image into feature vectors, such as latent feature vectors, and the decoder restores the latent feature vectors back to the image. After inputting the image, certain translation, rotation, and scaling image processing is applied, allowing the encoder to extract translation, rotation, and scaling invariant features of the printed characters.
[0113] Training unit 20 is used to iteratively train the autoencoder model using multiple character images until the loss function value of the autoencoder model in the current iteration is less than the loss function value of the autoencoder model in the previous iteration, and the encoder of the autoencoder model in the current iteration is determined as an optimized encoder.
[0114] Specifically, printed character image samples are used as training data to optimize the parameters of the autoencoder model in order to minimize the reconstruction error, i.e., the loss function value of the autoencoder model. If the loss function value of the autoencoder model in this iteration is less than the loss function value of the autoencoder model in the previous iteration, the reconstruction error is considered to have reached its minimum, thereby improving the autoencoder model's ability to represent and reconstruct the input data and learn the latent features of the character image. At this time, the encoder of the autoencoder model is the first-order optimized encoder.
[0115] The optimization unit 30 is used to compare and learn the first-order optimization encoder to obtain a second-order optimization encoder, so that the feature vector output by the second-order optimization encoder contains information about the printing defects of the character image.
[0116] Specifically, the first-order optimized encoder is compared and learned to obtain the second-order optimized encoder. The feature vector output by the second-order optimized encoder contains information about the printing defects of the character image, so as to effectively distinguish the character defects.
[0117] Extraction unit 40 is used to input the image to be tested and the template image into the above-mentioned secondary optimization encoder to obtain the first feature vector and the second feature vector, wherein the image to be tested is the printed image of the above-mentioned template image;
[0118] Specifically, the image to be tested is the character image of the printing defect to be detected. By inputting it and the corresponding template image into the above-mentioned secondary optimization encoder, the first feature vector and the second feature vector corresponding to the two images can be obtained, so that the first feature vector carries information about the printing defects that may exist in the image to be tested.
[0119] The first determining unit 50 is used to determine that the image to be tested has a printing defect when the cosine distance between the first feature vector and the second feature vector is less than a second predetermined threshold.
[0120] Specifically, if the first feature vector carries information about printing defects in the image under test, the difference between the first feature vector and the second feature vector will be large, and the cosine distance between them will be small, satisfying the condition of being less than the second predetermined threshold, then it can be determined that the image under test has printing defects.
[0121] In the aforementioned printing defect detection device, the establishment unit establishes an autoencoder model, which includes an encoder and a decoder. The encoder is used to convert a character image into a feature vector, and the decoder is used to convert the feature vector back into a character image. The training unit iteratively trains the autoencoder model using multiple character images until the loss function value of the current iteration of the autoencoder model is less than a first predetermined threshold compared to the loss function value of the previous iteration. The encoder of the current iteration of the autoencoder model is then determined as a first-order optimized encoder. The optimization unit performs comparative learning on the first-order optimized encoder to obtain a second-order optimized encoder, such that the feature vector output by the second-order optimized encoder contains information about printing defects in the character image. The extraction unit inputs the image to be tested and the template image into the second-order optimized encoder to obtain a first feature vector and a second feature vector. The image to be tested is the printed image of the template image. The first determination unit determines that the image to be tested has printing defects when the cosine distance between the first feature vector and the second feature vector is less than a second predetermined threshold. By employing an autoencoder model structure and training it on a large number of unlabeled printed character images, a first-order optimized encoder is obtained. This encoder learns the inherent structure and feature representation of the data, enabling the model to express the structure and features of characters, i.e., feature vectors, without relying on manually designed feature engineering. The model is trained by comparing sample sets and uses contrastive learning to effectively distinguish character defects, resulting in a second-order optimized encoder. The second-order optimized encoder then extracts feature vectors from the test image and the template image, i.e., the first feature vector and the second feature vector. The cosine distance between the first and second feature vectors determines whether the test image has printing defects, thus solving the problem of time-consuming and labor-intensive printing defect detection methods. This method has broad adaptability and can be adapted to printing character defect detection tasks of different types, styles, and sizes.
[0122] To reduce reconstruction errors, in one optional implementation, the training unit includes:
[0123] The first adjustment module is used to perform the first adjustment step, adjust the parameters of the above autoencoder model, and obtain the updated autoencoder model.
[0124] The input module is used to perform the input step, inputting multiple of the above character images into the updated autoencoder model to obtain multiple printed character images;
[0125] The first calculation module is used to perform calculation steps, calculate the mean square error between the pixel data corresponding to the multiple printed character images and the corresponding pixel data of the multiple printed character images, obtain the loss function value of the autoencoder model, and complete one iteration.
[0126] The first repetition module is used to repeat the first adjustment step, the input step, and the calculation step at least once, until the difference between the loss function value of the current iteration and the loss function value of the previous iteration is less than the first predetermined threshold, thereby obtaining the first optimized encoder, which is the encoder in the current autoencoder model.
[0127] In the above embodiments, a large number of printed character images are used for training. The parameters of the autoencoder model are optimized once by calculating the mean square error between the pixel data corresponding to multiple printed character images and the corresponding pixel data of multiple printed character images, which is the loss function value of the autoencoder model. This process continues until the difference between the loss function value of the current iteration and the loss function value of the previous iteration is less than the first predetermined threshold. The reconstruction error is then considered to have reached its minimum, and the optimized encoder is obtained. This improves the autoencoder model's ability to represent and reconstruct input image data and learns the latent features of character images.
[0128] The instruction manual specifies that the Mean Squared Error (MSE) is used as the loss function for the autoencoder model, and its calculation formula is as follows: MSE=1 / n*Σ(xx′) 2 In this equation, n represents the number of samples, x represents the original input character image data, and x' represents the output character image data reconstructed by the autoencoder model. MSE is the average of the sum of squared reconstruction errors for each sample in each dimension. It measures the degree of difference between the reconstructed output of the autoencoder model and the original input; a smaller value indicates better performance of the autoencoder model in the reconstruction process.
[0129] In order to effectively distinguish character defects, in one optional implementation, the above-mentioned optimization unit includes:
[0130] A module is established to build a contrastive learning model based on the above-mentioned first-order optimized encoder. The output of the contrastive learning model is the printing defect difference degree, which is used to characterize the differences in multiple above-mentioned character images before and after printing due to printing defects.
[0131] The second adjustment module is used to perform the second adjustment step, adjusting the parameters of the optimized encoder in the contrastive learning model to obtain the updated contrastive learning model.
[0132] The output module is used to perform the output step. It takes the comparison sample set as input to the updated comparison learning model, obtains the printing defect difference degree, and completes one iteration. The comparison learning model is used to determine that the comparison sample set includes multiple first character images and corresponding second character images. The first character image is the character image used as a printing template, and the second character image is the character image obtained by printing the first character image.
[0133] The second repetition module is used to repeat the above adjustment steps and the above output steps at least once until the difference between the above printing defect difference degree of the current iteration and the above printing defect difference degree of the previous iteration is less than a third predetermined threshold, thereby obtaining the above secondary optimization encoder, which is the encoder in the current above contrastive learning model.
[0134] In the above implementation, a contrastive learning network model is constructed using a primary optimized encoder as the backbone network and a pre-trained model. The model is iterated multiple times to reduce the difference in printing defects, making the contrastive learning model increasingly sensitive to the printing defects that need to be detected, so as to effectively distinguish character defects.
[0135] To improve the accuracy of defect detection, in one optional implementation, the comparison sample set includes positive samples, simple negative samples, and difficult negative samples. The character position of the second character image x' in the positive sample differs from the character position of the first character image x in the positive sample. The character content of the second character image x" in the simple negative sample differs from the character content of the first character image x in the simple negative sample. The character shape of the second character image x"' in the difficult negative sample differs from the character shape of the first character image x in the difficult negative sample. The output module includes:
[0136] The acquisition submodule is used to obtain the updated objective function of the above contrastive learning model, and to obtain the printing defect difference function. The above printing defect difference function is... Where, N p N represents the number of positive samples mentioned above. n Let N be the number of simple negative samples mentioned above. h a1 is the number of negative samples in the above difficult examples, a2 is the weight of the above positive samples, a3 is the weight of the above simple negative samples, and a3 > a1.
[0137] The calculation submodule is used to substitute the above-mentioned comparison sample set into the above-mentioned printing defect difference function to obtain the above-mentioned printing defect difference.
[0138] In the above embodiments, such as Figure 3As shown, positive samples are created for labels with identical character content but different printing positions. These are then used to generate corresponding positive samples based on image transformation methods, such as translation, rotation, and scaling. A trained autoencoder model is used to extract the feature representations of these positive samples as positive sample features. Simple negative samples are created for issues like incomplete printing or errors in printing content, using random cropping and labels with other character content. Difficult negative samples are created for issues like uneven ink distribution or other printing quality problems, using random partial or complete dilation and erosion image operations. The trained autoencoder model is used to extract the feature representations of these difficult negative samples as negative sample features. The ratio of positive samples, simple negative samples, and difficult negative samples is 5:3:2. Only the defect type needs to be classified into different samples; manual annotation of each sample is not required. The feature representations of positive and negative sample pairs are compared and learned, and the loss function is optimized to further obtain the expression of character defects. For each positive sample pair (x, x') and each negative sample pair (x, x”), calculate their distances in the embedding space, denoted as d(x, x') and d(x, x”), respectively. Define a margin to represent a reference value for the distance between sample pairs, where m is a pre-set margin value, which can be set to 0.5. Use the hinge loss function to enable the contrastive learning model to better distinguish the similarity and difference between positive and negative sample pairs, i.e. Where, N p N represents the number of positive samples mentioned above. n Let N be the number of simple negative samples mentioned above. h Let a1 be the number of difficult negative samples, a2 be the weight of the simple negative samples, and a3 be the weight of the difficult negative samples. The loss function is decomposed into positive sample loss, simple negative sample loss, and difficult negative sample loss, so that the model can increase the similarity of positive sample pairs to ignore positional changes, decrease the similarity of negative sample pairs, and increase the sensitivity to defects with different content and different shapes. Since a3 > a1, the detection capability of difficult negative samples is improved to achieve accurate defect detection.
[0139] To improve the accuracy of printing defect detection, in one optional embodiment, the above-mentioned device further includes:
[0140] The input unit is configured to input the comparison sample set into the secondary optimization encoder before determining that the image to be tested has a printing defect when the cosine distance between the first feature vector and the second feature vector is less than a second predetermined threshold, thereby obtaining multiple feature vector pairs. Each feature vector pair includes a first feature vector and a second feature vector. A positive sample corresponds to a feature vector pair, a simple negative sample corresponds to a feature vector pair, and a difficult negative sample corresponds to a feature vector pair.
[0141] The first calculation unit is used to calculate the cosine distance of each of the above-mentioned eigenvector pairs, and obtain multiple cosine distances;
[0142] The second determining unit is used to perform the determining step, which determines the sample corresponding to the cosine distance as a predicted positive sample when the cosine distance is greater than or equal to the pre-set second predetermined threshold, and determines the sample corresponding to the cosine distance as a predicted negative sample when the cosine distance is less than the pre-set second predetermined threshold.
[0143] The second calculation unit is used to perform calculation steps and calculate the evaluation score of the above-mentioned second predetermined threshold. The evaluation score is used to characterize the judgment accuracy of the above-mentioned predicted positive sample and the above-mentioned predicted negative sample.
[0144] The repeating unit is used to repeat the above-mentioned determination step and the above-mentioned calculation step at least once to obtain multiple evaluation scores of the above-mentioned second predetermined threshold.
[0145] The third determining unit is used to determine the preliminary second predetermined threshold corresponding to the highest of the above evaluation scores as the second predetermined threshold.
[0146] In the above implementation, an appropriate threshold is set according to the distribution of training samples and actual needs to determine whether there are character defects. The threshold is adjusted and optimized using a test set, and the F1 score, i.e., the evaluation score, is calculated. The evaluation score F1-score is used to evaluate the accuracy of printing defect detection. The detection threshold T is determined based on the optimal F1 score to improve the accuracy of printing defect detection.
[0147] To ensure the accuracy of printing defect detection, in one optional implementation, the second calculation unit includes:
[0148] The second calculation module is used to calculate the ratio of the first quantity to the second quantity to obtain the first ratio, and to calculate the ratio of the first quantity to the third quantity to obtain the second ratio. The first quantity is the number of predicted positive samples of the positive samples, the second quantity is the number of predicted positive samples, and the third quantity is the number of positive samples.
[0149] The third calculation module is used to calculate the product of the first ratio and the second ratio to obtain a predetermined product, and to calculate the sum of the first ratio and the second ratio to obtain a predetermined sum.
[0150] The fourth calculation module is used to calculate twice the ratio of the predetermined product to the predetermined sum to obtain the evaluation score.
[0151] In the above implementation, the evaluation score F1-score = 2*(Precision*Recall) / (Precision+Recall), where Precision represents the proportion of samples predicted as positive that are actually positive, defined as: Precision = TP / (TP+FP), and Recall represents the proportion of samples that are actually positive that are correctly predicted as positive, defined as: Recall = TP / (TP+FN), where TP (True Positive) represents the number of true positives, FP (False Positive) represents the number of false positives, and FN (False Negative) represents the number of false negatives, so that the evaluation score F1-score can be used to evaluate the accuracy of printing defect detection.
[0152] To facilitate the identification of printing defects, in one optional embodiment, the above-mentioned device further includes:
[0153] The fifth calculation module is used to substitute the first feature vector and the second feature vector into the cosine distance formula to obtain the cosine distance before determining that the image under test has a printing defect, when the cosine distance between the first feature vector and the second feature vector is less than a second predetermined threshold. The cosine distance formula is d = dot(a,b) / (norm(a)*norm(b)), where dot(a,b) is the dot product of the first feature vector and the second feature vector, norm(a) is the L2 norm of the first feature vector, and norm(b) is the L2 norm of the second feature vector.
[0154] Specifically, such as Figure 4 As shown, the encoder is the above-mentioned second-order optimized encoder obtained after training. The image to be tested and the template image are respectively input into the above-mentioned second-order optimized encoder to obtain the first feature vector and the second feature vector. The similarity module uses the cosine distance between the two feature vectors to represent the difference between the two feature vectors. The larger the difference, the more likely there may be printing defects. The cosine distance is simple to calculate. It can be compared with the corresponding threshold T to determine whether there are printing defects, which is convenient for judging printing defects.
[0155] The aforementioned printing defect detection device includes a processor and a memory. The aforementioned setup unit, training unit, optimization unit, extraction unit, and first determination unit are all stored as program units in the memory. The processor executes these program units stored in the memory to achieve the corresponding functions. All of the aforementioned modules are located in the same processor; alternatively, the aforementioned modules may be located in different processors in any combination.
[0156] The processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured; adjusting kernel parameters can address the time-consuming and labor-intensive nature of traditional printing defect detection methods.
[0157] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0158] This invention provides a computer-readable storage medium including a stored program, wherein, when the program is executed, it controls the device containing the computer-readable storage medium to perform the printing defect detection method.
[0159] Specifically, methods for detecting printing defects include:
[0160] Step S201: Establish an autoencoder model, which includes an encoder and a decoder. The encoder is used to convert a character image into a feature vector, and the decoder is used to convert the feature vector into a character image.
[0161] Specifically, using deep learning frameworks such as TensorFlow or PyTorch, a fully convolutional network autoencoder model is constructed, enabling the autoencoder model to adapt to images of arbitrary sizes. The autoencoder model consists of two parts: an encoder and a decoder. The encoder converts the input image into feature vectors, such as latent feature vectors, and the decoder restores the latent feature vectors back to the image. After inputting the image, certain translation, rotation, and scaling image processing is applied, allowing the encoder to extract translation, rotation, and scaling invariant features of the printed characters.
[0162] Step S202: The autoencoder model is iteratively trained using multiple character images until the loss function value of the autoencoder model in the current iteration is less than the loss function value of the autoencoder model in the previous iteration, and the encoder of the autoencoder model in the current iteration is determined as an optimized encoder.
[0163] Specifically, printed character image samples are used as training data to optimize the parameters of the autoencoder model in order to minimize the reconstruction error, i.e., the loss function value of the autoencoder model. If the loss function value of the autoencoder model in this iteration is less than the loss function value of the autoencoder model in the previous iteration, the reconstruction error is considered to have reached its minimum, thereby improving the autoencoder model's ability to represent and reconstruct the input data and learn the latent features of the character image. At this time, the encoder of the autoencoder model is the first-order optimized encoder.
[0164] Step S203: Compare and learn the first-order optimized encoder to obtain the second-order optimized encoder, so that the feature vector output by the second-order optimized encoder contains information about the printing defects of the character image.
[0165] Specifically, the first-order optimized encoder is compared and learned to obtain the second-order optimized encoder. The feature vector output by the second-order optimized encoder contains information about the printing defects of the character image, so as to effectively distinguish the character defects.
[0166] Step S204: Input the image to be tested and the template image into the above-mentioned secondary optimization encoder to obtain the first feature vector and the second feature vector. The image to be tested is the printed image of the template image.
[0167] Specifically, the image to be tested is the character image of the printing defect to be detected. By inputting it and the corresponding template image into the above-mentioned secondary optimization encoder, the first feature vector and the second feature vector corresponding to the two images can be obtained, so that the first feature vector carries information about the printing defects that may exist in the image to be tested.
[0168] Step S205: If the cosine distance between the first feature vector and the second feature vector is less than a second predetermined threshold, it is determined that the image to be tested has a printing defect.
[0169] Specifically, if the first feature vector carries information about printing defects in the image under test, the difference between the first feature vector and the second feature vector will be large, and the cosine distance between them will be small, satisfying the condition of being less than the second predetermined threshold, then it can be determined that the image under test has printing defects.
[0170] This invention provides a processor for running a program, wherein the program executes the printing defect detection method described above.
[0171] Specifically, methods for detecting printing defects include:
[0172] Step S201: Establish an autoencoder model, which includes an encoder and a decoder. The encoder is used to convert a character image into a feature vector, and the decoder is used to convert the feature vector into a character image.
[0173] Specifically, using deep learning frameworks such as TensorFlow or PyTorch, a fully convolutional network autoencoder model is constructed, enabling the autoencoder model to adapt to images of arbitrary sizes. The autoencoder model consists of two parts: an encoder and a decoder. The encoder converts the input image into feature vectors, such as latent feature vectors, and the decoder restores the latent feature vectors back to the image. After inputting the image, certain translation, rotation, and scaling image processing is applied, allowing the encoder to extract translation, rotation, and scaling invariant features of the printed characters.
[0174] Step S202: The autoencoder model is iteratively trained using multiple character images until the loss function value of the autoencoder model in the current iteration is less than the loss function value of the autoencoder model in the previous iteration, and the encoder of the autoencoder model in the current iteration is determined as an optimized encoder.
[0175] Specifically, printed character image samples are used as training data to optimize the parameters of the autoencoder model in order to minimize the reconstruction error, i.e., the loss function value of the autoencoder model. If the loss function value of the autoencoder model in this iteration is less than the loss function value of the autoencoder model in the previous iteration, the reconstruction error is considered to have reached its minimum, thereby improving the autoencoder model's ability to represent and reconstruct the input data and learn the latent features of the character image. At this time, the encoder of the autoencoder model is the first-order optimized encoder.
[0176] Step S203: Compare and learn the first-order optimized encoder to obtain the second-order optimized encoder, so that the feature vector output by the second-order optimized encoder contains information about the printing defects of the character image.
[0177] Specifically, the first-order optimized encoder is compared and learned to obtain the second-order optimized encoder. The feature vector output by the second-order optimized encoder contains information about the printing defects of the character image, so as to effectively distinguish the character defects.
[0178] Step S204: Input the image to be tested and the template image into the above-mentioned secondary optimization encoder to obtain the first feature vector and the second feature vector. The image to be tested is the printed image of the template image.
[0179] Specifically, the image to be tested is the character image of the printing defect to be detected. By inputting it and the corresponding template image into the above-mentioned secondary optimization encoder, the first feature vector and the second feature vector corresponding to the two images can be obtained, so that the first feature vector carries information about the printing defects that may exist in the image to be tested.
[0180] Step S205: If the cosine distance between the first feature vector and the second feature vector is less than a second predetermined threshold, it is determined that the image to be tested has a printing defect.
[0181] Specifically, if the first feature vector carries information about printing defects in the image under test, the difference between the first feature vector and the second feature vector will be large, and the cosine distance between them will be small, satisfying the condition of being less than the second predetermined threshold, then it can be determined that the image under test has printing defects.
[0182] This invention provides a printing system, which includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs at least the following steps:
[0183] Step S201: Establish an autoencoder model, which includes an encoder and a decoder. The encoder is used to convert a character image into a feature vector, and the decoder is used to convert the feature vector into a character image.
[0184] Specifically, using deep learning frameworks such as TensorFlow or PyTorch, a fully convolutional network autoencoder model is constructed, enabling the autoencoder model to adapt to images of arbitrary sizes. The autoencoder model consists of two parts: an encoder and a decoder. The encoder converts the input image into feature vectors, such as latent feature vectors, and the decoder restores the latent feature vectors back to the image. After inputting the image, certain translation, rotation, and scaling image processing is applied, allowing the encoder to extract translation, rotation, and scaling invariant features of the printed characters.
[0185] Step S202: The autoencoder model is iteratively trained using multiple character images until the loss function value of the autoencoder model in the current iteration is less than the loss function value of the autoencoder model in the previous iteration, and the encoder of the autoencoder model in the current iteration is determined as an optimized encoder.
[0186] Specifically, printed character image samples are used as training data to optimize the parameters of the autoencoder model in order to minimize the reconstruction error, i.e., the loss function value of the autoencoder model. If the loss function value of the autoencoder model in this iteration is less than the loss function value of the autoencoder model in the previous iteration, the reconstruction error is considered to have reached its minimum, thereby improving the autoencoder model's ability to represent and reconstruct the input data and learn the latent features of the character image. At this time, the encoder of the autoencoder model is the first-order optimized encoder.
[0187] Step S203: Compare and learn the first-order optimized encoder to obtain the second-order optimized encoder, so that the feature vector output by the second-order optimized encoder contains information about the printing defects of the character image.
[0188] Specifically, the first-order optimized encoder is compared and learned to obtain the second-order optimized encoder. The feature vector output by the second-order optimized encoder contains information about the printing defects of the character image, so as to effectively distinguish the character defects.
[0189] Step S204: Input the image to be tested and the template image into the above-mentioned secondary optimization encoder to obtain the first feature vector and the second feature vector. The image to be tested is the printed image of the template image.
[0190] Specifically, the image to be tested is the character image of the printing defect to be detected. By inputting it and the corresponding template image into the above-mentioned secondary optimization encoder, the first feature vector and the second feature vector corresponding to the two images can be obtained, so that the first feature vector carries information about the printing defects that may exist in the image to be tested.
[0191] Step S205: If the cosine distance between the first feature vector and the second feature vector is less than a second predetermined threshold, it is determined that the image to be tested has a printing defect.
[0192] Specifically, if the first feature vector carries information about printing defects in the image under test, the difference between the first feature vector and the second feature vector will be large, and the cosine distance between them will be small, satisfying the condition of being less than the second predetermined threshold, then it can be determined that the image under test has printing defects.
[0193] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program having at least the following method steps:
[0194] Step S201: Establish an autoencoder model, which includes an encoder and a decoder. The encoder is used to convert a character image into a feature vector, and the decoder is used to convert the feature vector into a character image.
[0195] Specifically, using deep learning frameworks such as TensorFlow or PyTorch, a fully convolutional network autoencoder model is constructed, enabling the autoencoder model to adapt to images of arbitrary sizes. The autoencoder model consists of two parts: an encoder and a decoder. The encoder converts the input image into feature vectors, such as latent feature vectors, and the decoder restores the latent feature vectors back to the image. After inputting the image, certain translation, rotation, and scaling image processing is applied, allowing the encoder to extract translation, rotation, and scaling invariant features of the printed characters.
[0196] Step S202: The autoencoder model is iteratively trained using multiple character images until the loss function value of the autoencoder model in the current iteration is less than the loss function value of the autoencoder model in the previous iteration, and the encoder of the autoencoder model in the current iteration is determined as an optimized encoder.
[0197] Specifically, printed character image samples are used as training data to optimize the parameters of the autoencoder model in order to minimize the reconstruction error, i.e., the loss function value of the autoencoder model. If the loss function value of the autoencoder model in this iteration is less than the loss function value of the autoencoder model in the previous iteration, the reconstruction error is considered to have reached its minimum, thereby improving the autoencoder model's ability to represent and reconstruct the input data and learn the latent features of the character image. At this time, the encoder of the autoencoder model is the first-order optimized encoder.
[0198] Step S203: Compare and learn the first-order optimized encoder to obtain the second-order optimized encoder, so that the feature vector output by the second-order optimized encoder contains information about the printing defects of the character image.
[0199] Specifically, the first-order optimized encoder is compared and learned to obtain the second-order optimized encoder. The feature vector output by the second-order optimized encoder contains information about the printing defects of the character image, so as to effectively distinguish the character defects.
[0200] Step S204: Input the image to be tested and the template image into the above-mentioned secondary optimization encoder to obtain the first feature vector and the second feature vector. The image to be tested is the printed image of the template image.
[0201] Specifically, the image to be tested is the character image of the printing defect to be detected. By inputting it and the corresponding template image into the above-mentioned secondary optimization encoder, the first feature vector and the second feature vector corresponding to the two images can be obtained, so that the first feature vector carries information about the printing defects that may exist in the image to be tested.
[0202] Step S205: If the cosine distance between the first feature vector and the second feature vector is less than a second predetermined threshold, it is determined that the image to be tested has a printing defect.
[0203] Specifically, if the first feature vector carries information about printing defects in the image under test, the difference between the first feature vector and the second feature vector will be large, and the cosine distance between them will be small, satisfying the condition of being less than the second predetermined threshold, then it can be determined that the image under test has printing defects.
[0204] It is obvious to those skilled in the art that the modules or steps of the present invention described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. They can be implemented using computer-executable program code, and thus can be stored in a storage device for execution by a computing device. In some cases, the steps shown or described can be performed in a different order than those described herein, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.
[0205] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0206] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0207] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0208] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0209] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0210] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0211] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0212] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0213] As can be seen from the above description, the embodiments of this application achieve the following technical effects:
[0214] 1) In the above-mentioned method for detecting printing defects in this application, firstly, an autoencoder model is established, which includes an encoder and a decoder. The encoder is used to convert a character image into a feature vector, and the decoder is used to convert the feature vector into a character image. Then, the autoencoder model is iteratively trained using multiple character images until the loss function value of the autoencoder model in the current iteration is less than the loss function value of the autoencoder model in the previous iteration, and the encoder of the autoencoder model in the current iteration is determined as a first-order optimized encoder. Afterwards, the first-order optimized encoder is compared and learned to obtain a second-order optimized encoder, such that the feature vector output by the second-order optimized encoder contains information about the printing defects of the character image. Then, the image to be tested and the template image are respectively input into the second-order optimized encoder to obtain a first feature vector and a second feature vector, where the image to be tested is the printed image of the template image. Finally, if the cosine distance between the first feature vector and the second feature vector is less than a second predetermined threshold, it is determined that the image to be tested has printing defects. By employing an autoencoder model structure and training it on a large number of unlabeled printed character images, a first-order optimized encoder is obtained. This encoder learns the inherent structure and feature representation of the data, enabling the model to express the structure and features of characters, i.e., feature vectors, without relying on manually designed feature engineering. The model is trained by comparing sample sets and uses contrastive learning to effectively distinguish character defects, resulting in a second-order optimized encoder. The second-order optimized encoder then extracts feature vectors from the test image and the template image, i.e., the first feature vector and the second feature vector. The cosine distance between the first and second feature vectors determines whether the test image has printing defects, thus solving the problem of time-consuming and labor-intensive printing defect detection methods. This method has broad adaptability and can be adapted to printing character defect detection tasks of different types, styles, and sizes.
[0215] 2) In the printing defect detection device of this application, the establishment unit establishes an autoencoder model, which includes an encoder and a decoder. The encoder is used to convert a character image into a feature vector, and the decoder is used to convert the feature vector into a character image. The training unit uses multiple character images to iteratively train the autoencoder model until the loss function value of the current iteration of the autoencoder model is less than the loss function value of the previous iteration of the autoencoder model, and determines the encoder of the current iteration of the autoencoder model as a first-order optimized encoder. The optimization unit performs comparative learning on the first-order optimized encoder to obtain a second-order optimized encoder, so that the feature vector output by the second-order optimized encoder contains information about the printing defects of the character image. The extraction unit inputs the image to be tested and the template image into the second-order optimized encoder to obtain a first feature vector and a second feature vector, where the image to be tested is the printed image of the template image. The first determination unit determines that the image to be tested has printing defects when the cosine distance between the first feature vector and the second feature vector is less than a second predetermined threshold. By employing an autoencoder model structure and training it on a large number of unlabeled printed character images, a first-order optimized encoder is obtained. This encoder learns the inherent structure and feature representation of the data, enabling the model to express the structure and features of characters, i.e., feature vectors, without relying on manually designed feature engineering. The model is trained by comparing sample sets and uses contrastive learning to effectively distinguish character defects, resulting in a second-order optimized encoder. The second-order optimized encoder then extracts feature vectors from the test image and the template image, i.e., the first feature vector and the second feature vector. The cosine distance between the first and second feature vectors determines whether the test image has printing defects, thus solving the problem of time-consuming and labor-intensive printing defect detection methods. This method has broad adaptability and can be adapted to printing character defect detection tasks of different types, styles, and sizes.
[0216] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A method for detecting printing defects, characterized in that, include: An autoencoder model is established, comprising an encoder and a decoder. The encoder is used to convert a character image into a feature vector, and the decoder is used to convert the feature vector back into the character image. The autoencoder model is iteratively trained using multiple character images until the loss function value of the autoencoder model in the current iteration is less than the loss function value of the autoencoder model in the previous iteration, and the encoder of the autoencoder model in the current iteration is determined as an optimized encoder. The primary optimized encoder is compared and learned to obtain a secondary optimized encoder, so that the feature vector output by the secondary optimized encoder contains information about the printing defects of the character image; The image to be tested and the template image are respectively input into the secondary optimization encoder to obtain the first feature vector and the second feature vector. The image to be tested is the printed image of the template image. If the cosine distance between the first feature vector and the second feature vector is less than a second predetermined threshold, it is determined that the image under test has a printing defect. The process of performing comparative learning on the primary optimized encoder to obtain a secondary optimized encoder includes: establishing a comparative learning model based on the primary optimized encoder, wherein the output of the comparative learning model is a printing defect difference degree, which is used to characterize the difference caused by printing defects before and after printing of multiple character images; a second adjustment step, adjusting the parameters of the primary optimized encoder in the comparative learning model to obtain an updated comparative learning model; an output step, using a comparative sample set as input to the updated comparative learning model to obtain the printing defect difference degree, completing one iteration, wherein the comparative learning model is used to determine that the comparative sample set includes multiple first character images and corresponding second character images, wherein the first character images are the character images used as printing templates, and the second character images are the character images obtained by printing the first character images; repeating the second adjustment step and the output step at least once until the difference between the printing defect difference degree of the current iteration and the printing defect difference degree of the previous iteration is less than a third predetermined threshold, thereby obtaining the secondary optimized encoder, which is the primary optimized encoder in the current comparative learning model; The comparison sample set includes positive samples, simple negative samples, and difficult negative samples. The character position of the second character image x' in the positive sample differs from the character position of the first character image x in the positive sample. The character content of the second character image x'' in the simple negative sample differs from the character content of the first character image x in the simple negative sample. The character shape of the second character image x''' in the difficult negative sample differs from the character shape of the first character image x in the difficult negative sample. The comparison sample set is used as input to the updated comparison learning model to obtain the printing defect difference degree. This includes: obtaining the objective function of the updated comparison learning model to obtain the printing defect difference degree function, where the printing defect difference degree function is... in, The number of positive samples. The number of simple negative samples. The number of negative samples in the difficult cases. The weights of the positive samples are... The weights of the simple negative samples are... The weights of the negative samples in the difficult cases, > , Indicates positive sample pairs Distance in the embedded space, Represents simple negative sample pairs Distance in the embedded space, Indicates the negative sample pairs of the difficult examples In the embedding space, the distance m is a preset margin value, representing a reference value for the distance between sample pairs; the printing defect difference degree is obtained by substituting the comparison sample set into the printing defect difference degree function.
2. The method according to claim 1, characterized in that, The autoencoder model is iteratively trained using multiple character images until the loss function value of the autoencoder model in the current iteration is less than the loss function value of the autoencoder model in the previous iteration, and the encoder of the autoencoder model in the current iteration is determined as an optimized encoder, including: The first adjustment step is to adjust the parameters of the autoencoder model to obtain the updated autoencoder model; The input step involves inputting multiple character images into the updated autoencoder model to obtain multiple printed character images. The calculation steps involve calculating the mean square error between the pixel data corresponding to multiple printed character images and the pixel data corresponding to the multiple character images, obtaining the loss function value of the autoencoder model, and completing one iteration. Repeat the first adjustment step, the input step, and the calculation step at least once until the difference between the loss function value of the current iteration and the loss function value of the previous iteration is less than the first predetermined threshold, to obtain the first-order optimized encoder, which is the encoder in the current autoencoder model.
3. The method according to claim 1, characterized in that, Before determining that the image to be tested has a printing defect when the cosine distance between the first feature vector and the second feature vector is less than a second predetermined threshold, the method further includes: The comparison sample set is input into the secondary optimization encoder to obtain multiple feature vector pairs. Each feature vector pair includes a first feature vector and a second feature vector. One positive sample corresponds to one feature vector pair, one simple negative sample corresponds to one feature vector pair, and one difficult negative sample corresponds to one feature vector pair. Calculate the cosine distance between each of the aforementioned feature vector pairs to obtain multiple cosine distances; The determination steps are as follows: if the cosine distance is greater than or equal to a pre-set second predetermined threshold, the sample corresponding to the cosine distance is determined as a predicted positive sample; if the cosine distance is less than the pre-set second predetermined threshold, the sample corresponding to the cosine distance is determined as a predicted negative sample. The calculation step involves calculating the evaluation score of the pre-set second predetermined threshold, whereby the evaluation score is used to characterize the accuracy of the judgment of the predicted positive sample and the predicted negative sample. The determination step and the calculation step are repeated at least once to obtain multiple evaluation scores for the preparatory second predetermined threshold. The preliminary second predetermined threshold corresponding to the highest evaluation score is determined as the second predetermined threshold.
4. The method according to claim 3, characterized in that, Calculating the evaluation score of the pre-defined second threshold includes: Calculate the ratio of the first quantity to the second quantity to obtain the first ratio, calculate the ratio of the first quantity to the third quantity to obtain the second ratio, where the first quantity is the number of predicted positive samples of the positive samples, the second quantity is the number of predicted positive samples, and the third quantity is the number of positive samples; Calculate the product of the first ratio and the second ratio to obtain a predetermined product; calculate the sum of the first ratio and the second ratio to obtain a predetermined sum. The evaluation score is obtained by calculating twice the ratio of the predetermined product to the predetermined sum.
5. The method according to any one of claims 1 to 4, characterized in that, Before determining that the image to be tested has a printing defect when the cosine distance between the first feature vector and the second feature vector is less than a second predetermined threshold, the method further includes: Substituting the first eigenvector and the second eigenvector into the cosine distance formula yields the cosine distance, which is d = dot(a, b) / (norm(a) * norm(b)), where dot(a, b) is the dot product of the first eigenvector and the second eigenvector, norm(a) is the L2 norm of the first eigenvector, and norm(b) is the L2 norm of the second eigenvector.
6. A device for detecting printing defects, characterized in that, include: A building unit is used to build an autoencoder model, the autoencoder model including an encoder and a decoder, the encoder being used to convert a character image into a feature vector, and the decoder being used to convert the feature vector into the character image; The training unit is used to iteratively train the autoencoder model using multiple character images until the loss function value of the autoencoder model in the current iteration is less than the loss function value of the autoencoder model in the previous iteration, and the encoder of the autoencoder model in the current iteration is determined as an optimized encoder. An optimization unit is used to perform comparative learning on the primary optimization encoder to obtain a secondary optimization encoder, such that the feature vector output by the secondary optimization encoder contains information about the printing defects of the character image. An extraction unit is used to input the image to be tested and the template image into the secondary optimization encoder respectively to obtain a first feature vector and a second feature vector, wherein the image to be tested is a printed image of the template image; The first determining unit is configured to determine that the image under test has a printing defect if the cosine distance between the first feature vector and the second feature vector is less than a second predetermined threshold. The optimization unit includes: a building module, used to build a contrastive learning model based on the primary optimization encoder, wherein the output of the contrastive learning model is a printing defect difference degree, which is used to characterize the difference caused by printing defects before and after printing of multiple character images; a second adjustment module, used to perform a second adjustment step, adjusting the parameters of the primary optimization encoder in the contrastive learning model to obtain an updated contrastive learning model; an output module, used to perform an output step, using a contrast sample set as input to the updated contrastive learning model to obtain the printing defect difference degree, completing one iteration, wherein the contrastive learning model is used to determine that the contrast sample set includes multiple first character images and corresponding second character images, wherein the first character images are the character images used as printing templates, and the second character images are the character images obtained by printing the first character images; and a second repetition module, used to repeat the second adjustment step and the output step at least once, until the difference between the printing defect difference degree of the current iteration and the printing defect difference degree of the previous iteration is less than a third predetermined threshold, to obtain the secondary optimization encoder, wherein the secondary optimization encoder is the primary optimization encoder in the current contrastive learning model; The comparison sample set includes positive samples, simple negative samples, and difficult negative samples. The character position of the second character image x' in the positive sample differs from the character position of the first character image x in the positive sample. The character content of the second character image x'' in the simple negative sample differs from the character content of the first character image x in the simple negative sample. The character shape of the second character image x''' in the difficult negative sample differs from the character shape of the first character image x in the difficult negative sample. The output module includes an acquisition submodule, used to acquire the updated objective function of the comparison learning model to obtain the printing defect difference function, wherein the printing defect difference function is... , in, The number of positive samples. The number of simple negative samples. The number of negative samples in the difficult cases. The weights of the positive samples are... The weights of the simple negative samples are... The weights of the negative samples in the difficult cases, > , Indicates positive sample pairs Distance in the embedded space, Represents simple negative sample pairs Distance in the embedded space, Indicates the negative sample pairs of the difficult examples The distance in the embedding space, m is a preset margin value, representing a reference value for the distance between sample pairs; the calculation submodule is used to substitute the comparison sample set into the printing defect difference function to obtain the printing defect difference.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, wherein, when the program is executed, it controls the device on which the computer-readable storage medium is located to perform the method according to any one of claims 1 to 5.
8. A printing system, characterized in that, include: One or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs comprising methods for performing any one of claims 1 to 5.
Citation Information
Patent Citations
Auto-encoder anomaly detection method based on comparative learning
CN114724043A