A target identification method and device, a terminal device and a readable storage medium
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- UBTECH ROBOTICS CORP LTD
- Filing Date
- 2022-12-13
- Publication Date
- 2026-08-07
AI Technical Summary
[0003]相关技术中,通常采用三元组损失函数来进行模型训练,三元组损失函数的优化方向易受到三元组中样本图像的特征和标签的影响,导致采用三元组损失函数训练得到的模型不能准确地进行目标识别
[0010] In the embodiments of this application, feature extraction is performed on the target image of the target to be identified to obtain image features in the target image. The image features are then input into the target recognition network model to obtain the recognition result of the category to which the target belongs. The loss function of the target recognition network model is used to constrain the first distance and the second distance corresponding to each triplet in multiple triplets. The first distance represents the distance between the baseline image features in the triplet and the positive sample image features in the same triplet. The second distance represents the distance between the baseline image features in the triplet and the negative sample image features of multiple categories in the same triplet. That is, the number of categories and the number of images of negative sample images are increased in a single optimization, reducing the influence of the wrong labels of negative sample images on the optimization direction of the model. It also avoids the situation where different negative sample images are used in different optimizations and the optimization is in the opposite direction. This makes the trained model more accurate in target recognition and improves the accuracy of target recognition.
Smart Images

Figure CN116091783B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of image recognition technology, and in particular relates to a target recognition method, apparatus, terminal device and readable storage medium. Background Technology
[0002] Object recognition is an important application area of computer vision technology, and deep learning-based network models are commonly used to achieve this. The loss function is a crucial component of the network model. Typically, the network model is trained by minimizing the loss function, using data as input, to optimize the model by minimizing the error between the network model's predictions and the actual values of the data.
[0003] In related technologies, triplet loss functions are commonly used for model training. However, the optimization direction of triplet loss functions is easily affected by the features and labels of the sample images in the triplet, which can lead to models trained using triplet loss functions failing to accurately identify targets. Summary of the Invention
[0004] This application provides a target recognition method, apparatus, terminal device, and readable storage medium, which can improve the accuracy of target recognition.
[0005] The first aspect of this application provides a target recognition method, comprising: acquiring a target image of a target to be recognized; extracting features from the target image to obtain image features in the target image; inputting the image features into a target recognition network model to obtain a recognition result of the category to which the target to be recognized belongs, wherein the loss function of the target recognition network model is used to constrain a first distance and a second distance corresponding to each of the multiple triplets, the first distance representing the distance between the reference image features in the triplet and the positive sample image features in the same triplet, and the second distance representing the distance between the reference image features in the triplet and the negative sample image features of multiple categories in the same triplet.
[0006] A target recognition device provided in the second aspect of this application includes: an image acquisition unit for acquiring a target image of a target to be recognized; a feature extraction unit for extracting features from the target image to obtain image features in the target image; and a target recognition unit for inputting the image features into a target recognition network model to obtain a recognition result of the category to which the target to be recognized belongs. The loss function of the target recognition network model is used to constrain a first distance and a second distance corresponding to each of the multiple triplets. The first distance represents the distance between a reference image feature in the triplet and positive sample image features in the same triplet, and the second distance represents the distance between the reference image feature in the triplet and negative sample image features of multiple categories in the same triplet.
[0007] A third aspect of this application provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the target recognition method described above.
[0008] A fourth aspect of this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the target recognition method described above.
[0009] The fifth aspect of this application provides a computer program product that, when run on a terminal device, causes the terminal device to execute the target recognition method described in the first aspect.
[0010] In the embodiments of this application, feature extraction is performed on the target image of the target to be identified to obtain image features in the target image. The image features are then input into the target recognition network model to obtain the recognition result of the category to which the target belongs. The loss function of the target recognition network model is used to constrain the first distance and the second distance corresponding to each triplet in multiple triplets. The first distance represents the distance between the baseline image features in the triplet and the positive sample image features in the same triplet. The second distance represents the distance between the baseline image features in the triplet and the negative sample image features of multiple categories in the same triplet. That is, the number of categories and the number of images of negative sample images are increased in a single optimization, reducing the influence of the wrong labels of negative sample images on the optimization direction of the model. It also avoids the situation where different negative sample images are used in different optimizations and the optimization is in the opposite direction. This makes the trained model more accurate in target recognition and improves the accuracy of target recognition. Attached Figure Description
[0011] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0012] Figure 1 The image shows a schematic diagram of model training based on the cross-entropy loss function in related technologies.
[0013] Figure 2 This is a schematic diagram illustrating the implementation process of a target recognition method provided in an embodiment of this application;
[0014] Figure 3 This is a schematic diagram illustrating the specific implementation process of calculating the loss value provided in the embodiments of this application;
[0015] Figure 4 This is a schematic diagram of model training based on the loss function provided in the embodiments of this application;
[0016] Figure 5 This is a schematic diagram of the structure of a target recognition device provided in an embodiment of this application;
[0017] Figure 6 This is a schematic diagram of the structure of the terminal device provided in the embodiments of this application. Detailed Implementation
[0018] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are protected by this application.
[0019] In related technologies, the cross-entropy loss function is commonly used for model training. The triplet loss function is one of the most common loss functions, frequently used in visual tasks such as face recognition and person re-identification. Its main function is to increase intra-class similarity and decrease inter-class similarity. The input to the triplet loss function is a triplet {f} of image features. a f p f n The formula is as follows:
[0020]
[0021] Among them, f a f p f nN represents the baseline image feature, positive sample image feature, and negative sample image feature in a triplet. Positive sample image features are those belonging to the same category as the baseline image features, while negative sample image features are those belonging to a different category than the baseline image features. tp This represents the total number of triples in a batch. {x} + Let {x} represent the maximum value between x and 0. + =max{x, 0}. During the model optimization phase, the triplet loss function constrains the distance D(f) between the baseline image features and the positive sample image features. i a , i p The distance D(f) between the features of the reference image and the features of the negative sample image i a , i n If the difference is greater than a threshold α, the optimization goal of increasing the intra-class similarity of image features within the same category and decreasing the inter-class similarity between image features of different categories can be achieved.
[0022] The original triplet loss function often uses all triples to train the model, and its computational complexity is O(N). 3 Here, N is the number of images in the training dataset. To improve the training efficiency of the model, some related techniques use a "hard example mining" strategy to select "effective" triples. As shown below, the formula for the triple loss function based on hard example mining can be expressed as:
[0023]
[0024] Where P is the total number of target categories in a batch, and A is the number of sample images for each target (e.g., pedestrian) in a batch. max() represents the maximum value, and min() represents the minimum value.
[0025] In practical applications, it has been found that the optimization direction of the triplet loss function is easily affected by the features and labels of the sample images in the triplet.
[0026] For details, please refer to Figure 1 Solid-color filled circles, diagonally filled circles, and hollow circles represent sample image features of different target categories. Here, a and p represent the baseline image feature and positive sample image feature, respectively. n1 and n2 represent negative sample image features of different categories, and v1 and v2 represent the optimization direction of the baseline image feature a when n1 and n2 are used as negative sample image features.
[0027] Depend on Figure 1It can be seen that v1 and v2 are significantly different, which will lead to instability in the optimization direction when optimizing the baseline image feature a. Specifically, when n1 is selected as the negative sample image feature, the traditional triplet loss function causes the baseline image feature a to... Figure 1 The top-right optimization; however, when n2 is selected as the negative sample image feature, the traditional triplet loss function causes the baseline image feature a to shift towards the top right. Figure 1 The optimization occurs in the lower right corner. When two negative sample image features optimize the baseline image feature a, the optimization direction is inconsistent, causing the optimization direction of feature point a to change with the negative sample image features during model training. In some extreme cases, different negative sample image features may optimize the baseline image feature a in opposite directions, creating a "tug-of-war" phenomenon, which prevents the model from converging during training.
[0028] Furthermore, in a single optimization process, the traditional triplet loss function uses only one negative sample image. For example, the traditional triplet loss function based on the "hard example mining" strategy only uses the image most similar to the benchmark image (i.e., the hardest) as the negative sample image, and calculates the loss value using its corresponding negative sample image features. This approach is susceptible to mislabeling. Specifically, since the traditional triplet loss function only considers the information of one negative sample image, if this negative sample image is mislabeled (e.g., the true category of the negative sample image is the same as the category of the benchmark image, but the label is incorrect), the traditional triplet loss function will cause the benchmark image features to be optimized in the wrong direction.
[0029] In summary, using a trained model for target recognition may result in recognition errors.
[0030] Therefore, this application improves the traditional triplet loss function, which can optimize the network model in the wrong direction to a certain extent, thereby improving the robustness and accuracy of target recognition.
[0031] To illustrate the technical solution of this application, specific embodiments are described below.
[0032] Figure 2 This illustration shows a schematic flowchart of a target recognition method provided in an embodiment of this application. This method can be applied to terminal devices and is suitable for situations requiring improved target recognition accuracy. The terminal device can be a smartphone, computer, in-vehicle device, monitoring equipment, or other intelligent device with target recognition requirements.
[0033] Specifically, the above target recognition method may include the following steps S201 to S203.
[0034] Step S201: Obtain the target image of the target to be identified.
[0035] The target to be identified is the object that needs to be identified, and the target image is the image obtained by acquiring the target. It should be understood that the target to be identified can be a person, vehicle, pet, or other object, and can be adjusted according to the needs of the recognition task.
[0036] In embodiments of this application, the terminal device can acquire the target image in different ways. For example, the terminal device can take a picture of the target to be identified using a camera to obtain the target image. Alternatively, the terminal device can download the target image to be identified from the network. This application does not impose any limitations on this method.
[0037] Step S202: Extract features from the target image to obtain the image features in the target image.
[0038] Image features refer to the features in the target image, which can include features of different image information such as pixel values, contours, and textures in the target image, or features of the target to be identified in the target image, such as key feature points of the target to be identified.
[0039] It should be noted that this application does not restrict the feature extraction method of image features. The terminal device may use Local Binary Patterns (LBP) feature extraction algorithm, Histogram of Oriented Gradient (HOG) feature extraction algorithm, SIFT (Scale-invariant feature transform) feature point extraction algorithm, feature extraction algorithm based on deep neural network (e.g., ResNet), or other algorithms to extract image features of the target image.
[0040] Step S203: Input the image features into the target recognition network model to obtain the recognition result of the category to which the target to be recognized belongs.
[0041] In the embodiments of this application, the target recognition network model is a network model used to perform target recognition and classification on the target to be identified. The loss function of the target recognition network model can be used to constrain the first distance and the second distance corresponding to each triple in multiple triplets.
[0042] The first distance can characterize the distance between the baseline image features in the triplet and the positive sample image features in the same triplet, while the second distance can characterize the distance between the baseline image features in the triplet and the negative sample image features of multiple classes in the same triplet.
[0043] In embodiments of this application, sample images are images used to train the target recognition network model. Sample images can include multiple batches, and each batch can include one or more triples. Each triple is a group of sample images used for a single optimization. Specifically, each triple can include baseline image features of a baseline sample image, positive sample image features of positive sample images, and negative sample image features of multiple categories of negative sample images.
[0044] The reference image can be any image from the sample images, the positive sample image can be a sample image of the same category as the reference image, and the negative sample image can be a sample image of a different category than the reference image. The reference image features, positive sample image features, and negative sample image features are the features extracted from the reference image, positive sample image, and negative sample image, respectively.
[0045] In other words, this application can use multiple triples for model training. Since the triples used in a single optimization include negative sample image features of multiple categories, the loss function needs to consider the distance between the baseline image features and the negative sample image features of multiple categories each time, thus achieving a balance between the number of categories and the number of images in the negative sample images.
[0046] More specifically, the loss value of the target recognition network model's loss function is positively correlated with the first distance and negatively correlated with the second distance.
[0047] It should be understood that the acquisition methods of the above-mentioned sample images (reference sample images, positive sample images and negative sample images) and the feature extraction methods of the sample image features (reference image features, positive sample image features and negative sample image features) can refer to the acquisition methods of the target images and the image feature extraction methods, and this application will not elaborate on these.
[0048] In the embodiments of this application, feature extraction is performed on the target image of the target to be identified to obtain image features in the target image. The image features are then input into the target recognition network model to obtain the recognition result of the category to which the target belongs. The loss function of the target recognition network model is used to constrain the first distance and the second distance corresponding to each triplet in multiple triplets. The first distance represents the distance between the baseline image features in the triplet and the positive sample image features in the same triplet. The second distance represents the distance between the baseline image features in the triplet and the negative sample image features of multiple categories in the same triplet. That is, the number of categories and the number of images of negative sample images are increased in a single optimization, reducing the influence of the wrong labels of negative sample images on the optimization direction of the model. It also avoids the situation where different negative sample images are used in different optimizations and the optimization is in the opposite direction. This makes the trained model more accurate in target recognition and improves the accuracy of target recognition.
[0049] In some embodiments of this application, such as Figure 3 As shown, the calculation process of the above loss function may include the following steps S301 to S305.
[0050] Step S301: Calculate the category center for each category based on the sample image features of each sample image in the batch.
[0051] In the embodiments of this application, the category center can be the mean of the features of all sample images of the corresponding category. The terminal device can calculate the category center of each category based on the sample image features of each sample image in the batch and the category center calculation formula.
[0052] The formula for calculating the category center can be expressed as: f i f represents the category center of the i-th category. i k N represents the sample image features of the k-th sample image of the i-th category in the batch. i This represents the total number of sample images of the i-th category in the batch, which is also the total number of features of the sample images of the i-th category.
[0053] Step S302: Calculate the target negative sample image features for each triplet based on the category center of each category.
[0054] Among them, the target negative sample image features can characterize the negative sample image features of all categories in the triplet.
[0055] In some embodiments of this application, the terminal device can obtain the weight value corresponding to each category in each triplet, and perform a weighted average of the category centers of the corresponding negative sample images in the corresponding triplet based on the weight value corresponding to each category in each triplet, to obtain the target negative sample image features of the corresponding triplet.
[0056] In some implementations, the terminal device can calculate a third distance between the reference image features in the triplet and the category center of each category corresponding to the negative sample image in the triplet, and determine the weight value of the category corresponding to the negative sample image in the triplet based on the third distance. The weight value is inversely proportional to the third distance.
[0057] Specifically, the terminal device can calculate the features of the target negative sample image according to the following feature calculation formula:
[0058] in, Let represent the target negative sample image features of the i-th triplet. C is the total number of classes contained in the triplet. Preferably, each triplet can include negative sample images of all classes in its batch, in which case C is the total number of classes contained in the batch.
[0059] w c w represents the weight of category c. c It can be represented as f c f represents the category center of the c-th category. a Let |i| represent the baseline image feature of the i-th triplet, and |||| represent the norm.
[0060] By using the weighted average method described above, the optimization process can take into account the category center that is relatively closer to the features of the reference sample image.
[0061] Step S303: Calculate the first distance corresponding to each triplet based on the baseline image features of each triplet and the positive sample image features in the corresponding triplet.
[0062] Step S304: Calculate the second distance corresponding to each triplet based on the baseline image features of each triplet and the target negative sample image features of the corresponding triplet.
[0063] Step S305: Determine the loss value of the loss function based on the first distance and the second distance corresponding to each triplet.
[0064] Specifically, using the baseline image features f of the i-th triplet i a and the positive sample image features f in the triplet i p The first distance D(f) corresponding to the triple can be calculated. i a ,f i p For example, it can be done by adjusting f. i a and f i p The first distance is obtained by subtraction.
[0065] Similarly, using the baseline image features f of the i-th triplet i a and the target negative sample image features F of the triple i n The second distance D(f) corresponding to each triple can be calculated. i a ,F i n For example, it can be done by adjusting f.i a and F i n The first distance D(f) is obtained by subtraction. i a ,F i n ).
[0066] At this point, the above loss function can be expressed as:
[0067] Where, N tp f represents the number of triples in the batch. i a Represents the baseline image features of the i-th triple. F represents the positive sample image features of the i-th triplet. i n This represents the target negative sample image features obtained based on the negative sample image features of the i-th triplet. α is a preset distance threshold, α>0, and its specific value can be adjusted according to actual conditions. {x} + This represents the maximum value between x and 0, i.e., {x}. + =max(x,0), D(s,y) represents the distance between x and y.
[0068] Specifically, the loss function proposed in this application considers information from negative sample images of different categories when determining the direction of feature optimization for the baseline image. Please refer to [link / reference]. Figure 4 Solid-color filled circles, diagonally filled circles, and hollow circles represent sample image features of different target categories. Here, a and p represent the baseline image feature and positive sample image feature, respectively. C1 and C2 represent the category centers of different categories, and v1 and v2 represent the optimization directions of baseline image feature a for C1 and C2, respectively. When determining the optimization direction of the baseline image feature a, the optimization directions provided by negative sample image features from two different categories are considered, i.e. Figure 4 The examples shown are v1 and v2. To reduce the impact of mislabeled images, the loss function proposed in this application applies a balancing strategy to the number of negative sample images. When determining the optimization direction of the feature points of the benchmark image for the category corresponding to the features of the negative sample image, we consider not only one image of that category, but all negative sample images of that category in the batch. Figure 4 As shown, the optimization directions (v1 and v2) provided by the negative sample images are determined by the class center of the corresponding category of the negative sample image (the mean of the features of all negative sample images). Therefore, the trained target recognition network model can still classify targets relatively well, improving the accuracy and robustness of target recognition to a certain extent.
[0069] Based on this loss function, the terminal device can acquire sample images of the target object, determine multiple triples based on the sample images, and use the triples to iteratively train the recognition network model to be trained until the loss value of the loss function is less than or equal to a preset loss value threshold, or until the number of iterations of the recognition network model to be trained is greater than or equal to a number threshold, thus obtaining the target recognition network model.
[0070] More specifically, for the sample image {I1,I2,...,I... p Extract the features {f1, f2, ..., f} of the sample images respectively. p}, where p represents the total number of sample images, I p Let f represent the p-th sample image. p Let represent the sample image features of the p-th sample image. Several images are selected from this batch to form a group, which contains sample images of each category. Based on the category, several triplets can be formed.
[0071] The baseline image features of the triples in this batch are input into the recognition network model to be trained to obtain its predicted values. The loss function L is then calculated using the predicted values, positive sample image features, and negative sample image features. eq_triplet The convergence condition of the recognition network model to be trained is that the loss value is less than or equal to the loss value threshold. If the convergence condition is that the loss value is less than or equal to the loss value threshold, then when the loss value is greater than the loss value threshold, the model parameters of the recognition network model to be trained are adjusted, and then a new batch is used to retrain the recognition network model to be trained until the loss value is less than or equal to the loss value threshold, thus obtaining the target recognition network model. If the convergence condition is that the number of iterations is greater than or equal to the number of iterations threshold, then when the number of iterations is less than the number of iterations threshold, the model parameters of the recognition network model to be trained are adjusted, and then a new batch is used to retrain the recognition network model to be trained, and so on, until the number of iterations is greater than or equal to the number of iterations threshold, thus obtaining the target recognition network model.
[0072] Both the number of attempts threshold and the loss threshold can be adjusted according to the actual situation.
[0073] Once the target recognition network model is obtained, the terminal device can use it for target recognition. This target recognition method can be applied to fields such as pedestrian re-identification and vehicle recognition, and this application does not impose any limitations on these applications.
[0074] The target recognition method proposed in this application uses a triplet loss function based on an equalization strategy. This loss function applies an equalization strategy from the perspectives of the number of categories and the number of images in the negative sample images, which alleviates the problems of unstable optimization direction and susceptibility to mislabeling in the traditional triplet loss function, thereby improving the quality of features extracted by the model and improving the accuracy of target recognition.
[0075] It should be noted that, for the sake of simplicity, the aforementioned method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, because according to this application, some steps can be performed in other orders.
[0076] like Figure 5 The diagram shown is a structural schematic of a target identification device 500 provided in an embodiment of this application. The target identification device 500 is configured on a terminal device.
[0077] Specifically, the target identification device 500 may include:
[0078] Image acquisition unit 501 is used to acquire target images of the target to be identified;
[0079] Feature extraction unit 502 is used to extract features from the target image to obtain image features in the target image;
[0080] The target recognition unit 503 is used to input the image features into the target recognition network model to obtain the recognition result of the category to which the target to be recognized belongs. The loss function of the target recognition network model is used to constrain the first distance and the second distance corresponding to each triple in multiple triples. The first distance represents the distance between the reference image features in the triple and the positive sample image features in the same triple. The second distance represents the distance between the reference image features in the triple and the negative sample image features of multiple categories in the same triple.
[0081] In some embodiments of this application, the target recognition device 500 may include a model training unit, configured to: calculate the category center of each category based on the sample image features of each sample image in a batch, wherein the batch includes one or more of the triplets; calculate the target negative sample image features of each triplet based on the category center of each category; calculate the first distance corresponding to each triplet based on the reference image features of each triplet and the positive sample image features in the corresponding triplet; calculate the second distance corresponding to each triplet based on the reference image features of each triplet and the target negative sample image features in the corresponding triplet; and determine the loss value of the loss function based on the first distance and the second distance corresponding to each triplet.
[0082] In some embodiments of this application, the model training unit described above may be specifically used to: obtain the weight value corresponding to each category in each triplet; and, based on the weight value corresponding to each category in each triplet, perform a weighted average of the category centers of the corresponding categories of the negative sample images in the corresponding triplet to obtain the target negative sample image features corresponding to the triplet.
[0083] In some embodiments of this application, the above-mentioned model training unit may be specifically used to: calculate the third distance between the reference image features in the triplet and the category center of each category corresponding to the negative sample image in the triplet; and determine the weight value of the corresponding category of the negative sample image in the triplet based on the third distance, wherein the weight value is inversely proportional to the third distance.
[0084] In some embodiments of this application, the model training unit described above can be specifically used to: calculate the category center for each category based on the sample image features of each sample image in the batch and the category center calculation formula; wherein, the category center calculation formula is expressed as: f i f represents the category center of the i-th category. i k N represents the sample image features of the k-th sample image of the i-th category in the batch. i This represents the total number of sample images of the i-th category in the batch.
[0085] In some embodiments of this application, the above loss function is expressed as: Where, N tp Indicates the number of triples. i a f represents the reference image feature of the i-th triplet. ip F represents the positive sample image feature of the i-th triplet. i n This represents the target negative sample image features obtained based on the negative sample image features of the i-th triplet, where α is a preset distance threshold, and {x} + This indicates taking the maximum value between x and 0.
[0086] D(x,y) represents the distance between x and y.
[0087] In some embodiments of this application, the above-mentioned model training unit can be specifically used to: determine multiple triples based on the sample images; and iteratively train the recognition network model to be trained using the triples with the goal of minimizing the loss function, until the loss value of the loss function is less than or equal to a preset loss value threshold, or until the number of iterations of the recognition network model to be trained is greater than or equal to a number threshold, thereby obtaining the target recognition network model.
[0088] It should be noted that, for the sake of convenience and brevity, the specific working process of the target recognition device 500 described above can be found in the following reference: Figures 2 to 4 The corresponding process of the method will not be described in detail here.
[0089] like Figure 6 The diagram shown is a schematic of a terminal device provided in an embodiment of this application. The terminal device 6 may include: a processor 60, a memory 61, and a computer program 62 stored in the memory 61 and executable on the processor 60, such as a target recognition program. When the processor 60 executes the computer program 62, it implements the steps in the various target recognition method embodiments described above, for example... Figure 2 The steps S201 to S203 are shown. Alternatively, when the processor 60 executes the computer program 62, it implements the functions of each module / unit in the above-described device embodiments, for example... Figure 5 The image acquisition unit 501, feature extraction unit 502, and target recognition unit 503 are shown.
[0090] The computer program can be divided into one or more modules / units, which are stored in the memory 61 and executed by the processor 60 to complete this application. The one or more modules / units can be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program in the terminal device.
[0091] For example, the computer program can be divided into: an image acquisition unit, a feature extraction unit, and a target recognition unit. The specific functions of each unit are as follows: the image acquisition unit is used to acquire a target image of the target to be recognized; the feature extraction unit is used to extract features from the target image to obtain image features in the target image; the target recognition unit is used to input the image features into a target recognition network model to obtain the recognition result of the category to which the target belongs, wherein the loss function of the target recognition network model is used to constrain a first distance and a second distance corresponding to each of the multiple triplets, the first distance representing the distance between the baseline image features in the triplet and the positive sample image features in the same triplet, and the second distance representing the distance between the baseline image features in the triplet and the negative sample image features of multiple categories in the same triplet.
[0092] The terminal device may include, but is not limited to, a processor 60 and a memory 61. Those skilled in the art will understand that... Figure 6 This is merely an example of a terminal device and does not constitute a limitation on the terminal device. It may include more or fewer components than shown, or combine certain components, or different components. For example, the terminal device may also include input / output devices, network access devices, buses, etc.
[0093] The processor 60 may be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.
[0094] The memory 61 can be an internal storage unit of the terminal device, such as a hard drive or RAM. The memory 61 can also be an external storage device of the terminal device, such as a plug-in hard drive, Smart Media Card (SMC), Secure Digital (SD) card, or Flash Card. Furthermore, the memory 61 can include both internal and external storage units. The memory 61 is used to store the computer program and other programs and data required by the terminal device. The memory 61 can also be used to temporarily store data that has been output or will be output.
[0095] It should be noted that, for the sake of convenience and brevity, the structure of the terminal device described above can also be referred to the specific description of the structure in the method embodiment, which will not be repeated here.
[0096] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0097] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0098] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for various specific applications, but such implementations should not be considered beyond the scope of this application.
[0099] In the embodiments provided in this application, it should be understood that the disclosed devices / terminal equipment and methods can be implemented in other ways. For example, the device / terminal equipment embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling or direct coupling or communication connection may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0100] The units described as separate components may or may not be physically separate. 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 the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0101] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0102] If the integrated module / unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electrical carrier signals and telecommunication signals.
[0103] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.
Claims
1. A target recognition method, characterized in that, include: Acquire the target image of the target to be identified; Feature extraction is performed on the target image to obtain the image features in the target image; The image features are input into a target recognition network model to obtain the recognition result of the category to which the target to be recognized belongs. The loss function of the target recognition network model is used to constrain the first distance and the second distance corresponding to each of the multiple triplets. The calculation process of the loss function includes: calculating the category center of each category based on the sample image features of each sample image in a batch, wherein the batch includes one or more triplets; calculating the third distance between the baseline image features in the triplet and the category center of each category corresponding to the negative sample image in the triplet; determining the weight value of the category corresponding to the negative sample image in the corresponding triplet based on the third distance, wherein the weight value is inversely proportional to the third distance; and adjusting the weight value of each category in each triplet according to the weight value of each triplet. The category centers of the corresponding categories of the negative sample images in the group are weighted and averaged to obtain the target negative sample image features of the corresponding triplet. Based on the baseline image features of each triplet and the corresponding positive sample image features in the triplet, a first distance is calculated for each triplet. The first distance represents the distance between the baseline image features in the triplet and the positive sample image features in the same triplet. Based on the baseline image features of each triplet and the corresponding target negative sample image features of the triplet, a second distance is calculated for each triplet. The second distance represents the distance between the baseline image features in the triplet and the negative sample image features of multiple categories in the same triplet. Based on the first distance and the second distance for each triplet, the loss value of the loss function is determined.
2. The target recognition method as described in claim 1, characterized in that, The step of calculating the category center for each category based on the sample image features of each sample image in each batch includes: The category center for each category is calculated based on the sample image features and category center calculation formula of each sample image in the batch. The formula for calculating the category center is as follows: ; This represents the category center of the i-th category. This represents the sample image features of the k-th sample image of the i-th category in the batch. This represents the total number of sample images of the i-th category in the batch.
3. The target recognition method according to any one of claims 1 to 2, characterized in that, The loss function is expressed as: ; in, Indicates the number of triples. Indicates the first The reference image features of the triples Indicates the first Positive sample image features of the triples. Indicates according to the first The target negative sample image features are obtained from the negative sample image features of the triplet. The preset distance threshold, This indicates taking the maximum value between x and 0. .
4. The target recognition method according to any one of claims 1 to 2, characterized in that, The training process of the target recognition network model includes: Acquire the sample image; Multiple triplets are determined based on the sample images; With the goal of minimizing the loss function, the triplet is used to iteratively train the recognition network model to be trained until the loss value of the loss function is less than or equal to a preset loss value threshold, or until the number of iterations of the recognition network model to be trained is greater than or equal to a number threshold, thereby obtaining the target recognition network model.
5. A target recognition device, characterized in that, include: The image acquisition unit is used to acquire the target image of the target to be identified. A feature extraction unit is used to extract features from the target image to obtain image features in the target image; A target recognition unit is used to input the image features into a target recognition network model to obtain the recognition result of the category to which the target to be recognized belongs. The loss function of the target recognition network model is used to constrain the first distance and the second distance corresponding to each of the multiple triplets. The calculation process of the loss function includes: calculating the category center of each category based on the sample image features of each sample image in a batch, wherein the batch includes one or more triplets; calculating the third distance between the baseline image features in the triplet and the category center of each category corresponding to the negative sample image in the triplet; determining the weight value of the category corresponding to the negative sample image in the corresponding triplet based on the third distance, wherein the weight value is inversely proportional to the third distance; and adjusting the weight value of each category in each triplet according to the weight value of each category. The target negative sample image features for each triplet are obtained by weighted averaging the category centers of the corresponding categories of the negative sample images in the triplet. A first distance is calculated for each triplet based on the baseline image features and the corresponding positive sample image features in the triplet. The first distance represents the distance between the baseline image features and the positive sample image features in the same triplet. A second distance is calculated for each triplet based on the baseline image features and the corresponding target negative sample image features. The second distance represents the distance between the baseline image features and the negative sample image features of multiple categories in the same triplet. The loss value of the loss function is determined based on the first distance and the second distance for each triplet.
6. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the target recognition method as described in any one of claims 1 to 4.
7. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the target recognition method as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Accurate retrieval method for target on the basis of deep metric learning
CN106897390A
Image retrieval method based on sorting learning and multivariate loss
CN110188225A
Training method and device of pedestrian image identification model, apparatus and storage medium
CN113780243A