Image classification method, device and equipment and readable storage medium

By constructing the current prompt network and combining it with the historical image classification model, the problem of the sustainable learning image classification model forgetting old knowledge when learning new tasks is solved, achieving efficient knowledge retention and new task adaptation, avoiding privacy security risks and training speed. Slow problem.

CN118537628AActive Publication Date: 2024-08-23ZHEJIANG LAB +1

Patent Information

Application Number
CN202410557143.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-07
Publication Date
2024-08-23
Estimated Expiration
2044-05-07

Smart Images

  • Figure CN118537628A
    Figure CN118537628A
Patent Text Reader

Abstract

The invention discloses an image classification method, device and equipment and a readable storage medium, and the method comprises the steps: obtaining a sample image and an annotation type corresponding to a current image classification task in response to the current image classification task, determining a current prompt network according to each obtained prompt sub-network matched with the current image classification task, and carrying out the detection of the current prompt network. And obtaining a current image classification model in combination with the current prompt network and a trained historical image classification model, training the current image classification model according to the sample image and the annotation type thereof, and inputting the to-be-classified image into the trained current image classification model in response to an image classification request to obtain the type of the to-be-classified image. Therefore, by means of the scheme, the problem of disastrous forgetting is effectively solved, the flexibility and accuracy of the model during new task learning are enhanced, and meanwhile, loss of knowledge obtained before is avoided. In addition, an end-to-end training mode enables the learning process of the model to be more stable and efficient.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to an image classification method, device, equipment and readable storage medium. Background Art

[0002] With the rapid development of computer vision technology, AI-based image classification technology is crucial for understanding complex visual scenes and achieving more advanced visual processing tasks such as target detection, image recognition, scene parsing, etc. In particular, image classification models based on sustainable learning are widely used in various fields such as industrial production, medical health, and daily life.

[0003] Unlike traditional image classification models that are only trained on a fixed data set and then no longer updated, image classification models based on continuous learning can continue to learn and adapt when new data arrives, improving the model's adaptability and flexibility in the face of new environments and new categories. However, in the process of continuous learning, image classification models may forget the knowledge of old image classification tasks after learning new image classification tasks.

[0004] Currently, a large amount of training data can be stored for replay to deal with this catastrophic forgetting problem. However, long-term storage of training data not only incurs huge memory costs, but may also undermine the security of private data. Summary of the invention

[0005] This specification provides an image classification method, device, equipment and readable storage medium to partially solve the above-mentioned problems existing in the prior art.

[0006] This manual adopts the following technical solutions:

[0007] This specification provides an image classification method, including:

[0008] In response to a current image classification task, obtaining a sample image corresponding to the current image classification task and a label type of the sample image;

[0009] Acquire each prompt subnetwork matching the current image classification task, and determine the current prompt network according to each prompt subnetwork;

[0010] According to the current prompt network and the trained historical image classification model, a current image classification model to be trained is obtained; wherein the historical image classification model is pre-trained according to sample images corresponding to a historical image classification task, and the historical image classification task is different from the current image classification task;

[0011] Inputting a sample image corresponding to the current image classification task into the current image classification model to be trained, obtaining a predicted type of the sample image output by the image classification model, optimizing the current prompt network with minimization of the difference between the predicted type and the labeled type as an optimization goal, and obtaining a trained current image classification model based on the optimized current prompt network;

[0012] In response to an image classification request, the acquired image to be classified is input into the trained current image classification model to obtain the type of the image to be classified.

[0013] The determining the current prompt network according to each prompt subnet specifically includes:

[0014] Acquire each prompt vector, and determine the corresponding relationship between each prompt vector and each prompt subnet;

[0015] Inputting a sample image corresponding to the current image classification task into a pre-trained encoder to obtain original features of the sample image;

[0016] Determining weights corresponding to the hint vectors according to the original features of the sample image and the hint vectors;

[0017] Determine the weights corresponding to the prompt subnetworks according to the corresponding relationship between the prompt vectors and the prompt subnetworks, and the weights corresponding to the prompt vectors;

[0018] A current prompt network is determined according to the prompt subnetworks and the weights respectively corresponding to the prompt subnetworks.

[0019] Optionally, determining the weights corresponding to the hint vectors according to the original features of the sample image and the hint vectors specifically includes:

[0020] Determining target features of the sample image through a self-attention mechanism according to original features of the sample image;

[0021] According to the similarities between the target feature of the sample image and the prompt vectors, the weights corresponding to the prompt vectors are determined, wherein the similarities between the target feature of the sample image and the prompt vector are proportional to the weights corresponding to the prompt vectors.

[0022] Optionally, the step of inputting the sample image corresponding to the current image classification task into the current image classification model to be trained to obtain the predicted type of the sample image output by the image classification model specifically includes:

[0023] Inputting a sample image corresponding to the current image classification task into the current image classification model to be trained, and obtaining first features of the sample image through each prompt subnet included in the current prompt network;

[0024] Weighting the first features according to the weights respectively corresponding to the prompt subnetworks included in the current prompt network, and obtaining the second feature of the sample image according to the weighted first features;

[0025] Inputting the second feature into a pre-trained encoder in the current image classification model to obtain a third feature of the sample image;

[0026] The third feature is input into a classification network in the current image classification model to obtain a predicted type of the sample image.

[0027] Optionally, the obtaining of each prompt vector specifically includes:

[0028] According to the current image classification task, determining a plurality of different reference image classification tasks matching the current image classification task;

[0029] Obtain sample images corresponding to each reference image classification task;

[0030] The sample images corresponding to the reference image classification tasks are respectively input into the pre-trained encoder to obtain the feature vectors of the sample images corresponding to the reference image classification tasks as the acquired prompt vectors.

[0031] Optionally, the acquiring of each prompt subnetwork matching the current image classification task specifically includes:

[0032] According to the current image classification task, determining a plurality of different reference image classification tasks matching the current image classification task;

[0033] Obtaining sample images corresponding to each reference image classification task and annotation types of the sample images corresponding to each reference image classification task;

[0034] Obtaining several layers of neural networks to be trained as prompt subnets to be trained;

[0035] For each reference image classification task, according to the sample image corresponding to the reference image classification task and the annotation type of the sample image corresponding to the reference image classification task, the parameters of the prompt subnet to be trained are optimized to obtain the prompt subnet corresponding to the reference image classification task;

[0036] The prompt subnetworks corresponding to the reference image classification tasks are used as the acquired prompt subnetworks matching the current image classification task.

[0037] Optionally, before inputting the acquired image to be classified into the trained current image classification model to obtain the type of the image to be classified, the method further includes:

[0038] Acquire a first test image corresponding to the current image classification task and a labeling type of the first test image, and acquire a second test image corresponding to the historical image classification task and a labeling type of the second test image;

[0039] According to the first test image, the annotation type of the first test image, the second test image and the annotation type of the second test image, the trained current image classification model is tested to determine whether the test result of the trained current image classification model meets preset conditions.

[0040] This specification provides an image classification device, comprising:

[0041] An acquisition module, configured to, in response to a current image classification task, acquire a sample image corresponding to the current image classification task and a label type of the sample image;

[0042] A current prompt network determination module, used to obtain each prompt subnetwork matching the current image classification task, and determine the current prompt network according to each prompt subnetwork;

[0043] A model building module, used to obtain a current image classification model to be trained according to the current prompt network and the trained historical image classification model; wherein the historical image classification model is pre-trained according to sample images corresponding to a historical image classification task, and the historical image classification task is different from the current image classification task;

[0044] A training module, used for inputting the sample image corresponding to the current image classification task into the current image classification model to be trained, obtaining the predicted type of the sample image output by the image classification model, optimizing the current prompt network with minimization of the difference between the predicted type and the labeled type as the optimization goal, and obtaining the trained current image classification model according to the optimized current prompt network;

[0045] The classification module is used to respond to an image classification request, input the acquired image to be classified into the trained current image classification model, and obtain the type of the image to be classified.

[0046] This specification provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the above-mentioned image classification method is implemented.

[0047] This specification provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned image classification method when executing the program.

[0048] At least one of the above technical solutions adopted in this specification can achieve the following beneficial effects:

[0049] In the image classification method provided in this specification, in response to the current image classification task, the sample image and annotation type corresponding to the current image classification task are obtained, the current prompt network is determined according to the acquired prompt subnetworks matching the current image classification task, the current image classification model is obtained by combining the current prompt network and the trained historical image classification model, and the current image classification model is trained according to the sample image and its annotation type, so that in response to the image classification request, the image to be classified is input into the trained current image classification model to obtain the type of the image to be classified. It can be seen that through the above scheme, the catastrophic forgetting problem is effectively dealt with, the flexibility and accuracy of the model when learning new tasks are enhanced, and the loss of previously acquired knowledge is avoided. In addition, the end-to-end training method makes the learning process of the model more robust and efficient. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] The drawings described herein are used to provide a further understanding of this specification and constitute a part of this specification. The exemplary embodiments and descriptions of this specification are used to explain this specification and do not constitute an improper limitation on this specification.

[0051] In the figure:

[0052] Figure 1 A flowchart of an image classification method in this specification;

[0053] Figure 2 is a schematic diagram of a current image classification model in this specification;

[0054] Figure 3 A flowchart of an image classification method in this specification;

[0055] Figure 4 A schematic diagram of an image classification device provided in this specification;

[0056] Figure 5 The corresponding Figure 1 Schematic diagram of electronic equipment. DETAILED DESCRIPTION

[0057] In order to make the purpose, technical solutions and advantages of this specification more clear, the technical solutions of this specification will be clearly and completely described below in combination with the specific embodiments of this specification and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of this specification, not all of them. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this specification.

[0058] In addition, it should be noted that all actions of acquiring signals, information or data in this manual are performed in compliance with the relevant local data protection laws and policies and with the authorization given by the owner of the corresponding device.

[0059] It should be noted that, in the absence of conflict, the features in the following embodiments and implementations may be combined with each other.

[0060] Continual Learning is a machine learning paradigm that aims to enable machine learning models to continuously learn based on new data as they encounter new tasks, while retaining and utilizing previously learned knowledge to avoid the phenomenon of "catastrophic forgetting". Specifically, in the field of image classification, the application of image classification models built based on machine learning algorithms in the real world often requires image classification models to be able to adapt to the ever-changing image distribution and newly added image categories. After learning the newly added image categories and image distributions, the image classification models also need to avoid forgetting the previously learned image categories and image distributions. For example, after learning to classify images of flowers and images of grass, the image classification model can continue to learn to classify images of cats and images of dogs. After the image classification model is trained based on images of cats and images of dogs, it is still necessary for the image classification model to not lose the ability to distinguish between images of flowers and images of grass.

[0061] At present, in order to avoid the problem of catastrophic forgetting in image classification models, replay-based methods and prompt-based continuous learning methods can be used. However, the replay-based method relies on long-term storage of historical task training data, or generates model samples, and replays the model based on the stored data and samples to deal with the problem of catastrophic forgetting. The prompt-based continuous learning method maintains a prompt pool or prompt library, stores the knowledge of historical tasks in the form of prompt vectors in the prompt pool or prompt library, and when the model learns a new task, it queries the prompt vector that matches the knowledge of the new task from the prompt pool or prompt library and splices it into the input of the model, thereby ensuring that the model does not forget the old knowledge while learning new knowledge.

[0062] However, in the above two solutions, the replay-based method relies on long-term storage of training data, which usually contains a large amount of private data, posing the risk of violating data privacy. The prompt-based continuous learning method cannot be optimized in an end-to-end manner, relying on a secondary, localized optimization process to learn key prompts, and the model gradient cannot be back-propagated through key / query index selection, that is, it does not fully consider the convergence speed of the model to new task data, resulting in a slow model training speed and is not suitable for application in practical applications.

[0063] Based on this, this specification provides an image classification method, which constructs a current prompt network based on each prompt subnetwork, and then constructs a current image classification model based on the current prompt network, thereby adopting an end-to-end training method, and optimizing the current prompt network in the current image classification model by using a standard back-propagation algorithm, which not only improves the training speed of the current image classification model, but also improves the performance of the image classification model on new tasks because the introduced current prompt network can work in conjunction with the original model architecture. This not only improves the efficiency of learning, but also helps to maintain the stability of existing knowledge, thereby avoiding catastrophic forgetting. In this way, the current image classification model can retain the memory of past tasks while accepting new information, achieving true continuous learning.

[0064] The technical solutions provided by the embodiments of this specification are described in detail below in conjunction with the accompanying drawings.

[0065] Figure 1 A flowchart of an image classification method provided in this specification.

[0066] S100: In response to a current image classification task, a sample image corresponding to the current image classification task and a labeling type of the sample image are obtained.

[0067] An image classification method provided in an embodiment of this specification can be executed by an electronic device such as a server for image classification. In addition, in the process of executing this method, the electronic device involved in the model training of the image classification model and the electronic device executing this method can be the same or different, and this specification does not limit this.

[0068] In practical applications, the image classification model can learn knowledge of different image classification tasks at different stages, so that the image classification model that has completed learning at different stages can adapt to the actual image classification scenarios with increasing image types. Therefore, in this specification, the image classification knowledge that the image classification model currently needs to learn is taken as the current image classification task, and the image classification knowledge of different stages learned by the image classification model before the current image classification task is taken as each historical image classification task.

[0069] In each image classification task, the categories of sample images may be two or more, and this specification does not limit the number of sample images, the number of categories, the size, etc.

[0070] Since the image classification method provided in this specification trains the image classification model in a supervised learning manner during the continuous learning process of the image classification model, in addition to obtaining the sample images corresponding to the current image classification task as training samples, it is also necessary to obtain the annotation type of the sample images corresponding to the current image classification task as the annotation of the training samples.

[0071] In addition, in an optional embodiment of the present specification, the sample image corresponding to the current image classification task may include not only image objects of the image type corresponding to the current image classification task, but also image objects of the image type corresponding to other image classification tasks (especially historical image classification tasks). For example, if the current image classification task is to classify whether there is a cat in the sample image, and the historical image classification task is to classify whether there is a dog in the sample image, then the sample image corresponding to the current image classification task may contain either a cat or a dog.

[0072] S102: Acquire each prompt subnetwork matching the current image classification task, and determine a current prompt network according to each prompt subnetwork.

[0073] In this specification, the prompt subnet is a neural network used to assist the current image classification model in learning the knowledge corresponding to the current image classification task. The prompt subnet can be a parameter-learnable network composed of one or more layers of neural networks. The network structures of different prompt subnets can be the same or different.

[0074] Specifically, in order to avoid the catastrophic forgetting problem, the current image classification model that needs to be constructed can not only stabilize the knowledge of historical image classification tasks that have been learned in the past, but also learn the knowledge of the current image classification task. To this end, each prompt subnet included in the introduced current prompt network needs to match the current image classification task. The prompt subnets that match the current image classification task may refer to each prompt subnet that has been pre-optimized based on the sample images and annotation types of each reference image classification task, where each reference image classification task is similar to the current image classification task.

[0075] For example, if the current image classification task is to classify whether there is a white cat in the sample image, then the task of classifying whether there is a black cat in the sample image can be used as a reference image classification task similar to the current classification task, and the parameters of the untrained prompt subnet can be optimized based on the task of classifying whether there is a black cat in the sample image, so as to obtain a prompt subnet that matches the task of classifying whether there is a white cat in the sample image.

[0076] Of course, depending on the specific application scenario, the parameters in each prompt subnet that matches the current image classification task may also be unoptimized. Since the parameters in the prompt subnet are only initialization parameters, the prompt subnet does not contain any knowledge of the image classification task. At this time, the so-called prompt subnet that matches the current image classification task refers to a neural network that does not interfere with or conflict with the historical image classification task.

[0077] Furthermore, when determining the current prompt network based on each prompt subnet, the current prompt network can be determined based on all the acquired prompt subnets, or based on at least one of all the acquired prompt subnets. The current prompt network can be constructed based on the prompt subnets by splicing the prompt subnets in a certain order, that is, the output of the previous prompt subnet is the input of the next prompt subnet, or by juxtaposing the prompt subnets, that is, the prompt subnets have the same input, and the output of the current prompt network is the fusion of the outputs of the prompt subnets.

[0078] In this way, the constructed current prompt network can not only more accurately match the learning requirements of the current image classification task, but also because the prompt capacity and complexity of the current prompt network can be expanded with the increase of the number of prompt subnetworks, rather than a single prompt length. Compared with the traditional single prompt method, it has higher flexibility and scalability. This dynamic adjustment capability enables the image classification model to more effectively cope with various learning tasks, thereby improving the overall classification performance and adaptability.

[0079] Optionally, in determining the current prompt network based on each prompt subnetwork, one or more prompt subnetworks matching the current image classification task may be selected from each prompt subnetwork, and the current prompt network may be constructed according to the selected one or more prompt subnetworks.

[0080] S104: Obtain a current image classification model to be trained based on the current prompt network and the trained historical image classification model; wherein the historical image classification model is pre-trained based on sample images corresponding to a historical image classification task, and the historical image classification task is different from the current image classification task.

[0081] Traditional image classification models will forget the knowledge of historical image classification tasks during the incremental learning process. To address this problem, in this specification, based on the historical image classification model that has been trained, the current prompt network constructed in step S102 is introduced to obtain the current image classification model to be trained. Because the historical image classification model has been supervised trained based on the sample images and their annotation types of the historical image classification task before responding to the current image classification task, that is, the neural networks in each layer of the historical image classification model have learned the knowledge of the historical image classification task, and thus, the current prompt network is introduced on the basis of the historical image classification model, and the current image classification model includes both one or more prompt subnets that match the current image classification task and a neural network that has learned the knowledge of the historical image classification task.

[0082] Therefore, in this step, according to the current prompt network and the historical image classification model, the current image classification model to be trained is actually to directly embed the current prompt network in the specific layers of the historical image classification model, especially the first few layers or the layers related to the image classification task. Specifically, the historical image classification model at least includes a historical prompt network, an encoder, and a classification network. Updating the historical image classification model according to the current prompt network is actually to splice the historical prompt network and the current prompt network, and then combine the encoder and classification network in the original image classification model. Therefore, the current image classification model at least includes the current prompt network, the historical prompt network, the encoder, and the classification network, such as Figure 2 As shown. The encoder is obtained through pre-training, and the training samples used by the encoder in the pre-training process can be sample images in a general image library. Moreover, whether in the training process of the current image classification model or in the training process of the historical image classification model, the parameters of the encoder will not be updated and optimized.

[0083] In order to enable the image classification model to continuously adapt to the ever-increasing and expanding image classification needs in actual application scenarios, in the sustainable learning process of the image classification model, in general, the image classification tasks that the image classification model continuously learns are different from each other. For example, the historical image classification task is to classify whether there is a cat in the image, and the current image classification task is to classify whether there is a dog in the image. Therefore, in this specification, usually, the historical image classification task is different from the current image classification task. The difference can not only be that the image objects of classification are different, such as whether there is a cat in the image and whether there is a dog in the image, but also that the number of target types of classification is different, such as whether there is a cat in the image is a binary classification task, and whether there is a white cat, a black cat, and an orange cat in the image is a multi-classification task.

[0084] In addition, it should be noted that the historical image classification model used to construct the current image classification model can be trained based on sample images and their annotation types of one or more historical image classification tasks, that is, the historical image classification tasks can be one or more, and this specification does not limit this. Furthermore, if the current image classification task is the first training task performed by the image classification model, the historical image classification model has not been trained based on any historical image classification task. At this time, the historical image classification model only includes the pre-trained encoder and classification network.

[0085] S106: Input the sample image corresponding to the current image classification task into the current image classification model to be trained, obtain the predicted type of the sample image output by the image classification model, optimize the current prompt network with minimizing the difference between the predicted type and the labeled type as the optimization goal, and obtain the trained current image classification model based on the optimized current prompt network.

[0086] The model structure of the current image classification model is actually divided into two parts: the current prompt network that has not yet learned the knowledge of the current image classification task, and the historical prompt network and classification network that have learned the knowledge of the historical image classification tasks. In order to prevent the current image classification model from forgetting the knowledge of the historical image classification tasks while learning the knowledge of the current image classification task, during the training process of the current image classification model, only the parameters of the current prompt network are updated and optimized, and the parameters of the historical prompt network, the pre-trained encoder and the classification network will be frozen and will not participate in the update and optimization. Therefore, in the trained current image classification model, the current prompt network trained based on the current image classification task masters the knowledge of the current image classification task, the historical prompt network trained based on the historical image classification task masters the knowledge of the historical image classification tasks, and the pre-trained encoder has learned the knowledge of general images in advance.

[0087] In this way, the trained current image classification model, which is composed of the optimized current prompt network, the trained historical prompt network and the pre-trained encoder, can learn the knowledge of the current image classification task and will not forget the knowledge of the historical image classification tasks, thus avoiding the problem of catastrophic forgetting in the process of sustainable learning.

[0088] In addition, optionally, when optimizing the parameters of the current prompt network based on the sample image and its annotation type of the current image classification task, the parameters of the classification network in the current image classification model can also be optimized. The classification network can be an untrained fully connected network and softmax layer introduced when constructing the current image model, or it can be a classification network that has been optimized in the historical image classification model. This specification does not limit this. To this end, S106 can be specifically as follows: input the sample image corresponding to the current image classification task into the current image classification model to be trained, obtain the predicted type of the sample image output by the image classification model, optimize the current prompt network and the classification network in the current image classification model with the minimization of the difference between the predicted type and the annotation type as the optimization goal, and obtain the trained current image classification model based on the optimized current prompt network and the optimized classification network.

[0089] S108: In response to the image classification request, the acquired image to be classified is input into the trained current image classification model to obtain the type of the image to be classified.

[0090] Since the trained current image classification model is based on the trained historical image classification model, the current prompt network is added and the parameters of the original trained historical image classification model are frozen and unchanged. Therefore, the trained current image classification model can recognize both the images to be classified corresponding to the current image classification task and the images to be classified corresponding to the historical image classification task. That is, after learning the knowledge of the current image classification task, the current image classification model will not forget the knowledge of the historical image classification task, thus avoiding the problem of catastrophic forgetting.

[0091] Therefore, when the input image to be classified is classified based on the trained current image classification model, Figure 2 The model structure shown by the solid line and the dotted line, the image to be classified will be input into the current prompt network and the historical prompt network. Therefore, no matter the image to be classified is the image of the current image classification task or the image of the historical image classification task, the prediction type with the expected accuracy can be obtained based on the current image classification model.

[0092] Therefore, in this specification, the image to be classified carried in the image classification request can be the image to be classified corresponding to the current image classification task, or it can be the image to be classified corresponding to the historical image classification task before the current image classification task during the incremental training process of the image classification model in sustainable learning. For example, if the current image classification task is to classify leaves and flowers, and the historical image classification task is to classify cats and dogs, then the image to be classified carried in the image classification request can be an image of leaves or an image of a cat.

[0093] Of course, the image to be classified carried in the image classification request may not match any image classification task of the current image classification model in the incremental training process based on sustainable learning. The probability that the type of the image to be classified output by the current image classification model after training belongs to any known image type is low. At this time, it can be determined that the type of the image to be classified is an unknown type.

[0094] In the image classification method provided in this specification, in response to the current image classification task, the sample image and annotation type corresponding to the current image classification task are obtained, the current prompt network is determined according to the acquired prompt subnetworks matching the current image classification task, the current image classification model is obtained by combining the current prompt network and the trained historical image classification model, the current image classification model is trained according to the sample image and its annotation type, and then in response to the image classification request, the image to be classified is input into the trained current image classification model to obtain the type of the image to be classified.

[0095] It can be seen that the above solution effectively addresses the problem of catastrophic forgetting, enhances the flexibility and accuracy of the model when learning new tasks, and avoids the loss of previously acquired knowledge. In addition, the end-to-end training method makes the model's learning process more robust and efficient.

[0096] In one or more embodiments of this specification, Figure 1 Step S102 shown can be implemented according to the following scheme: Figure 3 As shown:

[0097] S200: Acquire each hint vector, and determine the corresponding relationship between each hint vector and each hint subnet.

[0098] Specifically, the prompt vector is used to query the prompt subnet that matches the current image classification task. Therefore, there needs to be a correspondence between each prompt subnet and each prompt vector. By determining the prompt vector that matches the current image classification task, based on the correspondence between each prompt vector and each prompt subnet, the prompt subnet that matches the current image classification task can be screened out.

[0099] Since each hint vector needs to be compared with the sample image of the current image classification task to determine which hint vectors are related to the current image classification task, or to further determine the degree of match between each hint vector and the current image classification task, each hint vector can also be a feature vector of the sample image.

[0100] Based on this, in this specification, each prompt vector can be a feature vector of a sample image corresponding to each image classification task in the incremental training process of continuous learning of the image classification model. Of course, it can also be a feature vector of a sample image corresponding to other reference image classification tasks that are different from the image classification tasks in the incremental training process. This specification does not limit this.

[0101] Furthermore, it is also necessary to determine the correspondence between each hint vector obtained in step S200 and each hint subnet obtained in the aforementioned step S102. Specifically, each hint subnet obtained can be optimized in advance based on sample images and their annotation types of each reference image classification task, that is, each hint subnet obtained can learn the knowledge of each reference image classification task in advance, thereby improving the learning efficiency of the current image classification model.

[0102] Based on the above, it can be known that each hint vector is also obtained based on the sample image corresponding to each reference image classification model. Therefore, in this specification, the hint vector and hint subnet determined based on the same reference image classification task are regarded as hint vectors and hint subnets with corresponding relationships.

[0103] That is, for each prompt vector, determine the reference image classification task to which the sample image used by the prompt vector belongs, and use it as the reference image classification task corresponding to the prompt vector. Determine the prompt subnet trained based on the sample image and annotation type of the reference image classification task corresponding to the prompt vector, and use the determined prompt subnet as the prompt subnet corresponding to the prompt vector, that is, there is a corresponding relationship between the two.

[0104] Optionally, each hint vector can be obtained by the following scheme:

[0105] First, sample images corresponding to multiple different reference image classification tasks are obtained.

[0106] The reference image classification tasks may be individual image classification tasks in the incremental training process of the image classification model in continuous learning, or may be other reference image classification tasks different from the individual image classification tasks in the incremental training process. This specification does not limit the number and specific task content of the reference image classification tasks.

[0107] In this specification, the hint vector is obtained by inputting the sample image corresponding to the reference image classification task into a pre-trained encoder. Thus, for each reference image classification task, the sample image corresponding to the reference image classification task obtained can be one or more. The number of sample images corresponding to different reference image classification tasks can be the same or different, and this specification does not limit this.

[0108] In addition, in this specification, the description of the different reference image classification tasks can refer to the description of the differences between the historical image classification task and the current image classification task in the aforementioned step S104, which will not be repeated here.

[0109] Secondly, the sample images corresponding to the reference image classification tasks are respectively input into the pre-trained encoder to obtain the feature vectors of the sample images corresponding to the reference image classification tasks.

[0110] Specifically, since the encoder is pre-trained based on sample images in a general image library, the encoder can map sample images corresponding to each reference image into a vector space to obtain a feature vector of the sample image corresponding to each reference image.

[0111] Then, the feature vectors of the sample images corresponding to the image classification tasks are used as the acquired prompt vectors.

[0112] S202: Inputting a sample image corresponding to the current image classification task into a pre-trained encoder to obtain original features of the sample image.

[0113] As mentioned above, the pre-trained encoder can be pre-trained based on sample images in a general image library. The encoder has the ability to map the sample image of the current image classification task to a vector space and obtain a feature vector of the sample image. The feature vector output by the encoder based on the sample image corresponding to the input current image classification task is the original feature of the sample image corresponding to the current image classification task.

[0114] S204: Determine weights corresponding to the hint vectors according to the original features of the sample image and the hint vectors.

[0115] Specifically, the similarities between the original features of the sample image and each prompt vector can be determined. The higher the similarity, the higher the matching degree between the prompt vector and the original features of the sample image of the current image classification task. Conversely, the lower the similarity, the lower the matching degree between the prompt vector and the original features of the sample image of the current image classification task.

[0116] In addition, if the similarity between a hint vector and the original features of the sample image is lower than the preset similarity lower limit, it means that the similarity between the hint vector and the original features of the sample image is too low, and the hint vector does not match the sample image of the current image classification task. In this case, the hint vector can be eliminated, and the weight corresponding to the hint vector is not determined. That is, the hint subnet corresponding to the hint vector will not be used to construct the current hint network.

[0117] Afterwards, weights are assigned to the prompt vectors based on the similarities between the sample image of the current image classification task and the prompt vectors. The similarities between the sample image of the current image classification task and the prompt vectors can be directly used as the weights corresponding to the prompt vectors, but in practical applications, the sum of the weights of the prompt vectors is usually 1, and directly using the similarities as the weights of the prompt vectors may not satisfy the constraint that the sum of the weights is 1. For this reason, the similarities between the sample image of the current image classification task and the prompt vectors can be normalized, and the normalized results can be used as the weights corresponding to the prompt vectors.

[0118] The weights corresponding to each prompt vector are determined by similarity calculation, which not only considers the visual content of the sample image of the current image classification task, but also integrates the contextual information of the current image classification task, so that the generated weights can more accurately reflect the overall characteristics and learning requirements of the current image classification task. In this way, the weights of each prompt subnetwork in the current prompt network can ensure that the model can select the most appropriate prompt subnetwork for learning and adaptation according to the specific characteristics of the input image and task requirements. Through this weight generation mechanism, the model can achieve higher accuracy and efficiency in the continuous learning process.

[0119] Optionally, in order to further improve the accuracy of the weights corresponding to each hint vector, the original features of the sample image can be further processed. In this specification, the original features are processed using a self-attention mechanism so that the model can focus its computing resources on those image parts that are most critical to the current image classification task. Specifically, first, based on the original features of the sample image, the target features of the sample image are determined through a self-attention mechanism. Then, based on the similarities between the target features of the sample image and each hint vector, the weights corresponding to each hint vector are determined.

[0120] Specifically, the original features of the sample image are further processed using the self-attention mechanism. By introducing the self-attention mechanism, the image content of the sample image can be understood and analyzed more deeply, so as to more accurately obtain the matching degree between the sample image of the current image classification task and each prompt vector, thereby improving the accuracy of the weight corresponding to each prompt vector. In this way, the image can be classified and understood more accurately.

[0121] The core of the self-attention mechanism is to make the target features of the obtained sample image more reflective of the key areas in the sample image, and generate more refined query indexes based on the features of these key areas, and then based on the more refined query indexes, query the degree of match between each hint vector and the sample image of the current image classification task.

[0122] This mechanism works by calculating the correlation between the original features of the sample image, thereby determining which features are important for understanding the overall content and structure of the sample image. In this process, the features of different regions (pixels) are given different weights, thereby concentrating their computing resources on those parts of the image that are most critical to the current image classification task. The target features of the sample image obtained through the self-attention mechanism can more comprehensively and accurately represent the key information of the sample image. This not only includes the basic visual features of the image, but also incorporates an assessment of the importance of features in different regions of the sample image. Such processing enables the subsequent construction of the current prompt network and the update and optimization of the current prompt network to more effectively target the key content of the image, thereby improving the classification accuracy and efficiency in the continuous learning process.

[0123] S206: Determine the weights corresponding to the prompt subnetworks according to the corresponding relationship between the prompt vectors and the prompt subnetworks, and the weights corresponding to the prompt vectors.

[0124] In this step, based on the correspondence between each prompt vector and each prompt subnet determined in the aforementioned step S200, for each prompt subnet, the weight of the prompt vector corresponding to the prompt subnet is used as the weight corresponding to the prompt subnet.

[0125] S208: Determine a current prompt network according to each prompt subnetwork and the weights corresponding to each prompt subnetwork.

[0126] Therefore, the current prompt network is composed of each prompt subnetwork and the weights corresponding to each prompt subnetwork.

[0127] It should be noted that the weights corresponding to each prompt subnet are not the network parameters of each prompt subnet. The weights corresponding to each prompt subnet will be used as weighted parameters of the output of each prompt subnet to weight the vectors output by each prompt subnet. Usually, during the training process of the current prompt network, the weights corresponding to each prompt subnet will not be optimized and updated. Of course, depending on the specific actual situation, it is also possible to choose to update and optimize the weights corresponding to each prompt subnet contained in the current prompt network during the training process of the current prompt network, and this manual does not limit this.

[0128] based on Figure 3 In the scheme shown, different prompt networks correspond to the characteristics of different image classification tasks. Based on the weights corresponding to each prompt subnetwork, each prompt subnetwork is combined to obtain the current prompt network, so that the current prompt network can target the specific needs of the current image classification task. Such a weighted combination not only includes the visual content of the image, but also the contextual information related to the task to which the image belongs, so that the generated current prompt network can more accurately match the current learning needs of the image classification model. In addition, this method of generating the current prompt network based on the prompt subnetwork has higher flexibility and scalability than the traditional single prompt method. With this method, the prompt capacity of the model can be expanded with the complexity of the task, rather than being fixed to a single prompt length. This dynamic adjustment capability enables the model to more effectively cope with a variety of different learning tasks, thereby improving the overall classification performance and adaptability.

[0129] In one or more embodiments of this specification, based on Figure 2 The current prompt network obtained by the scheme shown actually contains each prompt subnetwork and the weights corresponding to each prompt subnetwork. Figure 1 When step S106 is shown, it is actually implemented by the following steps:

[0130] The first step: inputting the sample image into the current prompt network in the image classification model to be trained, and obtaining the first features of the sample image through the prompt subnetworks included in the current prompt network.

[0131] The model structure of the current image classification model on which this solution is based can be found in Figure 2 In this specification, the current prompt network is directly embedded in a specific layer of the historical image classification model, especially in the first few layers or layers related to the image classification task. Figure 2In the current image classification model shown, the sample image of the current image classification task input into the current image classification model will directly enter the current prompt network. Since the current prompt network includes various prompt subnets, and the prompt subnets in this specification can be arranged in parallel, that is, each prompt subnet has the same input, the output of each prompt subnet will be fused as the output of the current prompt network. Therefore, the sample image of the current image classification model input into the current prompt network will be respectively input into each prompt subnet, and each prompt subnet can obtain each first feature based on the sample image.

[0132] Step 2: weighting each of the first features according to the weights corresponding to each of the prompt subnetworks included in the current prompt network, and obtaining the second feature of the sample image according to the weighted first features.

[0133] Afterwards, each first feature is fused. In this specification, each first feature is weighted using the weights corresponding to each prompt subnetwork contained in the current prompt network as weighting coefficients. Afterwards, each weighted first feature is fused to obtain the second feature of the sample image.

[0134] Step 3: Input the second feature into the pre-trained encoder to obtain the third feature of the sample image.

[0135] Step 4: Input the third feature into the classification network to obtain the predicted type of the sample image.

[0136] In the training process of the aforementioned image classification model, the historical prompt network in the historical image classification model is not actually applied. In this way, after optimizing the parameters of the current prompt network based on the above scheme, the trained current image classification model can be constructed based on the optimized current prompt network, the trained historical prompt network, the pre-trained encoder and the classification network.

[0137] Of course, in one or more embodiments of this specification, the parameters of the current prompt network can also be optimized in combination with the historical prompt network in the historical image classification model. The specific scheme is as follows:

[0138] The first step: inputting the sample image into the current prompt network in the image classification model to be trained, and obtaining the first features of the sample image through the prompt subnetworks included in the current prompt network.

[0139] Step 2: weighting each of the first features according to the weights corresponding to each of the prompt subnetworks included in the current prompt network, and obtaining the second feature of the sample image according to the weighted first features.

[0140] The third step is to input the sample image corresponding to the current image classification task into the history prompt network of the image classification model to be trained, and obtain the historical features of the sample image through the history prompt network.

[0141] The model structure of the current image classification model on which this solution is based refers to Figure 2 As shown by the solid and dotted lines. Different from the aforementioned scheme, in this optional embodiment, the sample images of the current image classification task input to the image classification model to be trained will enter the historical prompt network. The historical prompt network has been trained based on the historical image classification tasks during the sustainable learning process of the image classification model, that is, the historical prompt network has mastered the knowledge of the historical image classification tasks. The historical features of the sample images obtained by inputting the sample images of the current image classification task into the historical prompt network actually define the degree of association between the current image classification task and the historical image classification tasks, and use the degree of association to assist the training of the current prompt network, or to assist in the classification of the input samples input to the current image classification model.

[0142] Step 4: Take the second feature and the historical feature as input and input them into the pre-trained encoder to obtain the third feature of the sample image output by the encoder.

[0143] Step 5: Input the third feature of the sample image into the classification network to obtain the predicted type of the sample image.

[0144] But even based on the above scheme combined with the historical question, the network obtains the predicted type of the sample image, and when performing back propagation, the same is true Figure 1 As shown in step S106, the current prompt network is optimized with minimization of the difference between the predicted type and the labeled type as the optimization goal, and a trained current image classification model is obtained based on the optimized current prompt network.

[0145] In one or more embodiments of this specification, Figure 1 The acquisition of each prompt subnetwork matching the current image classification task in step S102 may be implemented by the following scheme:

[0146] Step 1: Obtain sample images and annotation types corresponding to multiple different reference image classification tasks.

[0147] Step 2: Get the prompt subnet to be trained.

[0148] Step 3: For each reference image classification task, according to the sample image and annotation type corresponding to the reference image classification task, the parameters of the prompt subnet to be trained are optimized to obtain the prompt subnet corresponding to the reference image classification task.

[0149] Specifically, each prompt subnet obtained in step S102 may be pre-trained based on sample images and annotation types corresponding to multiple different reference image classification tasks. The prompt subnet to be trained may include one or more layers of neural networks. Generally, the network parameters of the prompt subnet to be trained are initialized and not optimized. Moreover, the number of neural network layers of the prompt subnet to be trained used by the prompt subnets for different reference image classification tasks may be the same or different, that is, the number of neural network layers of the prompt subnets corresponding to the different reference image classification tasks may be the same or different, and this specification does not limit this.

[0150] In addition, as mentioned above, when constructing the current prompt network based on each prompt subnetwork, it is necessary to determine the correspondence between each prompt subnetwork and each prompt vector to determine the degree of matching between each prompt subnetwork and the current image classification task. Therefore, in general, each prompt subnetwork corresponds to each prompt vector one by one, and the sample image of the reference image classification task used by the prompt subnetwork with a corresponding relationship during pre-optimization is the same as the sample image of the reference image classification task used when the prompt vector with a corresponding relationship is determined.

[0151] Step 4: Take the prompt subnetworks corresponding to each reference image classification task as the acquired prompt subnetworks.

[0152] In addition, in an optional embodiment of the present specification, after obtaining the trained image classification model in step S104, before executing step S106, the trained image classification model may be tested to evaluate the performance and accuracy of the trained image classification model. Specifically:

[0153] First, a first test image corresponding to the current image classification task and a labeling type of the first test image are obtained, and a second test image corresponding to a historical image classification task and a labeling type of the second test image are obtained.

[0154] The historical image classification task is a model training task that is ranked before the current image classification task in the model training process of the image classification model based on sustainable learning.

[0155] The first test image and its annotation type can be used to test whether the trained current image classification model has mastered the knowledge of the current image classification task, and the second test image and its annotation type can be used to test whether the trained current image classification model has no knowledge of abnormal historical image classification tasks.

[0156] Afterwards, the trained image classification model is tested based on the first test image, the annotation type of the first test image, the second test image and the annotation type of the second test image to determine whether the test result of the trained image classification model meets preset conditions.

[0157] Thus, based on the first test image and its annotation type, as well as the second test image and its annotation type, the trained current image classification model is tested, and the test results may include the classification performance of the current image classification model on images of the current image classification task, as well as the classification performance of the current image classification model on images of historical image classification tasks.

[0158] Moreover, only when the classification performance of the current image classification model for the images of the current image classification task and the classification performance of the images of the historical image classification tasks meet the preset performance requirements, is it determined that the test results of the trained image classification model meet the preset conditions.

[0159] The above is an image classification method provided by one or more embodiments of this specification. Based on the same idea, this specification also provides a corresponding image classification device, such as Figure 4 shown.

[0160] Figure 4 A schematic diagram of an image classification device provided in this specification specifically includes:

[0161] An acquisition module 300 is used to acquire, in response to a current image classification task, a sample image corresponding to the current image classification task and a label type of the sample image;

[0162] A current prompt network determination module 302 is used to obtain prompt subnetworks matching the current image classification task and determine a current prompt network according to the prompt subnetworks;

[0163] A model building module 304 is used to obtain a current image classification model to be trained based on the current prompt network and the trained historical image classification model; wherein the historical image classification model is pre-trained based on sample images corresponding to a historical image classification task, and the historical image classification task is different from the current image classification task;

[0164] A training module 306 is used to input the sample image corresponding to the current image classification task into the current image classification model to be trained, obtain the predicted type of the sample image output by the image classification model, optimize the current prompt network with minimization of the difference between the predicted type and the labeled type as the optimization goal, and obtain the trained current image classification model based on the optimized current prompt network;

[0165] The classification module 308 is used to input the acquired image to be classified into the trained current image classification model in response to the image classification request to obtain the type of the image to be classified.

[0166] Optionally, the current prompt network determination module 302 is specifically used to obtain each prompt vector and determine the corresponding relationship between each prompt vector and each prompt subnetwork; input the sample image corresponding to the current image classification task into the pre-trained encoder to obtain the original features of the sample image; determine the weights corresponding to each prompt vector according to the original features of the sample image and the prompt vectors; determine the weights corresponding to each prompt subnetwork according to the corresponding relationship between each prompt vector and each prompt subnetwork, and the weights corresponding to each prompt vector; determine the current prompt network according to each prompt subnetwork and the weights corresponding to each prompt subnetwork.

[0167] Optionally, the current prompt network determination module 302 is specifically used to determine the target features of the sample image through a self-attention mechanism based on the original features of the sample image; and determine the weights corresponding to the respective prompt vectors based on the similarities between the target features of the sample image and the prompt vectors, wherein the similarity between the target features of the sample image and the prompt vector is proportional to the weight corresponding to the prompt vector.

[0168] Optionally, the training module 306 is specifically used to input the sample image corresponding to the current image classification task into the current image classification model to be trained, and obtain the first features of the sample image through the prompt subnetworks contained in the current prompt network; weight the first features according to the weights corresponding to the prompt subnetworks contained in the current prompt network, and obtain the second feature of the sample image according to the weighted first features; input the second feature into the pre-trained encoder in the current image classification model to obtain the third feature of the sample image; input the third feature into the classification network in the current image classification model to obtain the predicted type of the sample image.

[0169] Optionally, the current prompt network determination module 302 is specifically used to determine, based on the current image classification task, a plurality of different reference image classification tasks that match the current image classification task; obtain sample images corresponding to each reference image classification task; and input the sample images corresponding to each reference image classification task into a pre-trained encoder to obtain feature vectors of the sample images corresponding to each reference image classification task as the acquired prompt vectors.

[0170] Optionally, the current prompt network determination module 302 is specifically used to determine, according to the current image classification task, a plurality of different reference image classification tasks that match the current image classification task; obtain sample images corresponding to each reference image classification task and the annotation type of the sample images corresponding to each reference image classification task; obtain several layers of neural networks to be trained as prompt subnets to be trained; for each reference image classification task, according to the sample images corresponding to the reference image classification task and the annotation type of the sample images corresponding to the reference image classification task, optimize the parameters of the prompt subnet to be trained to obtain the prompt subnet corresponding to the reference image classification task; and use the prompt subnets corresponding to the reference image classification tasks as the acquired prompt subnets that match the current image classification task.

[0171] Optionally, the device further comprises:

[0172] The testing module 310 is specifically used to obtain the first test image corresponding to the current image classification task and the annotation type of the first test image, and to obtain the second test image corresponding to the historical image classification task and the annotation type of the second test image; according to the first test image, the annotation type of the first test image, the second test image and the annotation type of the second test image, the trained current image classification model is tested to determine whether the test result of the trained current image classification model meets the preset conditions.

[0173] This specification also provides a computer-readable storage medium, which stores a computer program, which can be used to execute the above Figure 1 The image classification method shown.

[0174] This manual also provides Figure 5 The schematic structure diagram of the electronic device shown in FIG. Figure 5 As mentioned above, at the hardware level, the electronic device includes a processor, an internal bus, a network interface, a memory, and a non-volatile memory, and may also include other hardware required for the business. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it to achieve the above Figure 1 Of course, in addition to the software implementation, this specification does not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.

[0175] In the 1990s, improvements to a technology could be clearly distinguished as hardware improvements (for example, improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the method flow). However, with the development of technology, many improvements to the method flow today can be regarded as direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that an improvement in a method flow cannot be implemented using a hardware entity module. For example, a programmable logic device (PLD) (such as a field programmable gate array (FPGA)) is such an integrated circuit whose logical function is determined by the user's programming of the device. Designers can "integrate" a digital system on a PLD by programming it themselves, without having to ask a chip manufacturer to design and produce a dedicated integrated circuit chip. Moreover, nowadays, instead of manually making integrated circuit chips, this kind of programming is mostly implemented by "logic compiler" software, which is similar to the software compiler used when developing and writing programs, and the original code before compilation must also be written in a specific programming language, which is called hardware description language (HDL). There is not only one HDL, but many kinds, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones are VHDL (Very-High-Speed ​​Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also know that it is only necessary to program the method flow slightly in the above-mentioned hardware description languages ​​and program it into the integrated circuit, and then it is easy to obtain the hardware circuit that implements the logic method flow.

[0176] The controller can be implemented in any appropriate manner, for example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing a computer-readable program code (such as software or firmware) that can be executed by the (micro)processor, a logic gate, a switch, an application-specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that in addition to implementing the controller in a purely computer-readable program code manner, the controller can be implemented in the form of a logic gate, a switch, an application-specific integrated circuit, a programmable logic controller, and an embedded microcontroller by logically programming the method steps. Therefore, this controller can be considered as a hardware component, and the devices included therein for implementing various functions can also be regarded as structures within the hardware component. Or even, the devices for implementing various functions can be regarded as both software modules for implementing the method and structures within the hardware component.

[0177] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.

[0178] For the convenience of description, the above device is described in various units according to their functions. Of course, when implementing this specification, the functions of each unit can be implemented in the same or multiple software and / or hardware.

[0179] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems, or computer program products. Therefore, this specification may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, this specification may 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-ROM, optical storage, etc.) that contain computer-usable program code.

[0180] This specification is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of this specification. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0181] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0182] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0183] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0184] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0185] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0186] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0187] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems or computer program products. Therefore, this specification may take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, this specification may 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-ROM, optical storage, etc.) containing computer-usable program code.

[0188] This specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. This specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.

[0189] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0190] The above description is only an embodiment of the present specification and is not intended to limit the present specification. For those skilled in the art, the present specification may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present specification shall be included in the scope of the claims of the present specification.

Claims

1. An image classification method, characterized in that: include: In response to a current image classification task, obtaining a sample image corresponding to the current image classification task and a label type of the sample image; Acquire each prompt subnetwork matching the current image classification task, and determine the current prompt network according to each prompt subnetwork; According to the current prompt network and the trained historical image classification model, a current image classification model to be trained is obtained; wherein the historical image classification model is pre-trained according to sample images corresponding to a historical image classification task, and the historical image classification task is different from the current image classification task; Inputting a sample image corresponding to the current image classification task into the current image classification model to be trained, obtaining a predicted type of the sample image output by the image classification model, optimizing the current prompt network with minimization of the difference between the predicted type and the labeled type as an optimization goal, and obtaining a trained current image classification model based on the optimized current prompt network; In response to an image classification request, the acquired image to be classified is input into the trained current image classification model to obtain the type of the image to be classified.

2. The method according to claim 1, characterized in that The determining the current prompt network according to each prompt subnet specifically includes: Acquire each prompt vector, and determine the corresponding relationship between each prompt vector and each prompt subnet; Inputting a sample image corresponding to the current image classification task into a pre-trained encoder to obtain original features of the sample image; Determining weights corresponding to the hint vectors according to the original features of the sample image and the hint vectors; Determine the weights corresponding to the prompt subnetworks according to the corresponding relationship between the prompt vectors and the prompt subnetworks, and the weights corresponding to the prompt vectors; A current prompt network is determined according to the prompt subnetworks and the weights respectively corresponding to the prompt subnetworks.

3. The method according to claim 2, characterized in that The step of determining the weights corresponding to the hint vectors according to the original features of the sample image and the hint vectors specifically includes: Determining target features of the sample image through a self-attention mechanism according to original features of the sample image; According to the similarities between the target feature of the sample image and the prompt vectors, the weights corresponding to the prompt vectors are determined, wherein the similarities between the target feature of the sample image and the prompt vector are proportional to the weights corresponding to the prompt vectors.

4. The method according to claim 2, characterized in that The step of inputting the sample image corresponding to the current image classification task into the current image classification model to be trained, and obtaining the predicted type of the sample image output by the image classification model, specifically includes: Inputting a sample image corresponding to the current image classification task into the current image classification model to be trained, and obtaining first features of the sample image through each prompt subnet included in the current prompt network; Weighting the first features according to the weights respectively corresponding to the prompt subnetworks included in the current prompt network, and obtaining the second feature of the sample image according to the weighted first features; Inputting the second feature into a pre-trained encoder in the current image classification model to obtain a third feature of the sample image; The third feature is input into a classification network in the current image classification model to obtain a predicted type of the sample image.

5. The method according to claim 2, characterized in that The obtaining of each prompt vector specifically includes: According to the current image classification task, determining a plurality of different reference image classification tasks matching the current image classification task; Obtain sample images corresponding to each reference image classification task; The sample images corresponding to the reference image classification tasks are respectively input into the pre-trained encoder to obtain the feature vectors of the sample images corresponding to the reference image classification tasks as the acquired prompt vectors.

6. The method according to claim 1, characterized in that The obtaining of each prompt subnetwork matching the current image classification task specifically includes: According to the current image classification task, determining a plurality of different reference image classification tasks matching the current image classification task; Obtaining sample images corresponding to each reference image classification task and annotation types of the sample images corresponding to each reference image classification task; Obtaining several layers of neural networks to be trained as prompt subnets to be trained; For each reference image classification task, according to the sample image corresponding to the reference image classification task and the annotation type of the sample image corresponding to the reference image classification task, the parameters of the prompt subnet to be trained are optimized to obtain the prompt subnet corresponding to the reference image classification task; The prompt subnetworks corresponding to the reference image classification tasks are used as the acquired prompt subnetworks matching the current image classification task.

7. The method according to claim 1, characterized in that Before inputting the acquired image to be classified into the trained current image classification model to obtain the type of the image to be classified, the method further includes: Acquire a first test image corresponding to the current image classification task and a labeling type of the first test image, and acquire a second test image corresponding to the historical image classification task and a labeling type of the second test image; According to the first test image, the annotation type of the first test image, the second test image and the annotation type of the second test image, the trained current image classification model is tested to determine whether the test result of the trained current image classification model meets preset conditions.

8. An image classification device, characterized in that: include: An acquisition module, configured to, in response to a current image classification task, acquire a sample image corresponding to the current image classification task and a label type of the sample image; A current prompt network determination module, used to obtain each prompt subnetwork matching the current image classification task, and determine the current prompt network according to each prompt subnetwork; A model building module, used to obtain a current image classification model to be trained according to the current prompt network and the trained historical image classification model; wherein the historical image classification model is pre-trained according to sample images corresponding to a historical image classification task, and the historical image classification task is different from the current image classification task; A training module, used for inputting the sample image corresponding to the current image classification task into the current image classification model to be trained, obtaining the predicted type of the sample image output by the image classification model, optimizing the current prompt network with minimization of the difference between the predicted type and the labeled type as the optimization goal, and obtaining the trained current image classification model according to the optimized current prompt network; The classification module is used to respond to an image classification request, input the acquired image to be classified into the trained current image classification model, and obtain the type of the image to be classified.

9. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Object classification method based on class increment learning, image classification method based on class increment learning and related equipment

    CN116778264A

  • Image classification method and device based on hierarchical prompt and image classification model

    CN116994063A

  • Continuous image question and answer method and product based on multi-mode prompt learning

    CN117456299A

  • Prompt fine tuning-based class incremental learning image classification method and device, and medium

    CN117611922A

  • Systems and methods for text classification using label modular prompts

    US20230419049A1

Cited By

  • Combined incremental learning method for image classification task

    CN119445327A