Neural network training and classification methods, systems, devices, and media
By selecting easily classifiable samples and constructing a center template loss function, and utilizing convolutional neural networks of two orders of magnitude, the problem of low accuracy in fine-grained image classification is solved, achieving efficient fine-grained image classification.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- GUANGZHOU SHIYUAN ELECTRONICS CO LTD
- Filing Date
- 2021-07-06
- Publication Date
- 2026-07-03
AI Technical Summary
Existing technologies have low accuracy in fine-grained image classification, and require manual annotation or complex network design when using location recognition.
Two convolutional neural networks of different orders of magnitude are used. The initial training samples are used to select easy-to-classify samples. The center template is determined using the easy-to-classify samples to construct the loss function. The second convolutional neural network is then trained to achieve accurate classification.
It achieves high-accuracy fine-grained image classification through conventional deep convolutional neural networks without the need for additional manual annotation, simplifying network design.
Smart Images

Figure CN115587619B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence, and more specifically, to methods, systems, devices, and media for training and classifying neural networks. Background Technology
[0002] Image recognition is an important branch of big data and artificial intelligence. It typically utilizes machine learning models such as neural networks to identify and classify images. Fine-grained images are among the most challenging types of images to process in image recognition. The characteristic of fine-grained images is that their features are very similar, differing only in key areas, while other parts may have identical or nearly identical features. For example, "dog" and "cat" are two broad categories, and classifying images of dogs and cats is relatively easy. However, the category of "cat" has subcategories, such as British Shorthair and American Shorthair. For animals, different subcategories within the same category often differ only in fur, color, or facial features. Distinguishing between two subcategories of "cat" falls under the category of fine-grained image recognition. Such subtle differences present a significant challenge for both humans and computers.
[0003] Currently, the following methods are generally used for classifying fine-grained images. The first method is to directly use deep convolutional neural networks (DCNNs), such as VGGNet and ResNet. However, this method is less effective due to the difficulty in capturing the differences in key areas, with an accuracy rate of only 75%–85%. Another method is based on localization and recognition, first locating key areas and then classifying them. However, the accuracy of recognition largely depends on the accuracy of localization and requires redundant annotation information, increasing both manual and time costs. The last method involves complex network design and the incorporation of GANs, Attention mechanisms, etc. This is currently the most effective method, but its network design is extremely complex and not the most suitable approach for classification tasks. Summary of the Invention
[0004] The present invention aims to overcome at least one of the defects of the prior art and provides a neural network training and classification method, system, device and medium to solve the problems of insufficient classification accuracy for fine-grained images, the need for manual annotation when using location recognition, or the need to use complex network design.
[0005] The technical solution adopted in this invention includes:
[0006] A neural network training method includes: training a first convolutional neural network using a plurality of initial training samples to obtain a trained first convolutional neural network; the plurality of initial training samples are divided into a plurality of categories; inputting the initial training samples into the trained first convolutional neural network to obtain classification results of the initial training samples; selecting easily classifiable samples from the initial training samples based on the classification results of the initial training samples; determining a center template for each category based on all the easily classifiable samples; constructing a loss function for a second convolutional neural network based on the center template; training the second convolutional neural network using the initial training samples to obtain a trained second convolutional neural network; wherein the order of magnitude of the first convolutional neural network is smaller than that of the second convolutional neural network.
[0007] The method provided by this invention trains two convolutional neural networks of different orders of magnitude using initial training samples. The first convolutional neural network, which has a smaller order of magnitude, can quickly filter out easily classifiable samples. The loss function of the second convolutional neural network is constructed using the center templates of each category determined by the easily classifiable samples. The second convolutional neural network, which has a larger order of magnitude, is then trained using this loss function and the initial training samples to obtain a second convolutional neural network that can accurately classify the initial training samples, especially the non-easily classifiable samples. The training process does not require additional manual annotation, and both the first and second convolutional neural networks are conventional deep convolutional neural networks, so there is no need to redesign complex network structures.
[0008] Furthermore, the loss function constructed using the center template is used to keep the distance between each initial training sample and the center template of its corresponding category less than or equal to a first threshold, while keeping the distance between each initial training sample and the center template of its non-corresponding category greater than or equal to a second threshold.
[0009] Furthermore, based on the classification results of the initial training samples, easy-to-classify samples of all categories are selected from the initial training samples. Specifically, it is determined whether the classification result of each initial training sample conforms to its corresponding category, and the initial training samples corresponding to the classification results that conform to the determination are taken as easy-to-classify samples in the initial training samples.
[0010] Furthermore, the initial training samples of each category contain at least three easily classifiable samples; the center template of each category is determined based on all the easily classifiable samples, specifically by: determining the sum of distances between each easily classifiable sample and other easily classifiable samples in the same category, and taking the easily classifiable sample with the smallest sum of distances to other easily classifiable samples in the same category as the center template of its corresponding category.
[0011] The central template is determined by the sum of the distances between each easily classifiable sample and other easily classifiable samples of the same category, which ensures that the determined central template has a high similarity to any sample of the same category.
[0012] Furthermore, the loss function is specifically as follows: L=λ1*L cp +λ2*L cn ; wherein, the L cp and the L cn Satisfies [X] + =max(0,X); where L is the loss function; where L cp The loss function is based on the distance between each initial training sample and the center template of its corresponding category; the L... cn The loss function is based on the distance between each hard-to-classify sample and the center template of its non-corresponding category, where b is the total number of initial training samples, and the vector of the initial training samples is x1, x2, ..., xn. b The initial training samples are divided into n (n≤b) categories, and the number of initial training samples in each of the n categories are m1, m2, ..., mn, respectively. n The vectors of the center templates for the n categories are c1, c2, ..., c3. n The c1, c2...c n One-to-one correspondence with m1, m2...m n The i and j represent the current order of the parameters; the δ cp The first threshold; the δ cn The second threshold is defined as λ1 and λ2, which are weighting coefficients.
[0013] Furthermore, the δ cp The value is 0.
[0014] Further, the sum of distances between each easily classifiable sample and other easily classifiable samples of the same category is determined by: obtaining and determining the sum of distances between each easily classifiable sample and other easily classifiable samples of the same category based on the vector of each easily classifiable sample after passing through the Softmax layer of the first convolutional neural network.
[0015] Furthermore, the first convolutional neural network is a micro neural network; the second convolutional neural network is a large neural network or a very large neural network.
[0016] A classification method includes: inputting a sample into a trained second convolutional neural network as described in any one of claims 1 to 8 to obtain a classification result for the sample.
[0017] A neural network training system includes: a first network training module for training a first convolutional neural network using a plurality of initial training samples to obtain a trained first convolutional neural network; wherein the plurality of initial training samples are divided into a plurality of categories; an easy-to-classify sample screening module for inputting the initial training samples into the trained first convolutional neural network to obtain the classification results of the initial training samples, and screening out easy-to-classify samples from the initial training samples based on the classification results of the initial training samples; a center template determination module for determining a center template for each category based on all the easy-to-classify samples; a second network training module for constructing a loss function for a second convolutional neural network based on the center template; training the second convolutional neural network using the initial training samples to obtain a trained second convolutional neural network; wherein the order of magnitude of the first convolutional neural network is smaller than the order of magnitude of the second convolutional neural network.
[0018] A computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the above-described neural network training method and / or the above-described classification method.
[0019] A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-described neural network training method and / or the above-described classification method.
[0020] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0021] The method provided by this invention utilizes a first convolutional neural network trained with a small order of magnitude from the initial training samples. This neural network can quickly filter out easily classifiable samples. The loss function of the second convolutional neural network is constructed using the center templates of each category determined by the easily classifiable samples. The second convolutional neural network with a large order of magnitude is then trained using this loss function and the initial training samples to obtain a second convolutional neural network that can accurately classify the initial training samples, especially the non-easily classifiable samples. The training process does not require additional manual annotation, and both the first and second convolutional neural networks are conventional deep convolutional neural networks, eliminating the need to redesign complex network structures. Attached Figure Description
[0022] Figure 1 This is a flowchart illustrating method steps S1 to S4 of an embodiment of the present invention.
[0023] Figure 2 This is a flowchart illustrating the method steps S21 to S23 of an embodiment of the present invention.
[0024] Figure 3 This is a flowchart illustrating the method steps S31 to S32 of an embodiment of the present invention.
[0025] Figure 4 This is a schematic diagram illustrating the principle of the loss function in the method of an embodiment of the present invention.
[0026] Figure 5 This is a flowchart illustrating steps T1 to T7 in one preferred embodiment of the present invention.
[0027] Figure 6 This is a schematic diagram of the system module composition of an embodiment of the present invention. Detailed Implementation
[0028] The accompanying drawings are for illustrative purposes only and should not be construed as limiting the invention. To better illustrate the following embodiments, some parts in the drawings may be omitted, enlarged, or reduced, and do not represent the actual product dimensions; it is understandable to those skilled in the art that some well-known structures and their descriptions may be omitted in the drawings.
[0029] This embodiment provides a neural network training method, such as... Figure 1 As shown, steps S1 to S4 are included:
[0030] S1: Train the first convolutional neural network using several initial training samples to obtain the trained first convolutional neural network;
[0031] The initial training samples are divided into several categories, meaning at least two categories. Each sample in the initial training samples belongs to a specific category. Specifically, initial training samples refer to image samples, and more specifically, fine-grained image samples. For example, initial training samples might be image samples of a particular animal. Image samples of the same animal share many common features, and the differences between samples are small, thus belonging to fine-grained image samples. Within this single animal image sample, the categories can be different breeds, different coat colors, or different sizes of that animal, etc.
[0032] The first convolutional neural network is a convolutional neural network with a smaller order of magnitude, which means that it contains fewer layers.
[0033] S2: Input the initial training samples into the first convolutional neural network after training to obtain the classification results of the initial training samples. Based on the classification results of the initial training samples, select easily classifiable samples from the initial training samples.
[0034] The architecture of the first convolutional neural network is basically the same as that of existing conventional neural networks with a smaller scale. Its main purpose is to filter out easily classifiable samples from the initial training samples. Easily classifiable samples are those that can be correctly classified even by a small neural network. Correspondingly, there are also samples in the initial training samples that cannot be correctly classified by a small neural network alone. These samples are not easily classifiable samples, and can also be called difficult-to-classify samples.
[0035] Preferably, the first convolutional neural network is a micro-neural network, which refers to a neural network model that requires fewer parameters and has lower computational cost. A first convolutional neural network that is a micro-neural network has a faster training speed, lower training difficulty, and can ensure that samples it can correctly classify are easily classified samples. In a more specific implementation, the first convolutional neural network can be ResNet-18, i.e., a deep residual network with 18 layers, which is a micro-convolutional neural network.
[0036] Based on the definition of easily classifiable samples, such as Figure 2 As shown, the specific execution process of step S2 is as follows:
[0037] S21: Input the initial training samples into the first convolutional neural network after training to obtain the classification results of the initial training samples;
[0038] The initial training samples used for training are samples whose classification results are known; that is, the category to which each initial training sample belongs is known. After the initial training samples are used as test samples and input into the first convolutional neural network after training, the first convolutional neural network will classify the initial training samples and output the classification result for each initial training sample. Test samples are similar to initial training samples, also referring to samples whose classification results are known, but test samples are not used to train the neural network; they are generally only used to test the classification accuracy of the trained neural network.
[0039] S22: In the classification results of the initial training samples, determine whether the classification result of each initial training sample matches its corresponding category. If it matches, proceed to step S23; if it does not match, repeat step S22 until the judgment of all initial training samples is completed.
[0040] The classification result of each initial training sample is compared with its known classification results to determine whether the classification result output by the first convolutional neural network matches the known classification results.
[0041] S23: Take the initial training sample corresponding to the classification result that meets the judgment as the easy-to-classify sample in the initial training sample, and repeat step S22 until the judgment of all initial training samples is completed.
[0042] Since the first convolutional neural network is a micro neural network, and the method in this embodiment does not make any additional improvements to its loss function or other layers, if the classification result output by the first convolutional neural network matches the classification result of the initial training sample, it means that the trained first convolutional neural network can correctly classify the initial training sample. Therefore, according to the definition of easy-to-classify sample, the initial training sample is regarded as an easy-to-classify sample.
[0043] S3: Determine the central template for each category based on all easily classifiable samples;
[0044] The central template for each category refers to the sample that can represent all samples in that category. For example, if the initial training samples are image samples, such as image samples of dogs, and one of the categories in the image samples is Husky, then the central template for that category is the image sample that best represents the Husky breed.
[0045] The center template is obtained by comparing the sum of distances between easily classifiable samples, and the initial training samples for each class contain at least three easily classifiable samples. Based on this, as... Figure 3 As shown, the specific execution process of step S3 is as follows:
[0046] S31: Determine the sum of distances between each easily classifiable sample and other easily classifiable samples in the same category;
[0047] Specifically, the easily classifiable samples are image samples. When calculating the distance between the easily classifiable samples and other easily classifiable samples, the vectors of the image samples are used for calculation, that is, the vector distance between the vector of each easily classifiable sample and the vectors of other easily classifiable samples is calculated.
[0048] Preferably, the vector of each easily classifiable sample is the vector after passing through the Softmax layer of the first convolutional neural network. The vector distance between the vectors of each easily classifiable sample and other easily classifiable samples is calculated using the vector after passing through the Softmax layer of the first convolutional neural network. The Softmax layer refers to processing the samples input to this layer using the Softmax function and outputting the result of the function processing. The Softmax function is a normalized exponential function, the purpose of which is to represent the results of multiple classifications of the input samples in the form of probabilities.
[0049] S32: The easily classifiable sample with the smallest sum of distances to other easily classifiable samples in the same category is used as the center template of its corresponding category;
[0050] Based on the definition of the central template, it can be seen that the central template can represent all samples of its corresponding category. When this definition is reflected in the specific vector distance, the central template is the vector of the sample with the smallest sum of vector distances with all other samples.
[0051] S4: Construct the loss function of the second convolutional neural network using the central template, and train the second convolutional neural network using the initial training samples to obtain the trained second convolutional neural network.
[0052] Specifically, the second convolutional neural network is a convolutional neural network with a larger order of magnitude, meaning that it contains a larger number of layers.
[0053] The second convolutional neural network has a network architecture that is basically the same as any existing conventional neural network of a larger scale. Its main purpose is to accurately classify all initial training samples, especially the difficult-to-classify samples in the initial training samples.
[0054] Preferably, the second convolutional neural network is a large-scale neural network or a very large-scale neural network. A large-scale neural network or a very large-scale neural network refers to a neural network model that requires a large number of parameters, a large number of layers, and has a high computational cost. In a more specific embodiment, the second convolutional neural network can be ResNet-101, which is a deep residual network with 101 layers, belonging to the category of large-scale convolutional neural networks.
[0055] Specifically, by using the central template to construct the loss function of the second convolutional neural network, the trained second convolutional neural network can avoid retraining when new samples are added to a very small number of categories, and can also achieve high classification accuracy.
[0056] Specifically, the constructed loss function in the second convolutional neural network functions as follows: it keeps each initial training sample close to the center template of its corresponding class, while keeping each initial training sample far away from the center template of its non-corresponding class. More specifically, the loss function is used to keep the distance between each initial training sample and the center template of its corresponding class less than or equal to a first threshold, and to keep the distance between each initial training sample and the center template of its non-corresponding class greater than or equal to a second threshold.
[0057] The first threshold is the distance value, specifically the vector distance value, which refers to the maximum distance that each initial training sample should maintain with the center template of its corresponding category. When the distance between the initial training sample and the center template of its corresponding category is greater than the first threshold, it indicates that the distance between the two is too large, and the second convolutional neural network is prone to incorrectly classifying the initial training sample into a non-corresponding category.
[0058] The second threshold is the distance value, specifically the vector distance value, which refers to the minimum distance that each initial training sample should maintain with the center template of its non-corresponding category. When the distance between the initial training sample and the center template of its non-corresponding category is less than the second threshold, it means that the distance between the two is too small, and the second convolutional neural network is prone to incorrectly classifying the initial training sample into the non-corresponding category.
[0059] The constructed loss function L is specifically as follows:
[0060] L=λ1*L cp +λ2*L cn ;
[0061] The loss function Lcp and the loss function Lcn are added together with certain weights to form the loss function L. λ1 and λ2 are weight coefficients. The value of the weight coefficient λ1 represents the weight of the loss function Lcp in the function value output by the loss function L. Similarly, the value of the weight coefficient λ2 represents the weight of the loss function Lcn in the function value output by the loss function L. The values of the weight coefficients λ1 and λ2 can be determined according to the actual situation.
[0062]
[0063] L cp The loss function is based on the distance between each initial training sample and the center template of its corresponding class.
[0064] b represents the total number of initial training samples;
[0065] The initial training sample vectors are x1, x2, ..., x b ;
[0066] The initial training samples are divided into n (n≤b) categories;
[0067] The initial training samples for each of the n classes are m1, m2, ..., m. n ;
[0068] The vectors of the center templates for the n categories are c1, c2, ..., c. n c1, c2...c n One-to-one correspondence m1, m2...m n ;
[0069] δ cp The first threshold;
[0070] i and j represent the current order of the parameters. For example, when i = 1, x i This indicates that the current sample is the first initial training sample, m. i This represents the number of items currently in the first category, c. i This represents the vector that is currently the center template for the first category.
[0071] Each category's initial training samples contain at least 3 easily classifiable samples. If each category's initial training samples contain only easily classifiable samples, then there is no need to train a second convolutional neural network. Therefore, the total number of initial training samples, b, should be greater than 3n, meaning that at least one category contains one difficult-to-classify sample.
[0072] L cp Satisfies [X] + =max(0,X), meaning that only when L is satisfied... cp The input condition, that is, the vector x of the i-th initial training sample. i The vector C of the center template of its corresponding category j The distance between them and the first threshold δ cp When the difference between the subtractions is greater than 0, L cp The current input value is the vector x of the i-th initial training sample. i The vector C of the center template of its corresponding category j The distance between them and the first threshold δ cp The difference between the subtractions, not 0; when L is not satisfied. cp When inputting conditions, L cp The current input value is 0. Finally, the average of all input values is calculated based on the number of classes belonging to the initial training samples, and this average is used as L. cp The output value.
[0073] The final output value of the loss function represents the loss situation of the event, in L cp In this loss function, the event is that the distance between the vector of each initial training sample and the vector of the center template of its corresponding class remains less than or equal to a first threshold δ. cp When the loss function output value is minimized, it means the loss of the event is also minimized, and the event can be fully realized. In other words, when L... cp The output function value reaches its minimum value, which is L. cp When each input value can only be 0, it means that the distance between the vector of each initial training sample and the vector of the center template of its corresponding class can be kept less than or equal to the first threshold δ. cp .like Figure 4 As shown, samples of the same color belong to the same category, L cp This ensures that the distance between the vector of each initial training sample and the vector of the center template of its corresponding class remains less than or equal to a first threshold δ. cp This is equivalent to each conforming to L cp The initial training samples are given an additional pull force. This means that if the vector of an initial training sample exceeds the vector centered on the template, a first threshold δ is applied. cp When L is a circle with a radius of 1 / 2,cp This will add a pulling force to the initial training sample, bringing it closer to the center template of its corresponding category. This will enable the trained second convolutional neural network to accurately classify all samples input into the neural network into their corresponding categories.
[0074] Preferably, the first threshold δ cp The value is 0.
[0075]
[0076] L cn Let δ be the loss function based on the distance between the vector of each initial training sample and the vector of the center template of its non-corresponding class. cn The second threshold is used; the meanings of the other parameters are the same as L. cp Consistent with the above.
[0077] L cn Satisfies [X] + =max(0,X), similarly, means that only when L is satisfied cn The input conditions are the second threshold and the vector x of the i-th initial training sample. i The vector C of the center template of its non-corresponding category j When the difference between the distances is greater than 0, L cn The current input value is the vector x of the second threshold and the i-th initial training sample. i The vector C of the center template of its non-corresponding category j The difference between the distances is not 0; when L is not satisfied. cn When inputting conditions, L cn The current input value is 0. Finally, the average of all input values is calculated based on the number of classes belonging to the initial training samples, and this average is used as L. cn The output value.
[0078] The final output value of the loss function represents the loss situation of the event, in L cn In this loss function, the distance between the vector of each initial training sample and the vector of the center template of its non-corresponding class is kept greater than or equal to a second threshold. When the function value output by the loss function is minimized, it means that the loss of the event is also minimized, and the event can be fully realized. In other words, when L... cn The output function value reaches its minimum value, which is L. cn When each input value can only be 0, it means that the distance between the vector of each initially trained sample and the vector of the center template of its non-corresponding category can remain greater than or equal to the second threshold. For example... Figure 4 As shown, L cnThis ensures that the distance between the vector of each initial training sample and the vector of the center template of its non-corresponding class remains greater than or equal to the second threshold, which is equivalent to ensuring that for each sample that meets the L... cn The initial training samples are given an additional push force. That is, when a vector of an initial training sample enters a vector centered on a non-corresponding class's center template, a second threshold δ is applied. cn When L is a circle with a radius of 1 / 2, cn By adding a push to the initial training sample, moving it away from the center template of its non-corresponding category, the trained second convolutional neural network will not classify any sample input into the neural network into its non-corresponding category.
[0079] In a preferred embodiment, such as Figure 5 As shown, the method in this embodiment includes the following steps:
[0080] T1: Train the first convolutional neural network using b initial training samples to obtain the trained first convolutional neural network;
[0081] The initial training samples are divided into n categories, each category includes at least 3 easily classifiable samples, and the total number b of the initial training samples is greater than 3n.
[0082] T2: Input the initial training samples into the first convolutional neural network after training to obtain the classification results of the initial training samples;
[0083] T3: In the classification results of the initial training samples, determine whether the classification result of each initial training sample matches its corresponding category. If it matches, proceed to step T4; if it does not match, repeat step T3 until the judgment of all initial training samples is completed.
[0084] T4: Take the initial training sample corresponding to the matching classification result as the easy-to-classify sample in the initial training sample, and repeat step T3 until the judgment of all initial training samples is completed.
[0085] T5: Determine the sum of distances between each easily classifiable sample and other easily classifiable samples in the same category;
[0086] T6: The easily classifiable sample with the smallest sum of distances to other easily classifiable samples in the same category is used as the center template of its corresponding category;
[0087] T7: Construct the loss function of the second convolutional neural network using the central template, and train the second convolutional neural network using the initial training samples to obtain the trained second convolutional neural network.
[0088] The loss function L is specifically L = λ1*L cp +λ2*L cn;
[0089]
[0090]
[0091] L cp and L cn Satisfies [X] + =max(0,X); The initial training sample vectors are x1, x2, ..., x b The initial training samples for the n classes are m1, m2, ..., m... n The vectors of the center templates for the n categories are c1, c2, ..., c3. n The c1, c2...c n One-to-one correspondence m1, m2...m n ; i and j represent the current order of the parameters; δ cp The first threshold is 0; δ cn λ1 and λ2 are the second threshold; λ1 and λ2 are the weighting coefficients.
[0092] The neural network training method provided in this embodiment utilizes a first convolutional neural network trained with a relatively small number of initial training samples. This first convolutional neural network can quickly filter out easily classifiable samples. Using the center templates of each category determined by the easily classifiable samples, the loss function of the second convolutional neural network is constructed using the center templates. This loss function can shorten the distance between difficult-to-classify samples and the center templates of their corresponding categories, and widen the distance between difficult-to-classify samples and the center templates of their non-corresponding categories. Thus, a second convolutional neural network that can accurately classify the initial training samples, especially the difficult-to-classify samples, is obtained. The training process does not require additional manual annotation, and both the first and second convolutional neural networks are conventional deep convolutional neural networks, so there is no need to redesign complex network structures.
[0093] Based on the same concept as the neural network training method described above, this embodiment also provides a classification method for classifying samples using a second convolutional neural network trained by the aforementioned neural network training method. The samples can be test samples and / or any other samples with unknown classification results. The method includes the following steps:
[0094] C1: Input the sample into the trained second convolutional neural network to obtain the classification result of the sample.
[0095] After the sample is input into the trained second convolutional neural network, the second convolutional neural network calculates the distance between the sample and the center template of each category, takes the category corresponding to the center template closest to the sample as the category to which the sample belongs, and outputs the category as the classification result of the sample.
[0096] If the sample is an image sample, the specific execution process of step C1 is as follows:
[0097] Image samples are input into a trained second convolutional neural network to obtain the classification result for the image sample. Specifically, after inputting the image sample into the trained second convolutional neural network, the network calculates the distance between the image sample and the center templates of each image category. This distance calculation can be performed using the vector of the image sample and the vectors of the center templates of each image category. The image category corresponding to the center template closest to the image sample is taken as the image category to which the image sample belongs, and this image category is output as the classification result for the image sample.
[0098] Based on the same concept as the neural network training method described above, this embodiment also provides a neural network training system, such as... Figure 6 As shown, it includes:
[0099] The first network training module 100 is used to train the first convolutional neural network using several initial training samples to obtain the trained first convolutional neural network.
[0100] Several initial training samples are divided into several categories.
[0101] Easy-to-classify sample screening module 200: used to input the initial training samples into the trained first convolutional neural network, obtain the classification result of the initial training samples, and screen out easy-to-classify samples from the initial training samples according to the classification result of the initial training samples;
[0102] Center template determination module 300: for determining the center template for each of the categories;
[0103] Second network training module 400: used to construct a loss function for the second convolutional neural network based on the central template; and to train the second convolutional neural network using the initial training samples to obtain the trained second convolutional neural network;
[0104] The order of magnitude of the first convolutional neural network is smaller than that of the second convolutional neural network.
[0105] Furthermore, the loss function constructed using the center template is used to keep the distance between each initial training sample and the center template of its corresponding category less than or equal to a first threshold, while keeping the distance between each initial training sample and the center template of its non-corresponding category greater than or equal to a second threshold.
[0106] Furthermore, the easy-to-classify sample screening module 200 includes:
[0107] The easy-to-classify sample judgment submodule 210 is used to judge whether the classification result of each of the initial training samples conforms to its corresponding category in the classification result of the initial training samples;
[0108] The easy-to-classify sample screening submodule 220 is used to select the initial training samples corresponding to the classification results as easy-to-classify samples in the initial training samples.
[0109] Furthermore, the initial training samples for each category contain at least three easily classifiable samples; based on this, the center template determination module 300 includes:
[0110] The sample distance calculation submodule 310 is used to determine the sum of the distances between each easily classifiable sample and other easily classifiable samples in the same category;
[0111] The template determination submodule 320 is used to select the easily classifiable sample with the smallest sum of distances to other easily classifiable samples in the same category as the center template of its corresponding category.
[0112] Specifically, the sample distance calculation submodule 310 includes:
[0113] The first sample distance calculation subunit 311 is used to obtain and calculate the vector of each easily classifiable sample after passing through the Softmax layer of the first convolutional neural network.
[0114] The second sample distance calculation subunit 312 is used to determine the sum of distances between each easily classifiable sample and other easily classifiable samples of the same category.
[0115] Furthermore, the loss function is specifically as follows:
[0116] L=λ1*L cp +λ2*L cn ;
[0117]
[0118]
[0119] Wherein, the L cp and the L cn Satisfies [X] + =max(0,X); where L is the loss function; where L cp The loss function is based on the distance between each initial training sample and the center template of its corresponding category; the L... cn The loss function is based on the distance between each initial training sample and the center template of its non-corresponding category; b is the total number of initial training samples, and the vector of the initial training samples is x1, x2, ..., xn.b The initial training samples are divided into n (n≤b) categories, and the number of initial training samples in each of the n categories are m1, m2, ..., mn, respectively. n The vectors of the center templates for the n categories are c1, c2, ..., c3. n The c1, c2...c n One-to-one correspondence with m1, m2...m n The i and j represent the current order of the parameters; the δ cp The first threshold; the δ cn The second threshold is defined as λ1 and λ2, which are weighting coefficients.
[0120] Furthermore, the δ cp The value is 0.
[0121] Furthermore, the first convolutional neural network is a micro neural network; the second convolutional neural network is a large neural network or a very large neural network.
[0122] In the above-described implementation of the neural network training system, the logical division of each functional module is merely illustrative. In practical applications, the functions described above can be assigned to different functional modules as needed, such as due to hardware configuration requirements or software implementation considerations. This would allow the internal structure of the neural network training system to be divided into functional modules different from those described above, while still fulfilling all the functions described. Furthermore, the execution process of the modules in the above-described neural network training system is based on the same concept as the neural network training method described in this embodiment. Its principles and resulting technical effects are the same as those of the aforementioned neural network training method. For details, please refer to the description of the method implementation method; further elaboration is not provided here.
[0123] This embodiment also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the above-described neural network training and / or classification methods.
[0124] This embodiment also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the above-described neural network training and / or classification methods.
[0125] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the technical solution of the present invention, and are not intended to limit the specific implementation of the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the claims of the present invention should be included within the protection scope of the claims of the present invention.
Claims
1. A neural network training method, characterized by, include: The first convolutional neural network is trained using several initial training samples to obtain the trained first convolutional neural network. The initial training samples are divided into several categories; The initial training samples include fine-grained image samples; The initial training samples are input into the first convolutional neural network after training to obtain the classification results of the initial training samples. Based on the classification results of the initial training samples, easy-to-classify samples are selected from the initial training samples. Determine the central template for each category based on all the easily classifiable samples; Each category's initial training samples contain at least three of the easily classifiable samples; The center template of each category is determined based on all the easily classifiable samples. Specifically, the sum of distances between each easily classifiable sample and other easily classifiable samples in the same category is determined, and the easily classifiable sample with the smallest sum of distances to other easily classifiable samples in the same category is taken as the center template of its corresponding category. Determining the sum of distances between each easily classifiable sample and other easily classifiable samples in the same category involves: obtaining and determining the sum of distances between each easily classifiable sample and other easily classifiable samples in the same category based on the vector of each easily classifiable sample after passing through the Softmax layer of the first convolutional neural network; The loss function of the second convolutional neural network is constructed based on the central template; the second convolutional neural network is trained using the initial training samples to obtain the trained second convolutional neural network. The loss function constructed using the central template is used to keep the distance between each initial training sample and the central template of its corresponding category less than or equal to a first threshold, while keeping the distance between each initial training sample and the central template of its non-corresponding category greater than or equal to a second threshold. The order of magnitude of the first convolutional neural network is smaller than that of the second convolutional neural network.
2. The neural network training method according to claim 1, characterized in that, Based on the classification results of the initial training samples, easily classifiable samples are selected from the initial training samples, specifically as follows: In the classification results of the initial training samples, it is determined whether the classification result of each initial training sample conforms to its corresponding category, and the initial training samples corresponding to the classification results that conform to the corresponding category are taken as easy-to-classify samples in the initial training samples.
3. The neural network training method according to claim 1, characterized in that, The loss function is specifically as follows: ; ; ; Among them, the and stated satisfy ; The The loss function is... The The loss function is based on the distance between each initial training sample and the center template of its corresponding category; The loss function is based on the distance between each initial training sample and the center template of its non-corresponding category; The The total number of initial training samples is given, and the vector of the initial training samples is given. , ... ; The initial training samples are divided into Categories ≤ , The number of initial training samples for each category are respectively , ... ; The vectors of the center templates for each category are respectively , ... The , ... One-to-one correspondence , ... The and stated The current order of the parameters; The The first threshold; The second threshold; and stated These are the weighting coefficients.
4. The neural network training method according to claim 3, characterized in that, The The value is 0.
5. The neural network training method according to any one of claims 1 to 4, characterized in that, The first convolutional neural network is a micro neural network; the second convolutional neural network is a large neural network or a very large neural network.
6. A classification method, characterized in that, include: The sample is input into the trained second convolutional neural network according to any one of claims 1 to 5 to obtain the classification result of the sample.
7. A neural network training system for implementing the neural network training method according to any one of claims 1 to 5, characterized in that, include: The first network training module is used to train the first convolutional neural network using several initial training samples to obtain the trained first convolutional neural network. The initial training samples are divided into several categories; the initial training samples refer to fine-grained image samples. Easy-to-classify sample screening module: used to input the initial training samples into the trained first convolutional neural network to obtain the classification results of the initial training samples, and to screen out easy-to-classify samples from the initial training samples based on the classification results of the initial training samples; Center template determination module: used to determine the center template for each category based on all the easily classifiable samples; The second network training module is used to construct the loss function of the second convolutional neural network based on the central template; and to train the second convolutional neural network using the initial training samples to obtain the trained second convolutional neural network. The order of magnitude of the first convolutional neural network is smaller than that of the second convolutional neural network.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the neural network training method of any one of claims 1 to 5, and / or the classification method of claim 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the neural network training method of any one of claims 1 to 5, and / or the classification method of claim 6.