Image classification method and device based on prompt word learning, equipment and medium

By using a cue word-based learning method and adjusting the vector offset of the image and text encoders with a preset channel factor, the problems of high manpower consumption and declining transfer performance in traditional image classification are solved, and fast and accurate image classification is achieved.

CN118397350BActive Publication Date: 2026-11-24HARBIN INSTITUTE OF TECHNOLOGY (SHENZHEN) (INSTITUTE OF SCIENCE AND TECHNOLOGY INNOVATION HARBIN INSTITUTE OF TECHNOLOGY SHENZHEN)
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202410511838.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-26
Publication Date
2026-11-24
Estimated Expiration
2044-04-26

AI Technical Summary

Technical Problem

Traditional image classification methods are labor-intensive and their performance degrades during model transfer, making it difficult to classify quickly and accurately.

Method used

By using a cue word-based learning method, the vector offsets of the text and image encoders are adjusted using preset channel factors, thereby enhancing the model's transferability and generalization, and improving image classification accuracy.

Benefits of technology

It improves the accuracy and efficiency of image classification and ensures that the model maintains its original representational capabilities during the transfer process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118397350B_ABST
    Figure CN118397350B_ABST
Patent Text Reader

Abstract

This invention provides an image classification method, apparatus, device, and medium based on cue word learning. The method includes: acquiring an image to be classified, multiple preset labels, and multiple initial cue words corresponding to each label; inputting each label and its corresponding initial cue words into a text encoder of a preset classification model to obtain a first text vector corresponding to each label output by the text encoder; adjusting the first text vector corresponding to each label using a preset channel factor to obtain a second text vector corresponding to each label; determining the similarity between the image to be classified and each label based on the first image vector corresponding to the image to be classified and the second text vector corresponding to each label; and classifying the image to be classified based on the similarity between the image to be classified and each label. This invention enables fast and accurate image classification.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image classification technology, and in particular to an image classification method, apparatus, device, and medium based on cue word learning. Background Technology

[0002] With the development of information technology, images are being used more and more widely, such as for image recognition and classification of industrial products with different defect types. Among these applications, the ability to quickly and accurately classify and label images for subsequent training in image recognition is crucial.

[0003] Traditional image classification primarily relies on manual labeling and categorization of images using keywords, but this method is extremely labor-intensive and time-consuming. Related technologies also involve transferring pre-trained models to downstream tasks for image classification; however, the transfer and training process can negatively impact the original model, weakening its representational capabilities, reducing its performance, and making it difficult to achieve fast and accurate image classification. Summary of the Invention

[0004] This invention provides an image classification method, apparatus, device, and medium based on cue word learning, to achieve image classification quickly and accurately.

[0005] In a first aspect, embodiments of the present invention provide an image classification method based on cue word learning, including:

[0006] Obtain the image to be classified, multiple preset labels, and multiple initial prompt words corresponding to each label;

[0007] Each label and its corresponding multiple initial prompt words are input into the text encoder of the preset classification model to obtain the first text vector corresponding to each label output by the text encoder;

[0008] By using a preset channel factor, the first text vector corresponding to each tag is adjusted to obtain the second text vector corresponding to each tag; wherein, the preset channel factor is used to correct the offset of the text vector output by the text encoder;

[0009] The similarity between the image to be classified and each label is determined based on the first image vector corresponding to the image to be classified and the second text vector corresponding to each label.

[0010] The image to be classified is classified based on the similarity between the image to be classified and each label.

[0011] In one possible implementation, the preset classification model further includes an image encoder;

[0012] Before determining the similarity between the image to be classified and each label based on the first image vector corresponding to the image to be classified and the second text vector corresponding to each label, the method further includes:

[0013] The image to be classified is input into the image encoder of the preset classification model to obtain the second image vector corresponding to the image to be classified output by the image encoder;

[0014] The second image vector is adjusted using the preset channel factor to obtain the first image vector corresponding to the image to be classified; wherein, the preset channel factor is also used to correct the offset of the image vector output by the image encoder.

[0015] In one possible implementation, before adjusting the first text vector corresponding to each tag using a preset channel factor to obtain the second text vector corresponding to each tag, the method further includes:

[0016] Obtain training samples, which include multiple sample images, multiple labels, initial prompt words corresponding to each label, and the true similarity between each sample image and each label;

[0017] Each sample image, each label, and the corresponding initial prompt word are input into the preset classification model to obtain the predicted similarity between each sample image and each label output by the preset classification model.

[0018] The preset channel factor is determined based on the predicted similarity between each sample image and each label, and the actual similarity between each sample image and each label.

[0019] In one possible implementation, the text vector includes text elements of multiple dimensions, the image vector includes image elements of multiple dimensions, and the preset channel factor includes channel factors of multiple dimensions.

[0020] The step of determining the similarity between the image to be classified and each label based on the first image vector corresponding to the image to be classified and the second text vector corresponding to each label includes:

[0021] For each label, the similarity score between the image to be classified and the label in each dimension is calculated based on the text elements in each dimension of the second text vector corresponding to the label, the image elements in the corresponding dimension of the first image vector, and the preset channel factor in the corresponding dimension.

[0022] Based on the similarity score between the image to be classified and each label in each dimension, the similarity between the image to be classified and each label is calculated respectively.

[0023] In one possible implementation, the preset channel factor is determined based on the predicted similarity between each sample image and each label, and the true similarity between each sample image and each label, including:

[0024] The loss function value of the preset classification model is determined based on the predicted similarity between each sample image and each label, and the true similarity between each sample image and each label.

[0025] Determine whether the channel factor meets the preset requirements, wherein the preset requirements are set according to the loss function value;

[0026] If the preset requirements are not met, the channel factor is adjusted according to the gradient descent method and the loss function of the preset classification model, and the steps of inputting each sample image, each label and the corresponding initial prompt word into the preset classification model are repeated until the preset requirements are met, the optimal channel factor is obtained, and the optimal channel factor is determined as the preset channel factor.

[0027] In one possible implementation, the text encoder includes multiple transformation layers, each with a deep cue word set in it;

[0028] Each label and its corresponding multiple initial prompt words are input into the text encoder of a preset classification model to obtain the first text vector corresponding to each label output by the text encoder, including:

[0029] Each label is converted into a vector, and the initial prompt word is concatenated onto the vector to obtain the input vector;

[0030] The input vector of each label is input into the first transformation layer of the text encoder of the preset classification model, so that the input vector is concatenated with the deep cue words set in the transformation layer to obtain the first concatenated vector, and then input into the next transformation layer, until the second concatenated vector output by the last transformation layer is obtained;

[0031] Based on the second concatenation vector of each tag, the first text vector corresponding to each tag output by the text encoder is obtained.

[0032] In one possible implementation, the text encoder includes multiple transformation layers, each with a deep cue word set in it;

[0033] Each label and its corresponding multiple prompt words are input into the text encoder of a preset classification model to obtain the first text vector corresponding to each label output by the text encoder, including:

[0034] Each label is converted into a vector, and the initial prompt word is concatenated onto the vector to obtain the input vector;

[0035] The input vector of each label is input into the first transformation layer of the text encoder of the preset classification model to remove a preset number of elements from the input vector and concatenate the deep cue words set in the transformation layer to obtain the third concatenated vector, which is then input into the next transformation layer until the fourth concatenated vector is obtained from the last transformation layer.

[0036] Based on the fourth concatenation vector of each tag, the first text vector corresponding to each tag output by the text encoder is obtained.

[0037] Secondly, embodiments of the present invention provide an image classification device based on cue word learning, comprising:

[0038] The acquisition module is used to acquire the image to be classified, multiple preset labels, and multiple initial prompt words corresponding to each label;

[0039] The encoding module is used to input each label and its corresponding multiple initial prompt words into the text encoder of the preset classification model, so as to obtain the first text vector corresponding to each label output by the text encoder;

[0040] The correction module is used to adjust the first text vector corresponding to each tag using a preset channel factor to obtain the second text vector corresponding to each tag; wherein, the preset channel factor is used to correct the offset of the text vector output by the text encoder.

[0041] The calculation module is used to determine the similarity between the image to be classified and each label based on the first image vector corresponding to the image to be classified and the second text vector corresponding to each label.

[0042] The classification module is used to classify the image to be classified based on the similarity between the image to be classified and each label.

[0043] Thirdly, embodiments of the present invention provide an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the method described in the first aspect or any possible implementation thereof.

[0044] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the method described in the first aspect or any possible implementation thereof.

[0045] The beneficial effects of the embodiments of the present invention compared with the prior art are as follows:

[0046] This invention, through its embodiments, inputs each label and its corresponding initial prompts into a text encoder to obtain a first text vector corresponding to each label. Then, it adjusts the first text vector corresponding to each label using a preset channel factor to obtain a second text vector corresponding to each label. Based on the first image vector corresponding to the image to be classified and the second text vector corresponding to each label, the similarity between the image to be classified and each label is calculated. This approach fully considers the shift in each dimension of the first text vector when the preset classification model is transferred to specific image classification tasks, such as classifying different types of cats. The preset channel factor reduces dimensional shifts, increases the weight of important features in the second text vector, reduces the weight of features with low discriminative power, improves the consistency between the text space and the image space, and ensures the representational ability of the original preset classification model. This improves the accuracy of calculating the similarity between the image to be classified and each label, enabling accurate image classification based on similarity. Attached Figure Description

[0047] To more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0048] Figure 1 This is a schematic diagram of the CLIP model provided in an embodiment of the present invention;

[0049] Figure 2 This is a flowchart illustrating the implementation of an image classification method based on cue word learning, provided in an embodiment of the present invention.

[0050] Figure 3 This is a flowchart illustrating the implementation of another image classification method based on cue word learning provided in this embodiment of the invention;

[0051] Figure 4 This is a schematic diagram of the structure of the preset classification model provided in the embodiments of the present invention;

[0052] Figure 5 This is a comparative diagram of the preset channel factor before and after adjustment provided in an embodiment of the present invention;

[0053] Figure 6 This is a schematic diagram of the structure of the image classification device based on cue word learning provided in an embodiment of the present invention;

[0054] Figure 7 This is a schematic diagram of an electronic device provided in an embodiment of the present invention. Detailed Implementation

[0055] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of the invention. However, those skilled in the art will understand that the invention can be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods are omitted so as not to obscure the description of the invention with unnecessary detail.

[0056] To make the objectives, technical solutions, and advantages of the present invention clearer, specific embodiments will be described below in conjunction with the accompanying drawings.

[0057] The Contrastive Language-Image Pre-Training (CLIP) model is a multimodal model based on contrastive learning. It directly utilizes the supervision of the original text to learn from images, thereby aligning the text and image modalities. The CLIP model is pre-trained on a massive dataset of 400 million text and image data. By learning general visual and linguistic representations, it can match images and text, demonstrating broad and universal image cognition.

[0058] See Figure 1 The diagram shows the structure of the CLIP model. When using the CLIP model for image classification, the text encoder encodes the prompt words, the image encoder encodes the image to be classified, and finally the label of the image to be classified is determined by calculating the cosine similarity between the two codes.

[0059] The inventors have discovered that when the CLIP model is applied to specific downstream classification tasks, such as classifying images of different types of cats, different types of dogs, and different types of plant leaves, directly performing traditional fine-tuning on the CLIP model may weaken the representational ability learned by the model during the pre-training stage, disrupt the alignment relationship between text and images in its feature space, and significantly reduce the performance of the CLIP model.

[0060] In order to ensure that the original performance of the model is not compromised, in the embodiments of this application, the text encoding obtained by the CLIP model is fine-tuned by setting a preset channel factor, further aligning the text and image encoding spaces, so that the text and images have a better matching relationship, enhancing the generalization and transferability of the model, thereby improving the classification accuracy when the CLIP model is applied to specific image classification.

[0061] Figure 2 The implementation flowchart of the image classification method based on cue word learning provided in the embodiments of the present invention is described in detail below:

[0062] Step S201: Obtain the image to be classified, multiple preset labels, and multiple initial prompt words corresponding to each label.

[0063] In this embodiment, the preset labels can be determined based on target features in the image. These target features can include objects contained in the image and type information contained in the image. This can be determined according to the specific classification task.

[0064] For example, in industrial production, the image to be classified can be an image of a manufactured product, and the preset labels can be determined based on the product in the image. Labels can also refer to defects and flaws of the same product, specifically such as "good product," "cracked," "dented," "broken," and "perforated." Labels can also represent different product types or the location of cracks within different products. In the medical field, the image to be classified can be a medical image of a different disease, and the preset labels can represent different diseases. In the field of remote sensing, the image to be classified can be a remote sensing image, and the preset labels can represent different ground features and buildings within the remote sensing image, which can be determined based on spectral, spatial, and textural information in the remote sensing image.

[0065] When classifying images of different types of animals, the image to be classified can be an image containing an animal. Multiple preset labels can be determined based on the already classified animals. Labels can be different types of animals, such as Chinese domestic cats, Ragdoll cats, Persian cats, Alaskan Malamutes, Golden Retrievers, sika deer, moose, giraffes, red deer, zebras, and pandas. Similarly, when classifying images of different types of cats, the image to be classified can be an image containing a cat. Multiple preset labels can be determined based on the already classified cats. Labels can be different types of cats, such as Chinese domestic cats, Ragdoll cats, Persian cats, Norwegian Forest cats, Siberian cats, British Shorthairs, and Sphynx cats. Likewise, when classifying images of different types of plant leaves, the image to be classified can be an image containing plant leaves. Multiple preset labels can be determined based on the already classified leaves. Labels can be plants, such as trees, shrubs, vines, grasses, ferns, algae, and lichens, or trees, shrubs, and woody vines, or even banyan trees, poplar trees, willow trees, cypress trees, and sycamore trees.

[0066] Here, the initial prompt can use a prompt template similar to "a photo of a{class}", where "a photo of a" can be the initial prompt and {class} can be the corresponding category label. For example, when classifying cat images, Chinese domestic cat, Ragdoll cat, Persian cat, Norwegian Forest cat, Siberian cat, British Shorthair cat, and Sphynx cat can be filled in {class} as labels.

[0067] Step S202: Input each label and its corresponding multiple initial prompt words into the text encoder of the preset classification model to obtain the first text vector corresponding to each label output by the text encoder.

[0068] In this embodiment, the text encoder can encode each tag and its corresponding initial prompt word to obtain the corresponding first text vector.

[0069] Here, the preset classification model is trained based on a specific image classification task. For example, when classifying images of different industrial products, the CLIP model can be trained using images of industrial products with different defects and flaws, labels of different defects and flaws, and prompt words. The prompt words include the initial prompt words.

[0070] Step S203: Adjust the first text vector corresponding to each tag using a preset channel factor to obtain the second text vector corresponding to each tag; wherein, the preset channel factor is used to correct the offset of the text vector output by the text encoder.

[0071] In this embodiment, considering that the training using prompt words may cause the resulting text vector to shift in different dimensions, the inventors of this application adjust the elements of the vectors in different dimensions of the first text vector by using a preset channel factor to correct the shift and increase the weight of important features.

[0072] Here, by adjusting the first text vector using a preset channel factor, an adjusted second text vector is obtained, which can make the second text vector correspond to the corresponding image vector, thereby improving the consistency between the text space and the image space.

[0073] Step S204: Determine the similarity between the image to be classified and each label based on the first image vector corresponding to the image to be classified and the second text vector corresponding to each label.

[0074] In this embodiment, the similarity between the first image vector corresponding to the image to be classified and the second text vector corresponding to each label is calculated respectively, and used as the similarity between the image to be classified and each label. Here, the similarity can be determined by cosine similarity.

[0075] Step S205: Classify the image to be classified based on the similarity between the image to be classified and each label.

[0076] In this embodiment, the label with the highest similarity between the image to be classified and each label can be determined as the label for classifying the image.

[0077] For example, the image classification method provided in this embodiment can be used to classify images of industrial products with different types of defects in industrial production, thereby facilitating the subsequent application and processing of industrial products, such as putting them into use, repairing them, and destroying them. The image classification method provided in this embodiment can also be used to classify medical images of rare cases in the medical field, in order to identify rare cases and assist in their diagnosis.

[0078] Alternatively, the image classification method provided in this embodiment can be used to classify images of leaves from different plant species. This allows users to quickly identify the species or variety of a plant by examining its leaf images when encountering leaves they do not recognize or have never seen before. The image classification method also provides the ability to classify images of seeds from different crops, facilitating seed classification and improving efficiency.

[0079] In specific image classification scenarios such as images of industrial products, medical images of rare cases, and satellite remote sensing images, labeled sample images are scarce and difficult to obtain, resulting in typically low accuracy in classifying such small sample images. In this embodiment, the image classification method provided herein is used to classify these small sample images. The first text vector of the label is adjusted using a preset channel factor. The similarity between the adjusted second text vector and the first image vector corresponding to the image to be classified is calculated before image classification. This approach addresses the issue of small sample size in image classification by accurately describing the labels, ensuring the correspondence between the text space and image space, thereby accurately classifying small sample images and improving the accuracy of image classification.

[0080] This invention, through its embodiments, inputs each label and its corresponding initial prompts into a text encoder to obtain a first text vector corresponding to each label. Then, it adjusts the first text vector corresponding to each label using a preset channel factor to obtain a second text vector corresponding to each label. Based on the first image vector corresponding to the image to be classified and the second text vector corresponding to each label, the similarity between the image to be classified and each label is calculated. This approach fully considers the shift in each dimension of the first text vector when the preset classification model is transferred to specific image classification tasks, such as classifying different types of cats. The preset channel factor can reduce dimensional shifts, increase the weight of important features in the second text vector, reduce the weight of features with low discriminative power, improve the consistency between the text space and the image space, and ensure the representational ability of the original preset classification model. This improves the accuracy of calculating the similarity between the image to be classified and each label, enabling accurate image classification based on similarity in subsequent steps.

[0081] In some embodiments, the preset classification model further includes an image encoder.

[0082] See Figure 3 The flowchart shown illustrates another image classification method based on cue word learning. In this embodiment, before determining the similarity between the image to be classified and each label based on the first image vector corresponding to the image to be classified and the second text vector corresponding to each label, the method may further include: firstly, inputting the image to be classified into the image encoder of a preset classification model to obtain the second image vector corresponding to the image to be classified output by the image encoder; then, adjusting the second image vector using a preset channel factor to obtain the first image vector corresponding to the image to be classified; wherein, the preset channel factor is also used to correct the offset of the image vector output by the image encoder.

[0083] In this embodiment, the image encoder can encode the input image to be classified to obtain a corresponding second image vector. Accordingly, considering the problem of image vectors shifting in different dimensions, a preset channel factor can be used to adjust the elements of vectors in different dimensions of the second image vector, correcting the aforementioned shift and increasing the weight of important features.

[0084] Optionally, the text vector includes text elements of multiple dimensions, the image vector includes image elements of multiple dimensions, and the preset channel factor includes channel factors of multiple dimensions. Here, the number of dimensions of the text vector, image vector, and preset channel factor are equal; for example, they can be set to 128 dimensions or 512 dimensions, etc.

[0085] See Figure 4 The schematic diagram of the preset classification model shown in this embodiment determines the similarity between the image to be classified and each label based on the first image vector corresponding to the image to be classified and the second text vector corresponding to each label. First, for each label, the similarity score between the image to be classified and the label in each dimension is calculated based on the text elements in each dimension of the second text vector corresponding to the label, the image elements in the corresponding dimension of the first image vector, and the preset channel factor in the corresponding dimension. Then, based on the similarity score between the image to be classified and each label in each dimension, the similarity between the image to be classified and each label is calculated respectively.

[0086] In this embodiment, the text encoder of the preset classification model outputs a first text vector, which consists of elements in n dimensions, i.e. Figure 4 In the y1, y2, y3, ..., y n The image encoder of the pre-defined classification model outputs a second image vector, which also consists of n-dimensional elements, i.e. Figure 4 x1, x2, x3, ..., x n Accordingly, each dimension also has a corresponding channel factor set, i.e. Figure 4 α1, α2, α3,..., α in n By adjusting and correcting the first text vector and the second image vector in each dimension using channel factors, the text space and the image space can be aligned. That is, by using preset channel factors, the first text vector and the second image vector are adjusted to the corresponding second text vector and first image vector, so as to accurately calculate the similarity score between the image to be classified and the label in each dimension, thereby obtaining the similarity between the image to be classified and each label.

[0087] Optionally, this embodiment can be based on the expression: Calculate the similarity between the image to be classified and each label; where cosθ j Let x represent the similarity between the image to be classified and the j-th label. i Let y represent the element of the i-th dimension in the second image vector corresponding to the image to be classified. ji α represents the element in the i-th dimension of the first text vector corresponding to the j-th label. i Let i represent the preset channel factor of the i-th dimension, where i represents the i-th dimension, j represents the j-th label, and n represents the set of all dimensions.

[0088] In this embodiment, the similarity between the image to be classified and each label can be directly calculated according to the above formula. The numerator is obtained by multiplying the channel factor, the corresponding element in the second image vector, and the corresponding element in the first text vector, thus adjusting the second image vector and the first text vector using a preset channel factor. Then, by calculating the cosine similarity, the similarity between the image to be classified and each label can be obtained.

[0089] In some embodiments, before adjusting the first text vector corresponding to each label using a preset channel factor to obtain the second text vector corresponding to each label, the method may further include: firstly acquiring training samples, which include multiple sample images, multiple labels, initial prompt words corresponding to each label, and the true similarity between each sample image and each label; then inputting each sample image, each label, and the corresponding initial prompt words into a preset classification model to obtain the predicted similarity between each sample image and each label output by the preset classification model; finally, determining the preset channel factor based on the predicted similarity between each sample image and each label, and the true similarity between each sample image and each label.

[0090] In this embodiment, the preset classification model before determining the preset channel factor can be a model trained on the CLIP model according to a specific image classification task. This model is fine-tuned using initial and deep cue words to make the model more suitable for the specific image classification task, such as classifying images of different types of cats. However, fine-tuning with cue words can also lead to shifts in text vectors and image vectors, which can be corrected by determining the preset channel factor.

[0091] See here. Figure 5 The diagram shows a comparison before and after adjusting the preset channel factors. In the preset classification model before determining the preset channel factors, no preset channel factors were set. In fact, the channel factors for each dimension of the text encoder and image encoder in the preset classification model can be considered as 1, meaning the channel factors for each dimension are the same and have no impact on the output text and image vectors. See the corresponding diagram for further details. Figure 5 In the left-hand section, each rectangle corresponds to a channel factor for one dimension, and the length of the rectangle represents the magnitude of the channel factor. All rectangles on the left have equal lengths, meaning the channel factors are the same. After determining the preset channel factors using this method, the channel factors for each dimension will fluctuate around 1, thereby adjusting the elements of the corresponding dimensions in the text and image vectors. This allows for a better match between the text and image vectors. (See reference for further details.) Figure 5 In the right-hand section, each rectangle corresponds to a channel factor in one dimension. The length of the rectangle represents the size of the channel factor. The lengths of the rectangles on the right are different. The dashed line on the right side of the rectangle indicates the portion of the channel factor that has been reduced after adjustment, meaning that the channel factor has become smaller relative to the corresponding channel factor on the left. The solid line on the right side of the rectangle indicates the portion of the channel factor that has been increased after adjustment, meaning that the channel factor has become larger relative to the corresponding channel factor on the left.

[0092] Optionally, determining a preset channel factor based on the predicted similarity between each sample image and each label, and the true similarity between each sample image and each label, may include: first, determining the loss function value of a preset classification model based on the predicted similarity between each sample image and each label, and the true similarity between each sample image and each label; then, determining whether the channel factor meets preset requirements, wherein the preset requirements are set according to the loss function value; if the preset requirements are not met, adjusting the channel factor according to the gradient descent method and the loss function of the preset classification model, and re-executing the steps of inputting each sample image, each label, and the corresponding initial prompt word into the preset classification model until the preset requirements are met, obtaining the optimal channel factor, and determining the optimal channel factor as the preset channel factor.

[0093] In this embodiment, the minimum value of the loss function can be found using gradient descent to determine the optimal channel factor. This allows for accurate determination of the similarity between the image to be identified and the label based on the corrected text and image vectors. When determining the optimal channel factor, the parameters in the text encoder and image encoder of the model can be frozen or fixed, optimizing only the preset channel factor to avoid further amplifying the offsets in various dimensions of the text and image spaces.

[0094] The preset requirement can be that the derivative value of the loss function of the preset classification model is within a preset range, such as the derivative value being near 0. For example, the preset range can be -0.1 to 0.1. The derivative value of the loss function being near 0 indicates that the loss function has reached its minimum value, and the corresponding channel factor can be determined as the optimal channel factor, that is, the preset channel factor. The resulting preset classification model is also the optimal preset classification model, which can be used to perform the selected specific image classification task.

[0095] The expression for the loss function of the preset classification model can be: In the formula, L represents the loss function of the preset classification model, which can be calculated using cross-entropy; N represents the total number of sample images during the training of the preset classification model; n represents the nth sample image among all sample images, and its value can be 0, 1, 2, ..., N-1; y n p represents the true similarity between the nth sample image and each label. n Let F represent the predicted similarity between the nth sample image and each label, α represent the channel factor, I represent the sample image input to the preset classification model, T represent the label input to the preset classification model, and θ represent other parameters, such as the initial prompt word.

[0096] Here, the gradient descent method can be stochastic gradient descent. The channel factor can be adjusted using stochastic gradient descent and the loss function, based on the expression: Adjust the channel factor; where α i+1 Let α represent the channel factor in the (i+1)th iteration of stochastic gradient descent. i Let represent the channel factor in the i-th iteration of stochastic gradient descent, and η represent the learning rate in stochastic gradient descent. This represents the partial derivative of the loss function.

[0097] See Figure 4 The diagram shows the structure of the preset classification model. The text encoder includes multiple transformation layers, and each transformation layer has a depth cue word.

[0098] In this embodiment, the preset classification model includes a text encoder and an image encoder. Both the text encoder and the image encoder can have multiple transformation layers. Taking the text encoder as an example, depth-based cue words can be added to the text concatenation vector at each text transformation layer. Figure 4 In each text conversion layer, the rectangle with a dot represents an added depth cue word, and the rectangle to its left represents the input of the next text conversion layer. The first layer rectangle is specifically obtained by mapping the text vectors of the label and the initial cue word, while the second and subsequent rectangles are specifically the output of the previous text conversion layer. By adding depth cue words during the label encoding process, a more accurate first text vector can be obtained.

[0099] Here, the depth cue words in each transformation layer of the text encoder and image encoder can be trained according to the specific image classification task, so as to make the preset classification model more suitable for the selected specific image classification task. Other parameters in the text encoder and image encoder of the preset classification model are frozen. The depth cue words can be feature information of a class of images corresponding to a label or distinctive information of objects in the image. For example, for products with different defects and flaws, the depth cue words can be feature information of the defects in the product, including the shape and size features of cracks, dents, fractures, and perforations. For classifying different types of cats, the depth cue words can be distinctive information of the cat, such as long hair, short hair, hairless, green eyes, yellow eyes, orange eyes, blue eyes, no markings, spotted markings, and striped markings.

[0100] In some embodiments, each label and its corresponding multiple initial prompt words are input into the text encoder of a preset classification model to obtain the first text vector corresponding to each label output by the text encoder. This can be achieved by first converting each label into a vector and concatenating the initial prompt words to the vector to obtain the input vector; then, inputting the input vector of each label into the first transformation layer of the text encoder of the preset classification model, concatenating the input vector with the depth prompt words set in the transformation layer to obtain the first concatenated vector, and inputting it into the next transformation layer until the second concatenated vector output by the last transformation layer is obtained; finally, based on the second concatenated vector of each label, the first text vector corresponding to each label output by the text encoder is obtained.

[0101] In this embodiment, when adding depth prompts set in the conversion layer, the depth prompts set in the conversion layer can be directly concatenated into the vector input to the conversion layer to obtain the final first text vector. Multiple depth prompts can be added to the vector corresponding to the label to improve the matching relationship between the label and the image.

[0102] Here, the transformation layer does not change the size or dimension of the input and is not sensitive to the dimension of the input, so depth cue words can be concatenated into the input vector.

[0103] In other embodiments, each label and its corresponding multiple prompt words are input into the text encoder of a preset classification model to obtain the first text vector corresponding to each label output by the text encoder. This can be achieved by first converting each label into a vector and concatenating the initial prompt words onto the vector to obtain the input vector; then, the input vector of each label is input into the first transformation layer of the text encoder of the preset classification model to remove a preset number of elements from the input vector and concatenate it with the depth prompt words set in the transformation layer to obtain the third concatenated vector, which is then input into the next transformation layer until the fourth concatenated vector output by the last transformation layer is obtained; finally, based on the fourth concatenated vector of each label, the first text vector corresponding to each label output by the text encoder is obtained.

[0104] In this embodiment, when adding depth prompts set in the conversion layer, a preset number of elements can be deleted from the vector input to the conversion layer, and then the depth prompts set in the conversion layer can be concatenated. The initial prompts and depth prompts in the vector are updated to obtain the final first text vector. This allows multiple depth prompts to be added to the vector corresponding to the label, thereby improving the matching relationship between the label and the image.

[0105] Here, a predetermined number of elements corresponding to existing prompt words can be removed from the vector input to the transformation layer to update the prompt words in the vector and improve the accuracy of the final similarity calculation. The predetermined number is a pre-determined hyperparameter.

[0106] Alternatively, each tag can be converted into a vector, and the initial prompt word can be concatenated onto the vector to obtain the input vector. This can be done by first segmenting the tags into words, converting the text composed of characters into vectors, then embedding words into the vectors, and finally concatenating the initial prompt word onto the vectors to obtain the input vector.

[0107] Based on the fourth concatenation vector of each label, the first text vector corresponding to each label output by the text encoder is obtained. This can be achieved by extracting the category embedding from the fourth concatenation vector of each label, transforming it into the text space through a linear transformation, and finally obtaining the first text vector corresponding to each label.

[0108] This invention, through its embodiments, inputs each label and its corresponding initial prompts into a text encoder to obtain a first text vector for each label. Then, it adjusts the first text vector for each label using a preset channel factor to obtain a second text vector for each label. Based on the first image vector of the image to be classified and the second text vector for each label, the similarity between the image to be classified and each label is calculated. This approach fully considers the shift in each dimension of the first text vector when the preset classification model is transferred to specific image classification tasks, such as classifying different types of cats. The preset channel factor reduces dimensional shifts, increases the weight of important features in the second text vector, reduces the weight of less discriminative features, improves the consistency between the text space and the image space, and maintains the representational ability of the original preset classification model. This improves the accuracy of calculating the similarity between the image to be classified and each label, enabling accurate image classification based on similarity. The first image vector of the image to be classified can also be corrected using the preset channel factor to reduce dimensional shifts and increase the weight of important features, further enhancing the consistency between the text space and the image space. In determining the first text vector and the first image vector, depth cue words can be concatenated using each transformation layer of the text encoder and image encoder. This allows for the addition of multiple depth cue words to the vector corresponding to the label, improving the matching relationship between the label and the image, thereby enhancing the accuracy of image classification. Furthermore, this embodiment of the invention uses gradient descent to determine preset channel factors. This freezes the parameters in the text encoder and image encoder of the preset classification model, optimizing only the preset channel factors and preventing further expansion of the offsets in various dimensions of the text and image spaces.

[0109] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.

[0110] The following are device embodiments of the present invention. For details not described in detail, please refer to the corresponding method embodiments described above.

[0111] Figure 6 A schematic diagram of the image classification device based on cue word learning provided in an embodiment of the present invention is shown. For ease of explanation, only the parts related to the embodiment of the present invention are shown, and are described in detail below:

[0112] like Figure 6 As shown, the image classification device 60 based on cue word learning includes:

[0113] The acquisition module 61 is used to acquire the image to be classified, multiple preset labels, and multiple initial prompt words corresponding to each label;

[0114] Encoding module 62 is used to input each label and its corresponding multiple initial prompt words into the text encoder of the preset classification model to obtain the first text vector corresponding to each label output by the text encoder.

[0115] The correction module 63 is used to adjust the first text vector corresponding to each tag using a preset channel factor to obtain the second text vector corresponding to each tag; wherein, the preset channel factor is used to correct the offset of the text vector output by the text encoder.

[0116] The calculation module 64 is used to determine the similarity between the image to be classified and each label based on the first image vector corresponding to the image to be classified and the second text vector corresponding to each label.

[0117] Classification module 65 is used to classify the image to be classified based on the similarity between the image to be classified and each label.

[0118] In one possible implementation, the pre-defined classification model also includes an image encoder;

[0119] Encoding module 62 is also used for:

[0120] The image to be classified is input into the image encoder of the preset classification model to obtain the second image vector corresponding to the image to be classified output by the image encoder;

[0121] The second image vector is adjusted using a preset channel factor to obtain the first image vector corresponding to the image to be classified; the preset channel factor is also used to correct the offset of the image vector output by the image encoder.

[0122] In one possible implementation, the image classification device 60 based on cue word learning further includes a determination module, which is used for:

[0123] Obtain training samples, which include multiple sample images, multiple labels, initial prompt words corresponding to each label, and the true similarity between each sample image and each label;

[0124] Each sample image, each label, and the corresponding initial prompt word are input into the preset classification model to obtain the predicted similarity between each sample image and each label output by the preset classification model.

[0125] The preset channel factor is determined based on the predicted similarity between each sample image and each label, as well as the actual similarity between each sample image and each label.

[0126] In one possible implementation, the text vector includes text elements of multiple dimensions, the image vector includes image elements of multiple dimensions, and the preset channel factor includes channel factors of multiple dimensions.

[0127] Calculation module 64 is specifically used for:

[0128] For each label, the similarity score between the image to be classified and the label in each dimension is calculated based on the text elements in each dimension of the second text vector corresponding to the label, the image elements in the corresponding dimension of the first image vector, and the preset channel factor in the corresponding dimension.

[0129] Based on the similarity score between the image to be classified and each label in each dimension, the similarity between the image to be classified and each label is calculated.

[0130] The module is specifically used for:

[0131] Based on the predicted similarity between each sample image and each label, and the true similarity between each sample image and each label, the loss function value of the preset classification model is determined;

[0132] Determine whether the channel factor meets the preset requirements, where the preset requirements are set based on the loss function value;

[0133] If the preset requirements are not met, the channel factor is adjusted according to the gradient descent method and the loss function of the preset classification model, and the steps of inputting each sample image, each label and the corresponding initial prompt word into the preset classification model are repeated until the preset requirements are met, the optimal channel factor is obtained, and the optimal channel factor is determined as the preset channel factor.

[0134] In one possible implementation, the text encoder includes multiple transformation layers, each with a deep cue word set in its layer;

[0135] Encoding module 62 is specifically used for:

[0136] Each label is converted into a vector, and the initial prompt word is concatenated onto the vector to obtain the input vector;

[0137] The input vector for each label is fed into the first transformation layer of the text encoder of the preset classification model, so that the input vector is concatenated with the depth cue words set in the transformation layer to obtain the first concatenated vector, which is then fed into the next transformation layer until the second concatenated vector is obtained from the output of the last transformation layer.

[0138] Based on the second concatenation vector of each tag, the first text vector corresponding to each tag output by the text encoder is obtained.

[0139] In one possible implementation, the text encoder includes multiple transformation layers, each with a deep cue word set in its layer;

[0140] Encoding module 62 is specifically used for:

[0141] Each label is converted into a vector, and the initial prompt word is concatenated onto the vector to obtain the input vector;

[0142] The input vector of each label is input into the first transformation layer of the text encoder of the preset classification model to remove a preset number of elements from the input vector and concatenate it with the depth cue words set in the transformation layer to obtain the third concatenated vector, which is then input into the next transformation layer until the fourth concatenated vector is obtained from the output of the last transformation layer.

[0143] Based on the fourth concatenation vector of each tag, the first text vector corresponding to each tag output by the text encoder is obtained.

[0144] Figure 7 This is a schematic diagram of an electronic device provided in an embodiment of the present invention. For example... Figure 7 As shown, the electronic device 70 of this embodiment includes: a processor 71, a memory 72, and a computer program 73 stored in the memory 72 and executable on the processor 71. When the processor 71 executes the computer program 73, it implements the steps in the various image classification method embodiments based on cue word learning described above, for example... Figure 2 Steps S201 to S205 are shown. Alternatively, when processor 71 executes computer program 73, it implements the functions of each module in the above-described device embodiments, for example... Figure 6 The functions of modules 61 to 65 are shown.

[0145] For example, computer program 73 can be divided into one or more modules / units, one or more of which are stored in memory 72 and executed by processor 71 to complete the present invention. One or more modules / units can be a series of computer program instruction segments capable of performing a specific function, which describe the execution process of computer program 73 in electronic device 70. For example, computer program 73 can be divided into... Figure 6 Modules 61 to 65 are shown.

[0146] Electronic device 70 may include, but is not limited to, processor 71 and memory 72. Those skilled in the art will understand that... Figure 7 This is merely an example of electronic device 70 and does not constitute a limitation on electronic device 70. It may include more or fewer components than shown, or combine certain components, or different components. For example, electronic device may also include input / output devices, network access devices, buses, etc.

[0147] The processor 71 may be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.

[0148] The memory 72 can be an internal storage unit of the electronic device 70, such as a hard disk or RAM of the electronic device 70. The memory 72 can also be an external storage device of the electronic device 70, such as a plug-in hard disk, Smart Media Card (SMC), Secure Digital (SD) card, or Flash Card equipped on the electronic device 70. Furthermore, the memory 72 can include both internal and external storage units of the electronic device 70. The memory 72 is used to store computer programs and other programs and data required by the electronic device. The memory 72 can also be used to temporarily store data that has been output or will be output.

[0149] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0150] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0151] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0152] In the embodiments provided by this invention, it should be understood that the disclosed devices / electronic devices and methods can be implemented in other ways. For example, the device / electronic device embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.

[0153] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0154] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0155] If integrated modules / units are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of the present invention can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc.

[0156] The above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.

Claims

1. An image classification method based on cue word learning, characterized in that, include: Obtain the image to be classified, multiple preset labels, and multiple initial prompt words corresponding to each label; Each label and its corresponding multiple initial prompt words are input into the text encoder of the preset classification model to obtain the first text vector corresponding to each label output by the text encoder; By using a preset channel factor, the first text vector corresponding to each tag is adjusted to obtain the second text vector corresponding to each tag; wherein, the preset channel factor is used to correct the offset of the text vector output by the text encoder; The similarity between the image to be classified and each label is determined based on the first image vector corresponding to the image to be classified and the second text vector corresponding to each label. The image to be classified is classified based on the similarity between the image to be classified and each label; The preset classification model also includes an image encoder; Before determining the similarity between the image to be classified and each label based on the first image vector corresponding to the image to be classified and the second text vector corresponding to each label, the method further includes: The image to be classified is input into the image encoder of the preset classification model to obtain the second image vector corresponding to the image to be classified output by the image encoder; The second image vector is adjusted using the preset channel factor to obtain the first image vector corresponding to the image to be classified; wherein, the preset channel factor is also used to correct the offset of the image vector output by the image encoder; The text vector includes text elements of multiple dimensions, the image vector includes image elements of multiple dimensions, and the preset channel factor includes channel factors of multiple dimensions. The step of determining the similarity between the image to be classified and each label based on the first image vector corresponding to the image to be classified and the second text vector corresponding to each label includes: For each label, the similarity score between the image to be classified and the label in each dimension is calculated based on the text elements in each dimension of the second text vector corresponding to the label, the image elements in the corresponding dimension of the first image vector, and the preset channel factor in the corresponding dimension. Based on the similarity score between the image to be classified and each label in each dimension, the similarity between the image to be classified and each label is calculated respectively.

2. The image classification method based on cue word learning according to claim 1, characterized in that, Before adjusting the first text vector corresponding to each tag using a preset channel factor to obtain the second text vector corresponding to each tag, the method further includes: Obtain training samples, which include multiple sample images, multiple labels, initial prompt words corresponding to each label, and the true similarity between each sample image and each label; Each sample image, each label, and the corresponding initial prompt word are input into the preset classification model to obtain the predicted similarity between each sample image and each label output by the preset classification model. The preset channel factor is determined based on the predicted similarity between each sample image and each label, and the actual similarity between each sample image and each label.

3. The image classification method based on cue word learning according to claim 2, characterized in that, The preset channel factor is determined based on the predicted similarity between each sample image and each label, and the true similarity between each sample image and each label, including: The loss function value of the preset classification model is determined based on the predicted similarity between each sample image and each label, and the true similarity between each sample image and each label. Determine whether the channel factor meets the preset requirements, wherein the preset requirements are set according to the loss function value; If the preset requirements are not met, the channel factor is adjusted according to the gradient descent method and the loss function of the preset classification model, and the steps of inputting each sample image, each label and the corresponding initial prompt word into the preset classification model are repeated until the preset requirements are met, the optimal channel factor is obtained, and the optimal channel factor is determined as the preset channel factor.

4. The image classification method based on cue word learning according to claim 1, characterized in that, The text encoder includes multiple conversion layers, each of which contains deep cue words; Each label and its corresponding multiple initial prompt words are input into the text encoder of a preset classification model to obtain the first text vector corresponding to each label output by the text encoder, including: Each label is converted into a vector, and the initial prompt word is concatenated onto the vector to obtain the input vector; The input vector of each label is input into the first transformation layer of the text encoder of the preset classification model, so that the input vector is concatenated with the deep cue words set in the transformation layer to obtain the first concatenated vector, and then input into the next transformation layer, until the second concatenated vector output by the last transformation layer is obtained; Based on the second concatenation vector of each tag, the first text vector corresponding to each tag output by the text encoder is obtained.

5. The image classification method based on cue word learning according to claim 1, characterized in that, The text encoder includes multiple conversion layers, each of which contains deep cue words; Each label and its corresponding multiple prompt words are input into the text encoder of a preset classification model to obtain the first text vector corresponding to each label output by the text encoder, including: Each label is converted into a vector, and the initial prompt word is concatenated onto the vector to obtain the input vector; The input vector of each label is input into the first transformation layer of the text encoder of the preset classification model to remove a preset number of elements from the input vector and concatenate the deep cue words set in the transformation layer to obtain the third concatenated vector, which is then input into the next transformation layer until the fourth concatenated vector is obtained from the last transformation layer. Based on the fourth concatenation vector of each tag, the first text vector corresponding to each tag output by the text encoder is obtained.

6. An image classification device based on cue word learning, characterized in that, include: The acquisition module is used to acquire the image to be classified, multiple preset labels, and multiple initial prompt words corresponding to each label; The encoding module is used to input each label and its corresponding multiple initial prompt words into the text encoder of the preset classification model, so as to obtain the first text vector corresponding to each label output by the text encoder; The correction module is used to adjust the first text vector corresponding to each tag using a preset channel factor to obtain the second text vector corresponding to each tag; wherein, the preset channel factor is used to correct the offset of the text vector output by the text encoder. The calculation module is used to determine the similarity between the image to be classified and each label based on the first image vector corresponding to the image to be classified and the second text vector corresponding to each label. A classification module is used to classify the image to be classified based on the similarity between the image to be classified and each label; The preset classification model also includes an image encoder; The determination module is used for: The image to be classified is input into the image encoder of the preset classification model to obtain the second image vector corresponding to the image to be classified output by the image encoder; The second image vector is adjusted using the preset channel factor to obtain the first image vector corresponding to the image to be classified; wherein, the preset channel factor is also used to correct the offset of the image vector output by the image encoder; The text vector includes text elements of multiple dimensions, the image vector includes image elements of multiple dimensions, and the preset channel factor includes channel factors of multiple dimensions. The calculation module is specifically used for: For each label, the similarity score between the image to be classified and the label in each dimension is calculated based on the text elements in each dimension of the second text vector corresponding to the label, the image elements in the corresponding dimension of the first image vector, and the preset channel factor in the corresponding dimension. Based on the similarity score between the image to be classified and each label in each dimension, the similarity between the image to be classified and each label is calculated respectively.

7. An electronic device comprising a memory and a processor, the memory for storing a computer program, the processor for calling and running the computer program stored in the memory, characterized in that, When the processor executes the computer program, it implements the steps of the method as described in any one of claims 1 to 5 above.

8. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Small sample class increment image classification method based on cue word fine tuning and feature playback

    CN117746140A