Image recognition method based on explicit space and implicit logarithm relation prompt
By employing image recognition methods that utilize explicit spatial and implicit logarithmic relation cues, the problems of weak knowledge transfer capability and low recognition accuracy in the knowledge distillation compression model are addressed, achieving efficient image recognition in resource-constrained environments.
Patent Information
- Application Number
- CN202510947894.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-10
- Publication Date
- 2025-11-18
AI Technical Summary
Existing image recognition models that have undergone knowledge distillation and compression suffer from weak knowledge transfer capabilities and low recognition accuracy.
By constructing an image recognition method with explicit spatial and implicit logarithmic relation cues, explicit spatial cues are generated to locate the class interest regions co-occurring in the images for both the teacher and student models, while implicit logarithmic relation cues are generated to alleviate the confidence distribution bias. The total loss function during distillation is constructed by combining the two methods to optimize the student model.
Without increasing model parameters and computational overhead, the image recognition capability of the student model was significantly improved, achieving efficient knowledge transfer and recognition accuracy.
Smart Images

Figure CN120976707A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image processing, in particular to an image recognition method based on explicit space and implicit logarithmic relationship prompt. BACKGROUND
[0002] Deep learning is widely used in the field of image recognition due to its excellent performance, and the high performance of deep neural network model usually depends on its own massive learnable parameters, which leads to the consumption of a large amount of computing resources in storage and inference process. In actual application, the device resources are often limited, which limits the effect of image recognition.
[0003] In order to achieve better image recognition effect on limited resources, the prior art has the method of optimizing deep neural network through model compression technology, among which, knowledge distillation technology has been studied more and more because it can flexibly realize model compression. However, when using knowledge distillation to compress image processing model, there is a problem of weak knowledge transfer ability; and when using the model compressed by knowledge distillation to recognize images, there is also a problem of low recognition accuracy. SUMMARY
[0004] Therefore, the technical problem to be solved by the present application is to overcome the shortcomings in the prior art and provide an image recognition method based on explicit space and implicit logarithmic relationship prompt, which can improve the knowledge transfer ability from teacher model to student model during image recognition and improve the image recognition ability.
[0005] To solve the above technical problems, the present application provides an image recognition method based on explicit space and implicit logarithmic relationship prompt, comprising:
[0006] The image data is divided into a training set and a test set, a teacher model and a student model are constructed, the teacher model is divided into n segments in proportion, and the student model is divided into corresponding n segments according to network depth;
[0007] When training the teacher model and the student model using the training set, the forward propagation of the teacher model and the student model is simultaneously performed by synchronously inputting the image, to obtain the feature map of each segment and the final predicted logic value;
[0008] An explicit space prompt of the feature map of each segment is generated, and the explicit space prompt is used to locate the class interest region co-occurring to the image by the teacher model and the student model;
[0009] An implicit logarithmic relationship prompt of the final predicted logic value is generated, and the implicit logarithmic relationship prompt is used to relieve the confidence distribution bias of the image;
[0010] The total loss function during distillation is constructed in combination with the explicit spatial prompt and the implicit logarithmic relationship prompt, and the training of the student model is completed when the total loss function during distillation converges.
[0011] The test set is input into the trained student model to obtain an image recognition result.
[0012] Further, the explicit spatial prompt of the feature map of each segment is generated, specifically:
[0013] The gradient-weighted class activation mapping function is used to generate the heat map corresponding to the feature map of each segment of the teacher model and the heat map corresponding to the feature map of each segment of the student model,
[0014] The heat map corresponding to the feature map of each segment of the teacher model and the heat map corresponding to the feature map of each segment of the student model are unified in resolution and normalized to obtain the teacher prompt and the student prompt;
[0015] The non-co-occurrence area of the teacher prompt and the student prompt is filtered to obtain a co-occurrence mask, and the co-occurrence mask is used as the explicit spatial prompt, and the explicit spatial prompt is:
[0016]
[0017] Wherein, M j is the explicit spatial prompt of the jth segment, σ() is an activation function, is the teacher prompt, is the student prompt, and is an element-wise multiplication.
[0018] Further, the heat map corresponding to the feature map of each segment of the teacher model is specifically:
[0019]
[0020] Wherein, is the heat map corresponding to the feature map of the jth segment of the teacher model, GradCAM() is a gradient-weighted class activation mapping function operation, is the feature map of the jth segment of the teacher model, j=1, 2,.., n; ReLU() is an activation function, and k is the gradient weight of the teacher model.
[0021] The heat map corresponding to the feature map of each segment of the student model is specifically:
[0022]
[0023] Wherein, is the heat map corresponding to the feature map of the jth segment of the student model, is the feature map of the jth segment of the student model, j=1, 2,.., n; Fc j,s is the target class score of the kth token, F is the gradient weight of the student model.
[0024] Further, the calculation method of the gradient weight of the teacher model is:
[0025]
[0026] wherein T is the number of tokens in the neural network, y k is the target class score of the kth token, F t j,T is the target class score of the kth token, F
[0027] is the gradient weight of the student model, the calculation method is:
[0028]
[0029] wherein H is the height of the token, W is the width of the token, y k is the target class score of the kth token, is the F c j,s at position (h, w), h = 1, 2, …, H, w = 1, 2, …, W.
[0030] Further, the hidden logistic relationship hint for generating the logical value of the final prediction is specifically:
[0031] mapping the logical value of the final prediction of the student model to the dimension of the logical value of the final prediction of the teacher model through a learnable multi-layer perception, to obtain the mapped logical value of the final prediction of the student model, denoted as Z S is the logical value of the final prediction of the student model, W MLP is the weight of the learnable multi-layer perception;
[0032] normalizing the logical value of the final prediction of the teacher model to obtain the teacher hidden logistic relationship hint:
[0033]
[0034] wherein, is the teacher hidden logistic relationship hint, Z T is the logical value of the final prediction of the teacher model, and |||2 is the two-norm;
[0035] The normalized logical value of the mapped student model final prediction is obtained as a student hidden logarithmic relationship hint:
[0036]
[0037] wherein, is the student hidden logarithmic relationship hint, is the logical value of the mapped student model final prediction.
[0038] Further, when setting the weight decay rate equal to the learning rate of the learnable multilayer perceptron during training of the student model, the update method of the learnable multilayer perceptron weight is:
[0039]
[0040] wherein, W MLP ’ is the updated learnable multilayer perceptron weight, η is the weight decay rate, α MLP is the learning rate of the learnable multilayer perceptron, and () T is the transpose operation.
[0041] Further, the total loss function during distillation is:
[0042]
[0043] wherein, is the total loss function during distillation, is the cross-entropy loss of the student model, is the explicit space hint loss, is the hidden logarithmic relationship hint loss, and λ1 and λ2 are weight coefficients.
[0044] Further, the calculation method of the explicit space hint loss is:
[0045]
[0046] wherein, M j is the explicit space hint of the jth segment, is the feature map of the jth segment of the teacher model, is the feature map of the jth segment of the student model, j = 1, 2,.., n; is the element-wise multiplication, and |||2 is the two-norm.
[0047] Further, the calculation method of the hidden logarithmic relationship hint loss is:
[0048]
[0049] wherein, is the corresponding hidden logarithmic relationship hint of the student model, Hints for the implicit logarithmic relationship corresponding to the teacher model. Let p be the p-th level regularization for the i-th logits, where p is the smoothing factor.
[0050] Furthermore, when inputting the test set into the trained student model for image recognition, the steps of generating explicit spatial hints for the feature maps of each segment and implicit logarithmic relation hints for generating the final predicted logical value are not performed.
[0051] Compared with the prior art, the above-described technical solution of the present invention has the following advantages:
[0052] This invention mitigates cross-architecture representation discrepancies and accurately guides student models in image feature learning by constructing explicit spatial cues, and reduces gradient penalties and corrects confidence distribution bias by constructing implicit logarithmic relation cues. Both explicit spatial cues and implicit logarithmic relation cues are jointly embedded in the distillation loss to synergistically optimize the student model, enabling it to effectively absorb implicit knowledge without increasing the number of parameters. Thus, without increasing the student model's parameters or inference overhead, this invention significantly improves the student model's image recognition capabilities, achieving efficient knowledge transfer from heterogeneous teacher models to student models during image recognition. Attached Figure Description
[0053] To make the content of this invention easier to understand, the invention will be further described in detail below with reference to specific embodiments and accompanying drawings, wherein:
[0054] Figure 1 This is a flowchart of a method in a preferred embodiment of the present invention.
[0055] Figure 2 This is a schematic diagram of the knowledge distillation process in a preferred embodiment of the present invention.
[0056] Figure 3 This is a schematic diagram illustrating the generation of explicit spatial hints in a preferred embodiment of the present invention.
[0057] Figure 4 This is a schematic diagram illustrating the generation of implicit logarithmic relation hints in a preferred embodiment of the present invention. Detailed Implementation
[0058] The present invention will be further described below with reference to the accompanying drawings and specific embodiments, so that those skilled in the art can better understand and implement the present invention. However, the embodiments described are not intended to limit the present invention.
[0059] Reference Figure 1 , Figure 2 As shown, this invention discloses an image recognition method based on explicit space and implicit logarithmic relation cues, comprising the following steps:
[0060] S1: Obtain image data and divide it into a training set and a test set, and construct a teacher model and a student model; in this embodiment, VIT-small is selected as the teacher model, and ResNet18 is selected as the student model, and the specific selection of the teacher model and the student model can be adjusted according to actual conditions.
[0061] S2: Divide the teacher model into n segments in proportion, and divide the student model into corresponding n segments according to the network depth; in this embodiment, n=3 is taken as an example, the teacher model (denoted as T) is divided into three distillation layer stages according to the number of layers, denoted as {T1, T2, T3}, and the student model (denoted as S) is divided into corresponding three segments according to the distillation layer stage, denoted as {S1, S2, S3}. The weights of the teacher model are frozen, and the weights of the student model are randomly initialized or loaded as Imagenet pre-training parameters.
[0062] S3: When training the teacher model and the student model using the training set, forward propagation of the teacher model and the student model is simultaneously performed on an input batch of images x i (i=1, 2, …, B) synchronously, B is the size of a batch in the training process, to obtain feature maps of each segment and finally predicted logits.
[0063] S4: As shown in Figure 3 , an explicit spatial hint of the feature maps of each segment is generated, and the explicit spatial hint is used to locate a class interest region co-occurring to the image by the teacher model and the student model.
[0064] S4-1: A Gradient-weighted Class Activation Mapping (GradCAM) function is used to generate a heat map corresponding to the feature maps of each segment of the teacher model and a heat map corresponding to the feature maps of each segment of the student model.
[0065] The heat map corresponding to the feature maps of each segment of the teacher model is specifically:
[0066]
[0067] Wherein, is a heat map corresponding to the feature maps of the jth segment of the teacher model, GradCAM() is a Gradient-weighted Class Activation Mapping function operation, is the feature maps of the jth segment of the teacher model, j=1, 2, …, n; E is the dimension of token in Vision Transformer, N is the number of tokens; ReLU() is an activation function, and k is the gradient weight of the teacher model, and kThe calculation method of is:
[0068]
[0069] Wherein, T is the number of tokens in the neural network, y k is the target class score of the kth token, F t j,T is the target class score of the kth token, F
[0070] The feature map corresponding to the heat map of each segment of the student model is specifically:
[0071]
[0072] Wherein, is the heat map corresponding to the feature map of the jth segment of the student model, is the feature map of the jth segment of the student model, j=1,2,..,n; C is the channel dimension of the token, H is the height of the token, and W is the width of the token; F c j,S is the target class score of the cth token, is the gradient weight of the student model, The calculation method of is:
[0073]
[0074] Wherein, y k is the target class score of the kth token, is F c j,s at position (h,w), h=1,2,…,H, w=1,2,…,W.
[0075] GradCAM measures the spatial region most concerned in the decision-making process of the network by calculating the gradient contribution of the predicted class score to the feature map.
[0076] S4-2: unify the resolution and normalize the heat map corresponding to the feature map of each segment of the teacher model and the heat map corresponding to the feature map of each segment of the student model, to obtain the teacher prompt and the student prompt.
[0077] S4-2-1: unify the resolution of to resolution h j ×w j , to obtain the heat map of , which is denoted as , to obtain the heat map of , which is denoted as Wherein hj ×w j = min(H, W).
[0078] S4-2-2: Normalization Get the teacher hint, denoted as |||2 is the two-norm; normalized Get the student hint, denoted as
[0079] S4-3: Filter the non-co-occurrence area of the teacher hint and the student hint to get the co-occurrence mask, and take the co-occurrence mask as the explicit spatial hint, the explicit spatial hint is:
[0080]
[0081] Where, M j is the explicit spatial hint of the jth segment, σ() is the Sigmoid activation function, is the teacher hint, is the student hint, and is the element-wise multiplication.
[0082] S5: As shown in Figure 4 , generate the implicit log relationship hint of the logical value of the final prediction, which is used to alleviate the confidence distribution bias of the image.
[0083] S5-1: Map the logical value of the final prediction of the student model to the dimension of the logical value of the final prediction of the teacher model through a learnable multilayer perceptron (MLP), to obtain the mapped logical value of the final prediction of the student model, denoted as Z S is the logical value of the final prediction of the student model, W MLP is the weight of the learnable multilayer perceptron, B is the size of a batch in the training process, ds is the dimension of the token in the student network, and dr is the dimension of the token in the teacher network.
[0084] S5-2: Normalize the logical value of the final prediction of the teacher model to obtain the teacher implicit log relationship hint:
[0085]
[0086] Where, is the teacher implicit log relationship hint, Z T is the logical value of the final prediction of the teacher model, and |||2 is the two-norm.
[0087] The normalized logical value of the mapped final prediction of the student model is obtained as a student hidden logarithmic relationship prompt:
[0088]
[0089] wherein, is a student hidden logarithmic relationship prompt, is a logical value of the mapped final prediction of the student model.
[0090] The teacher model and the student model can learn hidden knowledge in the logarithmic space of the final layer output, but will produce serious bias on the prediction distribution of the final output, that is, the logarithmic relationship between the target class and the non-target class is different. For example, a convolutional neural network will predict a motorcycle image and a truck image to belong to the same class with the same probability, because the convolutional neural network tends to capture local features, such as the round wheels shared by the two; and the Vision Transformer is good at modeling global features, such as the arc-shaped body of the motorcycle and the rectangular body of the truck, so the classification probabilities of the two will be obviously biased. In order to alleviate the bias of the prediction confidence of the teacher model and the student output in image recognition, the present application designs a mapping head based on a soft maximum function, mainly including a normalization layer, a learnable multiple layer perception (MLP) and a soft maximum function. Specifically, the normalization layer and the learnable multiple layer perception are used to soften the logarithmic distribution output by the final layer of the teacher model and the student model, and the soft maximum function is used to constrain the knowledge distillation process in the softened hidden logarithmic space.
[0091] S4 and S5 can be performed simultaneously or sequentially, and in the present embodiment, an example of generating an explicit space prompt first and then generating a hidden logarithmic relationship prompt is taken. For the output features of each layer stage, the spatial position prompt related to the class mode information is interactively modeled to guide the teacher model and the student model to pay attention to the co-occurring class interest position; for the predicted logical value logits, firstly, the cross-entropy loss function is used to constrain the student model, and secondly, the logits distribution bias is optimized through a learnable mapping head and the hidden logarithmic relationship between the teacher model and the student model is constrained through a soft maximum function. In the test stage, the auxiliary distillation process of S4 and S5 is removed, the original architecture of the student model is maintained, and no additional calculation cost is introduced in the inference process.
[0092] S6: combining the explicit space prompt and the hidden logarithmic relationship prompt to construct a total loss function during distillation, using a stochastic gradient descent method to perform back propagation update on the learnable parameters of the student model and the mapping head, and completing the training of the student model when the total loss function during distillation converges.
[0093] During the distillation process, the gradient is calculated as Branches are Ws are learnable parameters in the student network.
[0094] The optimizer used by the student model is SGD (momentum 0.9), and the optimizer used by the mapping head is Adam (β1=0.9, β2=0.999).
[0095] Learning rate strategy: student 0.1→0, mapping head 1e-3→1e-5, both using cosine annealing.
[0096] When training the student model, when setting the weight decay rate η equal to the learning rate α of the learnable multilayer perceptron MLP , the update method of the learnable multilayer perceptron weight is:
[0097]
[0098] where W MLP ’ is the updated learnable multilayer perceptron weight, η is the weight decay rate, α MLP is the learning rate of the learnable multilayer perceptron, () T is the transpose operation. Through this update method, W MLP has a smoother and more stable mapping capability.
[0099] The total loss function during distillation is:
[0100]
[0101] where, is the total loss function during distillation, is the cross-entropy loss of the student model, B is the size of a batch in the training process, y i is the target class score of the i-th class, Z S,i is the Z S of the i-th class; is the explicit spatial cue loss, is the implicit logarithmic relationship cue loss, λ1 and λ2 are weight coefficients, λ1=1.0 and λ2=2.0 when the data set is small; λ1=0.5 and λ2=1.5 when the data set is large.
[0102] The calculation method of the explicit spatial cue loss is:
[0103]
[0104] where M j is the explicit spatial cue of the j-th segment, is the feature map of the j-th segment of the teacher model, is the feature map of the jth segment of the student model, j = 1, 2,.., n; is the element-wise multiplication, is the 2-norm. The explicit spatial cue loss performs pixel-level constraints on the co-occurrence area at each stage, thereby explicitly aligning the class interest position.
[0105] The calculation method of the implicit logit relation cue loss is defined by a mapping head of a soft-max function (softmax) as follows:
[0106]
[0107] wherein, is the corresponding implicit logit relation cue of the student model, is the corresponding implicit logit relation cue of the teacher model, is the p-level regularization of the i th logits, p is a smoothing factor, 0 < p < 1, and in the embodiment, p = 0.7 is taken to weaken the dominant role of high-confidence classes on the gradient and ensure more uniform knowledge transfer.
[0108] S7: inputting the test set into the trained student model to obtain an image recognition result.
[0109] When the test set is inputted into the trained student model for image recognition, the steps of generating the explicit spatial cue of the feature map of each segment and generating the implicit logit relation cue of the final predicted logic value are not performed. Only the student model is retained for lightweight inference, ensuring that the model parameter quantity and the calculation overhead remain completely consistent before distillation, and ensuring that there is no additional burden for mobile end deployment. The actual measured delay is only 12 ms per 224x224 picture on a mobile end (such as Snapdragon 865, 4GB RAM).
[0110] The application further discloses an image recognition system based on explicit spatial and implicit logit relation cues, comprising:
[0111] an image acquisition module, configured to acquire image data and divide the image data into a training set and a test set;
[0112] a model construction module, configured to construct a teacher model and a student model;
[0113] a model segmentation module, configured to divide the teacher model into n segments according to a proportion and divide the student model into corresponding n segments according to network depth;
[0114] a feature acquisition module, configured to input an image synchronously and perform forward propagation of the teacher model and the student model simultaneously to obtain feature maps of each segment and a final predicted logic value when the teacher model and the student model are trained using the training set;
[0115] An explicit spatial hint generation module is configured to generate an explicit spatial hint of a feature map of each segment, and the explicit spatial hint is used to locate a class interest region of the image co-occurred by the teacher model and the student model.
[0116] A hidden logarithmic relationship hint generation module is configured to generate a hidden logarithmic relationship hint of a final prediction of a logic value, and the hidden logarithmic relationship hint is used to relieve a confidence distribution bias of the image.
[0117] A training module is configured to train the teacher model and the student model using a training set, to construct a total loss function during distillation in combination with the explicit spatial hint and the hidden logarithmic relationship hint, and to complete the training of the student model when the total loss function during distillation converges.
[0118] An image recognition module is configured to input a test set into the trained student model to obtain an image recognition result.
[0119] The application further discloses a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the image recognition method based on the explicit spatial hint and the hidden logarithmic relationship hint.
[0120] The application further discloses a device, which comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the image recognition method based on the explicit spatial hint and the hidden logarithmic relationship hint when executing the computer program.
[0121] Compared with the prior art, the application has the following advantages:
[0122] 1. The gradient weighted class activation mapping is used to capture the class interest position of the image of the teacher model and the student model, the mask mechanism is used to interactively locate the co-occurrence spatial region, the explicit spatial hint is constructed, the accuracy of the spatial hint is improved, the cross-architecture representation difference is relieved, and the student model is accurately guided to learn the image features.
[0123] 2. The logits output by the teacher model and the student model are softened based on the learnable multilayer perception and normalization, the hidden logarithmic relationship hint is constructed by constraint construction through a soft maximum function, the gradient penalty is reduced, the confidence distribution bias is corrected, and the logarithmic distribution bias is effectively utilized.
[0124] 3. The explicit spatial hint and the hidden logarithmic relationship hint are embedded in the distillation loss together, the student model is optimized in cooperation, and the hidden knowledge is effectively absorbed by the student model under the premise of constant parameter quantity.
[0125] 4. In the image recognition stage after the training is completed, only the lightweight student model is retained, and efficient image classification suitable for resource-limited scenarios is achieved. Efficient knowledge transfer from the heterogeneous teacher model to the student model during image recognition can be achieved without increasing the parameters and inference overhead of the student model, thereby significantly improving the image recognition capability of the student model.
[0126] In order to further prove the beneficial effects of the present application, an ablation experiment is performed in this embodiment. The module for generating explicit spatial hints is denoted as an explicit spatial hint distillation module (ESH), and the module for generating implicit logarithmic relation hints is denoted as an implicit logits relation distillation module (ILR). The student model is distilled using the distillation method after ablation of ILR, the distillation method after ablation of ESH, and the complete distillation method of the present application, respectively. The image recognition accuracy of the distilled student model is shown in Table 1.
[0127] Table 1 Comparison of image recognition accuracy of student model under different knowledge distillation methods
[0128]
[0129] In Table 1, Teacher represents image recognition using only the Teacher large model, Student represents image recognition using only the Student small model, the accuracy of large model recognition is higher than that of small model but the large model cannot be deployed on limited device resources. Student+ESH represents image recognition using the student model after distilling the student model using the distillation method after ablation of ILR; Student+ILR represents image recognition using the student model after distilling the student model using the distillation method after ablation of ESH; Student+the method of the present application represents image recognition using the student model after distilling the student model using the complete distillation method (i.e., using both ESH and ILR) of the present application.
[0130] As can be seen from Table 1, the image recognition accuracy of the student model is significantly improved after using the method of the present application, thereby proving the beneficial effects of the present application.
[0131] Those skilled in the art will appreciate that embodiments of the present application can be provided as methods, systems, or computer program products. Accordingly, the present application can take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROMs, optical storage media, etc.) having computer-usable program code embodied therein.
[0132] The computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart block or blocks. Figure 1 one or more flowcharts and / or blocks Figure 1 means for functionally implementing the steps listed in the flowchart block or blocks.
[0133] These computer program instructions can also be stored in a computer readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer readable memory produce an article of manufacture including instructions which implement the function specified in the flowchart block or blocks. Figure 1 one or more flowcharts and / or blocks Figure 1 means for functionally implementing the steps listed in the flowchart block or blocks.
[0134] The computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart block or blocks. Figure 1 one or more flowcharts and / or blocks Figure 1 means for functionally implementing the steps listed in the flowchart block or blocks.
[0135] Obviously, the above-described embodiments are only examples for clarity of description and are not limiting on the implementation. Based on the above description, other different forms of changes or variations can be made by those of ordinary skill in the art. It is not necessary or possible to enumerate all the embodiments. The obvious changes or variations derived therefrom are still within the protection scope of the present application.
Claims
1. An image recognition method based on explicit spatial and implicit logarithmic relationship cues, characterized in that, The application relates to an image recognition method and device. The image data is divided into a training set and a test set, a teacher model and a student model are constructed, the teacher model is divided into n segments in proportion, and the student model is divided into corresponding n segments according to the network depth; When the teacher model and the student model are trained using the training set, the forward propagation of the teacher model and the student model is simultaneously performed by synchronously inputting the image, and the feature maps of the segments and the final predicted logic value are obtained; An explicit spatial prompt of the feature maps of the segments is generated, and the explicit spatial prompt is used to locate the class interest region of the image co-occurrence of the teacher model and the student model; An implicit logarithmic relationship prompt of the final predicted logic value is generated, and the implicit logarithmic relationship prompt is used to relieve the confidence distribution bias of the image; The total loss function during distillation is constructed by combining the explicit spatial prompt and the implicit logarithmic relationship prompt, and the training of the student model is completed when the total loss function during distillation converges; The test set is input into the trained student model to obtain an image recognition result.
2. The image recognition method based on explicit space and implicit logarithmic relationship cues according to claim 1, characterized in that: The explicit spatial prompt of the feature maps of the segments is generated in the following manner: A gradient-weighted class activation mapping function is used to generate the heat maps corresponding to the feature maps of the segments of the teacher model and the heat maps corresponding to the feature maps of the segments of the student model, The heat maps corresponding to the feature maps of the segments of the teacher model and the heat maps corresponding to the feature maps of the segments of the student model are unified in resolution and normalized to obtain teacher prompts and student prompts, Non-co-occurrence regions of the teacher prompts and the student prompts are filtered to obtain a co-occurrence mask, and the co-occurrence mask is used as the explicit spatial prompt, wherein the explicit spatial prompt is: where M j is the explicit spatial cue of the jth segment, σ() is an activation function, is the teacher cue, is the student cue, and ⊙ is element-wise multiplication.
3. The image recognition method based on explicit space and implicit logarithmic relationship cues according to claim 2, characterized in that: The heat map corresponding to the feature map of each segment of the teacher model, and the heat map corresponding to the feature map of each segment of the student model, wherein, is a heat map corresponding to the feature map of the jth segment of the teacher model, GradCAM( ) is a gradient-weighted class activation mapping function operation, is a feature map of the jth segment of the teacher model, j = 1, 2,.., n; ReLU( ) is an activation function, and a k is a gradient weight of the teacher model; The calculation method of the gradient weight of the teacher model is: wherein, is the heat map corresponding to the feature map of the jth segment of the student model, is the feature map of the jth segment of the student model, j = 1, 2,.., n; F c j,s is the cth token of the input sentence, is the gradient weight of the student model.
4. The image recognition method based on explicit space and implicit logarithmic relationship cues according to claim 3, characterized in that: The implicit logarithmic relationship prompt of the final predicted logic value is generated in the following manner: where T is the number of tokens in the neural network, y k is the target class score for the kth token, F t j,T is the target class score for the tth token gradient weights of the student model, The calculation method is: where H is the height of the token, W is the width of the token, y k is the target class score of the kth token, is the F at position (h, w) c j,s , h = 1, 2, …, H, w = 1, 2, …, W.
5. The image recognition method based on explicit space and implicit logarithmic relationship cues according to claim 1, characterized in that: The teacher implicit logarithmic relationship prompt is obtained by normalizing the final predicted logic value of the teacher model, mapping the logical value of the final prediction of the student model to the dimension of the logical value of the final prediction of the teacher model through the learnable multi-layer perception to obtain the mapped logical value of the final prediction of the student model, denoted as Z S is the logical value of the final prediction of the student model, W MLP is the weight of the learnable multi-layer perception. The student implicit logarithmic relationship prompt is obtained by normalizing the final predicted logic value of the student model after mapping, wherein, Z is the teacher hidden state, T Y is the logical value of the final prediction of the teacher model, and || ||2is the two-norm. When the weight decay rate is set to be equal to the learning rate of the learnable multilayer perceptron during the training of the student model, the update method of the weight of the learnable multilayer perceptron is: wherein, prompting the student for a logarithmic relationship, a logical value for the final prediction of the mapped student model.
6. The image recognition method based on explicit space and implicit logarithmic relationship cues according to claim 5, characterized in that: The total loss function during distillation is: where W MLP is the updated learnable multilayer perceptron weight, η is the weight decay rate, α MLP is the learning rate of the learnable multilayer perceptron, and ( ) T is the transpose operation.
7. The image recognition method based on explicit space and implicit logarithmic relationship cues according to claim 1, characterized in that: The calculation method of the explicit spatial prompt loss is: wherein, is a total loss function at distillation, is a cross-entropy loss of the student model, is an explicit spatial cue loss, is an implicit logarithmic relationship cue loss, and λ1, λ2 are weight coefficients.
8. The image recognition method based on explicit space and implicit logarithmic relationship cues according to claim 7, characterized in that: The calculation method of the implicit logarithmic relationship prompt loss is: where M j is the explicit spatial cue of the j-th segment, is the feature map of the j-th segment of the teacher model, is the feature map of the j-th segment of the student model, j = 1, 2,.., n; is the element-wise multiplication, and || ||2is the two-norm.
9. The image recognition method based on explicit space and implicit logarithmic relationship cues according to claim 7, characterized in that: When the test set is input into the trained student model for image recognition, the steps of generating the explicit spatial prompt of the feature maps of the segments and generating the implicit logarithmic relationship prompt of the final predicted logic value are not performed. wherein, is a hidden logistic relation hint corresponding to the student model, is a hidden logistic relation hint corresponding to the teacher model, is the p-level regularization for the i-th logits, p is a smoothing factor.
10. The image recognition method based on explicit space and implicit logarithmic relationship cues according to any one of claims 1-9, characterized in that: