A target recognition method, device and electronic equipment
By utilizing the first loss function and a feature fusion method calculated by self-attention during training, the problem of unsatisfactory target discrimination performance of deep learning models across different categories is solved, thereby improving the accuracy of target recognition.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG DAHUA TECH CO LTD
- Filing Date
- 2022-11-23
- Publication Date
- 2026-05-08
AI Technical Summary
In existing technologies, due to factors such as target pose, imaging scene, viewpoint, and occlusion, deep learning models have poor target discrimination performance among different categories, resulting in a decrease in target recognition accuracy.
By using the first loss function during training to reduce the feature space gap of easily confused types and by performing feature fusion through self-attention calculation, the recognition accuracy of the model is improved.
It effectively improves the accuracy of target recognition, especially in the recognition of easily confused target types, and enhances the model's discrimination ability.
Smart Images

Figure CN115761351B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image recognition technology, and in particular to a method, apparatus and electronic device for target recognition. Background Technology
[0002] Currently, deep learning models in the field of image recognition have greatly improved the performance of tasks such as classification and detection through learning and training on massive amounts of data. However, due to factors such as the pose of the target, the imaging scene, the viewpoint, and occlusion, the performance of deep learning models in distinguishing between targets of different categories is not ideal.
[0003] Taking vehicle type classification as an example, vehicles can be categorized into trucks, buses, public buses, cars, tricycles, etc. For some business scenarios, more detailed classification is needed; for example, trucks can be further divided into light trucks, medium trucks, and large trucks. When identifying different types of targets within a broad category, the accuracy of target type recognition is more easily affected by factors such as lighting, imaging angle, and imaging distance. Therefore, the accuracy of target recognition in existing technologies needs improvement. Summary of the Invention
[0004] This invention provides a method, apparatus, and electronic device for target recognition, which improves the accuracy of target recognition.
[0005] In a first aspect, embodiments of this application provide a method for target recognition, including:
[0006] The training image is input into the model to be trained, and the confidence level of the first target in the training image as a possible type is determined; wherein, the training image includes a one-to-one correspondence between the first target and a first preset type label, the first preset type label is used to indicate the first preset type; the possible types correspond one-to-one with the confidence level, and the first target corresponds to at least two possible types;
[0007] Among the possible types of the first target, the highest confidence level is identified as the first confidence level, and the possible type corresponding to the first confidence level is identified as the first possible type; and the confidence level that is only lower than the first confidence level is identified as the second confidence level, and the possible type corresponding to the second confidence level is identified as the second possible type.
[0008] In response to the first possible type being consistent with the first preset type label of the first target, the parameters in the model to be trained are adjusted using the first loss function to reduce the gap between the attribute elements of the first possible type and the attribute elements of the first preset type, and to increase the gap between the attribute elements of the first possible type and the attribute elements of the second possible type, until the value of the first loss function is less than the first preset threshold, thereby obtaining a classification model.
[0009] The image to be detected is input into the classification model to determine the target type of the target in the image to be detected.
[0010] This application embodiment, during the training process of the model to be trained, utilizes a first loss function to not only reduce the gap between the first possible type and the second possible type, but also applies a distance penalty in the feature space to the attribute elements of the two possible types (i.e., the first possible type and the second possible type) with higher confidence, thereby increasing the gap between the attribute elements of the first possible type and the attribute elements of the second possible type. This enables the model to be trained to accurately distinguish between the first possible type and the second possible type, thus enabling the model to be trained to more accurately identify and differentiate targets with similar features but different types, thereby effectively improving the accuracy of identifying the target type in the image to be detected.
[0011] In one possible implementation, the first loss function includes a first sub-loss function and a second sub-loss function; the second sub-loss function is negatively correlated with the distance between the attribute elements of the first possible type and the attribute elements of the second possible type in the feature space.
[0012] One possible implementation is that the first loss function is L = L cls +γ·L confuse , L cls L is a classification loss function corresponding to the difference between attribute elements of the first possible type and attribute elements of the first preset type. cnfuse The classification loss function is defined as the difference between attribute elements of the first possible type and attribute elements of the second possible type; γ is a preset hyperparameter, ε is a preset constant, and PT is a preset hyperparameter. j For the attribute element of the first possible type, PT i For the second possible type of attribute element; Dist(PT) i PT j ) is PT i and PT j The distance in the feature space.
[0013] One possible implementation includes, before adjusting the parameters in the model to be trained using the first loss function:
[0014] The attribute elements of the first preset type are updated using the attribute elements corresponding to the first possible type, resulting in the updated attribute elements of the first preset type.
[0015] One possible implementation, wherein updating the attribute elements of the first preset type using the attribute elements corresponding to the first possible type to obtain the updated attribute elements of the first preset type includes:
[0016] The attribute elements of the first preset type are updated using an update formula to obtain the updated attribute elements of the first preset type; wherein, the update formula is:
[0017] ω is the preset harmonic factor, t is the iteration number, j is the label of the first possible type, and PT j (t) For the updated attribute element of the first preset type, PT j (t-1) For the attribute element of the first preset type; T j (t) For the hidden layer input corresponding to the attribute element of the updated first preset type, score j This represents the first confidence level.
[0018] One possible implementation further includes, prior to responding to the first possible type matching the first preset type label of the first target:
[0019] In response to the inconsistency between the first possible type and the first preset label type, the L in the first loss function is adjusted. cnfuse Setting it to 0 yields the second loss function;
[0020] Among the possible types corresponding to the confidence level of the first target, a third possible type that is consistent with the first preset type label is determined;
[0021] Based on the third confidence level corresponding to the third possible type, the parameters in the model to be trained are adjusted using the second loss function until the value of the second loss function is less than the first preset threshold, thereby obtaining the classification model.
[0022] One possible implementation, in response to the first possible type corresponding to the first confidence level being consistent with the first preset type label of the first target, adjusting the parameters in the model to be trained using a first loss function until the value of the first loss function is less than a first preset threshold to obtain a classification model, includes:
[0023] In response to the first confidence level being greater than the second preset threshold, based on the first possible type and the second possible type corresponding to the second confidence level, the parameters in the model to be trained are adjusted using the first loss function until the value of the first loss function is less than the first preset threshold, thereby obtaining a classification model.
[0024] One possible implementation, after responding to the first possible type corresponding to the first confidence level being consistent with the first preset type label of the first target, further includes:
[0025] In response to the first confidence level being greater than the second preset threshold, it is determined whether the second confidence level is greater than the second preset threshold; if not, the parameters in the model to be trained are adjusted using the second loss function to reduce the gap between the attribute element of the first possible type and the attribute element of the first preset type until the value of the second loss function is less than the first preset threshold, thereby obtaining the classification model.
[0026] In one possible implementation, the second loss function is the L cls .
[0027] One possible implementation involves inputting the image to be detected into the classification model to determine the target type of the target in the image to be detected, including:
[0028] The image to be detected is input into the target classification model to obtain N types of image patches; wherein, the N types of image patches are image patches with the same shape but different sizes, and each type of image patch independently constitutes the image to be detected, and N is an integer greater than 1;
[0029] The target image patch size for feature fusion is determined based on the distance between the target image patch and the minimum-sized image patch. Based on self-attention calculation, feature fusion is performed using the minimum-sized image patch as the processing unit to obtain the feature matrix of the minimum-sized image patch and the feature matrix of the image to be detected. The size of the target image patch increases with the increase of the distance.
[0030] Based on the feature matrix of the image to be detected, the target type of the target in the image to be detected is identified.
[0031] One possible implementation involves determining the target image patch size for feature fusion based on the distance to the smallest image patch, and performing feature fusion using the smallest image patch as a processing unit based on self-attention computation to obtain the feature matrix of the smallest image patch and the feature matrix of the image to be detected, including:
[0032] The image to be detected is divided into M regions, including the smallest size image block; wherein the M regions are nested, the shape of each of the M regions is the same as the shape of the smallest size image block, M is an integer greater than 1, and M≤N;
[0033] Based on the distances between the M regions and the minimum-size image block, the size of the target image block after feature fusion between each of the M regions and the minimum-size image block is determined, as well as the target image block corresponding to the target image block size of each region;
[0034] Using the self-attention calculation, feature fusion is performed on the minimum size image patch and the target image patch in the M regions to obtain the feature matrix of the minimum size image patch;
[0035] The feature matrix of the image to be detected is obtained by combining the feature matrices of the smallest size image block.
[0036] In one possible implementation, where M = N and N = 2, the N types of image blocks include a first image block and a second image block, wherein the first image block and the second image block have the same shape, and the size of any combination of four first image blocks is the same as the size of the second image block;
[0037] The step of determining the target image patch size for feature fusion based on the distance to the smallest image patch, and performing feature fusion using the smallest image patch as the processing unit based on self-attention calculation to obtain the feature matrix of the smallest image patch, includes:
[0038] The image to be detected is divided into a first region and a second region, which includes a first image block to be processed; wherein the second region is embedded in the first region, and the size of the first region is not smaller than the size of the second image block.
[0039] Within the first region, the size of the target image block that is feature-fused with the first image block to be processed is determined to be the size of the first image block, and the target image block in the first region is the first image block; within the second region, the size of the target image block that is feature-fused with the first image block to be processed is determined to be the size of the second image block, and the target image block in the second region is the second image block;
[0040] Based on the self-attention calculation, feature fusion is performed between the first image block in the first region and the first image block to be processed, and feature fusion is performed between the second image block in the second region and the first image block to be processed, to obtain the feature matrix of the first image block to be processed.
[0041] Secondly, embodiments of this application provide a target recognition device, comprising:
[0042] Input unit: used to input training images into the model to be trained, and determine the confidence level of the first target in the training image as a possible type; wherein, the training image includes a one-to-one correspondence between the first target and a first preset type label, the first preset type label is used to indicate the first preset type; the possible types correspond one-to-one with the confidence level, and the first target corresponds to at least two possible types;
[0043] The marking unit is configured to: determine the highest confidence level as the first confidence level among the possible types of the first target, and mark the possible type corresponding to the first confidence level as the first possible type; and determine the confidence level that is only lower than the first confidence level as the second confidence level, and mark the possible type corresponding to the second confidence level as the second possible type.
[0044] Adjustment unit: In response to the first possible type being consistent with the first preset type label of the first target, the parameters in the model to be trained are adjusted using a first loss function to reduce the gap between the attribute elements of the first possible type and the attribute elements of the first preset type, and to increase the gap between the attribute elements of the first possible type and the attribute elements of the second possible type, until the value of the first loss function is less than a first preset threshold, thereby obtaining a classification model;
[0045] Detection unit: used to input the image to be detected into the classification model to determine the target type of the target in the image to be detected.
[0046] In one possible implementation, the first loss function includes a first sub-loss function and a second sub-loss function; the second sub-loss function is negatively correlated with the distance between the attribute elements of the first possible type and the attribute elements of the second possible type in the feature space.
[0047] One possible implementation is that the first loss function is L = L cls +γ·L confuse , L cls L is the classification loss function corresponding to the difference between the first confidence level and 1. cnfuse To distinguish the classification loss functions of the first and second possible types, the second confidence level corresponding to the second possible type is the confidence level that is only lower than the first confidence level; γ is a preset hyperparameter, ε is a preset constant, and PT... j For the attribute element of the first possible type, PT i For the second possible type of attribute element; Dist(PT) iPT j ) is PT i and PT j Distance in the feature space.
[0048] In one possible implementation, the device further includes an update unit, which is specifically used to update the attribute elements of the first preset type using the attribute elements corresponding to the first possible type, so as to obtain the updated attribute elements of the first preset type.
[0049] In one possible implementation, the update unit is specifically used to update the attribute elements of the first preset type using an update formula to obtain the updated attribute elements of the first preset type; wherein, the update formula is: ω is the preset harmonic factor, t is the iteration number, j is the label of the first possible type, and PT j (t) For the updated attribute element of the first preset type, PT j (t-1) For the attribute element of the first preset type; T j (t) For the hidden layer input corresponding to the attribute element of the updated first preset type, score j This represents the first confidence level.
[0050] In one possible implementation, the adjustment unit is specifically used to adjust the parameters in the model to be trained based on the first possible type and the second possible type corresponding to the second confidence level, in response to the first confidence level being greater than the second preset threshold, until the value of the first loss function is less than the first preset threshold, thereby obtaining a classification model.
[0051] In one possible implementation, the adjustment unit is further configured to, in response to the first confidence level being greater than the second preset threshold, determine whether the second confidence level is greater than the second preset threshold; if not, adjust the parameters in the model to be trained using the second loss function to reduce the gap between the attribute element of the first possible type and the attribute element of the first preset type until the value of the second loss function is less than the first preset threshold, thereby obtaining the classification model.
[0052] In one possible implementation, the detection unit is specifically used to input the image to be detected into a target classification model to obtain N types of image patches; wherein, the N types of image patches are image patches with the same shape but different sizes, and each type of image patch independently constitutes the image to be detected, and N is an integer greater than 1; the size of the target image patch for feature fusion is determined based on the distance between it and the smallest size image patch, and feature fusion is performed using the smallest size image patch as the processing unit based on self-attention calculation to obtain the feature matrix of the smallest size image patch and the feature matrix of the image to be detected; wherein, the size of the target image patch increases with the increase of the distance; and the target type of the target in the image to be detected is identified based on the feature matrix of the image to be detected.
[0053] In one possible implementation, the detection unit is further configured to divide the image to be detected into M regions including the minimum-size image block; wherein the M regions are nested, the shape of each of the M regions is the same as the shape of the minimum-size image block, M is an integer greater than 1, and M≤N; based on the distance between the M regions and the minimum-size image block, determine the size of the target image block in each of the M regions after feature fusion with the minimum-size image block, and the target image block corresponding to the target image block size of each region; use the self-attention calculation to perform feature fusion on the minimum-size image block and the target image blocks in the M regions to obtain the feature matrix of the minimum-size image block; combine the feature matrix of the minimum-size image block to obtain the feature matrix of the image to be detected.
[0054] In one possible implementation, where M = N and N = 2, the N image blocks of different sizes include a first image block and a second image block. The first image block and the second image block have the same shape, and the size of any combination of four first image blocks is the same as the size of the second image block. The detection unit is further configured to divide the image to be detected into a first region and a second region, including the first image block to be processed. The second region is embedded within the first region, and the size of the first region is not smaller than the size of the second image block. Within the first region, the size of the target image block that undergoes feature fusion with the first image block to be processed is determined to be the size of the first image block, and the target image block of the first region is the first image block. Within the second region, the size of the target image block that undergoes feature fusion with the first image block to be processed is determined to be the size of the second image block, and the target image block of the second region is the second image block. Based on the self-attention calculation, feature fusion is performed between the first image block in the first region and the first image block to be processed, and feature fusion is performed between the second image block in the second region and the first image block to be processed, to obtain the feature matrix of the first image block to be processed.
[0055] Thirdly, embodiments of this application provide a readable storage medium, including,
[0056] memory,
[0057] The memory is used to store instructions that, when executed by a processor, cause an apparatus including the readable storage medium to perform the method as described in the first aspect and any possible implementation.
[0058] Fourthly, embodiments of this application provide an electronic device, including:
[0059] Memory, used to store computer programs;
[0060] When a processor executes a computer program stored in the memory, it implements the method as described in the first aspect and any possible implementation. Attached Figure Description
[0061] Figure 1 A flowchart illustrating a target recognition method provided in an embodiment of this application;
[0062] Figure 2 This is a schematic diagram of the structure of a model to be trained provided in an embodiment of this application;
[0063] Figure 3 This is a schematic diagram of an image block obtained by dividing the image to be detected when N=3, as provided in an embodiment of this application.
[0064] Figure 4 This is a schematic diagram illustrating feature fusion of image blocks when N=3, provided as an embodiment of this application.
[0065] Figure 5 This is a schematic diagram of an image block obtained by dividing the image to be detected when N=2, according to an embodiment of this application.
[0066] Figure 6 This is a schematic diagram illustrating feature fusion of image blocks when N=2, provided as an embodiment of this application.
[0067] Figure 7 This is a schematic diagram illustrating feature fusion of image blocks when N=2, provided as an embodiment of this application.
[0068] Figure 8 A schematic diagram of the structure of a target recognition device provided in an embodiment of this application;
[0069] Figure 9 This is a schematic diagram of the structure of an electronic device for target recognition provided in an embodiment of this application. Detailed Implementation
[0070] To address the low accuracy of target recognition in existing technologies, this application proposes a target recognition method: First, a training image is input into the model to be trained to determine the possible types of a first target in the training image and the confidence level of that possible type. Then, the highest confidence level is labeled as the first confidence level, and the possible type corresponding to that first confidence level is labeled as the first possible type. Next, in response to the first possible type matching the first preset type label of the first target, the parameters in the model to be trained are adjusted using a first loss function to obtain a classification model for recognizing targets in the image to be detected. That is, the target recognition method in this application improves the accuracy of target recognition by applying distance penalty to easily confused types in the feature space through Lconfuse in the loss function, enabling the model to more clearly distinguish the target type of the target among easily confused types during training.
[0071] To better understand the above technical solutions, the technical solutions of this application will be described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the embodiments of this application and the specific features in the embodiments are detailed descriptions of the technical solutions of this application, rather than limitations on the technical solutions of this application. In the absence of conflict, the embodiments of this application and the technical features in the embodiments can be combined with each other.
[0072] Please refer to Figure 1 This application proposes a target recognition method to improve the accuracy of target recognition. The method specifically includes the following implementation steps:
[0073] Step 101: Input the training image into the model to be trained and determine the confidence that the first target in the training image is a possible type.
[0074] The training images include a first target and a one-to-one correspondence between the first target and a first preset type label, whereby the first preset type label indicates a first preset type. The possible types correspond one-to-one with confidence levels, and the first target corresponds to at least two possible types.
[0075] In practice, when training a model, multiple identical training images can be input sequentially, or training images containing different types of targets can be input sequentially. Each training image can include one or more different types of targets, such as a second target, a third target, etc., that have a different type label from the first target (i.e., a different type).
[0076] Once the training images are fed into the model to be trained, the model will output a confidence score for the first target as a possible type through an activation function. This confidence score indicates the probability that the first target is of the current possible type. Please refer to [reference needed]. Figure 2 For example, the confidence scores output by the activation function include 0.83, 0.35, 0.92, and 0.13. Each of these confidence scores carries a label indicating the possible types, i.e., the corresponding possible types. For instance, 0.83 and its corresponding possible type label k indicate that the probability of the first target being type k is 0.83.
[0077] In this embodiment of the application, the model to be trained can be constructed based on the Vision Transformer structure, such as... Figure 2 As shown, Merging is used to fuse features from training images, Transformer Encoder is the backbone network used for feature extraction, and MLP is the classification head used for further feature extraction.
[0078] Step 102: Among the possible types of the first target, determine the highest confidence level as the first confidence level and mark the possible type corresponding to the first confidence level as the first possible type; and determine the confidence level that is only lower than the first confidence level as the second confidence level and mark the possible type corresponding to the second confidence level as the second possible type.
[0079] Please continue to refer to this. Figure 2 ,but Figure 2 The first confidence level is 0.92, and the possible type corresponding to this confidence level is the first possible type; then the second confidence level is 0.83, and the possible type corresponding to this confidence level is the second possible type.
[0080] Step 103: In response to the first possible type being consistent with the first preset type label of the first target, the parameters in the model to be trained are adjusted using the first loss function to reduce the gap between the attribute elements of the first possible type and the attribute elements of the first preset type, and to increase the gap between the attribute elements of the first possible type and the attribute elements of the second possible type, until the value of the first loss function is less than the first preset threshold, thus obtaining the classification model.
[0081] In other words, when this embodiment uses the first loss function to adjust the parameters in the model to be trained, it does so by narrowing the distance between the attribute elements of the first possible type and the attribute elements of the first preset type in the feature space. Simultaneously, for the model to be trained, when faced with any type of target that is easily confused or difficult to identify, it generally identifies that type of target as one of the two possible types with the highest confidence levels. This is because the attribute elements of the two easily confused possible types are too close in the feature space. Therefore, the first loss function also applies a distance penalty to the attribute elements of the first type and the attribute elements of the second type in the feature space, increasing the gap between the attribute elements of the first possible type and the attribute elements of the second possible type.
[0082] The fact that the value of the first loss function is less than a first preset threshold indicates that the first loss function has converged. This first loss function may include a first sub-loss function and a second sub-loss function. The second sub-loss function is negatively correlated with the distance between attribute elements of the first possible type and attribute elements of the second possible type in the feature space.
[0083] For example, the first loss function is L = L cls +γ·L confuse , Then L confuse This is the second sub-loss function.
[0084] Among them, L cls This is the classification loss function corresponding to the difference between the aforementioned first confidence level and 1. It is used to inversely adjust the parameters in the model being trained to reduce this difference, thereby gradually improving the recognition accuracy of the model. cls The binary cross-entropy loss function L can be used. cls =-y i logy i ′, where y i y is the true value of the first preset type label corresponding to the first target. i ′ represents the predicted value corresponding to the first possible type.
[0085] γ is a preset hyperparameter, which can be set to 1. L confuse To distinguish between the first and second possible types of classification loss functions, i.e., through L... confueIn the feature space, a distance penalty is applied to the attribute elements corresponding to the first and second possible types to enable the model to be trained to distinguish between these two easily confused types. confuse ε is a preset constant, which is small (e.g., 0.01) to avoid division by zero.
[0086] PT j For the attribute element of the first possible type mentioned above, PT i The attribute element is of the second possible type; Dist(PT) i PT j ) for PT i and PT j The distance in the feature space. Dist(PT) i PT j The distance can be obtained using the cosine similarity function; that is, the cosine similarity function can be used as the distance function Dist(·).
[0087] This application's embodiment sets up global feature attribute elements for the loss function to facilitate adjustments to the parameters in the model to be trained. Please continue to refer to... Figure 2 Assuming there are n types, then for each type of target, we maintain a feature attribute element, denoted as PT. i (i = 1, 2, ..., n). T i It can be Figure 2 The input to the classifier MLP can also be the hidden layer of the MLP; PT i This is achieved by updating Ti using the corresponding values of multiple training images. Therefore, when the first possible type corresponding to the first confidence level matches the first preset type label, i.e., when the model being trained correctly identifies the type of the first target, the attribute elements corresponding to the first possible type can be used to update the attribute elements of the first preset type. This allows the first possible type identified by the model being trained to gradually overlap with the first preset type during the iteration process. The aforementioned first preset type label is used to indicate the first preset type. The update formula is as follows:
[0088] ω is a preset harmonic factor, w can be set to 2, t is the number of iterations, j is the label of the first possible type in the model to be trained, and PT j (t) For the updated attribute element of the first preset type, PT j (t-1) For the first preset type of attribute element; score j The first confidence level is the first objective mentioned above.
[0089] Furthermore, to avoid the situation where the recognition result of the model to be trained is unreliable due to a low first confidence level, in one embodiment of this application, the first confidence level must be greater than a second preset threshold. This second preset threshold can be 0.8; otherwise, the recognition result of the model to be trained is determined to be unreliable. Therefore, it is unnecessary to impose a distance penalty on the attribute elements of the first possible type and the attribute elements of the second possible type. Instead, the distance (i.e., the gap) between the attribute elements of the first possible type and the attribute elements of the first preset type can be narrowed first through a second loss function. The difference in the second loss function lies in the L value in the second loss function. cnfus The value is 0, meaning the second loss function is L. cls .
[0090] As the number of training iterations (intensity) of the model increases, the initial confidence level of the targets identified by the model will gradually increase, meaning the first possible type will gradually approach the first preset type. This continues until the first possible type exceeds a second preset threshold. Then, the first loss function is used to adjust the model until it converges. In this embodiment, the parameters of the model are first adjusted using the second loss function, and then the parameters are adjusted again using the first loss function after the initial confidence level exceeds the second preset threshold. This achieves the goal of setting different training objectives for the model at different learning stages, thereby improving the training efficiency of the model.
[0091] Furthermore, in response to the first confidence level being greater than the aforementioned second preset threshold, firstly, among the confidence levels of the first target, the confidence level that is only lower than the first confidence level is determined as the second confidence level. Then, based on the first possible type and the second possible type corresponding to the second confidence level, that is, based on the attribute elements corresponding to the first possible type and the second possible type respectively, the parameters in the model to be trained are adjusted in reverse using the first loss function. During this adjustment process, the first possible confidence level will gradually tend to 1, and the confusion between the first possible type and the second possible type in the model to be trained will be effectively alleviated.
[0092] Clearly, the above distinction between the first and second possible types is particularly applicable to two easily confused target types. When these two possible types are identified by the model to be trained, they will achieve high and similar similarities. Therefore, in one embodiment of this application, in response to both the first and second confidence scores being greater than a second preset threshold, the parameters of the model to be trained are adjusted using the first loss function to obtain a classification model. When the first confidence score is higher than the second preset threshold and the second confidence score is lower than the second preset threshold, it can be determined that the first and second confidence scores differ significantly, and therefore, it is unnecessary to apply distance penalties to the attribute elements of the first and second possible types.
[0093] That is, the possible types of the first confidence level and the second confidence level are not as easily mixed as described above, and because the second possible confidence level is lower than the second preset threshold, the identification results regarding the second possible confidence level and the second possible type are unreliable. Therefore, when the first possible confidence level is higher than the second preset threshold and the second possible confidence level is lower than the second preset threshold, the distance penalty step for training the model to distinguish between the first and second possible types can be omitted, i.e., let L... cnfuse Setting it to 0 yields the second loss function, which only narrows the distance (i.e., the gap) between the first possible type attribute element and the first preset type attribute element.
[0094] In other words, to improve the efficiency of the model to be trained, the parameters of the model to be trained can be adjusted in reverse using the second loss function until the value of the first loss function is less than the first preset threshold, thus obtaining the classification model.
[0095] Furthermore, in response to the inconsistency between the first possible type and the first preset type label of the first target, i.e., the first possible type is different from the first preset type, it is determined that the training model has made a recognition error. To improve the training efficiency of the training model, this embodiment focuses on the accuracy of target recognition rather than precision at this stage. Therefore, a second loss function can be used to adjust the training model at this time. Specifically, firstly, among the possible types corresponding to the confidence level of the first target, a third possible type that is the same as the first preset label is determined. Then, based on the third confidence level corresponding to the third possible type, the second loss function is used to adjust the training model.
[0096] Step 104: Input the image to be detected into the classification model to obtain the target type of the target in the image to be detected.
[0097] Specifically, in this embodiment of the application, when performing feature fusion based on Vision Transformer, i.e., when performing feature fusion on the input image to be detected, in order to improve the efficiency of feature fusion based on self-attention computation without affecting the accuracy of feature fusion, the classification model divides the model to be trained into N image blocks of different sizes but the same shape. Then, the size of the target image block and the target image block are determined based on the distance to the smallest image block; and based on self-attention computation, feature fusion is performed using the smallest image block as the processing unit to obtain the feature matrix of the smallest image block. The same feature fusion steps as described above are performed on each image block to obtain the feature matrix of the image to be detected. The size of the target image block increases with the distance, and N is an integer greater than 1, so the size of the target image block should be consistent with the N divided image blocks.
[0098] In this embodiment, the image block is rectangular. To facilitate the determination and division of the target image block for feature fusion, among the N sizes, the smaller image block can be combined into a larger image block.
[0099] It should be noted that, for the purpose of facilitating feature fusion, the token dimensions of image blocks of any size in this application embodiment are all equal.
[0100] Accordingly, after determining N partitioning methods, when performing feature fusion on each smallest-size image block, the image to be detected can be divided into M regions, including the currently processed smallest-size image block. These M regions are nested, forming M regions "radiating" outwards from the smallest-size image block to the surrounding areas of the image to be detected. Here, M is an integer greater than 1, and M ≤ N. During feature fusion, based on the distance from the currently processed image block, the size of the image block to be fused with the smallest-size image block in each region increases sequentially. That is, the size of the target image block to be fused with the smallest-size image block increases with the distance between the region and the smallest-size image block. The size of the target image block in each region is different and increases sequentially. The target image block corresponding to this size is then used to perform feature fusion with the smallest-size image block to obtain the feature matrix of the currently processed smallest-size image block. The aforementioned steps are repeated to obtain the feature matrices of each smallest-size image block in the image to be detected, and then combined to obtain the feature matrix of the image to be detected.
[0101] The following examples illustrate the division of image blocks into N sizes and M regions.
[0102] Figure 3 This application provides a method for dividing an image to be detected when N=3, as shown in the following embodiment. Figure 3 As shown, (a)-(c) represent three ways of dividing the same image to be detected, resulting in three image patch sizes. In part (a), the image patch size is 3a×4a. In part (b), the image patch size is 2a×a. In part (c), the image patch size is 1.5a×a. Further reference... Figure 3 Therefore, any four adjacent image blocks in part (b) can be combined to form an image block in part (a). Any two vertically adjacent image blocks in part (c) can be combined to form an image block in part (b).
[0103] Figure 4 To Figure 3 The smallest image patch in the diagram, i.e., any image patch feature fusion diagram in part (c), shows that the pure black image patch is the current processing unit, and the shadow image patches with different linear shapes are the target image patches that are divided into different regions for feature fusion targeting the current processing unit. (Continue to refer to...) Figure 4As can be seen, M = N = 3; as the distance between the target image block and the current processing unit increases, the size of the target image block increases, and the regions are nested with each other. The largest region (blank) is hollow, with a region containing a diagonal shaded area. The region containing the diagonal shaded area is a hollow shape with the same shape but a smaller area, and the smallest region is embedded in the hollow position.
[0104] That is, with the processing unit ( Figure 4 The key for feature fusion of the query (a pure black image patch) starts as the key of the smaller image patch and gradually changes to the key of the larger image patch as the distance from the current processing unit increases, until the key of the largest image patch is obtained.
[0105] In other words, before feature fusion, the image to be detected can be divided into M nested regions, and each of the M regions includes a minimum-sized image patch, such as... Figure 4 As shown in the diagram, M regions have the same shape as the smallest image patch, and the smallest region among the M regions includes the smallest image patch itself and image patches of the same size adjacent to the smallest image patch. Then, based on the distance between the M regions and the smallest image patch, the size of the target image patch for feature fusion between the image patches in the M regions and the smallest image patch is determined, and the target image patch for each region feature-fused with the smallest image patch is determined according to this target image patch size. Finally, using self-attention calculation, feature fusion is performed on the smallest image patch and the target image patches in the M regions to obtain the feature matrix of the smallest image patch; the M regions correspond to target image patches of N sizes.
[0106] The following example illustrates feature fusion based on self-attention computation when N=2. When M=N and N=2, as follows... Figure 5 As shown, the smaller image block obtained from (a) partial division is the first image block, and the larger image block obtained from (b) partial division is the second image block. If the first image block has a length and width of P, then the second image block has a length and width of 2P.
[0107] That is, the image to be detected is first divided into a first region and a second region, which includes the first image block to be processed. The second region is embedded within the first region, and the first region includes the first image block to be processed, and the size of the first region is not smaller than the size of the second image block. (Continue to refer to...) Figure 6If the pure black image block is the first image block to be processed, the shaded area is the first region, and the non-shaded area is the second region, then the second region is hollow, embedding the first region. The size of the first region is 3a×3a. The target image block size in the shaded area (first region) is the same as the size of the first image block, and the target image block size in the non-shaded area (second region) is the same as the size of the second image block. Then, within the first region, the target image block for feature fusion with the first image block to be processed is determined as the first image block; within the second region, the target image block for feature fusion with the first image block to be processed is determined as the second image block. Based on the self-attention calculation, feature fusion is performed using the first image block in the first region and the first image block to be processed, and feature fusion is performed using the second image block in the second region and the first image block to be processed, to obtain the feature matrix of the first image block to be processed. Repeating the above steps, each first image block in the image to be detected is taken as the first image block to be processed, its feature matrix is determined, and then combined to obtain the feature matrix of the image to be detected.
[0108] It should be noted that, in the embodiments of this application, when setting the first region, the second region, or the Mth region, it is preferable to use the first image block as the center of the region, such as... Figure 7 As shown. Specifically, when performing feature fusion on the first image patch at the four corners or near the edge of the image to be detected, the first region or the Mth region is no longer determined with the first image patch as the center; instead, the region closest to the center of the first image patch is used as the first region or the Mth region, as shown. Figure 8 As shown.
[0109] The feature fusion described in this embodiment corresponds to feature fusion in self-attention computation: each image patch corresponds to a token, which is mapped to obtain a query vector, a key vector, and a value vector. During feature fusion, the similarity between the query of the smallest-sized image patch and the key vector of each target-sized image patch is calculated, and used as the weight of the value vector. This process is repeated sequentially, and the value vectors are weighted and summed to obtain the feature matrix of the currently processed smallest-sized image patch.
[0110] By sequentially performing feature fusion on each image patch using the aforementioned steps, a feature matrix for each image patch is obtained. Combining these feature matrices yields the feature matrix of the image to be detected. That is, corresponding to... Figure 2 Output from the Merging module.
[0111] Next, the aforementioned feature matrix will be processed by the Encoder, MLP, and activation function in the classification model to output the confidence score. The possible type corresponding to the maximum confidence score is determined as the target type of the target in the image to be detected.
[0112] Based on the same inventive concept, this application provides a target recognition device, which is similar to the aforementioned device. Figure 1 The target recognition method shown corresponds to the specific implementation of this device, which can be found in the description of the aforementioned method embodiments. Repeated descriptions will not be repeated here. Figure 8 The device includes:
[0113] Input unit 801: Used to input training images into the model to be trained and determine the confidence level of the first target in the training image as a possible type.
[0114] The training images include a one-to-one correspondence between the first target and a first preset type label, the first preset type label being used to indicate a first preset type; the possible types correspond one-to-one with the confidence levels, and the first target corresponds to at least two of the possible types.
[0115] The marking unit 802 is configured to: determine the highest confidence level among the possible types of the first target as a first confidence level, and mark the possible type corresponding to the first confidence level as a first possible type; and determine the confidence level that is only lower than the first confidence level as a second confidence level, and mark the possible type corresponding to the second confidence level as a second possible type.
[0116] Adjustment unit 803: In response to the first possible type being consistent with the first preset type label of the first target, it uses a first loss function to adjust the parameters in the model to be trained, so that the gap between the attribute elements of the first possible type and the attribute elements of the first preset type is reduced, and the gap between the attribute elements of the first possible type and the attribute elements of the second possible type is increased, until the value of the first loss function is less than a first preset threshold, thereby obtaining a classification model.
[0117] The first loss function includes a first sub-loss function and a second sub-loss function; the second sub-loss function is negatively correlated with the distance between the attribute elements of the first possible type and the attribute elements of the second possible type in the feature space.
[0118] The first loss function is L = L cls +γ·L confuse , L cls L is the classification loss function corresponding to the difference between the first confidence level and 1. cnfuse To distinguish the classification loss functions of the first and second possible types, the second confidence level corresponding to the second possible type is the confidence level that is only lower than the first confidence level; γ is a preset hyperparameter, ε is a preset constant, and PT... j For the attribute element of the first possible type, PT iFor the second possible type of attribute element; Dist(PT) i PT j ) for PT i and PT j Distance in the feature space.
[0119] The adjustment unit 803 is specifically used to respond to the first confidence level being greater than the second preset threshold, determine whether the second confidence level is greater than the second preset threshold; if not, adjust the parameters in the model to be trained using the second loss function to reduce the gap between the attribute element of the first possible type and the attribute element of the first preset type until the value of the second loss function is less than the first preset threshold, thereby obtaining the classification model.
[0120] The second loss function is the L cls .
[0121] Detection unit 804: Used to input the image to be detected into the classification model to determine the target type of the target in the image to be detected.
[0122] The detection unit 804 is specifically used to input the image to be detected into the target classification model to obtain N types of image patches; wherein, the N types of image patches are image patches with the same shape but different sizes, and each type of image patch independently constitutes the image to be detected, and N is an integer greater than 1; the size of the target image patch for feature fusion is determined according to the distance between it and the smallest size image patch, and feature fusion is performed using the smallest size image patch as the processing unit based on self-attention calculation to obtain the feature matrix of the smallest size image patch and the feature matrix of the image to be detected; wherein, the size of the target image patch increases with the increase of the distance; and the target type of the target in the image to be detected is identified based on the feature matrix of the image to be detected.
[0123] The detection unit 804 is further configured to divide the image to be detected into M regions including the minimum-size image block; wherein the M regions are nested, the shape of each of the M regions is the same as the shape of the minimum-size image block, M is an integer greater than 1, and M≤N; based on the distance between the M regions and the minimum-size image block, determine the size of the target image block in each of the M regions after feature fusion with the minimum-size image block, and the target image block corresponding to the size of the target image block in each region; use the self-attention calculation to perform feature fusion on the minimum-size image block and the target image blocks in the M regions to obtain the feature matrix of the minimum-size image block; combine the feature matrix of the minimum-size image block to obtain the feature matrix of the image to be detected.
[0124] Where M = N and N = 2, the N types of image blocks include a first image block and a second image block. The first image block and the second image block have the same shape, and the size of any combination of four first image blocks is the same as the size of the second image block. The detection unit 804 is further configured to divide the image to be detected into a first region and a second region, which includes the first image block to be processed. The second region is embedded in the first region, and the size of the first region is not less than the size of the second image block. In the first region, the size of the target image block that is feature fused with the first image block to be processed is determined to be the size of the first image block, and the target image block in the first region is the first image block. In the second region, the size of the target image block that is feature fused with the first image block to be processed is determined to be the size of the second image block, and the target image block in the second region is the second image block. Based on the self-attention calculation, the first image block in the first region is used to perform feature fusion with the first image block to be processed, and the second image block in the second region is used to perform feature fusion with the first image block to be processed, to obtain the feature matrix of the first image block to be processed.
[0125] The aforementioned target recognition device further includes an update unit, which is specifically used to update the attribute elements of the first preset type using the attribute elements corresponding to the first possible type, so as to obtain the updated attribute elements of the first preset type.
[0126] The update unit is specifically used to update the attribute elements of the first preset type using an update formula to obtain the updated attribute elements of the first preset type; wherein, the update formula is: ω is the preset harmonic factor, t is the iteration number, j is the label of the first possible type, and PT j (t) For the updated attribute element of the first preset type, PT j (t-1) For the attribute element of the first preset type; T j (t) For the hidden layer input corresponding to the attribute element of the updated first preset type, score j This represents the first confidence level.
[0127] Based on the same inventive concept, embodiments of this application also provide a readable storage medium, including:
[0128] memory,
[0129] The memory is used to store instructions that, when executed by a processor, cause the apparatus including the readable storage medium to perform the target identification method as described above.
[0130] Based on the same inventive concept as the target recognition method described above, this application also provides an electronic device that can implement the function of the aforementioned target recognition method. Please refer to [link / reference needed]. Figure 9 The electronic device includes:
[0131] At least one processor 901 and a memory 902 connected to at least one processor 901. In this embodiment, the specific connection medium between the processor 901 and the memory 902 is not limited. Figure 9 The example shown is the connection between processor 901 and memory 902 via bus 900. Bus 900 is... Figure 9 The connections between other components are indicated by thick lines and are for illustrative purposes only, not as limiting information. The Bus 900 can be divided into address bus, data bus, control bus, etc., for ease of representation. Figure 9 The term is represented by a single thick line, but this does not imply that there is only one bus or one type of bus. Alternatively, the processor 901 can also be called a controller; there is no restriction on the name.
[0132] In this embodiment, memory 902 stores instructions executable by at least one processor 901. By executing the instructions stored in memory 902, at least one processor 901 can perform the target recognition method described above. Processor 901 can implement... Figure 8 The functions of each module in the device shown.
[0133] The processor 901 is the control center of the device. It can connect to various parts of the control device through various interfaces and lines. By running or executing instructions stored in memory 902 and calling data stored in memory 902, the processor can perform various functions and process data, thereby monitoring the device as a whole.
[0134] In one possible design, processor 901 may include one or more processing units. Processor 901 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may also not be integrated into processor 901. In some embodiments, processor 901 and memory 902 may be implemented on the same chip; in some embodiments, they may also be implemented on separate chips.
[0135] The processor 901 can be a general-purpose processor, such as a central processing unit (CPU), digital signal processor, application-specific integrated circuit, field-programmable gate array or other programmable logic device, discrete gate or transistor logic device, or discrete hardware component, capable of implementing or executing the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the target recognition method disclosed in the embodiments of this application can be directly manifested as being executed by a hardware processor, or executed by a combination of hardware and software modules within the processor.
[0136] Memory 902, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. Memory 902 may include at least one type of storage medium, such as flash memory, hard disk, multimedia card, card-type memory, random access memory (RAM), static random access memory (SRAM), programmable read-only memory (PROM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), magnetic storage, magnetic disk, optical disk, etc. Memory 902 can be any other medium capable of carrying or storing desired program code in the form of instructions or data structures that can be accessed by a computer, but is not limited thereto. In the embodiments of this application, memory 902 can also be a circuit or any other device capable of implementing storage functions for storing program instructions and / or data.
[0137] By designing and programming the processor 901, the code corresponding to the target recognition method described in the foregoing embodiments can be embedded into the chip, enabling the chip to execute it during operation. Figure 1 The steps of the target recognition method are shown. How to design and program the processor 901 is a technique well-known to those skilled in the art and will not be described further here.
[0138] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional modules is used as an example. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. The specific working process of the system, device, and unit described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0139] In the several embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus 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 coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0140] 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.
[0141] 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.
[0142] If the integrated 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, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes: Universal Serial Bus flash disks, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, optical disks, and other media capable of storing program code.
[0143] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.
Claims
1. A method for target recognition, characterized in that, include: The training image is input into the model to be trained, and the confidence level of the first target in the training image as a possible type is determined; wherein, the training image includes a one-to-one correspondence between the first target and a first preset type label, the first preset type label is used to indicate the first preset type; the possible types correspond one-to-one with the confidence level, and the first target corresponds to at least two possible types; Among the possible types of the first target, the highest confidence level is determined as the first confidence level, and the possible type corresponding to the first confidence level is marked as the first possible type; and the confidence level that is only lower than the first confidence level is determined as the second confidence level, and the possible type corresponding to the second confidence level is marked as the second possible type. In response to the first possible type matching the first preset type label of the first target, the parameters in the model to be trained are adjusted using a first loss function to reduce the gap between the attribute elements of the first possible type and the attribute elements of the first preset type, and to increase the gap between the attribute elements of the first possible type and the attribute elements of the second possible type, until the value of the first loss function is less than a first preset threshold, thus obtaining a classification model; wherein, the first loss function includes a first sub-loss function and a second sub-loss function; the second sub-loss function is negatively correlated with the distance between the attribute elements of the first possible type and the attribute elements of the second possible type in the feature space; The image to be detected is input into the classification model to determine the target type of the target in the image to be detected.
2. The method as described in claim 1, characterized in that, The first loss function is , , L cls The classification loss function corresponds to the difference between the attribute element of the first possible type and the attribute element of the first preset type. L cnfuse γ is the classification loss function corresponding to the difference between the attribute element of the first possible type and the attribute element of the second possible type; γ is a preset hyperparameter, and ε is a preset constant. PT j For the attribute element of the first possible type, PT i For the second possible type of attribute element; for PT i and PT j The distance in the feature space.
3. The method as described in claim 1, characterized in that, Before adjusting the parameters in the model to be trained using the first loss function, the method further includes: The attribute elements of the first preset type are updated using the attribute elements corresponding to the first possible type, resulting in the updated attribute elements of the first preset type.
4. The method as described in claim 3, characterized in that, The step of updating the attribute elements of the first preset type using the attribute elements corresponding to the first possible type to obtain the updated attribute elements of the first preset type includes: The attribute elements of the first preset type are updated using an update formula to obtain the updated attribute elements of the first preset type; wherein, the update formula is: ; , The preset harmonic factor, For the number of iterations, j For the first possible type of tag, PT j (t) For the updated first preset type of attribute element, PT j (t-1) For the attribute element of the first preset type; T j (t) For the hidden layer input corresponding to the attribute element of the updated first preset type, score j This represents the first confidence level.
5. The method according to any one of claims 1-4, characterized in that, After the response that the first possible type corresponding to the first confidence level is consistent with the first preset type label of the first target, it further includes: In response to the first confidence level being greater than the second preset threshold, it is determined whether the second confidence level is greater than the second preset threshold; if not, the parameters in the model to be trained are adjusted using the second loss function to reduce the gap between the attribute element of the first possible type and the attribute element of the first preset type until the value of the second loss function is less than the first preset threshold, thereby obtaining the classification model.
6. The method as described in claim 5, characterized in that, The second loss function is the L cls .
7. The method according to any one of claims 1-4, 6, characterized in that, The step of inputting the image to be detected into the classification model to determine the target type of the target in the image to be detected includes: The image to be detected is input into the target classification model to obtain N types of image patches; wherein, the N types of image patches are image patches with the same shape but different sizes, and each type of image patch independently constitutes the image to be detected, and N is an integer greater than 1; The target image patch size for feature fusion is determined based on the distance between the target image patch and the minimum-sized image patch. Based on self-attention calculation, feature fusion is performed using the minimum-sized image patch as the processing unit to obtain the feature matrix of the minimum-sized image patch and the feature matrix of the image to be detected. The size of the target image patch increases with the increase of the distance. Based on the feature matrix of the image to be detected, the target type of the target in the image to be detected is identified.
8. The method as described in claim 7, characterized in that, The step of determining the target image patch size for feature fusion based on the distance to the smallest image patch, and performing feature fusion using the smallest image patch as the processing unit based on self-attention calculation to obtain the feature matrix of the smallest image patch and the feature matrix of the image to be detected, includes: The image to be detected is divided into M regions, including the smallest size image block; wherein the M regions are nested, the shape of each of the M regions is the same as the shape of the smallest size image block, M is an integer greater than 1, and M≤N; Based on the distances between the M regions and the minimum-size image block, the size of the target image block after feature fusion between each of the M regions and the minimum-size image block is determined, as well as the target image block corresponding to the target image block size of each region; Using the self-attention calculation, feature fusion is performed on the minimum size image patch and the target image patch in the M regions to obtain the feature matrix of the minimum size image patch; The feature matrix of the image to be detected is obtained by combining the feature matrices of the smallest size image block.
9. The method as described in claim 8, characterized in that, If M=N and N=2, then the N types of image blocks include a first image block and a second image block. The first image block and the second image block have the same shape, and the size of any combination of four first image blocks is the same as the size of the second image block. The target image patch size for feature fusion is determined based on the distance to the smallest image patch. Then, based on self-attention calculation, feature fusion is performed using the smallest image patch as the processing unit to obtain the feature matrix of the smallest image patch, including: The image to be detected is divided into a first region and a second region, which includes a first image block to be processed; wherein the second region is embedded in the first region, and the size of the first region is not smaller than the size of the second image block. Within the first region, the size of the target image block that is feature-fused with the first image block to be processed is determined to be the size of the first image block, and the target image block in the first region is the first image block; within the second region, the size of the target image block that is feature-fused with the first image block to be processed is determined to be the size of the second image block, and the target image block in the second region is the second image block; Based on the self-attention calculation, feature fusion is performed between the first image block in the first region and the first image block to be processed, and feature fusion is performed between the second image block in the second region and the first image block to be processed, to obtain the feature matrix of the first image block to be processed.
10. A target recognition device, characterized in that, include: Input unit: used to input training images into the model to be trained, and determine the confidence level of the first target in the training image as a possible type; wherein, the training image includes a one-to-one correspondence between the first target and a first preset type label, the first preset type label is used to indicate the first preset type; the possible types correspond one-to-one with the confidence level, and the first target corresponds to at least two possible types; The marking unit is configured to: determine the highest confidence level as the first confidence level among the possible types of the first target, and mark the possible type corresponding to the first confidence level as the first possible type; and determine the confidence level that is only lower than the first confidence level as the second confidence level, and mark the possible type corresponding to the second confidence level as the second possible type. Adjustment unit: In response to the first possible type matching the first preset type label of the first target, the unit adjusts the parameters in the model to be trained using a first loss function to reduce the gap between the attribute elements of the first possible type and the attribute elements of the first preset type, and to increase the gap between the attribute elements of the first possible type and the attribute elements of the second possible type, until the value of the first loss function is less than a first preset threshold, thereby obtaining a classification model; wherein, the first loss function includes a first sub-loss function and a second sub-loss function; the second sub-loss function is negatively correlated with the distance between the attribute elements of the first possible type and the attribute elements of the second possible type in the feature space; Detection unit: used to input the image to be detected into the classification model to determine the target type of the target in the image to be detected.
11. A readable storage medium, characterized in that, include, memory, The memory is used to store instructions that, when executed by a processor, cause the apparatus including the readable storage medium to perform the method as described in any one of claims 1-9.
12. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor, when executing a computer program stored in the memory, implements the method as described in any one of claims 1-9.
Citation Information
Patent Citations
Image classification method and device, storage medium and terminal
CN114821207A