A lace retrieval method based on deep learning
The feature vector of the lace pattern is extracted through the twin neural network, and the Euclidean distance is used for retrieval, which solves the problem of low lace retrieval accuracy in the existing technology and achieves retrieval effects with high accuracy and strong generalization ability.
Patent Information
- Application Number
- CN202011559620.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-25
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2040-12-25
AI Technical Summary
Existing lace retrieval methods have low retrieval accuracy, are affected by manual annotation and dependency on feature extraction operators, and have poor robustness and generalization capabilities.
The twin neural network is used to extract the feature vector of the lace pattern. The positive and negative example pairs constructed through training are used for retrieval using Euclidean distance. Features are automatically extracted without human intervention and the retrieval accuracy is improved.
A high-accuracy lace image retrieval is achieved, with top1 accuracy reaching 98.39% and top10 accuracy 100%, significantly improving the robustness and generalization ability of the retrieval.
Smart Images

Figure CN112632313B
Abstract
Description
Technical Field
[0001] The invention relates to a lace retrieval method based on deep learning, and belongs to the technical field of machine vision and deep learning. Background Art
[0002] In recent years, the lace patterns developed by enterprises are complex and varied, and the number and variety are very large. The lace pattern database of enterprises may even contain tens of thousands of types. In the actual production or sales process, for the lace samples provided by customers, enterprises need to quickly find the lace that is most similar to the samples from the existing database, so as to quickly determine the design process and plan, and improve management and production efficiency.
[0003] As for the search of lace, it was initially based on text, that is, each type of lace was manually annotated, and then searched based on the annotations. This search method is easily affected by the subjective factors of different annotators, because each annotator may have a different description of the same lace, which makes the search very difficult and the search accuracy is relatively low.
[0004] In order to improve the retrieval efficiency and accuracy, content-based image retrieval methods have gradually been widely used. In content-based image retrieval methods, color features, texture features or geometric features of lace images are extracted by manually determining feature extraction operators. However, practical applications have shown that the image retrieval method with manually determined feature extraction operators has a low retrieval accuracy for new lace because it relies on manually determined feature extraction operators, which are determined based on existing lace patterns. In other words, its robustness and generalization ability are poor. Summary of the invention
[0005] In order to solve the problem of low retrieval accuracy in the current lace retrieval method, the present invention provides a lace retrieval method based on deep learning, the method comprising:
[0006] The twin neural network is used to extract the feature vector of the lace pattern to be retrieved, and the feature vectors are compared with the feature vectors of each lace pattern in the lace pattern database in turn, and the Euclidean distance between the two is calculated. The lace pattern corresponding to the minimum Euclidean distance is the retrieval result of the lace pattern to be retrieved; wherein the twin neural network is a twin neural network network trained by the following steps:
[0007] Step 1: Construct positive example pairs (A, P) or negative example pairs (A, N) for training the twin neural network;
[0008] Each lace pattern corresponds to M groups of flower pattern cycle images, and the cycle starting positions of each group of flower pattern cycle images are different; according to whether the flower pattern cycle images correspond to the same lace pattern, each two flower pattern cycle images are defined as a positive pair (A, P) or a negative pair (A, N); wherein A and P are two flower pattern cycle images corresponding to the same lace pattern, and A and N are two flower pattern cycle images corresponding to two different lace patterns;
[0009] Step 2: Use the two flower pattern cycle images in the positive pair (A, P) or the negative pair (A, N) as input sample pairs of the twin neural network to train the twin neural network;
[0010] If the two flower pattern cycle images in the positive example pair (A, P) are used as the input sample pair of the twin neural network, the twin neural network is trained with the purpose of minimizing the contrast loss function; if the two flower pattern cycle images in the negative example pair (A, N) are used as the input sample pair of the twin neural network, the twin neural network is trained with the purpose of maximizing the contrast loss function.
[0011] Optionally, the contrast loss function is:
[0012]
[0013] Where W is the network weight; X1 and X2 are the two flower cycle images in the input sample pair, respectively; Y is the label. If the input sample pair is a positive pair (A, P), the label Y is 1; if the input sample pair is a negative pair (A, N), the label Y is 0; D w is the Euclidean distance between X1 and X2; m is a pre-set threshold, m>0.
[0014] Optionally, when the input sample pair is a positive example pair (A, P), the contrast loss function is transformed into:
[0015]
[0016] When the input sample pair is a negative example pair (A, N), the contrast loss function is transformed into:
[0017]
[0018] Optionally, when using negative example pairs (A, N) to train the twin neural network, the negative example pairs (A, N) are divided into three categories: simple bigrams, moderate bigrams, and difficult bigrams:
[0019] Simple binary group: After less than 10 iterations, the L value in formula (3) can approach 0;
[0020] Moderate binary group: The network needs to go through more than 10 and less than 50 iterations, and the L value in formula (3) can approach 0;
[0021] Difficult binary group: The network needs more than 50 iterations before the L value in formula (3) can approach 0;
[0022] Moderate bigrams or difficult bigrams are selected as input sample pairs to train the Siamese neural network.
[0023] Optionally, before the step 1: constructing a positive example pair (A, P) or a negative example pair (A, N) for training the twin neural network, the lace pattern is also preprocessed:
[0024] The lace pattern is obtained by scanning with a scanner, and grayscale transformation is performed on the lace pattern to obtain a grayscale image;
[0025] Perform image rotation on the grayscale image to obtain a rotated image;
[0026] According to the rotated image, different starting positions are selected to obtain multiple groups of flower pattern cycle images each containing a flower pattern cycle;
[0027] Scale the pattern cycle images that all contain one pattern cycle to the same size;
[0028] The flower-pattern cycle images scaled to the same size are normalized so that their pixel grayscale values are scaled to between [0, 1].
[0029] Optionally, performing image rotation on the grayscale image to obtain a rotated image includes:
[0030] The minimum circumscribed rectangle MAR of the lace is extracted, and then the deflection angle between MAR and the horizontal direction is obtained. Finally, the image is rotated using the image rotation function to obtain the rotated image.
[0031] Optional, D w is the Euclidean distance between X1 and X2, calculated as:
[0032]
[0033] X1 and X2 have the same dimensions, n is the dimension of X1 and X2, (x1, x2, …, x n ) is the feature vector of sample X1, (y1,y2,…,y n ) is the feature vector of sample X2.
[0034] Optionally, when the trained twin neural network retrieves lace patterns, it obtains in advance a 128-dimensional feature vector corresponding to each flower pattern cycle image in the database, and uses the ratio of the height to the width of the flower pattern cycle image as an effective feature, performs feature fusion with the pre-obtained 128-dimensional feature vector to form a 129-dimensional feature vector, which is saved in the feature database for subsequent comparison with the feature vector of the lace pattern to be retrieved.
[0035] Optionally, the backbone network of the twin neural network is VGG16, and the weights of the two VGG16 networks are shared.
[0036] The present application also provides an application method of the above-mentioned deep learning-based lace retrieval method in lace production.
[0037] The beneficial effects of the present invention are:
[0038] When performing lace image retrieval, the present application automatically extracts the features of lace images by using a deep learning network without human intervention, so that the retrieval method has good robustness and strong generalization ability; specifically, a twin neural network is used, and the (A, P) positive example pairs and (A, N) negative example pairs required for training the twin neural network are constructed. When training the twin neural network, the Euclidean distance between the feature vectors of samples A and P in the positive example pair is made as small as possible, and for samples A and N in the negative example pair, the Euclidean distance between their feature vectors is made as large as possible, and finally a trained twin neural network is obtained to realize the retrieval of lace images. It has been verified that the lace retrieval method proposed in the present application has a high retrieval accuracy, and the percentage of the number of accurate results retrieved in the first position among all retrieval results accounts for 98.39% of the total number of test samples, and the percentage of the number of accurate results retrieved in the top 10 positions accounts for 100% of the total number of test samples. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0040] FIG. 1 is a schematic diagram of a lace pattern cycle with different starting and ending points in one embodiment of the present invention.
[0041] Figure 2 It is a schematic diagram of a twin neural network in one embodiment of the present invention.
[0042] Figure 3The figure is a flow chart of a lace retrieval method provided by an embodiment of the present invention.
[0043] FIG. 4 is a schematic diagram of search results of a lace search system provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0044] To make the objectives, technical solutions and advantages of the present invention more clear, the embodiments of the present invention will be further described in detail below with reference to the accompanying drawings.
[0045] Embodiment 1:
[0046] The present embodiment provides a lace retrieval method based on deep learning, the method comprising: using a twin neural network to extract a feature vector of a lace pattern to be retrieved, and comparing the feature vectors with the feature vectors of each lace pattern in a lace pattern database in turn, calculating the Euclidean distance between the two, and the lace pattern corresponding to the minimum Euclidean distance is the retrieval result of the lace pattern to be retrieved; wherein the twin neural network is a twin neural network network trained by the following steps:
[0047] Step 1: Construct positive example pairs (A, P) or negative example pairs (A, N) for training the twin neural network;
[0048] Each lace pattern corresponds to M groups of flower pattern cycle images, and the cycle starting positions of each group of flower pattern cycle images are different; according to whether the flower pattern cycle images correspond to the same lace pattern, each two flower pattern cycle images are defined as a positive pair (A, P) or a negative pair (A, N); wherein A and P are two flower pattern cycle images corresponding to the same lace pattern, and A and N are two flower pattern cycle images corresponding to two different lace patterns;
[0049] Step 2: Use the two flower pattern cycle images in the positive pair (A, P) or the negative pair (A, N) as input sample pairs of the twin neural network to train the twin neural network;
[0050] If the two flower pattern cycle images in the positive example pair (A, P) are used as the input sample pair of the twin neural network, the twin neural network is trained with the purpose of minimizing the contrast loss function; if the two flower pattern cycle images in the negative example pair (A, N) are used as the input sample pair of the twin neural network, the twin neural network is trained with the purpose of maximizing the contrast loss function.
[0051] Embodiment 2:
[0052] This embodiment provides a lace retrieval method based on deep learning, see Figure 3 , the method comprising:
[0053] Step 1: Preprocess the scanned lace images and construct training and test data sets.
[0054] 1. Lace image preprocessing
[0055] All lace images are preprocessed in the following order: grayscale transformation, image rotation, pattern acquisition cycle, image scaling, and normalization. Because the image size obtained by a scanner is equivalent to the actual size of the lace, and the lace in the image obtained by a camera or other means is not the actual size, which makes subsequent work impossible, so the lace image described in this application can usually be obtained by scanning with a scanner.
[0056] (1) Grayscale transformation: convert all lace images into grayscale images;
[0057] The lace image obtained by the scanner is generally a color image in RBG format, which needs to be converted into a grayscale image. Because the lace retrieval method provided in this application is to find the lace that is most similar to the flower pattern of the sample to be retrieved in the database, it has nothing to do with color. And because the color image is a three-channel image and the grayscale image is a single-channel image, the color image has a larger amount of data; therefore, the neural network processes the color image more slowly than the grayscale image, so the use of grayscale images in this application can speed up the subsequent preprocessing. In addition, the grayscale image is used as the input of the deep neural network, and the image features can be obtained more quickly.
[0058] (2) Image rotation: Perform image rotation on the grayscale image to obtain a rotated image;
[0059] like Figure 1A As shown, when using a scanner to obtain lace images, there will often be some inevitable deflection. In order to improve the accuracy of lace image detection, the lace images need to be rotated.
[0060] The method of rotation processing is to extract the minimum circumscribed rectangle (MAR) of the lace, then obtain the deflection angle between the MAR and the horizontal direction, and finally use the image rotation function to rotate the image.
[0061] (3) Obtaining a pattern cycle: Based on the rotated image, select different starting positions to obtain a plurality of pattern cycle images each containing a pattern cycle;
[0062] like Figure 1AAs shown, lace patterns generally change periodically, and one cycle is a pattern cycle. In order to improve the retrieval accuracy, the lace retrieval method provided in this application is based on pattern cycles, rather than the entire lace image. In addition, the pattern cycles obtained during actual retrieval are generally not completely consistent with the pattern cycles obtained during training the system (complete consistency of pattern cycles means that the starting and ending positions of the two pattern cycles are exactly the same). Therefore, in order to improve the generalization performance of the retrieval algorithm, when training the retrieval system, for each lace image, multiple pattern cycles at different positions will be obtained, such as Figure 1B and 1C They are Figure 1A In addition, based on a lace, obtaining multiple pattern cycles as training samples is also a method to expand the training samples and avoid overfitting of deep neural networks.
[0063] (4) Image scaling: scaling the pattern cycle images that all contain one pattern cycle to the same size;
[0064] The geometric dimensions, i.e., height and width, of the pattern loops at different positions obtained from the same lace should be the same, but the geometric dimensions of the pattern loops of different lace laces are generally different, but the input images of the subsequent deep neural network need to be of uniform size. The VGG16 network used in this application has an input image size of 224x224, that is, all pattern loops need to be scaled to 224x224.
[0065] (5) Normalization: Normalize the flower pattern cycle images scaled to the same size so that their pixel grayscale values are scaled to between [0, 1];
[0066] Normalize the image and scale the pixel grayscale value to [0,1] to speed up the convergence of the deep neural network.
[0067] 2. Construct training and test data sets
[0068] Because lace patterns change periodically, the lace retrieval method proposed in this application is based on the pattern cycle of each lace. In order to expand the number of samples and avoid network overfitting, for each lace, 4 pattern cycles at different positions are obtained, so that 4 groups of pattern cycle images can be obtained. Three groups of pattern cycle images are selected to construct the training data set, and the other group of pattern cycle images is used as the test data set.
[0069] The lace retrieval method of this application is based on the pairing of flower pattern cycle images in the training data set. Figure 2 The twin neural network shown in is trained; Figure 2As shown in the figure, the input of the twin neural network is 2 image samples (i.e., each pattern cycle image in the training data set), where sample 1 is a lace pattern cycle image, recorded as the anchor image. If sample 2 and the anchor image are pattern cycle images of the same lace at different positions, sample 2 is recorded as the positive image; if sample 2 and the anchor image are pattern cycle images of different laces, sample 2 is recorded as the negative image.
[0070] For the convenience of description, the Anchor picture, Positive picture and Negative picture are referred to as A picture, P picture and N picture respectively.
[0071] From the three groups of flower pattern cycles obtained above, the (A, P) positive example pairs and (A, N) negative example pairs required for training the twin neural network can be obtained, where the two flower pattern cycle images of the (A, P) positive example pair belong to the same lace, while the two flower pattern cycles of the (A, N) negative example pair belong to different lace.
[0072] Step 2: Train the Twin Neural Network
[0073] The training data set obtained in step 1 can be used for training Figure 2 The twin neural network shown in the figure, where the (A, P) positive example pair or the (A, N) negative example pair can be used as the input sample pair of the network. The backbone network of the twin neural network is VGG16, and the weights of the two VGG16 networks are shared (that is, the weights are the same). Each VGG16 network outputs a 128-dimensional feature vector, that is Figure 2 The feature vector 1 and feature vector 2 in are used, and finally the contrast loss function of the twin neural network is calculated based on the two feature vectors.
[0074] The contrast loss function can be defined as:
[0075]
[0076] Where W is the network weight. X1, X2 are input samples 1 and 2 respectively, and Y is the label.
[0077] If samples X1 and X2 belong to the same lace, that is, a positive pair (A, P), then Y = 0;
[0078] If they do not belong to the same lace, that is, (A, N) negative example pairs, then Y=1.
[0079] D w is the Euclidean distance between two samples X1 and X2, and the calculation formula is as follows:
[0080]
[0081] X1 and X2 have the same dimension, n is the dimension of the feature vector of X1 and X2. In this embodiment, the feature vector corresponding to samples X1 and X2 is 129-dimensional, (x1, x2, …, x n ) is the feature vector of sample X1, (y1,y2,…,y n ) is the feature vector of sample X2.
[0082] m is the set threshold (m>0).
[0083] When training the network, you need to minimize the contrast loss function value.
[0084] When Y = 0, that is, the network input is a positive example pair (A, P), the contrast loss function is transformed into:
[0085]
[0086] Minimize the L value in formula (2), that is, for the positive example pair (A, P), the network needs to be trained to minimize the distance D between two samples A and P belonging to the same lace w .
[0087] When Y=1, that is, the network input is a negative example pair (A, N), the contrast loss function is transformed into:
[0088]
[0089] Minimize the L value in formula (3), that is, for the negative example pair (A, N), the network needs to be trained to maximize the distance D between two samples A and N belonging to different laces w .
[0090] The purpose of setting the threshold m is: when the distance between the negative example pair sample A and sample N is less than the threshold m, the network will continue to train to make the distance close to m; and when the distance between the negative example pair sample A and N exceeds the threshold m, the network reaches the convergence condition and no further iterative training is required.
[0091] In general, the purpose of training a twin neural network is: for the positive example pair input (A, P), the Euclidean distance between the two feature vectors of samples A and P obtained by the network is as small as possible; and for the negative example pair input (A, N), the Euclidean distance between the two feature vectors of samples A and N obtained by the network is as large as possible.
[0092] Furthermore, in order to speed up the convergence of the network when training the twin neural network, the present invention adopts a strategy of learning samples of difficult negative examples. According to the distance between the feature vectors of the (A, N) negative example pairs obtained by the network, all (A, N) negative example pairs can be divided into three categories: simple bigrams, moderate bigrams and difficult bigrams.
[0093] (1) Simple binary pair: When the negative example (A, N) is input into the network, the distance between the feature vectors of samples A and N obtained by the network is large. After less than 10 iterations of the network, the L value in formula (3) can approach 0.
[0094] (2) Moderate binary pairs: When the negative example (A, N) is input into the network, the distance between the feature vectors of samples A and N obtained by the network is not too large. The network needs to go through more than 10 and less than 50 iterations before the L value in formula (3) approaches 0.
[0095] (3) Difficult binary pairs: When the negative example (A, N) is input into the network, the distance between the feature vectors of samples A and N obtained by the network is small. The network needs more than 50 iterations before the L value in formula (3) may approach 0.
[0096] Therefore, when training the twin neural network, if the input (A, N) negative example pair is a simple binary pair, the network can easily meet the convergence requirements (the L value in formula (3) is 0), but the generalization ability of the trained network is poor. Therefore, when training the network, the strategy of learning from difficult negative example pairs should be adopted, and moderate binary pairs or difficult binary pairs should be selected as training samples to effectively promote the training of the network. It has been verified that using moderate binary pairs or difficult binary pairs as training samples can reduce the training time by 30%.
[0097] Specifically, when training the twin neural network, the following method is used to select training samples for each batch:
[0098] Assuming that each batch of training is based on 32 lace images, then according to the method of constructing the training data set in step 1, for each lace image, 3 flower pattern cycle images at different positions are obtained to construct the training data set. 32 lace images can obtain 96 flower pattern cycle images. Then, the number of samples of (A, P) positive example pairs is The number of samples of (A, N) negative pairs is For all (A, N) negative example pairs, the current network can be used to obtain the distance between the corresponding feature vectors. The 96 (A, N) negative example pairs with the smallest distance are selected as hard negative example samples, and sent to the twin neural network for training as a batch of samples together with 96 (A, P) positive example pairs, and finally a trained twin neural network is obtained.
[0099] Step 3: Test the lace retrieval system
[0100] when Figure 2After the twin neural network is trained, the VGG16 network has the ability to extract effective features from the lace pattern cycle. In order to verify the retrieval ability of the trained twin neural network for lace images, a test data set is used for testing.
[0101] Figure 3 The figure is a schematic diagram of the lace retrieval process of the present invention. As shown in the figure, in order to speed up the retrieval efficiency of the system during testing, after the twin neural network is trained, a group of lace pattern cycle diagrams for training are selected, and the 128-dimensional feature vector corresponding to each pattern cycle is obtained in advance by the trained VGG16 network. In addition, as known from step one, the geometric dimensions of the pattern cycles of different lace laces are generally different, so the ratio of the height to the width of the pattern cycle can be used as an effective feature, and the 128-dimensional feature vector obtained by the network is fused to form a 129-dimensional feature vector, which is saved in the feature database.
[0102] To test the performance of the retrieval system, for each lace pattern cycle diagram in the test data set obtained in step 1, as the image to be retrieved, the trained VGG16 network obtains its corresponding 128-dimensional feature vector, which is then fused with its aspect ratio feature to obtain a 129-dimensional feature vector. This is then matched one-to-many with the feature vectors corresponding to each lace image in the feature database, that is, the Euclidean distance between the image to be retrieved and the two feature vectors corresponding to each lace image in the feature database is calculated, and the 10 retrieval results that are closest to the image to be retrieved are given in ascending order.
[0103] FIG. 4 shows one of the lace search result graphs. Figure 4A The lace pattern to be retrieved is a lace pattern numbered 002 selected from the database; Figure 4B The top 10 most similar lace images are arranged in ascending order of distance. The numbers in the database are 002, 031, 160, 061, 392, 327, 353, 378, 402 and 004. It can be clearly seen from the figure that Figure 4B The lace pattern with the smallest distance to the lace pattern to be searched is the same as the lace pattern to be searched, indicating that the accurate result retrieved is ranked first.
[0104] In the present invention, the retrieval performance evaluation index can be the top1 and top10 accuracy. Among them, the top1 accuracy indicates that for each image to be retrieved in the test data set, the number of accurate results retrieved by the system in the first position accounts for the percentage of the total number of test samples; the top10 accuracy indicates that for each image to be retrieved in the test data set, the number of accurate results retrieved by the system in the top 10 positions accounts for the percentage of the total number of test samples. The accurate result is the lace closest to the image to be retrieved. Because the images to be retrieved selected for testing and training in this application are all lace patterns selected from the database, the "accurate result" mentioned in this application is the image to be retrieved itself, which can be determined according to the number of the lace pattern.
[0105] In the present invention, it is assumed that there are 500 lace patterns in a lace pattern database of a certain enterprise, and each lace pattern includes three flower-type cycle patterns.
[0106] In order to compare and illustrate that the accuracy of the retrieval method of the present application is higher than that of the existing retrieval method, it is compared with the "LBP texture operator feature matching method", "GGCM-based texture feature matching method", and "LBP, GLCM, GCCM, Canny method using multiple texture features for matching and feature fusion". The results are as follows:
[0107] The top 1 retrieval accuracy of the LBP texture operator feature matching method is 66.38%; the top 1 retrieval accuracy of the GGCM texture feature matching method is 66.28%; the top 1 retrieval accuracy of the LBP, GLCM, GCCM, and Canny methods using multiple texture features for matching and after feature fusion is 94.14%. For the introduction of the above three methods, please refer to "Cao Xia, Li Yueyang, Luo Haichi, Jiang Gaoming, Cong Honglian. Improved texture feature retrieval method for lace [J]. Journal of Textile Research, 2016, 37(06): 142-147+154.".
[0108] The retrieval method provided in this application has an accuracy rate of 98.39% for top 1 retrieval and 100% for top 10 retrieval.
[0109] Some steps in the embodiments of the present invention may be implemented using software, and the corresponding software program may be stored in a readable storage medium, such as a CD or a hard disk.
[0110] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A lace retrieval method based on deep learning, It is characterized in that The method comprises: The twin neural network is used to extract the feature vector of the lace pattern to be retrieved, and the feature vectors are compared with the feature vectors of each lace pattern in the lace pattern database in turn, and the Euclidean distance between the two is calculated. The lace pattern corresponding to the minimum Euclidean distance is the retrieval result of the lace pattern to be retrieved; wherein the twin neural network is a twin neural network network trained by the following steps: Step 1: Construct positive example pairs (A, P) or negative example pairs (A, N) for training the twin neural network; Each lace pattern corresponds to M groups of flower pattern cycle images, and the cycle starting positions of each group of flower pattern cycle images are different; according to whether the flower pattern cycle images correspond to the same lace pattern, each two flower pattern cycle images are defined as a positive pair (A, P) or a negative pair (A, N); wherein A and P are two flower pattern cycle images corresponding to the same lace pattern, and A and N are two flower pattern cycle images corresponding to two different lace patterns; Step 2: Use the two flower pattern cycle images in the positive pair (A, P) or the negative pair (A, N) as input sample pairs of the twin neural network to train the twin neural network; If the two flower pattern cycle images in the positive example pair (A, P) are used as the input sample pair of the twin neural network, the twin neural network is trained with the purpose of minimizing the contrast loss function; if the two flower pattern cycle images in the negative example pair (A, N) are used as the input sample pair of the twin neural network, the twin neural network is trained with the purpose of maximizing the contrast loss function; The contrast loss function is: Where W is the network weight; X1 and X2 are the two flower cycle images in the input sample pair, respectively; Y is the label. If the input sample pair is a positive pair (A, P), the label Y is 1; if the input sample pair is a negative pair (A, N), the label Y is 0; D w is the Euclidean distance between X1 and X2; m is a pre-set threshold, m>0; When the input sample pair is a positive example pair (A, P), the contrast loss function is transformed into: When the input sample pair is a negative example pair (A, N), the contrast loss function is transformed into: D w is the Euclidean distance between X1 and X2, calculated as: n is the dimension of the feature vectors of X1 and X2, (x 1 ,x 2 ,…,x n ) is the feature vector of sample X1, (y 1 ,y 2 ,…,y n ) is the feature vector of sample X2.
2. The method according to claim 1, It is characterized in that When using negative example pairs (A, N) to train the twin neural network, the negative example pairs (A, N) are divided into three categories: simple bigrams, moderate bigrams, and difficult bigrams: Simple binary group: After less than 10 iterations, the L value in formula (3) can approach 0; Moderate binary group: The network needs to go through more than 10 and less than 50 iterations, and the L value in formula (3) can approach 0; Difficult binary group: The network needs more than 50 iterations before the L value in formula (3) can approach 0; Moderate bigrams or difficult bigrams are selected as input sample pairs to train the Siamese neural network.
3. The method according to claim 2, It is characterized in that The step 1: before constructing a positive example pair (A, P) or a negative example pair (A, N) for training the twin neural network, also includes preprocessing the lace pattern: The lace pattern is obtained by scanning with a scanner, and grayscale transformation is performed on the lace pattern to obtain a grayscale image; Perform image rotation on the grayscale image to obtain a rotated image; According to the rotated image, different starting positions are selected to obtain multiple groups of flower pattern cycle images each containing a flower pattern cycle; Scale the pattern cycle images that all contain one pattern cycle to the same size; The flower-pattern cycle images scaled to the same size are normalized so that their pixel grayscale values are scaled to between [0, 1].
4. The method according to claim 3, It is characterized in that The step of performing image rotation on the grayscale image to obtain a rotated image includes: The minimum circumscribed rectangle MAR of the lace is extracted, and then the deflection angle between MAR and the horizontal direction is obtained. Finally, the image is rotated using the image rotation function to obtain the rotated image.
5. The method according to claim 4, It is characterized in that When the trained twin neural network is performing lace pattern retrieval, it obtains the 128-dimensional feature vector corresponding to each flower pattern cycle image in the database in advance, and takes the ratio of the height to the width of the flower pattern cycle image as an effective feature, which is fused with the pre-obtained 128-dimensional feature vector to form a 129-dimensional feature vector, which is saved in the feature database for subsequent comparison with the feature vector of the lace pattern to be retrieved.
6. The method according to claim 5, It is characterized in that The backbone network of the twin neural network is VGG16, and the weights of the two VGG16 networks are shared.
7. The method according to any one of claims 1 to 6, It is characterized in that The deep learning-based lace retrieval method is applied in lace production.
