Training method, device, computer equipment and storage medium for alignment framework
Through the training method of the alignment framework, the feature extraction model and the converter alignment conversion are used to solve the problem of poor flexibility in feature alignment between the new and old models, achieve both recognition and alignment performance, and expand the scope of application and flexibility.
Patent Information
- Application Number
- CN202110820273.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-20
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2041-07-20
AI Technical Summary
In the existing technology, during the update process of the feature extraction model, the feature alignment flexibility of the new and old models is poor, making it difficult to adapt to various alignment scenarios, affecting the recognition performance and alignment effect.
By designing a training method for the alignment framework, using the first feature extraction model and the second feature extraction model, combined with the first converter and the second converter, the extraction results are aligned and converted, the loss value is calculated and the network parameters are updated to generate An alignment framework that takes into account recognition performance and alignment performance.
The scope of application of the alignment framework is expanded, the flexibility is enhanced, and the recognition and alignment effects of the feature extraction model are improved.
Smart Images

Figure CN113591639B
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a training method, apparatus, computer device and storage medium for an alignment framework. Background Art
[0002] In the fields of face recognition, person re-identification, and image search, the commonly used tool is the visual search system. The working mechanism of the above system is: the feature extraction model in the system maps each image to a feature vector. When there is a picture to be searched, the model compares the feature vector of the picture with the feature vector of the picture in the history library to obtain the search result. With the development of technology, the feature extraction model in the system also needs to be continuously updated. Since the output features of different feature extraction models are very different, it is necessary to align the features output by the new and old feature extraction models.
[0003] In related technologies, feature comparison is usually performed by directly aligning the features output by the historical model with the features output by the new model. The applicable scenarios are relatively fixed and the flexibility is poor. Summary of the invention
[0004] Based on this, it is necessary to provide a universal and flexible training method, device, computer equipment and storage medium for the alignment framework to address the above technical problems.
[0005] A training method for an alignment framework, the alignment framework comprising: a first feature extraction model, a second feature extraction model, a first converter and a second converter; the method comprising:
[0006] Acquire training data, where the training data includes sample images of multiple categories;
[0007] Inputting the sample images into the first feature extraction model and the second feature extraction model respectively, to obtain a first extraction result and a second extraction result corresponding to each sample image;
[0008] Performing alignment conversion on the first extraction result by the first converter to obtain a third extraction result;
[0009] Performing alignment conversion on the second extraction result by the second converter to obtain a fourth extraction result;
[0010] Calculating a loss value according to the first extraction result, the second extraction result, the third extraction result, and the fourth extraction result;
[0011] The network parameters of the alignment framework are updated according to the loss value, and the step of obtaining multiple sample images is returned to be executed until the loss value meets the preset training completion condition, thereby obtaining a trained alignment framework.
[0012] In one embodiment, the first extraction result includes a first feature, the second extraction result includes a second feature, the third extraction result includes a third feature, and the fourth extraction result includes a fourth feature;
[0013] The calculating the loss value according to the first extraction result, the second extraction result, the third extraction result and the fourth extraction result includes:
[0014] Performing a norm operation on the first feature, the second feature, the third feature, and the fourth feature to obtain an alignment loss value;
[0015] A loss value is calculated according to the alignment loss value, a first weight corresponding to the alignment loss value, and a preset classification loss value.
[0016] In one embodiment, calculating the alignment loss value includes:
[0017] Performing a norm operation on the first feature and the fourth feature to obtain a first loss value;
[0018] Performing a norm operation on the second feature and the third feature to obtain a second loss value;
[0019] The sum of the first loss value and the second loss value is used as the alignment loss value.
[0020] In one embodiment, the alignment loss value is calculated by the following formula:
[0021] L1=‖f 2→1 -f1‖2+‖f 1→2 -f2‖2
[0022] Among them, L1 is the alignment loss value, f1 is the first feature, f2 is the second feature, and f 1→2 is the third feature, f 2→1 is the fourth characteristic, ‖f 2→1 -f1‖2 is the first loss value, ‖f 1→2 -f2‖2 is the second loss value.
[0023] In one embodiment, the inputting the sample images into the first feature extraction model and the second feature extraction model respectively to obtain the first extraction result and the second extraction result corresponding to each sample image includes:
[0024] Inputting the sample images into the first feature extraction model according to categories to obtain first extraction results, wherein the first extraction results include a first category center and a plurality of first features;
[0025] The sample images are respectively input into the second feature extraction model to obtain a second extraction result, where the second extraction result includes a plurality of second features and a plurality of second class centers.
[0026] In one embodiment, the third extraction result includes a plurality of third features and a third type of centers, and the fourth extraction result includes a plurality of fourth features and a plurality of fourth type of centers;
[0027] The calculating the loss value according to the first extraction result, the second extraction result, the third extraction result and the fourth extraction result includes:
[0028] Calculating an alignment loss value according to the first type of center, the second type of center, the third type of center, and the fourth type of center;
[0029] Calculating a boundary loss value according to the fourth feature, the first type center and a preset angle threshold in the sample image;
[0030] The loss value is calculated according to the second weight corresponding to the alignment loss value, the alignment loss value, the third weight corresponding to the boundary loss value, the boundary loss value and the preset classification loss value.
[0031] In one embodiment, the alignment loss value is calculated by the following formula:
[0032]
[0033] in, represents the third category center of the j-th category sample image, represents the second type center of the sample image of the jth category, represents the fourth category center of the j-th category sample image, represents the first category center of the j-th category sample picture, d represents the distance function, and n represents the number of categories of the sample picture.
[0034] In one embodiment, the boundary loss value is calculated by the following formula:
[0035]
[0036] in, represents the fourth feature in the i-th sample image, represents the first class center of the i-th sample image, Represents the preset angle threshold, and N represents the number of sample images in a certain category.
[0037] In one embodiment, updating the network parameters of the alignment framework according to the loss value includes:
[0038] According to the loss value, updating the network parameters of the second feature extraction model, the network parameters of the first converter and the network parameters of the second converter; or,
[0039] According to the loss value, network parameters of the first converter and network parameters of the second converter are updated.
[0040] A training device for an alignment framework, the alignment framework comprising: a first feature extraction model, a second feature extraction model, a first converter and a second converter; the device comprising:
[0041] An acquisition module, used to acquire training data, wherein the training data includes sample images of multiple categories;
[0042] An extraction module, used to input the sample images into the first feature extraction model and the second feature extraction model respectively, to obtain a first extraction result and a second extraction result corresponding to each sample image;
[0043] A first alignment conversion module, configured to perform alignment conversion on the first extraction result through the first converter to obtain a third extraction result;
[0044] A second alignment conversion module, configured to perform alignment conversion on the second extraction result through the second converter to obtain a fourth extraction result;
[0045] a calculation module, configured to calculate a loss value according to the first extraction result, the second extraction result, the third extraction result, and the fourth extraction result;
[0046] A training module is used to update the network parameters of the alignment framework according to the loss value, and return to execute the step of obtaining multiple sample images until the loss value meets the preset training completion condition to obtain a trained alignment framework.
[0047] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0048] Acquire training data, where the training data includes sample images of multiple categories;
[0049] Inputting the sample images into the first feature extraction model and the second feature extraction model respectively, to obtain a first extraction result and a second extraction result corresponding to each sample image;
[0050] Performing alignment conversion on the first extraction result by the first converter to obtain a third extraction result;
[0051] Performing alignment conversion on the second extraction result by the second converter to obtain a fourth extraction result;
[0052] Calculating a loss value according to the first extraction result, the second extraction result, the third extraction result, and the fourth extraction result;
[0053] The network parameters of the alignment framework are updated according to the loss value, and the step of obtaining multiple sample images is returned to be executed until the loss value meets the preset training completion condition, thereby obtaining a trained alignment framework.
[0054] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the following steps:
[0055] Acquire training data, where the training data includes sample images of multiple categories;
[0056] Inputting the sample images into the first feature extraction model and the second feature extraction model respectively, to obtain a first extraction result and a second extraction result corresponding to each sample image;
[0057] Performing alignment conversion on the first extraction result by the first converter to obtain a third extraction result;
[0058] Performing alignment conversion on the second extraction result by the second converter to obtain a fourth extraction result;
[0059] Calculating a loss value according to the first extraction result, the second extraction result, the third extraction result, and the fourth extraction result;
[0060] The network parameters of the alignment framework are updated according to the loss value, and the step of obtaining multiple sample images is returned to be executed until the loss value meets the preset training completion condition, thereby obtaining a trained alignment framework.
[0061] The training method, apparatus, computer equipment and storage medium of the alignment framework described above obtain the first extraction result and the second extraction result corresponding to each sample image by inputting the sample images into the first feature extraction model and the second feature extraction model respectively; then the alignment conversion is performed through the first converter and the second converter, the loss value is calculated, and the alignment framework is updated according to the loss value. The alignment framework generated by the training can take into account multiple alignment scenarios at the same time, and can take into account the alignment performance while taking into account the recognition performance of the training model, thereby expanding the scope of application of the alignment framework and enhancing the flexibility of use of the alignment framework. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] Figure 1 A diagram of an application environment of a training method for an alignment framework in one embodiment;
[0063] Figure 2 is a flowchart of a training method for an alignment framework in one embodiment;
[0064] Figure 3A A schematic diagram of the structure of an alignment framework in one embodiment;
[0065] Figure 3B is a schematic diagram of the structure of a converter in one embodiment;
[0066] Figure 4 A schematic diagram of a process for calculating a loss value in one embodiment;
[0067] Figure 5 A schematic diagram of a flow chart of a step of calculating an alignment loss value in one embodiment;
[0068] Figure 6 A schematic diagram of a flow chart of steps for obtaining a first extraction result and a second extraction result in one embodiment;
[0069] Figure 7 A schematic diagram of a flow chart of a step of calculating a loss value in another embodiment;
[0070] Figure 8 A schematic diagram of the structure of a training alignment framework in one embodiment;
[0071] Fig. 9 A schematic diagram of a process for performing an image recognition step in an embodiment;
[0072] Fig.10 A schematic diagram of the structure of a training alignment framework in another embodiment;
[0073] Fig.11 is a structural block diagram of a training device for an alignment framework in one embodiment;
[0074] Fig.12 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0075] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0076] The present invention provides a training method, device, computer equipment and storage medium for an alignment framework. By training the alignment framework through the method, a feature extraction model can be trained while training a converter, taking into account the recognition performance and alignment performance of the new feature extraction model, reducing the mutual influence between the two, so that the feature extraction model in the alignment framework can achieve better recognition effect and alignment effect.
[0077] The training method of the alignment framework provided in this application can be applied to Figure 1 In the application environment shown. The training device 102 communicates with the server 104 through the network. The training device 102 obtains the training data sent by the server 104, and then inputs the training data into the first feature extraction model and the second feature extraction model according to the category, converts the extraction result through the converter in the alignment framework, and then calculates the loss value until the loss value meets the preset training completion condition, and obtains the alignment framework after the training is completed. The training device 102 can be but is not limited to various personal computers, laptops, smart phones, tablet computers and portable wearable devices, and the server 104 can be implemented with an independent server or a server cluster composed of multiple servers. It can be understood that the method can also be applied to terminals, servers, and systems including terminals and servers, and is implemented through the interaction between terminals and servers.
[0078] In one embodiment, Figure 2 As shown in , a training method for an alignment framework is provided. Figure 3A As shown, the alignment framework includes: a first feature extraction model, a second feature extraction model, a first converter and the second converter The output result A of the first feature extraction model is the first extraction result. The first converter performs alignment transformation on the first extraction result to obtain the third extraction result C. The output result B of the second feature extraction model is the second extraction result. The second converter performs alignment transformation on the second extraction result to obtain the fourth extraction result D. Figure 1 Taking the training device in as an example, the training method of the alignment framework includes the following steps:
[0079] Step 201: Obtain training data, where the training data includes sample images of multiple categories.
[0080] Specifically, the training device can obtain training data from a server or other terminal, and the training data includes sample images of multiple categories. Taking the scenario applied to face recognition as an example, at this time, the training data can include sample images of multiple users, that is, one category includes sample images of one user, and one category can include multiple images of the user in different scenes, such as images of the user wearing glasses, images of the user not wearing glasses, images in the shadow, images in the sun, etc.
[0081] Step 202: input the sample images into the first feature extraction model and the second feature extraction model respectively, and obtain the first extraction result and the second extraction result corresponding to each sample image.
[0082] Specifically, the first feature extraction model can be a feature extraction model that has been pre-configured in the training device and has been trained; the second feature extraction model can be a feature extraction model that has been pre-configured in the training device and has been trained, and the second feature extraction model can also be the training target of the training device, that is, the feature extraction model to be trained. The training device inputs the training data into the first feature extraction model to obtain the first extraction result of each sample image in the training data, and can input the training data into the second feature extraction model to obtain the second feature extraction result. The first feature extraction result can include a feature vector corresponding to each sample image and / or a class center vector corresponding to each class of sample images. Similarly, the second feature extraction result can include a feature vector and / or a class center vector corresponding to each sample image.
[0083] Step 203: Perform alignment conversion on the first extraction result by using the first converter to obtain a third extraction result.
[0084] Specifically, the first converter can be used to align the output results of different feature extraction models, such as Figure 3B As shown, the first converter can be a residual structure of N layers. The training device performs alignment conversion on the first extraction result through the first converter to obtain a third extraction result, which is an extraction result that can be compared with the second extraction result output by the second feature extraction model. In this way, the third extraction result output by the first converter can be forward aligned with the second extraction result output by the second feature extraction model.
[0085] Step 204: Perform alignment conversion on the second extraction result by a second converter to obtain a fourth extraction result.
[0086] Specifically, the second transformer can be used to align the output results of different feature extraction models, such as Figure 3BAs shown, the second converter can be a residual structure of N layers. The training device performs alignment conversion on the second extraction result through the second converter to obtain a fourth extraction result, which is an extraction result that can be compared with the first extraction result output by the first feature extraction model. In this way, the third extraction result output by the second converter can be forward aligned with the first extraction result output by the first feature extraction model.
[0087] Step 205, calculating the loss value according to the first extraction result, the second extraction result, the third extraction result and the fourth extraction result.
[0088] Specifically, the training device calculates the loss value according to the first extraction result and the second extraction result output by the first feature extraction model and the second feature extraction model. There can be many types of loss values, such as alignment loss value, classification loss value, etc. The specific calculation process will be described in detail later. The training device can calculate multiple loss values, and then perform weighted calculation on the multiple loss values through a preset weighting algorithm to obtain the final loss value.
[0089] Step 206, update the network parameters of the alignment framework according to the loss value, and return to execute the step of obtaining multiple sample images until the loss value meets the preset training completion condition to obtain a trained alignment framework.
[0090] Among them, the preset training completion condition can be that the loss value has converged, or that the number of iterations of the training data has reached the target number (such as 100 times), etc.
[0091] Specifically, the training device calculates new network parameters of the alignment framework according to the loss value, and then updates the alignment framework to obtain an updated alignment framework. The network parameters do not include the network parameters of the first feature extraction model. Then, the training device re-inputs the training data into the updated alignment framework, and re-executes the above steps 201 to 206 until the calculated loss value meets the preset convergence condition, or the number of iterations of the training data has reached the target number, and a trained alignment framework is obtained.
[0092] The training method, apparatus, computer equipment and storage medium of the alignment framework described above obtain the first extraction result and the second extraction result corresponding to each sample image by inputting the sample images into the first feature extraction model and the second feature extraction model respectively; then the alignment conversion is performed through the first converter and the second converter, the loss value is calculated, and the alignment framework is updated according to the loss value. The alignment framework generated by the training can take into account multiple alignment scenarios at the same time, and can take into account the alignment performance while taking into account the recognition performance of the training model, thereby expanding the scope of application of the alignment framework and enhancing the flexibility of use of the alignment framework.
[0093] In one embodiment, the first extraction result includes the first feature, the second extraction result includes the second feature, the third extraction result includes the third feature, and the fourth extraction result includes the fourth feature; Figure 4 As shown, the specific processing process of step 205 "calculating the loss value according to the first extraction result, the second extraction result, the third extraction result and the fourth extraction result" includes:
[0094] Step 301, performing norm operation on the first feature, the second feature, the third feature and the fourth feature to obtain an alignment loss value.
[0095] Specifically, there are multiple ways to align the first feature extraction model with the second feature extraction model, and the embodiments of the present application provide several feasible alignment methods. In one example, the alignment method can be direct alignment, that is, aligning the first feature with the second feature; the alignment method can also be backward alignment, that is, aligning the first feature with the fourth feature; the alignment method can also be forward alignment, that is, aligning the second feature with the third feature. The training device performs a norm operation on the difference between the first feature and the fourth feature, and performs a norm operation on the difference between the second feature and the third feature, and then uses the sum of the above operation results as the alignment loss value.
[0096] Step 302, calculate the loss value according to the alignment loss value, the first weight corresponding to the alignment loss value, and the preset classification loss value.
[0097] Specifically, the first weight corresponding to the alignment loss value and the preset classification loss value may be determined according to an actual application scenario. For example, the alignment framework is applied to a face recognition scenario, and the preset classification loss value may be a pre-configured face classification loss value.
[0098] Optionally, the loss value can be calculated by the following formula:
[0099] L=λ1L1+L c ,
[0100] Among them, L1 is the alignment loss value, L c is the preset classification loss value, λ1 is the first weight corresponding to the alignment loss value,
[0101] In this embodiment, the total loss value obtained by aligning the loss value and the preset classification loss value, and then updating the network parameters of the alignment framework, can ensure the balance between the alignment performance and the recognition learning performance.
[0102] In one embodiment, Figure 5 As shown, the specific processing process of step 301 "performing a norm operation on the first feature, the second feature, the third feature and the fourth feature to obtain an alignment loss value" includes:
[0103] Step 401, performing a norm operation on the first feature and the fourth feature to obtain a first loss value.
[0104] Specifically, the training device calculates the difference between the first feature output by the first feature extraction model and the fourth feature output by the second converter, and then performs a norm operation on the difference to obtain a first loss value.
[0105] Step 402, performing a norm operation on the second feature and the third feature to obtain a second loss value.
[0106] Specifically, the training device calculates the difference between the second feature output by the second feature extraction model and the third feature output by the first converter, and then performs a norm operation on the difference to obtain a second loss value.
[0107] Step 403: The sum of the first loss value and the second loss value is used as the alignment loss value.
[0108] Specifically, the training device can calculate the alignment loss value by the following formula:
[0109] L1=‖f 2→1 -f1‖2+‖f 1→2 -f2‖2,
[0110] Among them, L1 is the alignment loss value, f1 is the first feature, f2 is the second feature, and f 1→2 is the third feature, f 2→1 is the fourth characteristic, ‖f 2→1 -f1‖2 is the first loss value, ‖f 1→2 -f2‖2 is the second loss value.
[0111] In one embodiment, Figure 6 As shown, the specific processing process of step 202 "inputting the sample images into the first feature extraction model and the second feature extraction model respectively to obtain the first extraction result and the second extraction result corresponding to each sample image" includes:
[0112] Step 501: input sample images into a first feature extraction model according to categories to obtain a first extraction result.
[0113] Among them, the first extraction result includes the first category center and multiple first features. The training device can obtain training data from a server or other terminal, and the above training data includes sample images of multiple categories. Taking the scenario applied to face recognition as an example, at this time, the training data can include sample images of multiple users, that is, one category includes sample images of one user, and one category can include multiple images of this user in different scenes, such as pictures with glasses, pictures without glasses, pictures in the shadow, pictures in the sun, etc. The first feature extraction model is a feature extraction model that has been pre-configured and trained in the training device. The first feature is the image feature vector obtained after the first feature extraction model processes the sample image, and the first category center is the mean of multiple image feature vectors obtained after the first feature extraction model processes multiple sample images of a category.
[0114] Specifically, the training device inputs the received sample images of multiple categories into the first feature extraction model according to the categories. The first feature extraction model outputs the class center of each class of sample images for each class of sample images, and outputs the image feature vector of each sample image for each sample image. For example, the training device can input multiple sample images of a category into the first feature extraction model together to obtain the first class center of this category and the first features of each sample image of this category; the training device can also input multiple sample images of a category into the first feature extraction model separately. At this time, the first feature extraction model will first output the first feature for each sample image. After the first features of the sample images of this category are all output, the first class center of the sample images of this category is output based on the multiple first features.
[0115] Step 502: input the sample images into the second feature extraction model respectively to obtain the second extraction result.
[0116] Among them, the second extraction result includes multiple second features and multiple second class centers. The second feature extraction model can be the training target of the training device, that is, the feature extraction model that has not yet started training; the second feature extraction model can also be a feature extraction model that has been trained.
[0117] Specifically, the training device inputs the received multiple sample images of multiple categories into the second feature extraction model respectively, and the second feature extraction model outputs the class center and image feature vector of each sample image for each sample image. The second feature is the image feature vector of each sample image extracted by the second feature extraction model, and the second class center is the class center of the image feature vector of each sample image extracted by the second feature extraction model.
[0118] In one embodiment, the extraction result may include class centers in addition to features, that is, the third extraction result includes multiple third features and third class centers, and the fourth extraction result includes multiple fourth features and multiple fourth class centers. Figure 7 As shown, the specific execution process of step 205 "calculating the loss value according to the first extraction result, the second extraction result, the third extraction result and the fourth extraction result" is:
[0119] Step 601, calculating the alignment loss value according to the first type center, the second type center, the third type center and the fourth type center.
[0120] Specifically, Figure 8 As shown, the training device passes through a first converter The first feature extraction model outputs the first class center according to the j class sample image And the first feature Perform alignment transformation to obtain the third type of center corresponding to the second feature extraction model And the third feature At this time, the third class center and the third feature output by the first converter can be directly compared with the second feature and the second class center output by the second feature extraction model.
[0121] The training device also passes through a second converter The second type of center output by the second feature extraction model And the second feature Perform alignment transformation to obtain the fourth type of center corresponding to the first feature extraction model And the fourth characteristic At this time, the fourth class center and the fourth feature output by the second converter can be directly compared with the features and class center output by the first feature extraction model. The training device can calculate the alignment loss value according to the first class center extracted by the first feature extraction model, the second class center extracted by the second feature extraction model, the third class center obtained by converting the first class center by the first converter, and the fourth class center obtained by converting the second class center by the second converter.
[0122] For example, the training device can calculate the alignment loss value by the following formula:
[0123]
[0124] in, represents the third category center of the j-th category sample image, represents the second type center of the sample image of the jth category, represents the fourth category center of the j-th category sample image, represents the first category center of the j-th category sample image, d represents the distance function, and n represents the number of categories of the sample image.
[0125] Step 602, calculating the boundary loss value according to the fourth feature in the sample image, the center of the first category and the preset angle threshold.
[0126] Specifically, the training device inputs N sample images in the training data into the second feature extraction model respectively, outputs the second feature corresponding to each sample image, and then inputs the N sample images into the first feature extraction model by category to obtain the first category center corresponding to each category of sample images. The training device then converts the second feature into a fourth feature through a second converter, and the training device obtains the difference from the preset angle threshold through the fourth feature and the first category center, and calculates the boundary loss value based on the above difference.
[0127] For example, the boundary loss value is calculated by the following formula:
[0128]
[0129] in, represents the fourth feature in the i-th sample image, represents the first class center of the i-th sample image, Represents the preset angle threshold, and N represents the number of sample images in a certain category.
[0130] Step 603, calculate the loss value according to the second weight corresponding to the alignment loss value, the alignment loss value, the third weight corresponding to the boundary loss value, the boundary loss value and the preset classification loss value.
[0131] Specifically, the preset classification loss value may be a face classification loss in the field of image recognition.
[0132] For example, the loss value can be calculated by the following formula:
[0133] L LCE =λ a L a +λ b L b +L c
[0134] Among them, L a represents the alignment loss value, L b represents the boundary loss value, L c represents the classification loss value, λ a represents the second weight, λ b Represents the third weight.
[0135] In this embodiment, the total loss value is obtained by aligning the loss value and the boundary loss value, and then the training model is updated. The class center extracted by the first feature extraction model and the class center extracted by the second feature extraction model can be trained to the same position, and the feature vector obtained by converting the features output by the second feature extraction model can be overlapped with the class center output by the historical model to achieve alignment between classes and ensure a balance between alignment performance and recognition learning performance.
[0136] In one embodiment, for different second feature extraction models, the updating methods of network parameters are also different. The present application embodiment provides two examples.
[0137] In one example, the second feature extraction model in the alignment framework is a feature extraction model to be trained. In this case, the training device can update the network parameters of the second feature extraction model, the network parameters of the first converter, and the network parameters of the second converter according to the loss value.
[0138] In another example, the second feature extraction model in the alignment framework is a feature extraction model that has been trained. In this case, the training device can update the network parameters of the first converter and the network parameters of the second converter according to the loss value.
[0139] In this embodiment, the alignment framework generated by training can take into account multiple alignment scenarios at the same time, and can take into account the alignment performance while training the recognition performance of the model, thereby expanding the scope of application of the alignment framework, enhancing the flexibility of use of the alignment framework, and can also reduce the computational complexity of training and recognition while ensuring the alignment performance of the alignment framework.
[0140] In one embodiment, Fig. 9 As shown, the training method of the above alignment framework also includes:
[0141] Step 701, in response to a picture recognition request, obtain picture data to be recognized.
[0142] Specifically, the training device receives a picture recognition request sent by a user terminal or a user server, and then responds to the recognition request by parsing the recognition request to obtain the picture data to be recognized contained in the recognition request.
[0143] Step 702: input the image data to be identified into the second feature extraction model to obtain image feature data.
[0144] Specifically, the training device inputs the image data to be identified obtained through analysis into the second feature extraction model to obtain the image feature data output by the second feature extraction model.
[0145] Step 703, respectively calculating the distance between the image feature data and the center of each category in the preset historical database.
[0146] Step 704: taking the category with the smallest distance as the category recognition result of the image data to be recognized.
[0147] Specifically, the image feature data can be a feature vector of the image. The preset historical database stores class centers of various types of images. The training device calculates the distance between the feature vector of the image to be identified and the class center of each category, and takes the category corresponding to the class center with the smallest distance as the identification result of the image to be identified.
[0148] It should be understood that although Figure 2-9 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 2-9 At least part of the steps may include multiple steps or multiple stages. These steps or stages are not necessarily performed at the same time, but can be performed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed in turn or alternately with other steps or at least part of the steps or stages in other steps.
[0149] The following describes in detail the actual scenarios in which the above embodiments are applied in conjunction with the schematic diagram. Fig.10 As shown, for the training device, a first feature extraction model (model 1) and a second feature extraction model (model 2) are configured. The feature vector extracted by model 1 in the sample image is f 1 , model 2 extracts the feature vector from the sample image as f 2 , the first converter The feature f 1 Convert to f 1→2 , the second converter The feature f 2 Convert to f 2→1 .
[0150] At this time, there are three examples of model alignment: the first case is forward alignment, that is, f 1→2 and f 2 Direct alignment; in the second case, backward alignment, f 1 and f 2→1 Directly compare; the third case, direct alignment, f 1 and f 2Therefore, there are two examples of model alignment scenarios: In the first case, alignment training, when it is necessary to train the second feature extraction model, i.e., model 2, it can be implemented by the method of the above embodiment. In the second case, when the second feature extraction model has been trained, the first converter and the second converter can also be trained by the method of the above embodiment to improve the alignment performance.
[0151] In one embodiment, Fig.11 As shown, a training device for an alignment framework is provided, comprising: an acquisition module 801, an extraction module 802, a first alignment conversion module 803, a second alignment conversion module 804, a calculation module 805 and a training module 806, wherein:
[0152] An acquisition module 801 is used to acquire training data, where the training data includes sample images of multiple categories;
[0153] An extraction module 802 is used to input the sample images into the first feature extraction model and the second feature extraction model respectively, and obtain a first extraction result and a second extraction result corresponding to each sample image;
[0154] A first alignment conversion module 803, configured to perform alignment conversion on the first extraction result through a first converter to obtain a third extraction result;
[0155] A second alignment conversion module 804, configured to perform alignment conversion on the second extraction result through a second converter to obtain a fourth extraction result;
[0156] A calculation module 805, configured to calculate a loss value according to the first extraction result, the second extraction result, the third extraction result, and the fourth extraction result;
[0157] The training module 806 is used to update the network parameters of the alignment framework according to the loss value, and return to execute the step of obtaining multiple sample images until the loss value meets the preset training completion condition to obtain a trained alignment framework.
[0158] In one embodiment, the first extraction result includes the first feature, the second extraction result includes the second feature, the third extraction result includes the third feature, and the fourth extraction result includes the fourth feature; the calculation module 805 includes:
[0159] A first norm operation unit, used for performing a norm operation on the first feature, the second feature, the third feature, and the fourth feature to obtain an alignment loss value;
[0160] The calculation unit is used to calculate the loss value according to the alignment loss value, the first weight corresponding to the alignment loss value, and the preset classification loss value.
[0161] In one embodiment, the first norm calculation unit includes:
[0162] A first norm operator unit, used for performing a norm operation on the first feature and the fourth feature to obtain a first loss value;
[0163] A second norm operator unit, used for performing a norm operation on the second feature and the third feature to obtain a second loss value;
[0164] The calculation subunit is used to use the sum of the first loss value and the second loss value as the alignment loss value.
[0165] The first norm calculation unit calculates the alignment loss value through the following formula:
[0166] L1=‖f 2→1 -f1‖2+‖f 1→2 -f2‖2
[0167] Among them, L1 is the alignment loss value, f1 is the first feature, f2 is the second feature, and f 1→2 is the third feature, f 2→1 is the fourth characteristic, ‖f 2→1 -f1‖2 is the first loss value, ‖f 1→2 -f2‖2 is the second loss value.
[0168] In one embodiment, the extraction module 802 includes:
[0169] A first extraction unit, used to input the sample images into a first feature extraction model according to categories to obtain a first extraction result, wherein the first extraction result includes a first category center and a plurality of first features;
[0170] The second extraction unit is used to input the sample images into the second feature extraction model respectively to obtain a second extraction result, and the second extraction result includes a plurality of second features and a plurality of second class centers.
[0171] In one embodiment, the third extraction result includes a plurality of third features and a third type of center, and the fourth extraction result includes a plurality of fourth features and a plurality of fourth type of center; the calculation module 805 includes:
[0172] An alignment loss calculation unit, used for calculating an alignment loss value according to the first type center, the second type center, the third type center and the fourth type center;
[0173] A boundary loss calculation unit, used to calculate a boundary loss value according to the fourth feature, the first type center and a preset angle threshold in the sample image;
[0174] The loss calculation unit is used to calculate the loss value according to the second weight corresponding to the alignment loss value, the alignment loss value, the third weight corresponding to the boundary loss value, the boundary loss value and the preset classification loss value.
[0175] In one embodiment, the alignment loss calculation unit calculates the alignment loss value by the following formula:
[0176]
[0177] in, represents the third category center of the j-th category sample image, represents the second type center of the sample image of the jth category, represents the fourth category center of the j-th category sample image, represents the first category center of the j-th category sample image, d represents the distance function, and n represents the number of categories of the sample image.
[0178] In one embodiment, the boundary loss calculation unit calculates the boundary loss value by the following formula:
[0179]
[0180] in, represents the fourth feature in the i-th sample image, represents the first class center of the i-th sample image, Represents the preset angle threshold, and N represents the number of sample images in a certain category.
[0181] In one embodiment, the training module 806 is used to update the network parameters of the second feature extraction model, the network parameters of the first converter, and the network parameters of the second converter according to the loss value; or, to update the network parameters of the first converter and the network parameters of the second converter according to the loss value.
[0182] For the specific definition of the training device of the alignment framework, please refer to the definition of the training method of the alignment framework above, which will not be repeated here. The various modules in the above-mentioned training device of the alignment framework can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0183] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig.12As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store training data and trained feature extraction model data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a training method for an alignment framework is implemented.
[0184] Those skilled in the art will understand that Fig.12 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0185] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0186] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0187] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0188] The technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, all possible combinations of the technical features in the above embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification. The above embodiments only express several implementation methods of the present application, and their descriptions are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that for ordinary technicians in this field, without departing from the concept of the present application, several deformations and improvements can be made, which all belong to the protection scope of the present application. Therefore, the protection scope of the patent of this application shall be based on the attached claims.
Claims
1. A training method for an alignment framework, characterized in that: The alignment framework includes: a first feature extraction model, a second feature extraction model, a first converter and a second converter; the method includes: Acquire training data, where the training data includes sample images of multiple categories; Inputting the sample images into the first feature extraction model and the second feature extraction model respectively, to obtain a first extraction result and a second extraction result corresponding to each sample image; Performing alignment conversion on the first extraction result by the first converter to obtain a third extraction result; Performing alignment conversion on the second extraction result by the second converter to obtain a fourth extraction result; Calculating a loss value according to the first extraction result, the second extraction result, the third extraction result, and the fourth extraction result; Updating the network parameters of the alignment framework according to the loss value, and returning to execute the step of acquiring the training data until the loss value satisfies a preset training completion condition, thereby obtaining a trained alignment framework; The first extraction result includes a first feature, the second extraction result includes a second feature, the third extraction result includes a third feature, and the fourth extraction result includes a fourth feature; The calculating the loss value according to the first extraction result, the second extraction result, the third extraction result and the fourth extraction result includes: Performing a norm operation on the first feature, the second feature, the third feature, and the fourth feature to obtain an alignment loss value; A loss value is calculated according to the alignment loss value, a first weight corresponding to the alignment loss value, and a preset classification loss value.
2. The method according to claim 1, characterized in that The performing a norm operation on the first feature, the second feature, the third feature, and the fourth feature to obtain an alignment loss value includes: Performing a norm operation on the first feature and the fourth feature to obtain a first loss value; Performing a norm operation on the second feature and the third feature to obtain a second loss value; The sum of the first loss value and the second loss value is used as the alignment loss value.
3. The method according to claim 2, characterized in that The alignment loss value is calculated by the following formula: L1=‖f 2→1 -f1‖2+‖f 1→2 -f2‖2 Among them, L1 is the alignment loss value, f1 is the first feature, f2 is the second feature, and f 1→2 is the third feature, f 2→1 is the fourth characteristic, ‖f 2→1 -f1‖2 is the first loss value, ‖f 1→2 -f2‖2 is the second loss value.
4. The method according to claim 1, characterized in that: The step of inputting the sample images into the first feature extraction model and the second feature extraction model respectively to obtain a first extraction result and a second extraction result corresponding to each sample image includes: Inputting the sample images into the first feature extraction model according to categories to obtain first extraction results, wherein the first extraction results include a first category center and a plurality of first features; The sample images are respectively input into the second feature extraction model to obtain a second extraction result, where the second extraction result includes a plurality of second features and a plurality of second class centers.
5. The method according to claim 4, characterized in that The third extraction result includes a plurality of third features and a third type of center, and the fourth extraction result includes a plurality of fourth features and a plurality of fourth type of center; The calculating the loss value according to the first extraction result, the second extraction result, the third extraction result and the fourth extraction result includes: Calculating an alignment loss value according to the first type of center, the second type of center, the third type of center, and the fourth type of center; Calculating a boundary loss value according to the fourth feature, the first type center and a preset angle threshold in the sample image; The loss value is calculated according to the second weight corresponding to the alignment loss value, the alignment loss value, the third weight corresponding to the boundary loss value, the boundary loss value and the preset classification loss value.
6. The method according to claim 5, characterized in that The alignment loss value is calculated by the following formula: in, represents the third category center of the j-th category sample image, represents the second type center of the sample image of the jth category, represents the fourth category center of the j-th category sample image, represents the first category center of the j-th category sample picture, d represents the distance function, and n represents the number of categories of the sample picture.
7. The method according to claim 5, characterized in that The boundary loss value is calculated by the following formula: Among them, f i 2→1 represents the fourth feature in the i-th sample image, represents the first class center of the i-th sample image, Represents the preset angle threshold, N represents the number of sample images in a certain category, and θ() represents the angle function.
8. The method according to claim 1, characterized in that The updating of the network parameters of the alignment framework according to the loss value comprises: According to the loss value, updating the network parameters of the second feature extraction model, the network parameters of the first converter and the network parameters of the second converter; or, According to the loss value, network parameters of the first converter and network parameters of the second converter are updated.
9. A training device for aligning a frame, characterized in that: The alignment framework includes: a first feature extraction model, a second feature extraction model, a first converter and a second converter; the device includes: An acquisition module, used to acquire training data, wherein the training data includes sample images of multiple categories; An extraction module, used to input the sample images into the first feature extraction model and the second feature extraction model respectively, to obtain a first extraction result and a second extraction result corresponding to each sample image; A first alignment conversion module, configured to perform alignment conversion on the first extraction result through the first converter to obtain a third extraction result; A second alignment conversion module, configured to perform alignment conversion on the second extraction result through the second converter to obtain a fourth extraction result; a calculation module, configured to calculate a loss value according to the first extraction result, the second extraction result, the third extraction result, and the fourth extraction result; A training module, used for updating the network parameters of the alignment framework according to the loss value, and returning to execute the step of obtaining the training data until the loss value satisfies a preset training completion condition, thereby obtaining a trained alignment framework; The first extraction result includes a first feature, the second extraction result includes a second feature, the third extraction result includes a third feature, and the fourth extraction result includes a fourth feature; the calculation module includes: A first norm operation unit, used for performing a norm operation on the first feature, the second feature, the third feature, and the fourth feature to obtain an alignment loss value; A calculation unit is used to calculate a loss value according to the alignment loss value, a first weight corresponding to the alignment loss value, and a preset classification loss value.
10. 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, the steps of the method according to any one of claims 1 to 8 are implemented.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Image conversion method and device, computer equipment and storage medium
CN111489287A
Domain adaptive model training method and device, image detection method and device, equipment and medium
CN111860670A
Knowledge graph entity alignment method and device, computer equipment and storage medium
CN112765370A
Speech synthesis method and device based on artificial intelligence, computer equipment and medium
CN112837673A
Model training method and device, pedestrian analysis method and device, equipment and storage medium
CN113128478A
