Disclosure of Invention
In view of the above, it is a primary objective of the present invention to provide a contact lens edge defect detection model, a method for creating the same, and a method for detecting the same, which are intended to at least partially solve at least one of the above-mentioned problems.
In order to achieve the above object, according to an aspect of the present invention, there is provided a method for establishing a contact lens edge defect detection model, including:
(1) acquiring a sample image of the edge defect of the contact lens;
(2) preprocessing the obtained sample image to obtain a sample characteristic image;
(3) carrying out defect labeling on the sample characteristic images, summarizing the labeled sample characteristic images and establishing a training set;
(4) performing model training on the training set and performing fine adjustment to obtain an initial defect detection model;
(5) and detecting the initial defect detection model to obtain an initial accuracy, adjusting the initial defect detection model and then detecting again when the initial accuracy is less than a preset accuracy, and obtaining a final defect detection model when the initial accuracy is more than or equal to the preset accuracy.
As another aspect of the invention, a contact lens edge defect detection model is also provided, which is obtained by adopting the establishing method.
As a further aspect of the invention, there is also provided a method for detecting edge defects of a contact lens, comprising:
acquiring a detection image of a contact lens to be detected;
preprocessing the detection image to obtain a sample characteristic image corresponding to the detection image;
inputting the sample characteristic image into the contact lens edge defect detection model, and outputting a detection result, namely completing the detection of the contact lens edge defect.
Based on the above technical solution, the contact lens edge defect detection model, the establishment method and the detection method thereof according to the present invention have at least one of the following advantages over the prior art:
1. the invention provides a contact lens defect detection method based on deep learning, which solves the problems of strong subjective consciousness, low efficiency, fussy traditional image processing and detection and the like of manual detection;
2. according to the invention, through deep learning to train the mark sample with defects and continuous self-learning adjustment of parameters, a robust model with extremely high accuracy can be obtained, and the model can accurately extract defect characteristics, so that the rapid online detection of the contact lenses is realized.
Detailed Description
In order that the objects, technical solutions and advantages of the present invention will become more apparent, the present invention will be further described in detail with reference to the accompanying drawings in conjunction with the following specific embodiments.
The invention provides a novel detection method in view of the defects of the existing defect detection method of the contact lens in the prior art. The method is a contact lens defect detection method based on deep learning.
The invention discloses a method for establishing a contact lens edge defect detection model, which comprises the following steps:
(1) acquiring a sample image of the edge defect of the contact lens;
(2) preprocessing the obtained sample image to obtain a sample characteristic image;
(3) carrying out defect labeling on the sample characteristic images, summarizing the labeled sample characteristic images and establishing a training set;
(4) performing model training on the training set and performing fine adjustment to obtain an initial defect detection model;
(5) and detecting the initial defect detection model to obtain an initial accuracy, adjusting the initial defect detection model and then detecting again when the initial accuracy is less than a preset accuracy, and obtaining a final defect detection model when the initial accuracy is more than or equal to the preset accuracy.
In some embodiments of the present invention, the method for detecting the initial accuracy in step (5) comprises: and inputting the detected sample image into an initial defect detection model, automatically identifying and outputting a defect mark by the initial defect detection model, comparing with a manual detection result, and counting to obtain the initial accuracy.
In some embodiments of the present invention, the fine tuning method in the initial detection model forming process in step (4) includes a transfer learning technique.
In some embodiments of the present invention, the method for preprocessing the sample image in step (2) includes filtering, image equalization and image enhancement.
In some embodiments of the present invention, the sample image in step (1) is an image captured based on a preset imaging method.
In some embodiments of the present invention, the specimen images in step (1) comprise at least 1200 contact lens images with defects.
In some embodiments of the present invention, the contact lens of step (1) is a damaged-edge contact lens.
The invention also discloses a contact lens edge defect detection model obtained by adopting the establishing method.
The invention also discloses a method for detecting the edge defect of the contact lens, which comprises the following steps:
acquiring a detection image of a contact lens to be detected;
preprocessing the detection image to obtain a sample characteristic image corresponding to the detection image;
inputting the sample characteristic image into the contact lens edge defect detection model, and outputting a detection result, namely completing the detection of the contact lens edge defect.
In one exemplary embodiment, the method for establishing a novel contact lens edge defect detection model of the present invention comprises:
acquiring a contact lens sample image, and establishing a defect sample database; the specimen images include at least 1200 contact lens images with different types of defects;
preprocessing the sample image to obtain a sample characteristic image corresponding to the sample;
marking the defect area of the sample characteristic image, summarizing the marked sample image and establishing a training set;
performing model training on the training set, performing deep learning, and adjusting a score threshold value based on defect recognition to obtain an initial defect detection model;
inputting the sample image into the initial defect detection model, and outputting to obtain a predicted defect image corresponding to the sample image; the defect prediction image is a sample image of a defect area marked by the defect detection model;
and collecting test samples of the contact lenses, and establishing a contact lens defect test set. And judging whether the defect identification achieves the detection purpose or not based on the accuracy of the training model in the detection result of the test sample set. The accuracy rate set in this example was 95%.
And carrying out result statistics on the predicted defect image, and continuously adjusting a model according to a result to finally obtain the contact lens edge defect detection model.
The sample image is an image shot based on a preset imaging method;
wherein the defective contact lens is a damaged-edge contact lens.
The method comprises the following steps of carrying out model training on the training set, carrying out fine tuning by using a transfer learning technology, and outputting to obtain an initial defect detection model, and specifically comprises the following steps:
the method comprises the steps of carrying out initial training on a training set by utilizing a neural network to obtain a defect region of an initial prediction defect image, comparing the defect region of the initial prediction defect image with a defect region marked in a sample image, continuously updating training through comparison, and carrying out fine tuning by utilizing a transfer learning technology, wherein the fine tuning standard is a sub-training process and a verification set, when training, the network can use one part of input picture data as the training set, one part of the input picture data is divided into the verification set, parameters of training set training can be compared with the verification set, and iterative updating is carried out according to the comparison. And after the training is finished, fine adjustment is carried out again to form an initial defect detection model.
Wherein, the statistics of the predicted defect image result determines the accuracy of the defect detection model in the training process;
and when the accuracy is smaller than the preset accuracy, re-changing the corresponding parameters and the model selection and executing the training process until the accuracy is not smaller than the preset accuracy.
The embodiment also discloses a novel method for detecting edge defects of contact lenses, which comprises the following steps:
acquiring a detection image of glasses to be detected;
preprocessing the detection image to obtain a sample characteristic image corresponding to the detection image;
inputting the sample characteristic image into a defect detection model obtained by training according to the defect detection model training method, and outputting a predicted image of the detection image;
and determining the defects of the glasses to be detected based on the predicted image, judging whether the glasses to be detected contain the defects, comparing the defects with an artificial visual inspection result, and finishing the detection of the edge defects of the contact lenses.
In another exemplary embodiment, the method for detecting edge defects of a contact lens of the present invention comprises:
step A: acquiring a contact lens sample image under a specific imaging mode;
and B: preprocessing the sample image to obtain a sample characteristic image corresponding to the sample;
and C: marking the defect area of the sample characteristic image, summarizing the marked sample image and establishing a training set;
step D: performing model training on the training set, performing fine adjustment by using a transfer learning technology, and outputting to obtain an initial defect detection model;
step E: and D, inputting the sample image into an initial defect detection model, outputting to obtain a predicted defect image corresponding to the sample image, carrying out result statistics on the predicted defect image, continuously adjusting the model according to the result, and when the accuracy of the predicted defect image is lower than 95%, carrying out the step D again to adjust the model. And when the accuracy is greater than or equal to 95%, obtaining the final contact lens edge defect detection model.
Step F: and E, inputting the detection image of the contact lens to be detected into the contact lens edge defect detection model obtained in the step E for detection, namely completing the detection of the contact lens edge defect.
Wherein, in the imaging mode of the step A, at least one of the following methods is included: transmission, reflection and refraction, even in an imaging mode, change the brightness of a light source, and acquire images on the reverse surface and the front surface of the contact lens.
Wherein, the image preprocessing in the step B comprises: filtering, image equalization and image enhancement.
Wherein the defect area in step C is an edge damage area of the contact lens.
In the transfer learning technology, the initialization model is trained secondarily by using Faster R-CNN.
The technical solution of the present invention is further illustrated by the following specific embodiments in conjunction with the accompanying drawings. It should be noted that the following specific examples are given by way of illustration only and the scope of the present invention is not limited thereto.
The method for establishing the contact lens edge defect detection model of the present embodiment is shown in fig. 1, and specifically includes the following steps:
step A: selecting a specific imaging mode for one or more defects of the contact lens to make the defects prominent, and acquiring images by using an industrial CCD camera;
and B: preprocessing the acquired sample image to obtain a sample characteristic image corresponding to the sample;
and C: marking the defect area of the sample characteristic image, summarizing the marked sample image and establishing a training set;
step D: performing model training on the training set, performing fine adjustment by using a transfer learning technology, and outputting to obtain an initial defect detection model;
step E: inputting the sample image into an initial defect detection model, outputting to obtain a predicted defect image corresponding to the sample image, carrying out result statistics on the predicted defect image, and continuously adjusting the model according to the result. And when the accuracy of the predicted defect image is lower than 95%, the step D is carried out again to adjust the model. And when the accuracy is greater than or equal to 95%, obtaining the final contact lens edge defect detection model.
And E, inputting the detection image of the contact lens to be detected into the final contact lens edge defect detection model obtained in the step E for detection, namely completing the detection of the contact lens edge defect.
Specifically, in step a, the resolution of the acquired image may be from 1280 × 1024 to 2048 × 3072, and the imaging system acquires 1200 pictures, as shown in fig. 2, with clear boundaries and obvious defects.
And B, preprocessing the image in the step B, including filtering, image equalization and image enhancement, dividing the acquired image into a training set and a verification set and a test set according to the proportion of 8: 1, and carrying out defect marking on the training set.
And C, model training is carried out on 960 training set pictures and 120 verification set pictures, and a proper model frame and a convolution neural network are selected, wherein the model frame is one of fast R-CNN, Rception, ResNet and VGG. Setting an initial learning _ rate to be 0.01, iters _ num to be 100000, batch _ size to be 1, train _ size to be 120, setting a confidence parameter to be 0.8, calculating the error between a training set and a verification set by using a random gradient descent method, modifying a weight parameter according to the error, and fine-tuning by using fast R-CNN after the training is finished to obtain an initial training model so as to ensure the robustness and accuracy of the generated model. The fine tuning standard is that the sub-training process is compared with the verification set, and after the training is finished, the fine tuning is carried out to form an initial defect detection model
And for the generated model, performing final verification by using 120 test sets to perform result statistics on the predicted defect image, wherein the image prediction result is shown in fig. 3, the position of the defect is marked, the type of the defect and the defect are marked, and for the 120 test sets, when the accuracy is lower than 95%, selecting a neural network and setting various hyper-parameters, and retraining the model to obtain an expected model (namely the contact lens edge defect detection model).
The specific embodiments described herein are merely illustrative of the principles of the invention. Various modifications or additions may be made to the described embodiments or alternatives in a similar manner by those skilled in the art without departing from the principles of the present invention or exceeding the scope of the invention as defined in the appending claims.
Although the present invention is directed to contact lens edge defects, it does not exclude the possibility of using other terms, nor does it exclude other defect types.
The above-mentioned embodiments are intended to illustrate the objects, technical solutions and advantages of the present invention in further detail, and it should be understood that the above-mentioned embodiments are only exemplary embodiments of the present invention and are not intended to limit the present invention, and any modifications, equivalents, improvements and the like made within the spirit and principle of the present invention should be included in the protection scope of the present invention.