Training method, device and storage medium for object quantity recognition model
By adjusting the model parameters and using the high-level semantic information of the image to train the recognition model, the problem of poor accuracy in identifying the number of objects in the image in the existing technology is solved, and higher recognition accuracy is achieved.
Patent Information
- Application Number
- CN202210260457.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-16
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2042-03-16
AI Technical Summary
Existing methods for identifying the number of objects in an image lack high-level semantic information, resulting in poor model recognition accuracy.
By obtaining the first and second sample images from the sample image set, inputting them into the original recognition model, obtaining intermediate features and prediction results, and adjusting the model parameters according to the intermediate features, prediction results, and true values until the recognition accuracy reaches the target value, a target recognition model is formed.
The model's accuracy in identifying the number of objects in an image is improved, and the recognition model is trained through high-level semantic information of the image, thereby improving recognition accuracy.
Smart Images

Figure CN114694094B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of neural networks, and in particular to a training method, device and storage medium for an object quantity recognition model. Background Art
[0002] In the existing art, traditional algorithms for identifying the number of objects in an image typically first manually extract image features (such as edges, textures, and gradients) and then train a regressor that maps these features to the total number of people. This approach lacks high-level semantic information about the image and fails to effectively constrain the features, resulting in poor recognition accuracy in the trained model. Summary of the Invention
[0003] Embodiments of the present invention provide a method, device, and storage medium for training an object quantity recognition model to at least solve the technical problem of poor accuracy in object quantity recognition by the model.
[0004] According to one aspect of an embodiment of the present invention, a training method for an object quantity recognition model is provided, comprising: obtaining a first sample image and a second sample image from a sample image set; inputting the first sample image into an original recognition model to obtain a first intermediate feature and a first prediction result, and inputting the second sample image into the original recognition model to obtain a second intermediate feature and a second prediction result, wherein the first prediction result is the number of objects in the first sample image predicted by the original recognition model, and the second prediction result is the number of objects in the second sample image predicted by the original recognition model; adjusting model parameters of the original recognition model according to the first intermediate feature, the second intermediate feature, the first prediction result, the second prediction result, a first true value, and a second true value, wherein the first true value is the number of objects in the first sample image, and the second true value is the number of objects in the second sample image; and determining that a target recognition model is obtained when the recognition accuracy of the original recognition model after adjusting the model parameters is higher than a target value.
[0005] According to another aspect of an embodiment of the present invention, a training device for an object quantity recognition model is provided, comprising: a first acquisition module for acquiring a first sample image and a second sample image from a sample image set; a first input module for inputting the first sample image into an original recognition model to obtain a first intermediate feature and a first prediction result, and inputting the second sample image into the original recognition model to obtain a second intermediate feature and a second prediction result, wherein the first prediction result is the number of objects in the first sample image predicted by the original recognition model, and the second prediction result is the number of objects in the second sample image predicted by the original recognition model; an adjustment module for adjusting model parameters of the original recognition model according to the first intermediate feature, the second intermediate feature, the first prediction result, the second prediction result, a first true value, and a second true value, wherein the first true value is the number of objects in the first sample image, and the second true value is the number of objects in the second sample image; and a first determination module for determining that a target recognition model is obtained when the recognition accuracy of the original recognition model after adjusting the model parameters is higher than a target value.
[0006] As an optional example, the adjustment module includes: a first calculation unit for calculating the feature similarity between the first intermediate feature and the second intermediate feature; a second calculation unit for calculating the loss parameter between the first sample image and the second sample image, wherein the greater the absolute value of the difference between the first prediction result and the first true value, the greater the loss parameter, and the greater the absolute value of the difference between the second prediction result and the second true value, the greater the loss parameter; a determination unit for determining the sum of the feature similarity and the loss parameter as the target parameter; an adjustment unit for adjusting the model parameter when the absolute value of the difference between the target parameter and the first parameter is greater than a first threshold, wherein the first parameter is the sum of the feature similarity between the third sample image and the fourth sample image and the loss parameter, the first sample image and the second sample image are the images obtained from the sample image set for the Nth time, the third sample image and the fourth sample image are the images obtained from the sample image set for the N-1th time, and N is a natural number greater than 1.
[0007] As an optional example, the above-mentioned first calculation unit includes: a first calculation subunit, used to square the difference between the vector values of each pair of corresponding feature vectors of the above-mentioned first intermediate feature and the above-mentioned second intermediate feature to obtain a square result; a first determination subunit, used to determine half of the sum of all the above-mentioned square results as the above-mentioned feature similarity when the above-mentioned first true value is the same as the above-mentioned second true value; when the above-mentioned first true value is different from the above-mentioned second true value, take the square root of the sum of all the above-mentioned square results to obtain an intermediate value, use m to subtract the intermediate value to obtain an intermediate result, square the larger value between the above-mentioned intermediate result and 0, and take half of the obtained result as the above-mentioned feature similarity, wherein the above-mentioned m is the absolute value of the difference between the above-mentioned first true value and the above-mentioned second true value.
[0008] As an optional example, the above-mentioned first calculation subunit is also used to: determine the feature vectors corresponding to each pair of the above-mentioned first intermediate features and the above-mentioned second intermediate features as the current feature vector pair, and perform the following operations on the above-mentioned current feature vector pair: calculate the difference between the first vector and the second vector in the above-mentioned current feature vector pair, wherein the above-mentioned first vector is the vector in the above-mentioned first intermediate feature, and the above-mentioned second vector is the vector in the above-mentioned second intermediate feature; determine the square of the above-mentioned difference as the above-mentioned square result of the above-mentioned current feature vector pair.
[0009] As an optional example, the above-mentioned second calculation unit includes: a second calculation subunit, used to calculate the absolute value of the difference between the above-mentioned first true value and the above-mentioned first prediction result, to obtain a first absolute value; a third calculation subunit, used to calculate the absolute value of the difference between the above-mentioned second true value and the above-mentioned second prediction result, to obtain a second absolute value; a second determination subunit, used to determine the sum of the above-mentioned first absolute value and the above-mentioned second absolute value as the above-mentioned loss parameter.
[0010] As an optional example, the above-mentioned adjustment unit includes: a fourth calculation subunit, used to calculate the derivative of the above-mentioned target parameter with respect to the above-mentioned model parameter of the above-mentioned original recognition model; a third determination subunit, used to subtract the product of the above-mentioned derivative and the hyperparameter from the above-mentioned model parameter, and determine the obtained result as the above-mentioned model parameter of the adjusted above-mentioned original recognition model.
[0011] As an optional example, the above-mentioned device also includes: a second determination module, which is used to determine that the above-mentioned recognition accuracy of the above-mentioned original recognition model is higher than the above-mentioned target value when the absolute value of the difference between the above-mentioned target parameter and the above-mentioned first parameter is less than or equal to the above-mentioned first threshold.
[0012] As an optional example, the above-mentioned first input module includes: a first input unit, used to input the above-mentioned first sample image into the above-mentioned original recognition model, and obtain the above-mentioned first intermediate feature through the convolution layer and the first fully connected layer of the above-mentioned original recognition model, and input the above-mentioned second sample image into the above-mentioned original recognition model, and obtain the above-mentioned second intermediate feature through the above-mentioned convolution layer and the above-mentioned first fully connected layer of the above-mentioned original recognition model; a second input unit, used to input the above-mentioned first intermediate feature into the second fully connected layer of the above-mentioned original recognition model to obtain the above-mentioned first prediction result, and input the above-mentioned second intermediate feature into the second fully connected layer of the above-mentioned original recognition model to obtain the above-mentioned second prediction result.
[0013] As an optional example, the above-mentioned device also includes: a second acquisition module, used to obtain a target image of the number of objects in the image to be predicted; a second input module, used to input the above-mentioned target image into the above-mentioned target recognition model to obtain the recognition result output by the above-mentioned target recognition model, wherein the recognition result is used to indicate the number of objects in the target image.
[0014] According to another aspect of an embodiment of the present invention, a storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the training method of the object quantity recognition model is executed.
[0015] According to another aspect of an embodiment of the present invention, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute the training method of the object quantity recognition model through the computer program.
[0016] In an embodiment of the present invention, a first sample image and a second sample image are obtained from a sample image set; the first sample image is input into an original recognition model to obtain a first intermediate feature and a first prediction result, and the second sample image is input into the original recognition model to obtain a second intermediate feature and a second prediction result, wherein the first prediction result is the number of objects in the first sample image predicted by the original recognition model, and the second prediction result is the number of objects in the second sample image predicted by the original recognition model; the model parameters of the original recognition model are adjusted according to the first intermediate feature, the second intermediate feature, the first prediction result, the second prediction result, the first true value and the second true value, wherein the The first true value is the number of objects in the first sample image, and the second true value is the number of objects in the second sample image; when the recognition accuracy of the original recognition model after adjusting the model parameters is higher than the target value, a method for determining to obtain a target recognition model is provided. In the above method, when training the original recognition model for recognizing the number of objects in an image, the first sample image and the second sample image are obtained from the sample image set, and then the intermediate features of the two sample images and the model's prediction results for the two sample images are obtained. The model parameters of the model are adjusted according to the intermediate features and the prediction results, thereby realizing the training of the recognition model through the high-level semantic information of the image, improving the recognition accuracy of the model, and thus solving the technical problem of poor accuracy of the model in recognizing the number of objects. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0018] Figure 1 is a flowchart of an optional method for training an object quantity recognition model according to an embodiment of the present invention;
[0019] Figure 2 1 is a schematic diagram of target parameter calculation for an optional training method of an object quantity recognition model according to an embodiment of the present invention;
[0020] Figure 3 2 is a schematic diagram of calculating the difference between feature vectors of intermediate features of two sample images according to an optional training method of an object quantity recognition model according to an embodiment of the present invention;
[0021] Figure 4 is a schematic diagram of an original recognition model of an optional object quantity recognition model training method according to an embodiment of the present invention;
[0022] Figure 52 is a schematic structural diagram of an optional training device for an object quantity recognition model according to an embodiment of the present invention;
[0023] Figure 6 is a schematic diagram of an optional electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0024] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.
[0025] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0026] According to a first aspect of an embodiment of the present invention, a method for training an object quantity recognition model is provided. Optionally, as Figure 1 As shown, the above method includes:
[0027] S102, obtaining a first sample image and a second sample image from a sample image set;
[0028] S104: Input the first sample image into the original recognition model to obtain a first intermediate feature and a first prediction result, and input the second sample image into the original recognition model to obtain a second intermediate feature and a second prediction result, wherein the first prediction result is the number of objects in the first sample image predicted by the original recognition model, and the second prediction result is the number of objects in the second sample image predicted by the original recognition model;
[0029] S106, adjusting model parameters of the original recognition model according to the first intermediate feature, the second intermediate feature, the first prediction result, the second prediction result, the first true value, and the second true value, wherein the first true value is the number of objects in the first sample image, and the second true value is the number of objects in the second sample image;
[0030] S108 , when the recognition accuracy of the original recognition model after adjusting the model parameters is higher than the target value, determining to obtain the target recognition model.
[0031] Optionally, the object recognition model trained in this embodiment can be applied in a variety of scenarios. For example, identifying the flow of people in shopping malls, streets, and stations can be used to calculate the flow of people in shopping malls, streets, and stations by taking images at regular or random intervals and then identifying the number of people in the images.
[0032] Optionally, in this embodiment, the images in the sample image set may be images containing different numbers of objects, and the number of objects may be 0 or greater than 0.
[0033] In this embodiment, a first sample image and a second sample image can be obtained from a sample image set. The original recognition model then identifies the first and second sample images to obtain first intermediate features, second intermediate features, a first prediction result, and a second prediction result. The number of objects in the first and second sample images is known, and is represented by the first true value and the second true value, respectively. The model parameters of the original recognition model are adjusted using the first intermediate features, the second intermediate features, the first prediction result, the second prediction result, the first true value, and the second true value. This allows the recognition model to be trained using high-level semantic information from the images, thereby improving the model's recognition accuracy.
[0034] As an optional example, adjusting the model parameters of the original recognition model according to the first intermediate feature, the second intermediate feature, the first prediction result, the second prediction result, the first true value, and the second true value includes:
[0035] Calculating feature similarity between the first intermediate feature and the second intermediate feature;
[0036] Calculate the loss parameter of the first sample image and the second sample image, wherein the greater the absolute value of the difference between the first prediction result and the first true value, the greater the loss parameter, and the greater the absolute value of the difference between the second prediction result and the second true value, the greater the loss parameter;
[0037] The sum of feature similarity and loss parameter is determined as the target parameter;
[0038] When the absolute value of the difference between the target parameter and the first parameter is greater than the first threshold, the model parameters are adjusted, where the first parameter is the sum of the feature similarity between the third sample image and the fourth sample image and the loss parameter, the first sample image and the second sample image are images obtained from the sample image set for the Nth time, the third sample image and the fourth sample image are images obtained from the sample image set for the N-1th time, and N is a natural number greater than 1.
[0039] Optionally, in this embodiment, when adjusting the model parameters of the original recognition model based on the first intermediate feature, the second intermediate feature, the first prediction result, the second prediction result, the first true value, and the second true value, it is divided into two aspects. The first aspect is whether to adjust the model parameters. When judging whether to adjust the model parameters, the target parameters of the first sample image and the second sample image can be obtained. The target parameters include the feature similarity of the intermediate features of the first sample image and the second sample image and the loss parameter of the first sample image and the second sample image. The feature similarity is used to indicate the degree of similarity of the features, and the loss parameter is related to the difference between the prediction results and the true values of the first sample image and the second sample image. The target parameters are obtained by summing the feature similarity and the loss parameter.
[0040] In this embodiment, after obtaining two sample images and inputting them into the original recognition model each time, the feature similarity and loss parameter of the two sample images can be obtained and summed. Figure 2 As shown, Figure 2 In the example, sample images 1 and 2 are the sample images obtained from the sample image set for the i-th time, where i is a positive integer. After the original recognition model performs recognition calculations, parameter 1 is obtained, which is the sum of the feature similarity between sample images 1 and 2 and the loss parameter. Sample images 3 and 4 are the sample images obtained from the sample image set for the i+1th time. After the original recognition model performs recognition calculations, parameter 2 is obtained, which is the sum of the feature difference between sample images 3 and 4 and the loss parameter. Sample images 5 and 6 are the images obtained from the sample image set for the i+2th time. After the original recognition model performs recognition calculations, the target parameters are obtained. The magnitudes of parameters 1, 2, and the target parameters form a parameter change trend. If the parameter change trend is small and the fluctuation is small, it indicates that the original recognition model is stable. If the parameter change trend is large and the fluctuation is large, it indicates that the original recognition model is not stable and the model parameters can be adjusted.
[0041] When the absolute value of the difference between the target parameter and the first parameter is greater than the first threshold, it indicates that the difference between the target parameter and the first parameter is still large, and the model parameters are adjusted. If the absolute value of the difference between the target parameter and the first parameter is less than or equal to the first threshold, it indicates that the target parameter has not changed much compared to the first parameter, and the recognition accuracy of the original recognition model is determined to be higher than the target value, and the model parameters do not need to be adjusted.
[0042] As an optional example, calculating the feature similarity between the first intermediate feature and the second intermediate feature includes:
[0043] Calculate the square of the difference between the vector values of each pair of corresponding feature vectors of the first intermediate feature and the second intermediate feature to obtain a square result;
[0044] When the first true value is the same as the second true value, half of the sum of all square results is determined as the feature similarity;
[0045] When the first true value is different from the second true value, take the square root of the sum of all square results to obtain the intermediate value, subtract the intermediate value from m to obtain the intermediate result, square the larger value between the intermediate result and 0, and use half of the obtained result as the feature similarity, where m is the absolute value of the difference between the first true value and the second true value.
[0046] Optionally, in this embodiment, the similarity or difference between the first true value and the second true value may affect the feature similarity. Through the above calculation method, images with similar numbers of objects have more similar features, while images with different numbers of objects have more different features, thereby obtaining an accurate feature similarity.
[0047] As an optional example, when the first true value and the second true value are the same, the difference between the vector values of each pair of corresponding feature vectors of the first intermediate feature and the second intermediate feature is squared, and the square result obtained includes:
[0048] Determine the feature vector corresponding to each pair of the first intermediate feature and the second intermediate feature as the current feature vector pair, and perform the following operations on the current feature vector pair:
[0049] Calculate the difference between a first vector and a second vector in the current feature vector pair, where the first vector is a vector in the first intermediate feature and the second vector is a vector in the second intermediate feature;
[0050] The square of the difference is determined as the square of the current eigenvector pair.
[0051] Optionally, in this embodiment, for the first intermediate feature and the second intermediate feature, the difference between each pair of corresponding feature vectors is determined, and then the square of the difference is determined as the square result of the pair of feature vectors. Figure 3 As shown, taking the intermediate features including feature vectors 1-8 as an example, a difference ( Figure 3 Only differences 1-4 are shown). Each difference is squared to obtain a square result.
[0052] As an optional example, calculating the loss parameters of the first sample image and the second sample image includes:
[0053] Calculating the absolute value of the difference between the first true value and the first predicted result to obtain a first absolute value;
[0054] Calculating the absolute value of the difference between the second true value and the second predicted result to obtain a second absolute value;
[0055] The sum of the first absolute value and the second absolute value is determined as a loss parameter.
[0056] Optionally, in this embodiment, when calculating the loss parameter, if the absolute value of the difference between the first true value and the first predicted result is larger, then the first absolute value is larger, resulting in a larger loss parameter; if the absolute value of the difference between the second true value and the second predicted result is larger, then the second absolute value is larger, resulting in a larger loss parameter. A larger loss parameter indicates a less accurate recognition result.
[0057] As an optional example, adjusting the model parameters of the original recognition model according to the first intermediate feature, the second intermediate feature, the first prediction result, the second prediction result, the first true value, and the second true value includes:
[0058] Calculate the derivatives of the target parameters with respect to the model parameters of the original recognition model;
[0059] The product of the derivative and the hyperparameter is subtracted from the model parameter, and the obtained result is determined as the model parameter of the adjusted original recognition model.
[0060] Optionally, in this embodiment, if it is determined that model parameters need to be adjusted, the model parameters of the original recognition model can be adjusted based on the target parameters. Specifically, the derivative of the target parameter with respect to the model parameters of the original recognition model can be calculated, and the product of the derivative and the hyperparameter can be subtracted from the model parameters to obtain the result. The result is then subtracted from the original model parameters to obtain the new model parameters. Adjusting the model parameters using this method can accelerate model training.
[0061] As an optional example, inputting the first sample image into the original recognition model to obtain the first intermediate feature and the first prediction result, and inputting the second sample image into the original recognition model to obtain the second intermediate feature and the second prediction result includes:
[0062] Input the first sample image into the original recognition model, pass it through the convolution layer and the first fully connected layer of the original recognition model, and obtain the first intermediate feature; input the second sample image into the original recognition model, pass it through the convolution layer and the first fully connected layer of the original recognition model, and obtain the second intermediate feature;
[0063] The first intermediate feature is input into the second fully connected layer of the original recognition model to obtain a first prediction result, and the second intermediate feature is input into the second fully connected layer of the original recognition model to obtain a second prediction result.
[0064] Optionally, in this embodiment, the structure of the original recognition model can be as follows: Figure 4 Shown, incl.
[0065] As an optional example, the method further includes:
[0066] Get a target image of the number of objects in the image to be predicted;
[0067] The target image is input into the target recognition model to obtain a recognition result output by the target recognition model, wherein the recognition result is used to indicate the number of objects in the target image.
[0068] The trained object recognition model can be used to identify the number of objects in an image, such as the number of people in a street view image, thereby determining the passenger flow.
[0069] This is explained with an example.
[0070] In this embodiment, a crowd counting dataset D of a surveillance scene can be manually annotated. The dataset D includes multiple sample images, and the number of people in each sample image is marked. Specifically, the surveillance scene image data can be collected. Here we assume that a total of N images are collected, and the i-th image is represented by X i express.
[0071] For each image X i , mark the total number of people y appearing in the picture i , get the crowd counting dataset Divide D into training set D1 and test set D2 in a ratio of 10:1.
[0072] Design the network architecture of the deep crowd counting model Net, such as Figure 4 As shown. The input of Net is the crowd image X∈R H ×W×3 , where H is the image height, W is the image width, and 3 means the image depth is 3. Figure 4Each Block in the network is composed of a series of "convolution + activation functions". The specific number of Blocks and the number of "convolution + activation functions" in each Block can be determined by the speed and accuracy requirements of the specific application. The more Blocks there are, the deeper the network as a whole, the better the performance, and the slower the speed. FC stands for fully connected layer, and the network contains 3 fully connected layers. Among them, FC1 and FC2 form the first convolution layer, which outputs intermediate features, and FC3 is the second convolution layer, which outputs the prediction results. The input of Net is an image X of size H×W×3. X first passes through two Blocks (Block1-2) and two fully connected layers FC1 and FC2 to obtain a feature vector f∈R c .
[0073] Randomly initialize all parameters W of Net.
[0074] Each time, two images X1 and X2 are randomly selected from the training set D1 and fed into the Net to obtain the features f1∈R of X1 and X2 respectively. c ,f2∈R c .
[0075] The feature vectors f1 and f2 of X1 and X2 are respectively sent to the fully connected layer FC3 to obtain a scalar with a unit size of 1 and Represents the number of people predicted by Net.
[0076] Constraints are imposed on the features of X1 and X2 so that the features conform to the sequential relationship constraints. That is, the more similar the number of people in an image, the more similar the features are, and the more different the number of people in an image, the more different the features are. The specific feature constraint loss function is as follows:
[0077]
[0078] Among them, y1 and y2 represent the real number labels of X1 and X2 respectively, ||*||2 represents the two norm of the vector (that is, the square root of the sum of the squares of each element), and max(a, b) represents the maximum value of a and b. feature This is the feature similarity, which means: if the number of people in X1 and X2 is the same, then minimize L feature This will reduce the distance between f1 and f2, that is, make the features of images with the same number of people as similar as possible; if the number of people in X1 and X2 is different, then minimizing L feature The distance between f1 and f2 will increase. At the same time, the greater the difference in the number of people in X1 and X2, the greater the distance between their features will be. Therefore, the loss function L feature The features can be made to satisfy the sequence relationship constraints, that is, the more similar the images are, the more similar their features are, and the more different the images are, the more different their features are.
[0079] Calculate the crowd counting loss of X1 and X2, which is the loss parameter:
[0080]
[0081] The overall loss function of the deep crowd counting model Net is L feature With L number sum:
[0082] L=L feature +L number
[0083] Use the back propagation algorithm to find the derivative of the overall loss function L with respect to all parameters W of the Net Next, update the parameters of the Net using the stochastic gradient descent algorithm:
[0084]
[0085] The parameters of the original recognition model Net are continuously updated iteratively until convergence to obtain the target recognition model Net1. α is the learning rate, a pre-set hyperparameter with common values such as 0.01 and 0.001. Wnew represents the adjusted model parameters, and Woriginal represents the original model parameters.
[0086] In this embodiment, if Wnew no longer changes or changes very little compared to Woriginal, such as the absolute value of the difference between the two is less than or equal to the second threshold, or L (target parameter) no longer changes or changes very little compared to L (first parameter) calculated for the last time the sample image was acquired, such as the absolute value of the difference between the two is less than or equal to the first threshold, the model training can be considered complete and the target recognition model is obtained.
[0087] Select a test sample X from the test set D2 and send it to the target recognition model Net1 to obtain the predicted number of people: y∈R.
[0088] It should be noted that for the aforementioned method embodiments, for simplicity of description, they are all expressed as a series of action combinations. However, those skilled in the art should be aware that the present invention is not limited by the order of the actions described, because according to the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in this specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.
[0089] According to another aspect of the embodiment of the present application, a training device for an object quantity recognition model is also provided. Figure 5 Shown, including:
[0090] A first acquisition module 502 is configured to acquire a first sample image and a second sample image from a sample image set;
[0091] a first input module 504 configured to input a first sample image into an original recognition model to obtain a first intermediate feature and a first prediction result, and to input a second sample image into the original recognition model to obtain a second intermediate feature and a second prediction result, wherein the first prediction result is the number of objects in the first sample image predicted by the original recognition model, and the second prediction result is the number of objects in the second sample image predicted by the original recognition model;
[0092] an adjustment module 506, configured to adjust model parameters of the original recognition model based on the first intermediate feature, the second intermediate feature, the first prediction result, the second prediction result, the first true value, and the second true value, wherein the first true value is the number of objects in the first sample image and the second true value is the number of objects in the second sample image;
[0093] The first determining module 508 is configured to determine that a target recognition model is obtained when the recognition accuracy of the original recognition model after adjusting the model parameters is higher than a target value.
[0094] Optionally, the object recognition model trained in this embodiment can be applied in a variety of scenarios. For example, identifying the flow of people in shopping malls, streets, and stations can be used to calculate the flow of people in shopping malls, streets, and stations by taking images at regular or random intervals and then identifying the number of people in the images.
[0095] Optionally, in this embodiment, the images in the sample image set may be images containing different numbers of objects, and the number of objects may be 0 or greater than 0.
[0096] In this embodiment, a first sample image and a second sample image can be obtained from a sample image set. The original recognition model then identifies the first and second sample images to obtain first intermediate features, second intermediate features, a first prediction result, and a second prediction result. The number of objects in the first and second sample images is known, and is represented by the first true value and the second true value, respectively. The model parameters of the original recognition model are adjusted using the first intermediate features, the second intermediate features, the first prediction result, the second prediction result, the first true value, and the second true value. This allows the recognition model to be trained using high-level semantic information from the images, thereby improving the model's recognition accuracy.
[0097] For other examples of this embodiment, please refer to the above examples and will not be repeated here.
[0098] Figure 6 is a structural block diagram of an optional electronic device according to an embodiment of the present application, such as Figure 6As shown, it includes a processor 602, a communication interface 604, a memory 606 and a communication bus 608, wherein the processor 602, the communication interface 604 and the memory 606 communicate with each other through the communication bus 608, wherein,
[0099] Memory 606, for storing computer programs;
[0100] The processor 602 is configured to execute the computer program stored in the memory 606 to implement the following steps:
[0101] Acquire a first sample image and a second sample image from a sample image set;
[0102] Inputting the first sample image into the original recognition model to obtain a first intermediate feature and a first prediction result, and inputting the second sample image into the original recognition model to obtain a second intermediate feature and a second prediction result, wherein the first prediction result is the number of objects in the first sample image predicted by the original recognition model, and the second prediction result is the number of objects in the second sample image predicted by the original recognition model;
[0103] Adjusting model parameters of the original recognition model according to the first intermediate feature, the second intermediate feature, the first prediction result, the second prediction result, the first true value, and the second true value, wherein the first true value is the number of objects in the first sample image and the second true value is the number of objects in the second sample image;
[0104] When the recognition accuracy of the original recognition model after adjusting the model parameters is higher than the target value, it is determined that the target recognition model is obtained.
[0105] Optionally, in this embodiment, the communication bus may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 The use of only one thick line in the figure does not mean that there is only one bus or only one type of bus. The communication interface is used for communication between the above electronic devices and other devices.
[0106] The memory may include RAM, or may include non-volatile memory, such as at least one disk memory. Alternatively, the memory may also be at least one storage device located away from the aforementioned processor.
[0107] As an example, the memory 606 may include, but is not limited to, the first acquisition module 502, the first input module 504, the adjustment module 506, and the first determination module 508 in the request processing device. Furthermore, the memory 606 may also include, but is not limited to, other module units in the request processing device, which will not be described in detail in this example.
[0108] The above-mentioned processor can be a general-purpose processor, including but not limited to: CPU (Central Processing Unit), NP (Network Processor), etc.; it can also be DSP (Digital Signal Processing), ASIC (Application Specific Integrated Circuit), FPGA (Field-Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0109] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment will not be described in detail here.
[0110] It can be understood by those skilled in the art that Figure 6 The structure shown is for illustration only. The device for implementing the above request processing method may be a terminal device, which may be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile Internet device (Mobile Internet Devices, MID), a PAD, and other terminal devices. Figure 6 It does not limit the structure of the above electronic device. For example, the electronic device may also include Figure 6 More or fewer components (such as network interfaces, display devices, etc.) shown in, or with Figure 6 Different configurations shown.
[0111] A person skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a computer-readable storage medium, which can include: a flash drive, ROM, RAM, a magnetic disk or an optical disk, etc.
[0112] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is run by a processor, the steps in the training method of the above-mentioned object quantity recognition model are executed.
[0113] Optionally, in this embodiment, a person of ordinary skill in the art may understand that all or part of the steps in the various methods of the above embodiments may be completed by instructing the hardware related to the terminal device through a program, and the program may be stored in a computer-readable storage medium, which may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0114] The serial numbers of the above embodiments of the present invention are for description only and do not represent the advantages or disadvantages of the embodiments.
[0115] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above-mentioned computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the existing technology, or all or part of the technical solution can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes a number of instructions for causing one or more computer devices (such as personal computers, servers, or network devices) to execute all or part of the steps of the methods described in various embodiments of the present invention.
[0116] In the above embodiments of the present invention, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0117] In the several embodiments provided in this application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are merely illustrative. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, and can be electrical or other forms.
[0118] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0119] In addition, the functional units in the various embodiments of the present invention may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0120] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as within the scope of protection of the present invention.
Claims
1. A training method for an object quantity recognition model, characterized in that: include: Acquire a first sample image and a second sample image from a sample image set; Inputting the first sample image into an original recognition model to obtain a first intermediate feature and a first prediction result, and inputting the second sample image into the original recognition model to obtain a second intermediate feature and a second prediction result, wherein the first prediction result is the number of objects in the first sample image predicted by the original recognition model, and the second prediction result is the number of objects in the second sample image predicted by the original recognition model; adjusting the model parameters of the original recognition model according to the first intermediate feature, the second intermediate feature, the first prediction result, the second prediction result, a first true value, and a second true value, wherein the first true value is the number of objects in the first sample image, and the second true value is the number of objects in the second sample image; When the recognition accuracy of the original recognition model after adjusting the model parameters is higher than the target value, determining to obtain a target recognition model; Among them, the adjusting the model parameters of the original recognition model according to the first intermediate feature, the second intermediate feature, the first prediction result, the second prediction result, the first true value and the second true value includes: calculating the feature similarity between the first intermediate feature and the second intermediate feature; calculating the loss parameter of the first sample image and the second sample image, wherein the greater the absolute value of the difference between the first prediction result and the first true value, the greater the loss parameter, and the greater the absolute value of the difference between the second prediction result and the second true value, the greater the loss parameter; determining the sum of the feature similarity and the loss parameter as the target parameter; when the absolute value of the difference between the target parameter and the first parameter is greater than a first threshold, adjusting the model parameter, wherein the first parameter is the sum of the feature similarity between the third sample image and the fourth sample image and the loss parameter, the first sample image and the second sample image are images obtained from the sample image set for the Nth time, the third sample image and the fourth sample image are images obtained from the sample image set for the N-1th time, and N is a natural number greater than 1.
2. The method according to claim 1, characterized in that Calculating the feature similarity between the first intermediate feature and the second intermediate feature includes: squaring the difference between the vector values of each pair of corresponding feature vectors of the first intermediate feature and the second intermediate feature to obtain a square result; When the first true value is the same as the second true value, determining half of the sum of all the square results as the feature similarity; When the first true value is different from the second true value, take the square root of the sum of all the square results to obtain an intermediate value, subtract the intermediate value from m to obtain an intermediate result, square the larger value of the intermediate result and 0, and take half of the obtained result as the feature similarity, where m is the absolute value of the difference between the first true value and the second true value.
3. The method according to claim 2, characterized in that When the first true value and the second true value are the same, squaring the difference between the vector values of each pair of corresponding feature vectors of the first intermediate feature and the second intermediate feature to obtain the square result includes: Determine a feature vector corresponding to each pair of the first intermediate feature and the second intermediate feature as a current feature vector pair, and perform the following operation on the current feature vector pair: Calculating a difference between a first vector and a second vector in the current feature vector pair, wherein the first vector is a vector in the first intermediate feature and the second vector is a vector in the second intermediate feature; The square of the difference is determined as the square result of the current feature vector pair.
4. The method according to claim 1, wherein The calculating the loss parameters of the first sample image and the second sample image includes: Calculating an absolute value of a difference between the first true value and the first prediction result to obtain a first absolute value; Calculating the absolute value of the difference between the second true value and the second prediction result to obtain a second absolute value; A sum of the first absolute value and the second absolute value is determined as the loss parameter.
5. The method according to claim 1, wherein The adjusting the model parameters of the original recognition model according to the first intermediate feature, the second intermediate feature, the first prediction result, the second prediction result, the first true value, and the second true value includes: Calculating the derivative of the target parameter with respect to the model parameter of the original recognition model; The product of the derivative and the hyperparameter is subtracted from the model parameter, and the obtained result is determined as the model parameter of the adjusted original recognition model.
6. The method according to claim 1, characterized in that The method further comprises: When the absolute value of the difference between the target parameter and the first parameter is less than or equal to the first threshold, it is determined that the recognition accuracy of the original recognition model is higher than the target value.
7. The method according to claim 1, characterized in that The step of inputting the first sample image into the original recognition model to obtain a first intermediate feature and a first prediction result, and inputting the second sample image into the original recognition model to obtain a second intermediate feature and a second prediction result includes: Inputting the first sample image into the original recognition model and passing it through the convolution layer and the first fully connected layer of the original recognition model to obtain the first intermediate feature, and inputting the second sample image into the original recognition model and passing it through the convolution layer and the first fully connected layer of the original recognition model to obtain the second intermediate feature; The first intermediate feature is input into the second fully connected layer of the original recognition model to obtain the first prediction result, and the second intermediate feature is input into the second fully connected layer of the original recognition model to obtain the second prediction result.
8. The method according to any one of claims 1 to 7, characterized in that The method further comprises: Get a target image of the number of objects in the image to be predicted; The target image is input into the target recognition model to obtain a recognition result output by the target recognition model, wherein the recognition result is used to indicate the number of objects in the target image.
9. A training device for an object quantity recognition model, characterized in that: include: A first acquisition module, configured to acquire a first sample image and a second sample image from a sample image set; a first input module, configured to input the first sample image into an original recognition model to obtain a first intermediate feature and a first prediction result, and input the second sample image into the original recognition model to obtain a second intermediate feature and a second prediction result, wherein the first prediction result is the number of objects in the first sample image predicted by the original recognition model, and the second prediction result is the number of objects in the second sample image predicted by the original recognition model; an adjustment module, configured to adjust model parameters of the original recognition model according to the first intermediate feature, the second intermediate feature, the first prediction result, the second prediction result, a first true value, and a second true value, wherein the first true value is the number of objects in the first sample image, and the second true value is the number of objects in the second sample image; A first determining module is configured to determine a target recognition model when the recognition accuracy of the original recognition model after adjusting the model parameters is higher than a target value; Among them, the adjusting the model parameters of the original recognition model according to the first intermediate feature, the second intermediate feature, the first prediction result, the second prediction result, the first true value and the second true value includes: calculating the feature similarity between the first intermediate feature and the second intermediate feature; calculating the loss parameter of the first sample image and the second sample image, wherein the greater the absolute value of the difference between the first prediction result and the first true value, the greater the loss parameter, and the greater the absolute value of the difference between the second prediction result and the second true value, the greater the loss parameter; determining the sum of the feature similarity and the loss parameter as the target parameter; when the absolute value of the difference between the target parameter and the first parameter is greater than a first threshold, adjusting the model parameter, wherein the first parameter is the sum of the feature similarity between the third sample image and the fourth sample image and the loss parameter, the first sample image and the second sample image are images obtained from the sample image set for the Nth time, the third sample image and the fourth sample image are images obtained from the sample image set for the N-1th time, and N is a natural number greater than 1.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 8 is executed.
11. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to execute the method according to any one of claims 1 to 8 through the computer program.
Citation Information
Patent Citations
Crowd counting model training method and device, crowd counting method and device and server
CN111046747A