Disclosure of Invention
The embodiment of the invention aims to provide a classification model construction method, a classification model and an object identification method, so that the constructed classification model has multiple levels and high classification performance.
In order to solve the above technical problem, an embodiment of the present invention provides a classification model construction method, including: acquiring a feature vector of each category in known images of N categories; clustering the N categories according to the feature vectors to form a multi-layer classification level tree; and taking the inner nodes of the multi-layer classification level tree as the nodes of the classification model, and training each node to obtain the classification model.
The embodiment of the invention also provides a classification model, and the classification model is constructed by using the classification model construction method.
The embodiment of the invention also provides an object identification method, which comprises the following steps: and inputting the image of the object to be recognized into the classification model to obtain a recognition result and the confidence coefficient of the recognition result.
Compared with the prior art, the embodiment of the invention provides a classification model construction method, which comprises the following steps: acquiring a feature vector of each category in known images of N categories; clustering the N categories according to the feature vectors to form a multi-layer classification level tree; and taking the inner nodes of the multi-layer classification level tree as the nodes of the classification model, and training each node to obtain the classification model. In the embodiment, a clustering method is adopted for N categories to form a multi-layer classification level tree, so that the similarity between different categories of the same level is relatively more uniform, the trained classifier has better performance, and a high-performance classification model with the multi-layer classification level tree is obtained.
In addition, clustering the N categories according to the feature vectors to form a multi-layer classification level tree, which specifically comprises the following steps: judging whether a divided hierarchical tree exists or not; and if the divided hierarchical tree does not exist, performing clustering hierarchical division on the N categories according to the characteristic vector to obtain a multi-layer classification hierarchical tree.
In addition, the method for obtaining the multilayer classification level tree by carrying out clustering level division on the N categories according to the feature vector specifically comprises the following steps: s11: selecting a category from the N categories; s12: calculating the distance between the selected category and all other categories; s13: calculating a distance threshold value and a clustering termination threshold value according to the obtained distance; s14: judging whether the distance threshold is smaller than a clustering termination threshold or not; s15: if the distance threshold is smaller than the clustering termination threshold, the distance between every two of all the N categories is obtained; s16: merging classes less than or equal to the distance threshold into a new class; s17: classifying the new class and other classes larger than the distance threshold into the same level; s18: selecting a category from the new category and other categories greater than the distance threshold; s19: the steps S12 to S18 are re-executed until the distance threshold is greater than the cluster end threshold. The scheme provides a specific implementation mode for directly clustering the N categories.
Further, step S13 specifically includes: drawing a curve according to the obtained distance, and fitting an inflection point of the curve by utilizing a polynomial equation; the value at the inflection point of the curve is used as a distance threshold; calculating the average value and the standard deviation of the distance; and solving a clustering termination threshold value according to the average value and the standard deviation. The scheme provides a specific solving method of a distance threshold and a clustering termination threshold.
In addition, after determining whether there is a hierarchical tree that has already been divided, the method further includes: and if the divided hierarchical tree exists, integrating the N categories and the divided hierarchical tree according to the feature vector to obtain a multi-layer classification hierarchical tree.
In addition, the method integrates the hierarchical tree with the divided hierarchical tree according to the feature vector to obtain a multi-layer classification hierarchical tree, and specifically comprises the following steps: s21: calculating the distance between every two categories of each level in the divided level tree, and calculating a clustering threshold corresponding to each level; s22: calculating the distance between each category in the N categories and each category of the last level in the divided level tree; s23: judging whether at least one clustering category with the distance smaller than the clustering threshold of the last level exists in the N categories; s24: if the clustering type exists, the clustering type is merged into the last level in the divided level tree, and other types except the clustering type in the N types are merged with other levels of the divided level tree in sequence; s26: judging whether all the N categories are merged into the divided hierarchical tree or not; s27: if the N categories are not all merged into the divided hierarchical tree, performing clustering hierarchical division on the categories which are not merged into the divided hierarchical tree and the divided hierarchical tree in the N categories to form a multi-layer classification hierarchical tree; s28: if all the N categories are merged into the divided hierarchical tree, taking the merged divided hierarchical tree as a multi-layer classification hierarchical tree; s29: and if the clustering categories do not exist, carrying out clustering hierarchy division on the N categories and the divided hierarchical tree to form a multi-layer classification hierarchical tree. The scheme provides a specific implementation mode for integrating N categories and the divided hierarchical tree to form a multi-layer classification hierarchical tree.
In addition, the internal nodes of the multi-layer classification level tree are used as the nodes of the classification model, and each node is trained to obtain the classification model, which specifically comprises the following steps: acquiring a training sample image and a test image containing the category of each node; inputting training sample images into a multi-layer classification level tree, and training internal nodes of each level of the multi-layer classification level tree; inputting the test image into the trained multilayer classification level tree to obtain a test precision value; training the inner node of each level of the multi-level classification level tree until the variation amplitude of the test precision value is within a preset range; and taking the trained multilayer classification level tree as a classification model.
In addition, the confidence of the recognition result is obtained by the following steps: predicting a confidence value of each internal node in each level of a multi-level classification level tree of the classification model; and taking the maximum confidence value in each level as the parent confidence of the level, and taking the product of all parent confidence of the node in which the recognition result is positioned as the confidence of the recognition result. In the scheme, a layer-by-layer calculation method is adopted, and the product of the confidences of all parents of the node where the recognition result is located is used as the confidence of the recognition result, so that the confidence of the recognition result of the final object recognition is more credible.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention more apparent, embodiments of the present invention will be described in detail below with reference to the accompanying drawings. However, it will be appreciated by those of ordinary skill in the art that numerous technical details are set forth in order to provide a better understanding of the present application in various embodiments of the present invention. However, the technical solution claimed in the present application can be implemented without these technical details and various changes and modifications based on the following embodiments.
The first embodiment of the present invention relates to a classification model construction method, and the core of the present embodiment is to provide a classification model construction method, including: acquiring a feature vector of each category in known images of N categories; clustering the N categories according to the feature vectors to form a multi-layer classification level tree; and taking the inner nodes of the multi-layer classification level tree as the nodes of the classification model. In the embodiment, a clustering method is adopted for N categories to form a multi-layer classification level tree, so that the similarity between different categories of the same level is relatively more uniform, the trained classifier has better performance, and a high-performance classification model with the multi-layer classification level tree is obtained.
The following describes implementation details of the classification model construction method according to the present embodiment in detail, and the following is only provided for easy understanding and is not necessary for implementing the present embodiment.
A flow diagram of the classification model construction method in the present embodiment is shown in fig. 1:
step 101: feature vectors for each of the N classes of known images are obtained.
Specifically, images of N categories are acquired, and a feature vector capable of representing each category is calculated. Preferably, the number of the images of each category is multiple, the feature vector of each image in each category is obtained, and the average value of the feature vectors of all the images in the category is calculated and used as the feature vector of the category.
Step 102: and judging whether the divided hierarchical tree exists. If not, go to step 103; if so, step 104 is entered.
Specifically, before constructing the classification model, it is determined whether a divided hierarchical tree exists, and if yes, the step 103 is performed only by integrating N classes into the divided hierarchical tree; if not, step 104 is performed, and a multi-level classification level tree is formed according to the N classes to obtain a classification model.
Step 103: and performing clustering hierarchy division on the N categories according to the feature vectors to obtain a multi-layer classification hierarchy tree.
Specifically, as shown in fig. 3, step 103 specifically includes steps S11 through S18.
S11: a category is selected from the N categories.
S12: the distance between the selected category and all other categories is calculated.
Specifically, in the above steps S11 to S12, if there is no classification tree into which the hierarchy is divided, it is necessary to form a classification hierarchy tree directly from the N classes. And randomly selecting one category from the N categories, calculating the distance between the selected category and all other categories, and then obtaining a distance threshold value and a clustering termination threshold value according to the obtained distance. The method for calculating the distance between the selected category and all other categories is the same as the above-mentioned method for calculating the distance, and is not described herein again.
S13: and solving a distance threshold value and a clustering termination threshold value according to the obtained distance.
Step S13 specifically includes: drawing a curve according to the obtained distance, and fitting an inflection point of the curve by utilizing a polynomial equation; the value at the inflection point of the curve is used as a distance threshold; calculating the average value and the standard deviation of the distance; and solving a clustering termination threshold value according to the average value and the standard deviation.
Specifically, when the distance threshold is determined according to the obtained distances, the first determined distances are sorted from small to large and a curve is drawn, so that the similarity between the class similar to the class and the class dissimilar to the class is obviously different on the whole, that is, the drawn curve has an inflection point, and the value of the inflection point is set as the distance threshold for the first clustering. The curve may be fitted by a polynomial equation such as a cubic equation, and the distance threshold may be obtained by solving an inflection point of the polynomial equation. When the clustering termination threshold is obtained according to the obtained distance, the size of the clustering termination threshold λ is set to be λ ═ μ + θ × δ, where μ denotes an average value of distances from the selected category to all other categories, δ denotes a standard deviation of distances from the selected category to all other categories, θ is an empirical value, and θ has a value in a range of 0 to 1.
S14: judging whether the distance threshold is smaller than the clustering termination threshold;
s15: and if the distance threshold is smaller than the clustering termination threshold, the distance between every two of all the N categories is obtained.
S16: the classes that are less than or equal to the distance threshold are merged into a new class.
S17: and classifying the new class and other classes larger than the distance threshold into the same level.
S18: a category is selected from the new category and other categories that are greater than the distance threshold.
S19: the steps S12 to S17 are re-executed until the distance threshold is greater than the cluster end threshold.
Specifically, in the foregoing steps S14 to S18, when the distance threshold is smaller than the clustering termination threshold, the distance between every two of all the N categories is obtained, the categories smaller than or equal to the distance threshold are merged into a new category, the merged categories in the new category are in the same hierarchy, all the new categories and other categories not merged are in the same hierarchy, and one category is selected from the new category and the other categories larger than the distance threshold, and the next clustering is continued. When the distance threshold is larger than the clustering termination threshold, clustering is terminated, and a multi-layer classification level tree formed by clustering is automatically obtained;
step 104: and integrating the N categories and the divided hierarchical tree according to the feature vector to obtain a multi-layer classification hierarchical tree.
Specifically, as shown in fig. 2, step 104 specifically includes steps S21 through S29.
S21: and calculating the distance between every two categories in the large class of each level in the divided level tree, and calculating a clustering threshold corresponding to each level.
Specifically, since a divided hierarchical tree is known, assuming that the known divided hierarchical tree is a D-level tree, when clustering the N categories, it is first considered whether the N categories can be merged into a certain class of a certain level of the D-level tree. Firstly, the distance between every two categories in the large category of each level in the divided level tree is obtained, the maximum value of the distance between every two categories in the large category is taken as the distance threshold value of the large category, the distance threshold values of all the large categories of the level are compared, and the maximum distance threshold value is taken as the clustering threshold value of the level. The distance between every two categories in the large category of each level in the divided level tree is obtained, the distance represents the similarity between every two categories, and the distance is smaller when the similarity between every two categories is higher; the lower the similarity between two categories, the greater the "distance". How to obtain the distance between two categories according to the feature vectors of the two categories belongs to the prior art, and the embodiment will not be described in detail.
S22: and calculating the distance between each of the N categories and each category of the last level in the divided hierarchical tree.
S23: and judging whether at least one clustering category with the distance smaller than the clustering threshold of the last level exists in the N categories.
S24: if there are clusterable categories, the clusterable categories are merged into the last level in the partitioned hierarchical tree.
S25: and sequentially merging other classes except the clustering class in the N classes and other levels of the divided level tree.
S26: and judging whether all the N categories are merged into the divided hierarchical tree.
S27: and if the N categories are not all merged into the divided hierarchical tree, performing cluster hierarchical division on the categories which are not merged into the divided hierarchical tree and the divided hierarchical tree in the N categories to form a multi-layer classification hierarchical tree.
S28: and if all the N categories are merged into the divided hierarchical tree, taking the merged divided hierarchical tree as a multi-layer classification hierarchical tree.
S29: and if the clustering categories do not exist, carrying out clustering hierarchy division on the N categories and the divided hierarchical tree to form a multi-layer classification hierarchical tree.
Specifically, in the above steps S22 to S28, since there are inevitably a plurality of categories in the last level in the divided hierarchical tree, distances between the N categories and each category in the last level in the divided hierarchical tree are calculated, respectively, and there are inevitably a plurality of distances, and if there is at least one clusterable category whose distance is smaller than the clustering threshold of the last level among the N categories, the clusterable category is merged into a similar category in the last level in the divided hierarchical tree; and combining the other classes except the clusterable class in the N classes with the other levels of the divided level tree in sequence, that is, calculating the distance between the other uncombined classes and each class in the previous level of the divided level tree, and comparing the distance with the clustering threshold of the previous level, which is the same as steps S21 to S23, except that the corresponding levels and classes are changed. If not, the N categories and the well-divided hierarchical tree are clustered and hierarchically divided to form a multi-layer classification hierarchical tree.
After sequentially merging other classes except the clustering classes in the N classes with other levels of the divided level tree, judging whether the N classes are all merged into the divided level tree or not, and if the N classes are all merged into the divided level tree, directly taking the merged divided level tree as a multi-layer classification level tree; if the classes which are not merged into the divided hierarchical tree exist in the N classes, placing the rest classes and the divided hierarchical tree at the same level, and carrying out cluster hierarchical division on the N classes and the divided hierarchical tree to form the multilayer classification hierarchical tree.
Step 105: and taking the inner nodes of the multi-layer classification level tree as the nodes of the classification model, and training each node to obtain the classification model.
Specifically, the inner nodes of the multi-layer classification level tree are used as the nodes of the classification model, a classifier is trained on each node, and the classification model is obtained after training is completed.
Compared with the prior art, the multi-layer classification level tree is formed by adopting a clustering method for the N categories in the embodiment, so that the similarity between different categories of the same level is relatively more uniform, the trained classifier has better performance, and the high-performance classification model with the multi-layer classification level tree is obtained.
A second embodiment of the present invention relates to a classification model construction method. The second embodiment is substantially the same as the first embodiment, and mainly differs in that: in the embodiment, a specific implementation manner of training the classification model is given.
As shown in fig. 3, the method for constructing a classification model in this embodiment specifically includes:
step 201: feature vectors for each of the N classes of known images are obtained.
Step 202: and judging whether the divided hierarchical tree exists. If yes, go to step 203; if not, go to step 204.
Step 203: and integrating the N categories and the divided hierarchical tree according to the feature vector to obtain a multi-layer classification hierarchical tree.
Step 204: and performing clustering hierarchy division on the N categories according to the feature vectors to obtain a multi-layer classification hierarchy tree.
Steps 201 to 204 are substantially the same as steps 101 to 104 in the first embodiment, and are not repeated herein to avoid repetition.
Step 205: training sample images and test images containing the class of each node are acquired.
Step 206: and inputting the training sample image into the multi-layer classification level tree, and training the internal node of each level of the multi-layer classification level tree.
Step 207: and inputting the test image into the trained multilayer classification level tree to obtain a test precision value.
Step 208: and training the inner nodes of each level of the multi-level classification level tree until the variation amplitude of the test precision value is within a preset range.
Step 209: and taking the trained multilayer classification level tree as a classification model.
Specifically, in step 205 to step 209, a training sample image and a test image including a category of each internal node of the multi-layered classification level tree are acquired, the training sample image is input into the multi-layered classification level tree, and the internal node of each level of the multi-layered classification level tree is trained using the training sample image; after training for a certain time, testing the multi-layer classification level tree after training by using a test image to obtain a test precision value (such as classification accuracy); and continuing to train the multi-layer classification level tree by using the training sample image until the variation amplitude of the test precision value is within a preset range, wherein the preset range can be set by a user, and the test precision value is represented to be changed only in a small amplitude and is not changed obviously any more. At this time, the training is considered to be completed, and the multi-layered classification level tree after the training is completed is used as the classification model.
Compared with the prior art, the embodiment of the invention provides a classification model construction method, which takes inner nodes of a multi-layer classification level tree as nodes of a classification model, trains each node to obtain the classification model, and specifically comprises the following steps: acquiring a training sample image and a test image containing the category of each node; inputting training sample images into a multi-layer classification level tree, and training internal nodes of each level of the multi-layer classification level tree; inputting the test image into the trained multilayer classification level tree to obtain a test precision value; training the inner node of each level of the multi-level classification level tree until the variation amplitude of the test precision value is within a preset range; the multi-layer classification level tree after training is used as a classification model, and a specific implementation mode of training the classification model is provided in the embodiment.
The steps of the above methods are divided for clarity, and the implementation may be combined into one step or split some steps, and the steps are divided into multiple steps, so long as the same logical relationship is included, which are all within the protection scope of the present patent; it is within the scope of the patent to add insignificant modifications to the algorithms or processes or to introduce insignificant design changes to the core design without changing the algorithms or processes.
A third embodiment of the present invention relates to a classification model constructed by the classification model construction method according to the first or second embodiment.
The fourth embodiment of the present invention also provides an object identification method, including: the image of the object to be recognized is input into the classification model in the third embodiment to obtain the recognition result and the confidence coefficient of the recognition result, and the classification model constructed by the first or second embodiment has a plurality of levels, so that the recognition result is more accurate when the object recognized by the classification model is used.
The confidence of the recognition result in the present embodiment is obtained by the following steps: predicting a confidence value of each internal node in each level of a multi-level classification level tree of the classification model; and taking the maximum confidence value in each level as the parent confidence of the level, and taking the product of all parent confidence of the node in which the recognition result is positioned as the confidence of the recognition result.
Specifically, in order to obtain a more accurate recognition result, a multi-level sequential recognition method is used to output a final recognition result, and the confidence is obtained by a layer-by-layer calculation method.
Assuming that the formed multi-level classification level tree is a K-level classification tree, for each internal node of each level of the K-level classification tree, respectively training a classifier, Lk represents the number of classifiers in each level, M represents the total number of classifiers, where L1 is 1, and the relationship between M and Lk is shown in the following formula (1):
M=L1+L2+…+Lk (1)
inputting an image of an object to be recognized, and classifying the image layer by using the classifier of each layer until the final classification result is obtained by the last layer. And regarding the confidence coefficient of the final recognition result, adopting a layer-by-layer calculation method. First, a first-layer classifier M1 is used for prediction, and the confidence of each internal node in the first layer is respectively P21, P22 and P23, and falseSetting the maximum confidence value in the first layer as P21'; then, the confidence maximum predicted by L2 classifiers in the second layer is multiplied by the parent confidence of the layer to be the confidence result of the layer, the confidence of each inner node in the second layer is P31, P32, P33, and the like, and assuming that the confidence maximum in the second layer is P31, the parent confidence of the layer is P31 ═ P21 ═ P31. And each layer is analogized in the same way until the K layer, and the maximum confidence value of the K layer is assumed to be PK1The parent confidence of the K-12 th layer is P(K-1)1The confidence value P of the final recognition result is obtainedK1`=P(K-1)1`*PK1That is, the confidence of a certain node in the last layer is the product of the confidence of the node and the confidences of all parents of the node.
In the embodiment, a layer-by-layer calculation method is adopted, and the product of the confidence degrees of all parents of the node where the recognition result is located is used as the confidence degree of the recognition result, so that the confidence degree of the final recognition result of the image of the object to be recognized is more credible.
The fifth embodiment of the present invention also provides a computer-readable storage medium storing a computer program, which when executed by a processor implements the classification model construction method of the first or second embodiment.
That is, as can be understood by those skilled in the art, all or part of the steps in the method for implementing the embodiments described above may be implemented by a program instructing related hardware, where the program is stored in a storage medium and includes several instructions to enable a device (which may be a single chip, a chip, or the like) or a processor (processor) to execute all or part of the steps of the method described in the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
It will be understood by those of ordinary skill in the art that the foregoing embodiments are specific examples for carrying out the invention, and that various changes in form and details may be made therein without departing from the spirit and scope of the invention in practice.