Image classification method and system based on text classifier, storage medium and electronic equipment

Through the text classifier-based method, text features and image features are used to train text classifiers, which solves the problem of low training accuracy of image classification models, achieves efficient image classification, reduces costs and improves classification accuracy.

CN118587526APending Publication Date: 2024-09-03上海蜜度蜜巢智能科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410632356.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-21
Publication Date
2024-09-03

AI Technical Summary

Technical Problem

In the existing technology, it is difficult to collect considerable training sets when training image classification models, especially labels, which results in low training accuracy of image classification models and cannot meet the needs of practical applications.

Method used

Using a text classifier-based method, by generating a training data set for the text classifier, including the category and category description of the image, extracting text features and image features, and using the CLIP text encoder and image encoder to train the text classifier, and then realize the image Classification.

Benefits of technology

There is no need to train a special image classifier, which reduces costs, improves the efficiency of image classification, and significantly improves classification accuracy. It is highly intelligent and extremely practical.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118587526A
    Figure CN118587526A
Patent Text Reader

Abstract

The invention provides an image classification method and system based on a text classifier, a storage medium and electronic equipment, and the method comprises the following steps: generating a training data set of the text classifier, the training data set comprising image categories and category descriptions; extracting text features of the category description; training the text classifier based on the text features and the categories; extracting image features of the to-be-classified images; and inputting the image features into a trained text classifier to obtain the category of the to-be-classified image. According to the image classification method and system based on the text classifier, the storage medium and the electronic equipment, image classification is realized based on the text classification capability, and the image classification efficiency is effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of deep learning, and in particular relates to an image classification method, system, storage medium and electronic device based on a text classifier. Background Art

[0002] Image classification, as the name implies, is a pattern classification problem. Its goal is to classify different images into different categories to achieve the smallest classification error. In general, for single-label image classification problems, it can be divided into three categories: cross-species semantic-level image classification, sub-class fine-grained image classification, and instance-level image classification.

[0003] With the development of deep learning, image classification problems have been significantly improved. Deep learning models can automatically learn feature representations from large amounts of data and can handle nonlinear relationships in high-dimensional data, which makes it easier to solve complex image classification problems. However, in the prior art, it is usually difficult to collect a considerable training set when training image classification models, mainly because labels are difficult to collect, resulting in low training accuracy of image classification models and failure to meet the needs of practical applications. Summary of the invention

[0004] In view of the shortcomings of the prior art described above, the purpose of the present invention is to provide an image classification method, system, storage medium and electronic device based on a text classifier, which realizes image classification based on text classification capability and effectively improves the efficiency of image classification.

[0005] In a first aspect, the present invention provides an image classification method based on a text classifier, the method comprising the following steps: generating a training data set for a text classifier, the training data set comprising image categories and category descriptions; extracting text features of the category descriptions; training the text classifier based on the text features and the categories; extracting image features of the image to be classified; and inputting the image features into the trained text classifier to obtain the category of the image to be classified.

[0006] In an implementation of the first aspect, generating a training data set for a text classifier includes the following steps:

[0007] Get the category of the image;

[0008] Acquire multiple input text prompts; the input text prompts are used to indicate the category description of the acquired image;

[0009] Inputting the input text indication of each category into the large language model to obtain a category description corresponding to the category;

[0010] A training data set is constructed based on the categories and the corresponding category descriptions.

[0011] In an implementation of the first aspect, text features of the category description are extracted based on a CLIP text encoder; and image features of the image to be classified are extracted based on a CLIP image encoder.

[0012] In an implementation manner of the first aspect, the text classifier adopts a multilayer perceptron or a transformer encoder block.

[0013] In a second aspect, the present invention provides an image classification system based on a text classifier, the system comprising a generation module, a first extraction module, a training module, a second extraction module and a classification module;

[0014] The generation module is used to generate a training data set for a text classifier, wherein the training data set includes image categories and category descriptions;

[0015] The first extraction module is used to extract text features of the category description;

[0016] The training module is used to train the text classifier based on the text features and the categories;

[0017] The second extraction module is used to extract image features of the image to be classified;

[0018] The classification module is used to input the image features into a trained text classifier to obtain the category of the image to be classified.

[0019] In an implementation of the second aspect, generating a training data set for a text classifier includes the following steps:

[0020] Get the category of the image;

[0021] Acquire multiple input text prompts; the input text prompts are used to indicate the category description of the acquired image;

[0022] Inputting the input text indication of each category into the large language model to obtain a category description corresponding to the category;

[0023] A training data set is constructed based on the categories and the corresponding category descriptions.

[0024] In an implementation of the second aspect, text features of the category description are extracted based on a CLIP text encoder; and image features of the image to be classified are extracted based on a CLIP image encoder.

[0025] In an implementation manner of the second aspect, the text classifier adopts a multilayer perceptron or a transformer encoder block.

[0026] In a third aspect, the present invention provides an electronic device, the electronic device comprising: a processor and a memory;

[0027] The memory is used to store computer programs;

[0028] The processor is used to execute the computer program stored in the memory, so that the electronic device executes the above-mentioned image classification method based on text classifier.

[0029] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by an electronic device, implements the above-mentioned image classification method based on a text classifier.

[0030] As described above, the image classification method, system, storage medium and electronic device based on text classifier of the present invention have the following beneficial effects:

[0031] (1) Image classification is realized based on text classification capabilities, which effectively improves the efficiency of image classification;

[0032] (2) No need to train a dedicated image classifier, effectively reducing costs;

[0033] (3) Highly intelligent and practical. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] Figure 1 Shown is a schematic diagram of a scene of an electronic device in an embodiment of the present invention;

[0035] Figure 2 Shown is a flow chart of an image classification method based on a text classifier in one embodiment of the present invention;

[0036] Figure 3 It is a schematic diagram showing the structure of an image classification method based on a text classifier in one embodiment of the present invention;

[0037] Figure 4 Shown is a schematic diagram of the structure of an image classification system based on a text classifier in one embodiment of the present invention;

[0038] Figure 5 It is a schematic structural diagram of an electronic device of the present invention in one embodiment. DETAILED DESCRIPTION

[0039] The following describes the embodiments of the present invention by specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict.

[0040] It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present invention, and thus the drawings only show components related to the present invention rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.

[0041] The following embodiments of the present invention provide an image classification method based on a text classifier, which can be applied to Figure 1 The electronic device shown. The electronic device described in the present invention may include a mobile phone 11 with a wireless charging function, a tablet computer 12, a laptop computer 13, a wearable device, a vehicle-mounted device, an augmented reality (AR) / virtual reality (VR) device, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), etc. The embodiment of the present invention does not impose any restrictions on the specific type of the electronic device.

[0042] For example, the electronic device may be a station (STAION, ST) in a WLAN with a wireless charging function, a cellular phone, a cordless phone, a Session Initiation Protocol (SIP) phone, a Wireless Local Loop (WLL) station, a Personal Digital Assistant (PDA) device, a handheld device with a wireless charging function, a computing device or other processing device, a computer, a laptop computer, a handheld communication device, a handheld computing device, and / or other devices for communicating on a wireless system and a next generation communication system, such as a mobile terminal in a 5G network, a mobile terminal in a future evolved Public Land Mobile Network (PLMN), or a mobile terminal in a future evolved Non-terrestrial Network (NTN).

[0043] For example, the electronic device can communicate with the network and other devices through wireless communication. The above wireless communication can use any communication standard or protocol, including but not limited to Global System of Mobilecommunication (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Long Term Evolution (LTE), email, Short Messaging Service (SMS), BT, GNSS, WLAN, NFC, FM, and / or IR technology. The GNSS can include Global Positioning System (GPS), Global Navigation Satellite System (GLONASS), BeiDou navigation Satellite System (BDS), Quasi-Zenith Satellite System (QZSS) and / or Satellite Based Augmentation Systems (SBAS).

[0044] The technical solutions in the embodiments of the present invention will be described in detail below in conjunction with the accompanying drawings in the embodiments of the present invention.

[0045] like Figure 2 and Figure 3 As shown, in one embodiment, the image classification method based on text classifier of the present invention includes steps S1 to S5.

[0046] Step S1: Generate a training data set for a text classifier, wherein the training data set includes image categories and category descriptions.

[0047] Specifically, generating a training data set for a text classifier includes the following steps:

[0048] 11) Get the category of the image.

[0049] Among them, the category of the image in the image classification is obtained, such as car, dog, cat, etc.

[0050] 12) Acquire multiple input text prompts; the input text prompts are used to indicate the category description of the acquired image.

[0051] The user provides input prompt text through prompt. Prompt refers to text or instructions that provide input to the model to guide it to generate specific output. It is a text paragraph provided by the user when interacting with the model, which is used to describe the information, answer, text, etc. that the user wants to obtain from the model. The purpose of prompt is to guide the model to produce the desired response in order to better control the generated output.

[0052] For example, for the category "cars", use the following five prompt templates to customize the model's text input:

[0053] Template 1: Please describe the appearance of the category, such as "Please describe the appearance of the car";

[0054] Template 2: How to identify a category, such as “How to identify a car”;

[0055] Template 3; What does the category look like? , such as "What does a car look like?";

[0056] Template 4: Describes a web image from a category, such as “Describes a web image from a car”;

[0057] Template 5: Summary description of category images, such as “Summary description of car images”.

[0058] 13) Inputting the input text indication of each category into the large language model to obtain the category description corresponding to the category.

[0059] Among them, Large Language Model (LLM) is an AI model designed to understand and generate human language. They are trained on large amounts of text data and can perform a wide range of tasks, including text summarization, translation, sentiment analysis, and more. LLMs are characterized by their large size and contain billions of parameters, which help them learn complex patterns in language data. These models are usually based on deep learning architectures such as transformers, which helps them achieve impressive performance on various NLP tasks.

[0060] In the present invention, the input text indication of each category is input into the large language model to obtain the category description corresponding to the category.

[0061] 14) Constructing a training data set based on the categories and the corresponding category descriptions.

[0062] Each category and the corresponding category description is taken as a training data, and the set of training data is taken as the training data set.

[0063] Step S2: extracting text features of the category description.

[0064] Specifically, CLIP stands for Contrastive Language-Image Pre-training, which is a pre-training method or model based on contrastive text-image pairs. CLIP is a multimodal model based on contrastive learning. Unlike some contrastive learning methods in CV, such as moco and simclr, CLIP's training data is text-image pairs: an image and its corresponding text description. Through contrastive learning, the model can learn the matching relationship between text-image pairs. CLIP includes two models: a text encoder and an image encoder. The text encoder is used to extract text features and can use the text transformer model commonly used in NLP; while the image encoder is used to extract image features and can use the commonly used CNN model or vision transformer.

[0065] In one embodiment, the text features of the category description are extracted based on a CLIP text encoder. It should be noted that the CLIP text encoder is pre-trained, and its weights remain unchanged.

[0066] Step S3: training the text classifier based on the text features and the categories.

[0067] Specifically, the text features are input into the text classifier, and the text classifier outputs a predicted category; based on the predicted category and the category, the text classifier is trained using a cross entropy loss function until the text classifier converges. The text classifier is used to output a corresponding category according to the input feature information.

[0068] In one embodiment, the text classifier uses a multi-layer perceptron or a transformer encoder block, which can be customized by the user.

[0069] Step S4: extracting image features of the image to be classified.

[0070] Specifically, the image features of the image to be classified are extracted based on the CLIP image encoder.

[0071] Step S5: input the image features into a trained text classifier to obtain the category of the image to be classified.

[0072] Specifically, when performing image classification, the image features of the image to be classified are input into a trained text classifier to obtain the category corresponding to the image to be classified, so there is no need to train a special image classifier, and the text classifier can be used to achieve it. Compared with image classifiers, the training data set of text classifiers is easy to obtain and has obvious advantages in classification accuracy.

[0073] The protection scope of the image classification method based on text classifier described in the embodiment of the present invention is not limited to the execution order of the steps listed in this embodiment. All solutions implemented by adding, reducing or replacing steps in the prior art based on the principles of the present invention are included in the protection scope of the present invention.

[0074] An embodiment of the present invention also provides an image classification system based on a text classifier, which can implement the image classification method based on a text classifier described in the present invention. However, the implementation device of the image classification system based on a text classifier described in the present invention includes but is not limited to the structure of the image classification system based on a text classifier listed in this embodiment. All structural deformations and replacements of the prior art made according to the principles of the present invention are included in the protection scope of the present invention.

[0075] like Figure 4 As shown, in one embodiment, the text classifier-based image classification system of the present invention includes a generation module 41 , a first extraction module 42 , a training module 43 , a second extraction module 44 and a classification module 45 .

[0076] The generating module 41 is used to generate a training data set for a text classifier, wherein the training data set includes image categories and category descriptions.

[0077] The first extraction module 42 is connected to the generation module 41 and is used to extract text features of the category description.

[0078] The training module 43 is connected to the generating module 41 and the first extracting module 42, and is used for training the text classifier based on the text features and the categories.

[0079] The second extraction module 44 is used to extract image features of the image to be classified.

[0080] The classification module 45 is connected to the training module 43 and the second extraction module 44, and is used to input the image features into a trained text classifier to obtain the category of the image to be classified.

[0081] Among them, the structures and principles of the generation module 41, the first extraction module 42, the training module 43, the second extraction module 44 and the classification module 45 correspond one by one to the steps in the above-mentioned image classification method based on the text classifier, so they are not repeated here.

[0082] In the several embodiments provided by the present invention, it should be understood that the disclosed system, device or method can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules / units is only a logical function division, and there may be other division methods in actual implementation, such as multiple modules or units can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or modules or units, which can be electrical, mechanical or other forms.

[0083] The modules / units described as separate components may or may not be physically separated, and the components displayed as modules / units may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules / units may be selected according to actual needs to achieve the purpose of the embodiments of the present invention. For example, the functional modules / units in the various embodiments of the present invention may be integrated into one processing module, or each module / unit may exist physically separately, or two or more modules / units may be integrated into one module / unit.

[0084] Those of ordinary skill in the art should further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0085] The embodiment of the present invention also provides a computer-readable storage medium. A person of ordinary skill in the art can understand that all or part of the steps in the method for implementing the above embodiment can be completed by instructing the processor through a program, and the program can be stored in a computer-readable storage medium, and the storage medium is a non-transitory medium, such as a random access memory, a read-only memory, a flash memory, a hard disk, a solid-state hard disk, a magnetic tape, a floppy disk, an optical disc, and any combination thereof. The above storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or a data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a digital video disc (DVD)), or a semiconductor medium (e.g., a solid-state disk (SSD)), etc.

[0086] An embodiment of the present invention further provides an electronic device, which includes a processor and a memory.

[0087] The memory is used to store computer programs.

[0088] The memory includes: ROM, RAM, disk, USB flash drive, memory card or CD and other media that can store program codes.

[0089] The processor is connected to the memory and is used to execute the computer program stored in the memory so that the electronic device executes the above-mentioned image classification method based on the text classifier.

[0090] Preferably, the processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.

[0091] like Figure 5 As shown, the electronic device of the present invention is in the form of a general computing device. The components of the electronic device may include but are not limited to: one or more processors or processing units 51, a memory 52, and a bus 53 connecting different system components (including the memory 52 and the processing unit 51).

[0092] Bus 53 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. For example, these architectures include but are not limited to Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MAC) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus and Peripheral Component Interconnect (PCI) bus.

[0093] Electronic devices typically include a variety of computer system readable media. These media can be any available media that can be accessed by the electronic device, including volatile and non-volatile media, removable and non-removable media.

[0094] The memory 52 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 521 and / or cache memory 522. The electronic device may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 523 may be used to read and write non-removable, non-volatile magnetic media ( Figure 5 not shown, usually called a "hard drive"). Although Figure 5Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 53 via one or more data medium interfaces. The memory 52 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present invention.

[0095] A program / utility 524 having a set (at least one) of program modules 5241 may be stored, for example, in the memory 52, such program modules 5241 including but not limited to an operating system, one or more application programs, other program modules, and program data, each of which or some combination thereof may include an implementation of a network environment. The program modules 5241 generally perform the functions and / or methods of the embodiments described herein.

[0096] The electronic device may also communicate with one or more external devices (e.g., keyboards, pointing devices, displays, etc.), one or more devices that enable a user to interact with the electronic device, and / or any device that enables the electronic device to communicate with one or more other computing devices (e.g., network cards, modems, etc.). Such communication may be performed via input / output (I / O) interface 54. Furthermore, the electronic device may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via network adapter 55. Figure 5 As shown, the network adapter 55 communicates with other modules of the electronic device via the bus 53. It should be understood that, although not shown in the figure, other hardware and / or software modules can be used in conjunction with the electronic device, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0097] The above embodiments are merely illustrative of the principles and effects of the present invention, and are not intended to limit the present invention. Anyone familiar with the art may modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by a person of ordinary skill in the art without departing from the spirit and technical concept disclosed by the present invention shall still be covered by the claims of the present invention.

Claims

1. An image classification method based on a text classifier, characterized in that: The method comprises the following steps: Generate a training data set for a text classifier, wherein the training data set includes image categories and category descriptions; Extracting text features of the category description; Training the text classifier based on the text features and the categories; Extract image features of the image to be classified; The image features are input into a trained text classifier to obtain the category of the image to be classified.

2. The image classification method based on text classifier according to claim 1, characterized in that: Generating a training dataset for a text classifier involves the following steps: Get the category of the image; Acquire multiple input text prompts; the input text prompts are used to indicate the category description of the acquired image; Inputting the input text indication of each category into the large language model to obtain a category description corresponding to the category; A training data set is constructed based on the categories and the corresponding category descriptions.

3. The image classification method based on text classifier according to claim 1, characterized in that: The text features of the category description are extracted based on the CLIP text encoder; and the image features of the image to be classified are extracted based on the CLIP image encoder.

4. The image classification method based on text classifier according to claim 1, characterized in that: The text classifier adopts a multi-layer perceptron or a transformer encoder block.

5. An image classification system based on a text classifier, characterized in that: The system comprises a generation module, a first extraction module, a training module, a second extraction module and a classification module; The generation module is used to generate a training data set for a text classifier, wherein the training data set includes image categories and category descriptions; The first extraction module is used to extract text features of the category description; The training module is used to train the text classifier based on the text features and the categories; The second extraction module is used to extract image features of the image to be classified; The classification module is used to input the image features into a trained text classifier to obtain the category of the image to be classified.

6. The image classification system based on text classifier according to claim 5, characterized in that: Generating a training dataset for a text classifier involves the following steps: Get the category of the image; Acquire multiple input text prompts; the input text prompts are used to indicate the category description of the acquired image; Inputting the input text indication of each category into the large language model to obtain a category description corresponding to the category; A training data set is constructed based on the categories and the corresponding category descriptions.

7. The image classification system based on text classifier according to claim 5, characterized in that: The text features of the category description are extracted based on the CLIP text encoder; and the image features of the image to be classified are extracted based on the CLIP image encoder.

8. The image classification system based on text classifier according to claim 5, characterized in that: The text classifier adopts a multi-layer perceptron or a transformer encoder block.

9. An electronic device, characterized in that: The electronic device comprises: a processor and a memory; The memory is used to store computer programs; The processor is used to execute the computer program stored in the memory, so that the electronic device executes the image classification method based on a text classifier according to any one of claims 1 to 4.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by an electronic device, the image classification method based on a text classifier according to any one of claims 1 to 4 is implemented.