Method for training model based on positive sample clustering

Through the method of training model based on positive sample clustering, the positive sample images are automatically filtered and clustered, which solves the problem of low training efficiency caused by excessive positive samples in machine vision detection, and achieves efficient and stable training effects, and provides general The solution reduces labor costs and improves software capabilities.

CN119027757APending Publication Date: 2024-11-26BEIJING FOCUSIGHT TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411061725.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-05
Publication Date
2024-11-26

AI Technical Summary

Technical Problem

In machine vision detection, due to the excessive number of positive sample images, the training process is inefficient. The prior art relies on manual or algorithm-assisted screening, which has problems such as visual fatigue, high cost and non-generic algorithms.

Method used

Using a method based on positive sample clustering training model, we automatically filter representative positive samples through data preprocessing, feature extraction and clustering, combined with iterative training strategies, reduce the number of training sets and improve sample coverage.

Benefits of technology

Fully automatic processing is realized, training efficiency and effect stability is improved, labor and time cost is saved, and a general algorithm is designed to be integrated into related application software, which enhances the value of the software.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119027757A_ABST
    Figure CN119027757A_ABST
Patent Text Reader

Abstract

The invention relates to a method for training a model based on positive sample clustering. The method comprises the following steps: S1, preprocessing a data set; s2, feature extraction: obtaining a feature histogram; s3, clustering; and S4, performing iterative training by using a training strategy after clustering is completed. According to the method, a positive sample clustering method is adopted, and only representative positive samples are selected to participate in training, so that the number of the positive samples is greatly reduced; the training efficiency is improved, the time cost is saved, the number of positive samples is reduced, the quality of the positive samples is improved, the positive samples and the negative samples are more balanced, and therefore the training effect is better.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of machine vision detection, and in particular to a method based on a positive sample clustering training model. Background Art

[0002] In non-standard machine vision projects, in order to solve the problem of slow training speed caused by too many positive samples, a portion of positive samples are manually selected on the project site as training sets to participate in the training, thereby achieving the effect of speeding up.

[0003] However, manual processing requires human eyes to observe all positive sample images, filter out similar images in the positive samples, and select positive sample images with differences. Since the number of positive sample images is usually very large (tens of thousands), it is time-consuming and laborious to rely on human eyes for recognition, and it is easily affected by visual fatigue and different subjective cognition of different operators, resulting in no unified selection criteria, which will ultimately lead to unstable training effects under different circumstances.

[0004] For those who have algorithm capabilities, they will design algorithms for preliminary screening based on the characteristics of positive samples, and then have the results of the preliminary screening further screened manually, which is relatively more convenient than completely manual processing.

[0005] However, algorithm-assisted processing requires the processor to have algorithmic capabilities, which increases labor costs, and the algorithm designed for positive samples of a specific project can only be used for that type of positive samples of that project and cannot be universal. Summary of the invention

[0006] The technical problem to be solved by the present invention is to provide a method based on a positive sample clustering training model, which solves the problem of low efficiency of the training process caused by too many positive sample images in the process of machine vision detection using deep learning.

[0007] The technical solution adopted by the present invention to solve the technical problem is: a method based on a positive sample clustering training model, comprising the following steps:

[0008] S1. Dataset preprocessing: Calculate the positive sample image data of the training set, that is, the contrast value, average gray value and entropy value of all images in the data set, and calculate the contrast threshold t_contrast of the data set, and sort the data set from low to high according to the average gray value of the image;

[0009] S2, feature extraction: obtain feature histogram;

[0010] S3, clustering: including,

[0011] (1) Select the first image in the data set as a class. This image is called the template image of this class and is deleted from the data set.

[0012] (2) Select the remaining images in the data set in order. The currently selected image is called the image to be clustered.

[0013] (3) Perform similarity matching between the image to be clustered and the template image of the current class;

[0014] (4) If the matching score is less than the set threshold, the image to be matched and the template image of the current class are clustered into one class, and the image is deleted from the data set. Then, the process returns to step (2) and the next image is selected as the image to be clustered.

[0015] (5) Repeat the above steps to perform clustering until all images in the data set are deleted. The clustering is completed. Suppose that the images are clustered into n categories. Sort the images in each category from low to high according to the scores. The n categories of images obtained by clustering are called clustered data sets.

[0016] S4. Clustering is completed and iterative training is performed using the training strategy.

[0017] Furthermore, in step S1 of the present invention, the contrast value of each image is calculated as follows:

[0018] First, the image is Gaussian smoothed with a set size, and then the grayscale histogram is counted. The histogram is repeatedly smoothed with a Gaussian kernel of a set size until the histogram has only one trough. The grayscale value of the trough is used as the threshold to binarize the image into bright and dark areas. The average grayscale value of the bright area minus the average grayscale value of the dark area is the contrast value of the secondary image.

[0019] After counting the contrast of all image data, the data composed of the contrast of all images are classified into two categories using the Otsu threshold method to obtain the classification threshold, which is the contrast threshold.

[0020] Furthermore, in step S2 of the present invention, obtaining the feature histogram includes obtaining a grayscale histogram and a gradient direction histogram of each image in the data set;

[0021] The method for obtaining the gradient direction histogram is as follows: using the Sobel operator to obtain the gradient map of the image, binarizing the gradient amplitude map using the Otsu threshold method, counting the gradient directions in the bright area, thereby obtaining the gradient direction histogram, and obtaining the gradient direction histogram rotated from 0, 15, 30...360 degrees by the data circular displacement method, a total of 24 pictures.

[0022] Furthermore, in step (2) of step S3 of the present invention, if the average grayscale difference between the currently selected image and the image to be clustered is not less than a set value, then proceed to the subsequent steps, otherwise return to step (1).

[0023] Furthermore, in step (3) of step S3 of the present invention, the similarity matching method is:

[0024] If the contrast between the template image of the current class and the image to be clustered is less than t_contrast, their grayscale histograms are histogram matched to obtain the matching score, and the score threshold T = 0.25;

[0025] Otherwise, they are subjected to histogram matching of gradient direction histograms to obtain matching scores, with the score threshold T = 0.135.

[0026] Furthermore, the calculation formula of the grayscale histogram matching score of the present invention is:

[0027]

[0028] Among them: H1, H2 are 2 histograms,

[0029] and are the average grayscale values ​​of H1 and H2 respectively,

[0030] N is the number of gray levels in the histogram.

[0031] H1(I) and H2(I) are the values ​​of H1 and H2 at the horizontal axis at position I, respectively;

[0032] The gradient direction histogram matching method is: 24 gradient direction histograms of the template image and the first secondary gradient direction histogram with the matching image are used to calculate 24 matching scores according to the grayscale histogram matching formula, and the minimum matching score is taken as the final matching score.

[0033] Furthermore, in step S4 of the present invention, the iterative training step is:

[0034] A. Select the image with the highest entropy value in each category of n categories as the training set and train the network;

[0035] B. When the accuracy of the validation set reaches more than 70%, or the number of training rounds exceeds 30, the unselected clustering data set is sent to the network for prediction; if there is overkill, the overkill sample in each class with the largest difference from the average score of the samples in the class that have been moved into the training set is selected and added to the training set, and the graph is deleted from the clustering data set;

[0036] C. Continue training, and perform step B after each subsequent round of training until there is no overkill in the clustering data set.

[0037] The beneficial effect of the present invention is to solve the defects existing in the background technology:

[0038] 1. The present invention designs a general algorithm to cluster positive samples, selects a sample from each class for preliminary iterative training, and then cooperates with the subsequent training strategy of dynamically increasing positive samples, which ensures that the number of positive samples participating in the training is small and the appearance coverage of the positive samples participating in the training is guaranteed, thereby realizing full-automatic processing, which is more efficient than manual processing and has a stable effect, that is, it saves labor and time costs and improves the final effect;

[0039] 2. The present invention itself is a universal processing method, which solves the problem that the design algorithm-assisted processing cannot be universal, so that the method can be integrated into relevant application software as a universal function, making the software function more powerful and improving the value of the software; BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Figure 1 It is a flow chart of the training method of the present invention;

[0041] Figure 2 It is a flow chart of the image contrast calculation method of the present invention. DETAILED DESCRIPTION

[0042] The present invention will now be described in further detail in conjunction with the accompanying drawings and preferred embodiments. These drawings are simplified schematic diagrams, which only illustrate the basic structure of the present invention in a schematic manner, and therefore only show the components related to the present invention.

[0043] like Figure 1-Figure 2 The method shown is based on a positive sample clustering training model. It adopts a positive sample clustering method and only selects representative positive samples to participate in training, thereby greatly reducing the number of positive samples; improving the training efficiency, saving time costs, and reducing the number of positive samples, improving the quality of positive samples, and making positive and negative samples more balanced, thereby achieving better training results.

[0044] The specific method is as follows:

[0045] S1. Dataset preprocessing

[0046] (1) Calculate the average grayscale value, entropy value, and contrast value of each image in the positive samples in the training set (hereinafter referred to as the data set);

[0047] (2) Calculate the contrast threshold t_contratst of the data set. The calculation method is:

[0048] The contrast value of each image is calculated as follows: Figure 2As shown in the figure, the image is first smoothed with a 7*7 Gaussian, and then the grayscale histogram is counted. The histogram is repeatedly smoothed with a Gaussian kernel of size 3 until the histogram has only one trough. The grayscale value of the trough is used as the threshold to binarize the image into a bright area and a dark area. The average grayscale value of the bright area minus the average grayscale value of the dark area is the contrast value of the secondary image.

[0049] After counting the contrast of all image data, the data composed of the contrast of all images are classified into two categories using the Otsu threshold method to obtain the classification threshold, which is the contrast threshold t_contrast;

[0050] (3) Sort the data set from low to high according to the average grayscale of the image. All the data sets mentioned hereafter refer to the sorted data sets.

[0051] S2. Feature extraction

[0052] (1) Obtain the grayscale histogram of each image in the dataset;

[0053] (2) Use the Sobel operator to obtain the gradient map of the image, binarize the gradient amplitude map using the Otsu threshold method, count the gradient directions in the bright area, and obtain a gradient direction histogram. The gradient direction histogram is rotated from 0, 15, 30...360 degrees by the data circular shift method, a total of 24 pairs of gradient direction histograms;

[0054] S3, Clustering

[0055] (1) Select the first image in the data set as a class. This image is called the template image of this class and is deleted from the data set.

[0056] (2) Select the remaining images in the data set in order. The currently selected image is called the image to be clustered. If the average grayscale difference between the currently selected image and the image to be clustered is not less than 10, proceed to the following steps. Otherwise, return to step 1, that is, select the first image of the current data set as the template image.

[0057] (3) Perform similarity matching between the image to be clustered and the template image of the current class. The similarity matching method is:

[0058] If the contrast between the template image of the current class and the image to be clustered is less than t_contrast, their grayscale histograms are matched, and the matching score is recorded as score, with the score threshold T = 0.25;

[0059] Otherwise, they are subjected to histogram matching of gradient direction histograms, and the matching score is recorded as score, with the score threshold T = 0.135;

[0060] The calculation formula for the grayscale histogram matching score is as follows:

[0061]

[0062] Where: H1 and H2 are two histograms,

[0063] and are the average grayscale values of H1 and H2 respectively,

[0064] N is the number of grayscale levels of the histogram,

[0065] H1(I) and H2(I) are the values of H1 and H2 at I with the abscissa (gray level);

[0066] For the histogram matching of gradient directions, 24 gradient direction histograms of the template image and the first gradient direction histogram of the image to be matched (i.e., the gradient direction histogram without rotation) calculate 24 matching scores according to the formula of grayscale histogram matching, and the minimum matching score is taken as the final matching score;

[0067] (4) If score < T, then the image to be matched and the template image of the current class are grouped into one class, and at the same time, the image is deleted from the dataset. Otherwise, go back to step 2 and select the next image as the image to be clustered;

[0068] (5) Repeat the above steps for clustering until all images in the dataset are deleted, then the clustering is completed. Suppose it is grouped into n classes in total, and the images in each class are sorted from low score to high score (the score of the template image is recorded as 0). These n classes of images obtained by clustering are called the clustering dataset;

[0069] 4. Iterative training

[0070] (1) Select the image with the highest entropy value in each of the n classes as the training set (the positive samples, negative samples of the training set, and the test set and validation set are the same as the conventional training methods), and train the network;

[0071] (2) When the accuracy of the validation set reaches more than 70%, or the number of training rounds exceeds 30 rounds, send the unselected clustering dataset into the network for prediction. If there is overkill, select the overkill sample with the largest difference in the average score from the samples of this class that have been moved into the training set in each class, add it to the training set, and at the same time delete the image from the clustering dataset;

[0072] For example: If there are overkill cases in three images A, B, and C in a certain category of the unselected dataset, calculate the scores of these three images with all the samples that have been moved from this category to the training set, and calculate their average value according to the method in (3) of step S3. If the average matching score values are A < B < C, then move C to the training set;

[0073] (3) Continue training, and perform the operation in step 2 after each subsequent round of training until there is no overkill in the clustering dataset.

[0074] What is described in the above specification is only the specific implementation manner of the present invention. Various examples do not constitute a limitation to the essence of the present invention. Those of ordinary skill in the art can make modifications or deformations to the previously described specific implementation manner after reading the specification, without departing from the essence and scope of the invention.

Claims

1. A method based on positive sample clustering training model, Features: The following steps are included: S1. Dataset preprocessing: Calculate the positive sample image data of the training set, that is, the contrast value, average gray value and entropy value of all images in the data set, and calculate the contrast threshold t_contrast of the data set, and sort the data set from low to high according to the average gray value of the image; S2, feature extraction: obtain feature histogram; S3, Clustering: include, (1) Select the first image in the data set as a class. This image is called the template image of this class and is deleted from the data set. (2) Select the remaining images in the data set in order. The currently selected image is called the image to be clustered. (3) Perform similarity matching between the image to be clustered and the template image of the current class; (4) If the matching score is less than the set threshold, the image to be matched and the template image of the current class are clustered into one class, and the image is deleted from the data set. Then, the process returns to step (2) and the next image is selected as the image to be clustered. (5) Repeat the above steps to perform clustering until all images in the data set are deleted. The clustering is completed. Suppose that the images are clustered into n categories. Sort the images in each category from low to high according to the scores. The n categories of images obtained by clustering are called clustered data sets. S4. Clustering is completed and iterative training is performed using the training strategy.

2. The method based on positive sample clustering training model as claimed in claim 1, Features: In step S1, the contrast value of each image is calculated as follows: First, the image is Gaussian smoothed with a set size, and then the grayscale histogram is counted. The histogram is repeatedly smoothed with a Gaussian kernel of a set size until the histogram has only one trough. The grayscale value of the trough is used as the threshold to binarize the image into bright and dark areas. The average grayscale value of the bright area minus the average grayscale value of the dark area is the contrast value of the secondary image. After counting the contrast of all image data, the data composed of the contrast of all images are classified into two categories using the Otsu threshold method to obtain the classification threshold, which is the contrast threshold.

3. The method based on positive sample clustering training model as claimed in claim 1, Features: In the step S2, obtaining the feature histogram includes obtaining the grayscale histogram and the gradient direction histogram of each image in the data set; The method for obtaining the gradient direction histogram is as follows: using the Sobel operator to obtain the gradient map of the image, binarizing the gradient amplitude map using the Otsu threshold method, counting the gradient directions in the bright area, thereby obtaining the gradient direction histogram, and obtaining the gradient direction histogram rotated from 0, 15, 30...360 degrees by the data circular displacement method, a total of 24 pictures.

4. The method based on positive sample clustering training model as claimed in claim 1, Features: In step (2) of step S3, if the average grayscale difference between the currently selected image and the image to be clustered is not less than a set value, then proceed to the following steps, otherwise return to the previous step.

5. The method based on positive sample clustering training model as claimed in claim 3, Features: In step (3) of step S3, the similarity matching method is: If the contrast between the template image of the current class and the image to be clustered is less than t_contrast, their grayscale histograms are histogram matched to obtain the matching score, and the score threshold T = 0.25; Otherwise, they are subjected to histogram matching of gradient direction histograms to obtain matching scores, with the score threshold T = 0.

135.

6. The method based on positive sample clustering training model as claimed in claim 5, Features: The calculation formula of the grayscale histogram matching score is: Among them: H1, H2 are 2 histograms, and are the average grayscale values ​​of H1 and H2 respectively, N is the number of gray levels in the histogram. H1(I) and H2(I) are the values ​​of H1 and H2 at the horizontal axis at position I, respectively; The gradient direction histogram matching method is: 24 gradient direction histograms of the template image and the first secondary gradient direction histogram with the matching image are used to calculate 24 matching scores according to the grayscale histogram matching formula, and the minimum matching score is taken as the final matching score.

7. The method based on positive sample clustering training model as claimed in claim 1, Features: In step S4, the iterative training steps are: A. Select the image with the highest entropy value in each category of n categories as the training set and train the network; B. When the accuracy of the validation set reaches more than 70%, or the number of training rounds exceeds 30, the unselected clustering data set is sent to the network for prediction; If there is overkill, select the overkill sample in each class that has the largest difference from the average score of the samples in that class that have been moved into the training set, add it to the training set, and delete the graph from the clustering data set; C. Continue training, and perform step B after each subsequent round of training until there is no overkill in the clustering data set.