Image classification model training method, device and electronic equipment
Through the training method of image classification model, multiple training data sets and feature extraction networks are used to extract and calculate image features, which solves the problem of lack of image annotation data in fine-grained identification of species and improves identification accuracy.
Patent Information
- Application Number
- CN202310014934.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-05
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2043-01-05
AI Technical Summary
It is difficult to train a fine-grained species recognition model with high recognition accuracy using existing technology, mainly due to the similarity in body size and appearance of species, resulting in a lack of image annotation data.
Using the image classification model training method, by obtaining multiple training data sets, including support sets and query sets, determine the similarity of sample image pairs, and use the feature extraction network and attention mechanism network to extract image features, combined with the similarity calculation network , training to obtain an image classification model with higher accuracy.
It reduces the labor cost in species recognition tasks and improves the recognition accuracy in species recognition tasks. It is suitable for tasks where image annotation data is relatively lacking.
Smart Images

Figure CN115965817B
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of artificial intelligence technology, in particular to the field of natural language processing, computer vision, and deep learning technology, and in particular to a training method, device, and electronic device for an image classification model. Background Art
[0002] At present, for image recognition tasks, a large number of images need to be labeled to obtain image annotation data; the image annotation data is used to train the deep learning model to obtain an image recognition model with higher recognition accuracy for image recognition tasks.
[0003] Among them, for the task of fine-grained species identification, since many species are similar in size and appearance,
[0004] The feature differences are small, and only experts in the corresponding field can distinguish different species, resulting in a lack of image annotation data for this task and making it difficult to train a fine-grained species recognition model with high recognition accuracy. Summary of the invention
[0005] The present invention provides a method, device and electronic device for training an image classification model.
[0006] According to one aspect of the present disclosure, a method for training an image classification model is provided, the method comprising: obtaining a plurality of training data sets, the training data sets comprising a support set and a query set; the support set comprising a support sample image and a category of the support sample image; the query set comprising a query sample image and a category of the query sample image; obtaining an initial image classification model; for each training data set, determining a plurality of sample image pairs in the training data set and a sample similarity between the support sample image and the query sample image in the sample image pair according to the support sample image, the category of the support sample image, the query sample image and the category of the query sample image in the training data set; for each training data set in turn, taking the support sample image and the query sample image in the sample image pair in the training data set as the input of the image classification model, taking the sample similarity between the support sample image and the query sample image in the sample image pair as the output of the image classification model, training the image classification model to obtain a trained image classification model.
[0007] According to another aspect of the present disclosure, an image classification method is provided, the method comprising: obtaining an image to be processed and a support set, the support set comprising a plurality of support sample images and categories of the support sample images; generating a plurality of image pairs according to the image to be processed and the plurality of support sample images; the image pair comprising the image to be processed and the support sample images; inputting the image pair to be processed into a feature extraction network and an attention mechanism network of an image classification model to obtain image features of the image to be processed in the image pair and support image features of the support sample images in the image pair; the image classification model is trained based on the training method of the image classification model as described above; inputting the image features of the image to be processed in the image pair and the support image features of the support sample images in the image pair into a similarity calculation network in the image classification model to obtain the similarity between the image to be processed and the support sample images; determining the category of the image to be processed according to the similarity between the image to be processed and the support sample images and the category of the support sample images.
[0008] According to another aspect of the present disclosure, a training device for an image classification model is provided, the device comprising: a first acquisition module, used to acquire multiple training data sets, the training data sets comprising a support set and a query set; the support set comprising a support sample image and a category of the support sample image; the query set comprising a query sample image and a category of the query sample image; a second acquisition module, used to acquire an initial image classification model; a determination module, used to determine, for each training data set, multiple sample image pairs in the training data set and the sample similarity between the support sample image and the query sample image in the sample image pair according to the support sample image, the category of the support sample image, the query sample image and the category of the query sample image in the training data set; a training module, used to train the image classification model in turn for each training data set, using the support sample image and the query sample image in the sample image pair in the training data set as the input of the image classification model, and using the sample similarity between the support sample image and the query sample image in the sample image pair as the output of the image classification model, to obtain a trained image classification model.
[0009] According to another aspect of the present disclosure, there is provided an image classification device, the device comprising:
[0010] An acquisition module is used to acquire an image to be processed and a support set, wherein the support set includes multiple support sample images and categories of the support sample images; a generation module is used to generate multiple image pairs based on the image to be processed and the multiple support sample images; the image pair includes the image to be processed and the support sample images; a first input module is used to input the image pair to be processed into a feature extraction network and an attention mechanism network of an image classification model to obtain image features of the image to be processed in the image pair and support image features of the support sample images in the image pair; the image classification model is trained based on the training method of the image classification model described above; a second input module is used to input the image features of the image to be processed in the image pair and the support image features of the support sample images in the image pair into a similarity calculation network in the image classification model to obtain the similarity between the image to be processed and the support sample images; a determination module is used to determine the category of the image to be processed based on the similarity between the image to be processed and the support sample images, and the category of the support sample images.
[0011] According to another aspect of the present disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the training method of the image classification model proposed in the present disclosure, or execute the image classification method proposed in the present disclosure.
[0012] According to another aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable a computer to execute the image classification model training method proposed above in the present disclosure, or to execute the image classification method proposed above in the present disclosure.
[0013] According to another aspect of the present disclosure, a computer program product is provided, including a computer program, which, when executed by a processor, implements the training method of the image classification model proposed above in the present disclosure, or implements the image classification method proposed above in the present disclosure.
[0014] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0016] Figure 1 is a schematic diagram according to a first embodiment of the present disclosure;
[0017] Figure 2 is a schematic diagram according to a second embodiment of the present disclosure;
[0018] Figure 3 is a schematic diagram according to a third embodiment of the present disclosure;
[0019] Figure 4 is a schematic diagram according to a fourth embodiment of the present disclosure;
[0020] Figure 5 is a schematic diagram according to a fifth embodiment of the present disclosure;
[0021] Figure 6 is a schematic diagram according to a sixth embodiment of the present disclosure;
[0022] Figure 7 It is a block diagram of an electronic device used to implement the training method of the image classification model or the image classification method of the embodiment of the present disclosure. DETAILED DESCRIPTION
[0023] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0024] At present, for image recognition tasks, a large number of images need to be labeled to obtain image annotation data; the image annotation data is used to train the deep learning model to obtain an image recognition model with higher recognition accuracy for image recognition tasks.
[0025] Among them, for the task of fine-grained species identification, since many species are similar in size and appearance,
[0026] The feature differences are small, and only experts in the corresponding field can distinguish different species, resulting in a lack of image annotation data for this task and making it difficult to train a fine-grained species recognition model with high recognition accuracy.
[0027] In order to solve the above problems, the present invention provides a method, device and electronic device for training an image classification model.
[0028] Figure 1It is a schematic diagram according to the first embodiment of the present disclosure. It should be noted that the training method of the image classification model of the embodiment of the present disclosure can be applied to a training device for an image classification model, and the device can be configured in an electronic device so that the electronic device can perform the training function of the image classification model. In the following embodiments, the execution subject is an electronic device as an example for explanation.
[0029] Among them, the electronic device can be any device with computing capabilities, such as a personal computer (PC), a mobile terminal, a server, etc. The mobile terminal can be, for example, a vehicle-mounted device, a mobile phone, a tablet computer, a personal digital assistant, a wearable device, and other hardware devices with various operating systems, touch screens and / or display screens.
[0030] like Figure 1 As shown, the training method of the image classification model may include the following steps:
[0031] Step 101, obtaining multiple training data sets, the training data sets include a support set and a query set; the support set includes support sample images and categories of support sample images; the query set includes query sample images and categories of query sample images.
[0032] In the embodiment of the present disclosure, in the support set, the number of supporting sample images may be multiple, and the number of categories may be multiple. For example, the support set may include N categories, and each category may have K supporting sample images.
[0033] In the embodiment of the present disclosure, in the query set, the number of query sample images may be multiple, and the number of categories may be one or more. For example, the query set may include one category, and there may be K query sample images under the category.
[0034] It should be noted that the category in the query set can be one of the categories in the support set; or the category in the query set can be different from the category in the support set. If the category in the query set is different from the category in the support set, the image pairs generated based on the support set and the query set will include more image pairs of two sample images of different categories, and fewer or no image pairs of two sample images of the same category, resulting in an imbalance in the number of the two image pairs, which may affect the accuracy of the trained image classification model.
[0035] Among them, if the category in the query set is one of the categories in the support set, the number of the two image pairs in the subsequent image pairs generated based on the support set and the query set may be relatively balanced, ensuring the accuracy of the trained image classification model.
[0036] In the disclosed embodiment, the query sample image under a certain category in the query set and the support sample image under the same category in the support set may be the same as or different from each other.
[0037] In the disclosed embodiment, the supported sample image category may be the species to which the target object in the supported sample image belongs; the queried sample image category may be the species to which the target object in the queried sample image belongs. Wherein, when the category is species, the image classification model can be used for fine-grained species identification, thereby avoiding the need for experts to perform species identification in the species identification task, reducing the labor cost in the species identification task, and improving the species identification accuracy in the species identification task.
[0038] Step 102: Obtain an initial image classification model.
[0039] In an embodiment of the present disclosure, the image classification model includes a feature extraction network, an attention mechanism network and a similarity calculation network connected in sequence; the feature extraction network and the attention mechanism network are used to extract supporting image features of a supporting sample image in a sample image pair, and to extract query image features of a query sample image in a sample image pair; the similarity calculation network is used to perform splicing processing and similarity calculation processing on the supporting image features and the query image features to obtain the predicted similarity between the supporting sample image and the query sample image in the sample image pair.
[0040] Among them, the feature extraction network and the attention mechanism network can be respectively the feature extraction network and the attention mechanism network in the visual model (i.e., the Vision Transformer model). Among them, the attention mechanism network can perform importance screening and feature extraction processing on the image features extracted by the feature extraction network to obtain the more important image features. In the task of species recognition, the feature extraction network combined with the attention mechanism network can extract the smaller differences between species in the image and improve the accuracy of the similarity calculated subsequently. Among them, the architecture of the Vision Transformer model is better in extracting smaller differences between species, which can further improve the accuracy of similarity calculation, and thus improve the accuracy of species recognition.
[0041] The similarity calculation network may be, for example, a 4-layer convolutional network. The similarity calculation network is specifically used to perform splicing processing on the support image features and the query image features to obtain spliced image features; and perform similarity calculation processing based on the spliced image features to obtain the predicted similarity between the support sample image and the query sample image in the sample image pair.
[0042] Step 103, for each training data set, determine multiple sample image pairs in the training data set, and the sample similarity between the support sample images and the query sample images in the sample image pairs according to the support sample images, the categories of the support sample images, the query sample images, and the categories of the query sample images in the training data set.
[0043] In the embodiment of the present disclosure, the process of the electronic device executing step 103 may, for example, be: for each training data set, a plurality of sample image pairs are generated according to the supporting sample images and the query sample images in the training data set; for each sample image pair, the sample similarity between the supporting sample image and the query sample image in the sample image pair is determined according to the category of the supporting sample image in the sample image pair and the category of the query sample image in the sample image pair.
[0044] Among them, for each training data set, the process of the electronic device generating multiple sample image pairs can be, for example, randomly selecting a support sample image from a support set in the training data set, and randomly selecting a query sample image from a query set in the training data set; pairing the selected support sample image and query sample image to obtain a sample image pair; repeating all the above steps in this section to obtain multiple sample image pairs in the training data set.
[0045] Among them, the process of the electronic device determining the sample similarity between the supporting sample image and the query sample image in the sample image pair can, for example, be to determine whether the category of the supporting sample image in the sample image pair is the same as the category of the query sample image; if the two categories are the same, the sample similarity is determined to be 1; if the two categories are different, the sample similarity is determined to be 0.
[0046] Among them, the supporting sample images and the query sample images in the training data set are paired to obtain sample image pairs; and the sample similarity is determined in combination with the categories of the two sample images in the sample image pair. The sample similarity of the two sample images can be automatically and accurately determined, which facilitates the subsequent training of the image classification model and reduces the training cost.
[0047] Step 104, for each training data set in turn, using the support sample image and the query sample image in the sample image pair in the training data set as the input of the image classification model, and using the sample similarity between the support sample image and the query sample image in the sample image pair as the output of the image classification model, train the image classification model to obtain a trained image classification model.
[0048] The training method of the image classification model of the embodiment of the present disclosure obtains multiple training data sets, the training data sets include a support set and a query set; the support set includes support sample images and categories of support sample images; the query set includes query sample images and categories of query sample images; an initial image classification model is obtained; for each training data set, multiple sample image pairs in the training data set and the sample similarity between the support sample images and the query sample images in the sample image pairs are determined according to the support sample images, categories of support sample images, query sample images and categories of query sample images in the training data set; for each training data set in turn, the image classification model is trained with the support sample images and query sample images in the sample image pairs in the training data set as inputs of the image classification model and the sample similarity between the support sample images and the query sample images in the sample image pairs as outputs of the image classification model to obtain a trained image classification model, so that a highly accurate image classification model can be trained based on fewer sample images and corresponding categories, and can be applicable to tasks where image annotation data is relatively scarce, such as fine-grained species recognition tasks, to improve the recognition accuracy under fine-grained species recognition tasks.
[0049] In order to accurately obtain multiple training data sets, facilitate the subsequent training of image classification models, and improve the accuracy of the trained image classification models, the number of categories in the training data sets and the number of sample images in each category can be controlled, thereby controlling the ratio of the two sample image pairs. Figure 2 As shown, Figure 2 is a schematic diagram according to a second embodiment of the present disclosure, Figure 2 The illustrated embodiment may include the following steps:
[0050] Step 201 : obtaining an original data set, wherein the original data set includes sample images greater than a preset number and categories of the sample images.
[0051] In the embodiments of the present disclosure, taking the species recognition task or the species fine-grained recognition task as an example, the category of the sample image in the original data set, that is, the species of the target object in the sample image, is, for example, birds, dogs, monkeys, etc. Taking birds as an example, birds can be further subdivided into swimming birds, wading birds, climbing birds, land birds, raptors, songbirds, etc.
[0052] Step 202: extract a first category from multiple categories in the original data set, and extract support sample images from sample images of the first category in the original data set to obtain a support set.
[0053] In the embodiment of the present disclosure, the number of first categories may be N, and the number of supporting sample images under the first category may be, for example, K. The number of N may be determined according to the actual number of categories and the number of training data sets, etc. The number of K may be determined according to the number of sample images under each category.
[0054] Step 203: extract a category from the first category as the second category, and extract a query sample image from the sample images of the second category in the original data set to obtain a query set corresponding to the support set.
[0055] In the embodiment of the present disclosure, a category is extracted from the first category as the second category, and query sample images are extracted from sample images of the second category in the original data set, which can ensure that sample images of the same category exist in the support set and the query set of a training data set, so that when sample image pairs are generated based on the support set and the query set, the number of the two sample image pairs is balanced; based on the two sample image pairs with balanced number, the image classification model is trained, which can ensure the accuracy of the trained image classification model when calculating the similarity of the two sample image pairs.
[0056] In addition, as an alternative to step 203, the process of the electronic device generating a query set corresponding to the support set can also be, for example, extracting a category from multiple categories of the original data set as the second category, and extracting query sample images from sample images of the second category in the original data set to obtain the query set corresponding to the support set.
[0057] In addition, as an alternative to step 203, the process of the electronic device generating a query set corresponding to the support set can also be, for example, extracting a category from the first category as the second category, and using the sample image of the second category in the support set as the query sample image to obtain the query set corresponding to the support set.
[0058] Step 204: Generate a training data set based on the support set and the query set corresponding to the support set.
[0059] Step 205: Obtain an initial image classification model.
[0060] Step 206, for each training data set, determine multiple sample image pairs in the training data set, and sample similarities between the support sample images and the query sample images in the sample image pairs based on the support sample images, the categories of the support sample images, the query sample images, and the categories of the query sample images in the training data set.
[0061] Step 207, for each training data set in turn, using the support sample image and the query sample image in the sample image pair in the training data set as the input of the image classification model, and using the sample similarity between the support sample image and the query sample image in the sample image pair as the output of the image classification model, the image classification model is trained to obtain a trained image classification model.
[0062] It should be noted that the details of steps 205 to 207 can be found in Figure 1 Steps 102 to 104 in the illustrated embodiment will not be described in detail herein.
[0063] The training method of the image classification model of the embodiment of the present disclosure is by obtaining an original data set, wherein the original data set includes sample images greater than a preset number and categories of the sample images; extracting a first category from multiple categories of the original data set, and extracting support sample images from sample images of the first category in the original data set to obtain a support set; extracting a category from the first category as a second category, and extracting query sample images from sample images of the second category in the original data set to obtain a query set corresponding to the support set; generating a training data set based on the support set and the query set corresponding to the support set; obtaining an initial image classification model; for each training data set, based on the support sample images, categories of the support sample images, query sample images, and query images in the training data set, The category of the sample image is determined, and multiple sample image pairs in the training data set are determined, as well as the sample similarity between the support sample image and the query sample image in the sample image pair; for each training data set in turn, the support sample image and the query sample image in the sample image pair in the training data set are used as the input of the image classification model, and the sample similarity between the support sample image and the query sample image in the sample image pair is used as the output of the image classification model, and the image classification model is trained to obtain a trained image classification model, so that a higher accuracy image classification model can be trained based on fewer sample images and corresponding categories, which can be applicable to tasks where image annotation data is relatively scarce, such as fine-grained species recognition tasks, etc., to improve the recognition accuracy under fine-grained species recognition tasks.
[0064] In order to accurately train the image classification model according to multiple training data sets and further improve the accuracy of the trained image classification model, a loss function can be constructed for each training data set in turn to train the image classification model. Figure 3 As shown, Figure 3 is a schematic diagram according to a third embodiment of the present disclosure, Figure 3 The illustrated embodiment may include the following steps:
[0065] Step 301 , obtaining multiple training data sets, the training data sets include a support set and a query set; the support set includes support sample images and categories of support sample images; the query set includes query sample images and categories of query sample images.
[0066] Step 302: Obtain an initial image classification model.
[0067] Step 303, for each training data set, determine multiple sample image pairs in the training data set, and the sample similarity between the support sample images and the query sample images in the sample image pairs according to the support sample images, the categories of the support sample images, the query sample images, and the categories of the query sample images in the training data set.
[0068] Step 304 , for each training data set in turn, input the support sample image and the query sample image in the sample image pair in the training data set into the image classification model to obtain the predicted similarity between the support sample image and the query sample image in the sample image pair.
[0069] In the embodiment of the present disclosure, the process of the electronic device executing step 304 may, for example, be to input the supporting sample image and the query sample image in the sample image pair in the training data set into the feature extraction network and the attention mechanism network of the image classification model to obtain the supporting image features of the supporting sample image and the query image features of the query sample image; input the supporting image features and the query image features into the similarity calculation network of the image classification model to obtain the predicted similarity output by the similarity calculation network.
[0070] Step 305 : constructing a loss function according to the predicted similarity and the sample similarity between the supporting sample image and the query sample image in the sample image pair.
[0071] In the disclosed embodiment, the loss function can be constructed based on the predicted similarity and sample similarity of sample image pairs in a training data set. For example, the loss function can be the sum of squared differences of the predicted similarity and sample similarity of sample image pairs in a training data set.
[0072] Step 306, adjusting parameters of the image classification model according to the value of the loss function to implement training.
[0073] In the embodiment of the present disclosure, taking the number of training data sets as 5 as an example, for the first training data set, a loss function is constructed based on the predicted similarity and sample similarity of the sample image pairs in the training data set; according to the value of the loss function, the parameters of the image classification model are adjusted; for the second to fifth training data sets, the execution steps of the first training data set are respectively referred to; after the fifth training data set completes the above steps, a trained image classification model is obtained.
[0074] Among them, adjusting the parameters of the image classification model according to the predicted similarity and sample similarity of sample image pairs in multiple training data sets can enable the image classification model to learn smaller differences between different categories, so as to complete the classification task of new categories that have not been encountered before.
[0075] The training method of the image classification model of the embodiment of the present disclosure obtains multiple training data sets, the training data sets include a support set and a query set; the support set includes support sample images and categories of support sample images; the query set includes query sample images and categories of query sample images; an initial image classification model is obtained; for each training data set, according to the support sample images, categories of support sample images, query sample images and categories of query sample images in the training data set, multiple sample image pairs in the training data set and sample similarities between the support sample images and the query sample images in the sample image pairs are determined; for each training data set, the training data are sequentially classified into the training data set, the training data set is ... sample images are classified into the The supporting sample image and the query sample image in the concentrated sample image pair are input into the image classification model to obtain the predicted similarity between the supporting sample image and the query sample image in the sample image pair; a loss function is constructed according to the predicted similarity and the sample similarity between the supporting sample image and the query sample image in the sample image pair; and according to the value of the loss function, the parameters of the image classification model are adjusted to implement training, so that a highly accurate image classification model can be trained based on fewer sample images and corresponding categories, which can be applicable to tasks where image annotation data is relatively scarce, such as fine-grained species recognition tasks, etc., to improve the recognition accuracy under fine-grained species recognition tasks.
[0076] Figure 4 1 is a schematic diagram according to the fourth embodiment of the present disclosure. It should be noted that the image classification method of the embodiment of the present disclosure can be applied to an image classification device, which can be configured in an electronic device so that the electronic device can perform an image classification function. The following embodiments are described by taking the execution subject as an electronic device as an example.
[0077] Among them, the electronic device can be any device with computing capabilities, such as a personal computer (PC), a mobile terminal, a server, etc. The mobile terminal can be, for example, a vehicle-mounted device, a mobile phone, a tablet computer, a personal digital assistant, a wearable device, and other hardware devices with various operating systems, touch screens and / or display screens.
[0078] like Figure 4 As shown, the image classification method may include the following steps:
[0079] Step 401: Obtain an image to be processed and a support set, where the support set includes a plurality of support sample images and categories of support sample images.
[0080] In the embodiment of the present disclosure, in the support set, the number of supporting sample images may be multiple, and the number of categories may be multiple. For example, the support set may include N categories, and each category may have K supporting sample images.
[0081] In the embodiment of the present disclosure, the number of support sets may be multiple. The process of the electronic device obtaining the support set may be, for example, extracting a first category from multiple categories of the original data set, and extracting support sample images from sample images of the first category in the original data set to obtain a support set. The categories in the multiple support sets may be the same or different.
[0082] In the embodiment of the present disclosure, the supported sample image category is the species to which the target object in the supported sample image belongs; the queried sample image category is the species to which the target object in the queried sample image belongs. Wherein, when the category is species, the image classification model can be used for fine-grained species identification, thereby avoiding the need for experts to perform species identification in the species identification task, reducing the labor cost in the species identification task, and improving the species identification accuracy in the species identification task.
[0083] Step 402: Generate a plurality of image pairs according to the image to be processed and a plurality of supporting sample images; the image pairs include the image to be processed and the supporting sample images.
[0084] In the embodiment of the present disclosure, the process of the electronic device executing step 402 may be, for example, pairing each supporting sample image among the multiple supporting sample images with the image to be processed to obtain an image pair.
[0085] Step 403, input the image pair to be processed into the feature extraction network and the attention mechanism network of the image classification model, obtain the image features of the image to be processed in the image pair, and the supporting image features of the supporting sample images in the image pair; the image classification model is trained based on the training method of the image classification model.
[0086] In an embodiment of the present disclosure, the image classification model includes a feature extraction network, an attention mechanism network and a similarity calculation network connected in sequence; the feature extraction network and the attention mechanism network are used to extract supporting image features of a supporting sample image in an image pair, and to extract image features of an image to be processed in the image pair; the similarity calculation network is used to perform splicing processing and similarity calculation processing on the supporting image features and image features, and obtain the similarity between the supporting sample image in the image pair and the image to be processed.
[0087] Among them, the image classification model is based on Figures 1 to 3 The image classification model is obtained by training using the training method of any one of the embodiments.
[0088] It should be noted that the number of sample images supported in the embodiment of the present disclosure is Figures 1 to 3 In the embodiment, the ratio between the number of sample images in the plurality of training data sets may be a fixed value or close to a fixed value, wherein the fixed value may be, for example, 3:7, so as to ensure the accuracy of the image classification model and the accuracy of the classification of the processed images at the same time.
[0089] Step 404 , input the image features of the image to be processed in the image pair and the supporting image features of the supporting sample images in the image pair into the similarity calculation network in the image classification model to obtain the similarity between the image to be processed and the supporting sample images.
[0090] Step 405 : determining the category of the image to be processed according to the similarity between the image to be processed and the supporting sample images, and the category of the supporting sample images.
[0091] In an embodiment of the present disclosure, in one example, the process of the electronic device executing step 405 may be, for example, selecting a target sample image from multiple supporting sample images based on the similarity between the image to be processed and the supporting sample images; and determining the category of the target sample image as the category of the image to be processed.
[0092] The process of the electronic device selecting a target sample image from a plurality of supporting sample images may be, for example, to sort the plurality of supporting sample images in descending order according to similarity to obtain a sorting result; and to use the supporting sample image ranked first in the sorting result as the target sample image.
[0093] Among them, the supporting sample image with the greatest similarity to the image to be processed has the greatest possibility that its category is the same as the category of the image to be processed. Therefore, the electronic device uses the corresponding supporting sample image with the greatest similarity as the target sample image, which can further improve the accuracy of determining the category of the image to be processed and further improve the accuracy of image classification.
[0094] In another example, the process of the electronic device executing step 405 may be, for example, adding and averaging the similarities between each supporting sample image and the image to be processed under each category of supporting sample images to obtain the similarity of the category, and then obtaining the similarities of each category; the category with the largest corresponding similarity is determined as the category of the image to be processed.
[0095] The image classification method of the embodiment of the present disclosure obtains an image to be processed and a support set, wherein the support set includes multiple support sample images and categories of the support sample images; generates multiple image pairs according to the image to be processed and the multiple support sample images; the image pair includes the image to be processed and the support sample image; the image pair to be processed is input into a feature extraction network and an attention mechanism network of an image classification model to obtain image features of the image to be processed in the image pair and support image features of the support sample images in the image pair; the image classification model is trained based on a training method of the image classification model; the image features of the image to be processed in the image pair and the support image features of the support sample images in the image pair are input into a similarity calculation network in the image classification model to obtain the similarity between the image to be processed and the support sample images; the category of the image to be processed is determined according to the similarity between the image to be processed and the support sample images, as well as the category of the support sample images, so that the image classification model trained based on fewer sample images can be used to accurately determine the category of the image to be processed, thereby ensuring the accuracy of image classification while reducing labor costs.
[0096] In order to implement the above embodiment, the present disclosure also provides a training device for an image classification model. Figure 5 As shown, Figure 5 5 is a schematic diagram according to the fifth embodiment of the present disclosure. The training device 50 of the image classification model may include: a first acquisition module 501 , a second acquisition module 502 , a determination module 503 and a training module 504 .
[0097] Among them, the first acquisition module 501 is used to acquire multiple training data sets, and the training data sets include a support set and a query set; the support set includes support sample images and categories of the support sample images; the query set includes query sample images and categories of the query sample images; the second acquisition module 502 is used to acquire an initial image classification model; the determination module 503 is used to determine, for each training data set, multiple sample image pairs in the training data set, and the sample similarity between the support sample images and the query sample images in the sample image pairs according to the support sample images, categories of the support sample images, the query sample images, and categories of the query sample images in the training data set; the training module 504 is used to train the image classification model in turn for each training data set, using the support sample images and the query sample images in the sample image pairs in the training data set as inputs of the image classification model, and using the sample similarity between the support sample images and the query sample images in the sample image pairs as outputs of the image classification model to obtain a trained image classification model.
[0098] As a possible implementation method of the embodiment of the present disclosure, the first acquisition module 501 is specifically used to acquire an original data set, wherein the original data set includes sample images greater than a preset number, and categories of the sample images; extract a first category from multiple categories of the original data set, and extract support sample images from sample images of the first category in the original data set to obtain a support set; extract a category from the first category as a second category, and extract query sample images from sample images of the second category in the original data set to obtain a query set corresponding to the support set; generate a training data set based on the support set and the query set corresponding to the support set.
[0099] As a possible implementation method of an embodiment of the present disclosure, the determination module 503 is specifically used to, for each training data set, generate a plurality of sample image pairs based on the support sample images and the query sample images in the training data set; for each sample image pair, determine the sample similarity between the support sample image and the query sample image in the sample image pair based on the category of the support sample image in the sample image pair and the category of the query sample image in the sample image pair.
[0100] As a possible implementation method of an embodiment of the present disclosure, the image classification model includes a feature extraction network, an attention mechanism network and a similarity calculation network connected in sequence; the feature extraction network and the attention mechanism network are used to extract supporting image features of a supporting sample image in a sample image pair, and to extract query image features of a query sample image in the sample image pair; the similarity calculation network is used to perform splicing processing and similarity calculation processing on the supporting image features and the query image features to obtain the predicted similarity between the supporting sample image and the query sample image in the sample image pair.
[0101] As a possible implementation method of the embodiment of the present disclosure, the feature extraction network and the attention mechanism network are respectively the feature extraction network and the attention mechanism network in the vision Vision Transformer model.
[0102] As a possible implementation method of an embodiment of the present disclosure, the training module 504 is specifically used to, for each training data set in turn, input the supporting sample image and the query sample image in the sample image pair in the training data set into the image classification model to obtain the predicted similarity between the supporting sample image and the query sample image in the sample image pair; construct a loss function based on the predicted similarity and the sample similarity between the supporting sample image and the query sample image in the sample image pair; and adjust the parameters of the image classification model according to the value of the loss function to achieve training.
[0103] As a possible implementation manner of the embodiment of the present disclosure, the category of the supporting sample image is the species to which the target object in the supporting sample image belongs; the category of the query sample image is the species to which the target object in the query sample image belongs.
[0104] The training device of the image classification model of the embodiment of the present disclosure obtains multiple training data sets, the training data sets include a support set and a query set; the support set includes support sample images and categories of support sample images; the query set includes query sample images and categories of query sample images; obtains an initial image classification model; for each training data set, determines multiple sample image pairs in the training data set and the sample similarity between the support sample images and the query sample images in the sample image pairs according to the support sample images, categories of support sample images, query sample images and categories of query sample images in the training data set; for each training data set in turn, uses the support sample images and query sample images in the sample image pairs in the training data set as inputs of the image classification model, uses the sample similarity between the support sample images and the query sample images in the sample image pairs as outputs of the image classification model, trains the image classification model, and obtains a trained image classification model, thereby being able to train an image classification model with higher accuracy based on fewer sample images and corresponding categories, and being able to be applied to tasks where image annotation data is relatively scarce, such as fine-grained species recognition tasks, to improve the recognition accuracy under fine-grained species recognition tasks.
[0105] In order to implement the above embodiment, the present disclosure also provides an image classification device, such as Figure 6 As shown, Figure 6 6 is a schematic diagram according to the sixth embodiment of the present disclosure. The image classification device 60 may include: an acquisition module 601 , a generation module 602 , a first input module 603 , a second input module 604 and a determination module 605 .
[0106] Among them, the acquisition module 601 is used to acquire the image to be processed and the support set, and the support set includes multiple support sample images and the categories of the support sample images; the generation module 602 is used to generate multiple image pairs according to the image to be processed and the multiple support sample images; the image pair includes the image to be processed and the support sample images; the first input module 603 is used to input the image pair to be processed into the feature extraction network and the attention mechanism network of the image classification model to obtain the image features of the image to be processed in the image pair and the support image features of the support sample images in the image pair; the image classification model is trained based on the training method of the image classification model; the second input module 604 is used to input the image features of the image to be processed in the image pair and the support image features of the support sample images in the image pair into the similarity calculation network in the image classification model to obtain the similarity between the image to be processed and the support sample images; the determination module 605 is used to determine the category of the image to be processed according to the similarity between the image to be processed and the support sample images, and the category of the support sample images.
[0107] As a possible implementation method of the embodiment of the present disclosure, the determination module 605 is specifically used to select a target sample image from multiple supporting sample images according to the similarity between the image to be processed and the supporting sample images; and determine the category of the target sample image as the category of the image to be processed.
[0108] As a possible implementation manner of the embodiment of the present disclosure, the category of the supporting sample image is the species to which the target object in the supporting sample image belongs; the category of the image to be processed is the species to which the target object in the image to be processed belongs.
[0109] The image classification device of the embodiment of the present disclosure obtains an image to be processed and a support set, wherein the support set includes multiple support sample images and categories of the support sample images; generates multiple image pairs according to the image to be processed and the multiple support sample images; the image pair includes the image to be processed and the support sample image; the image pair to be processed is input into a feature extraction network and an attention mechanism network of an image classification model to obtain image features of the image to be processed in the image pair and support image features of the support sample images in the image pair; the image classification model is trained based on a training method of the image classification model; the image features of the image to be processed in the image pair and the support image features of the support sample images in the image pair are input into a similarity calculation network in the image classification model to obtain the similarity between the image to be processed and the support sample images; the category of the image to be processed is determined according to the similarity between the image to be processed and the support sample images, as well as the category of the support sample images, so that the category of the image to be processed can be accurately determined by using an image classification model trained based on fewer sample images, thereby ensuring the accuracy of image classification while reducing labor costs.
[0110] In the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information are all carried out with the user's consent, comply with the relevant laws and regulations, and do not violate public order and good morals.
[0111] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0112] Figure 7 A schematic block diagram of an example electronic device 700 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0113] like Figure 7As shown, the device 700 includes a computing unit 701, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 702 or a computer program loaded from a storage unit 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the device 700 can also be stored. The computing unit 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0114] A number of components in the device 700 are connected to the I / O interface 705, including: an input unit 706, such as a keyboard, a mouse, etc.; an output unit 707, such as various types of displays, speakers, etc.; a storage unit 708, such as a disk, an optical disk, etc.; and a communication unit 709, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 709 allows the device 700 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0115] The computing unit 701 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 701 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 701 performs the various methods and processes described above, such as the training method of the image classification model or the image classification method. For example, in some embodiments, the training method of the image classification model or the image classification method may be implemented as a computer software program, which is tangibly included in a machine-readable medium, such as a storage unit 708. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 700 via the ROM 702 and / or the communication unit 709. When the computer program is loaded into the RAM 703 and executed by the computing unit 701, one or more steps of the training method of the image classification model or the image classification method described above may be performed. Alternatively, in other embodiments, the computing unit 701 may be configured to execute the image classification model training method or the image classification method in any other appropriate manner (for example, by means of firmware).
[0116] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0117] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0118] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0119] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0120] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0121] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.
[0122] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0123] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A method for training an image classification model for fine-grained species identification, include: Acquire multiple training data sets, wherein the training data sets include a support set and a query set; the support set includes a support sample image and the species to which the target object in the support sample image belongs; The query set includes a query sample image and a species to which a target object in the query sample image belongs; wherein the species in the query set is one of the species in the support set; Get the initial image classification model; For each training data set, generating a plurality of sample image pairs according to the support sample images and the query sample images in the training data set; For each sample image pair, according to the species to which the target object in the supporting sample image in the sample image pair belongs and the species to which the target object in the query sample image in the sample image pair belongs, determine the sample similarity between the supporting sample image and the query sample image in the sample image pair, wherein if the species to which the target object in the supporting sample image belongs is the same as the species to which the target object in the query sample image belongs, then the sample similarity is determined to be 1, otherwise, then the sample similarity is determined to be 0; For each training data set in turn, inputting the support sample image and the query sample image in the sample image pair in the training data set into the image classification model to obtain the predicted similarity between the support sample image and the query sample image in the sample image pair; constructing a loss function according to the predicted similarity and the sample similarity between the support sample image and the query sample image in the sample image pair; According to the value of the loss function, the parameters of the image classification model are adjusted to achieve training; The image classification model includes a feature extraction network, an attention mechanism network and a similarity calculation network connected in sequence; the feature extraction network and the attention mechanism network are respectively the feature extraction network and the attention mechanism network in the Vision Transformer model; The feature extraction network and the attention mechanism network are used to extract supporting image features of a supporting sample image in a sample image pair, and to extract query image features of a query sample image in the sample image pair; The similarity calculation network is used to perform splicing processing and similarity calculation processing on the supporting image features and the query image features to obtain the predicted similarity between the supporting sample image and the query sample image in the sample image pair.
2. The method according to claim 1, in, The obtaining of multiple training data sets includes: Acquire an original data set, wherein the original data set includes sample images greater than a preset number and categories of the sample images; Extracting a first category from multiple categories of the original data set, and extracting support sample images from sample images of the first category in the original data set to obtain a support set; Extracting a category from the first category as the second category, and extracting a query sample image from sample images of the second category in the original data set to obtain a query set corresponding to the support set; A training data set is generated according to the support set and the query set corresponding to the support set.
3. An image classification method, include: Acquire an image to be processed and a support set, wherein the support set includes a plurality of support sample images and categories of the support sample images; Generate a plurality of image pairs according to the image to be processed and the plurality of the supporting sample images; the image pairs include the image to be processed and the supporting sample images; Input the image pair to be processed into a feature extraction network and an attention mechanism network of an image classification model to obtain image features of the image to be processed in the image pair and supporting image features of supporting sample images in the image pair; The image classification model is trained based on the method described in any one of claims 1-2; Inputting the image features of the image to be processed in the image pair and the supporting image features of the supporting sample image in the image pair into the similarity calculation network in the image classification model to obtain the similarity between the image to be processed and the supporting sample image; The category of the image to be processed is determined according to the similarity between the image to be processed and the supporting sample image, and the category of the supporting sample image.
4. The method according to claim 3, in, The step of determining the category of the image to be processed according to the similarity between the image to be processed and the supporting sample image, and the category of the supporting sample image, comprises: Selecting a target sample image from a plurality of the supporting sample images according to the similarity between the image to be processed and the supporting sample images; The category of the target sample image is determined as the category of the image to be processed.
5. The method according to claim 3 or 4, in, The category of the supporting sample image is the species to which the target object in the supporting sample image belongs; The category of the image to be processed is the species to which the target object in the image to be processed belongs.
6. A training device for an image classification model, the device being used for fine-grained species identification, include: A first acquisition module is used to acquire multiple training data sets, wherein the training data sets include a support set and a query set; the support set includes a support sample image and the species to which the target object in the support sample image belongs; the query set includes a query sample image and the species to which the target object in the query sample image belongs; wherein the species in the query set is one of the species in the support set; A second acquisition module is used to acquire an initial image classification model; A determination module, used for generating a plurality of sample image pairs according to the support sample images and the query sample images in the training data set for each training data set; for each sample image pair, determining the sample similarity between the support sample image and the query sample image in the sample image pair according to the species to which the target object in the support sample image in the sample image pair belongs and the species to which the target object in the query sample image in the sample image pair belongs, wherein if the species to which the target object in the support sample image belongs is the same as the species to which the target object in the query sample image belongs, then the sample similarity is determined to be 1, otherwise, then the sample similarity is determined to be 0; A training module is used to input the support sample image and the query sample image in the sample image pair in the training data set into the image classification model in turn for each training data set, and obtain the predicted similarity between the support sample image and the query sample image in the sample image pair; construct a loss function according to the predicted similarity and the sample similarity between the support sample image and the query sample image in the sample image pair; and adjust the parameters of the image classification model according to the value of the loss function to achieve training; The image classification model includes a feature extraction network, an attention mechanism network and a similarity calculation network connected in sequence; the feature extraction network and the attention mechanism network are respectively the feature extraction network and the attention mechanism network in the Vision Transformer model; The feature extraction network and the attention mechanism network are used to extract supporting image features of a supporting sample image in a sample image pair, and to extract query image features of a query sample image in the sample image pair; The similarity calculation network is used to perform splicing processing and similarity calculation processing on the supporting image features and the query image features to obtain the predicted similarity between the supporting sample image and the query sample image in the sample image pair.
7. The device according to claim 6, in, The first acquisition module is specifically used to: Acquire an original data set, wherein the original data set includes sample images greater than a preset number and categories of the sample images; Extracting a first category from multiple categories of the original data set, and extracting support sample images from sample images of the first category in the original data set to obtain a support set; Extracting a category from the first category as the second category, and extracting a query sample image from sample images of the second category in the original data set to obtain a query set corresponding to the support set; A training data set is generated according to the support set and the query set corresponding to the support set.
8. An image classification device, include: An acquisition module, used for acquiring an image to be processed and a support set, wherein the support set includes a plurality of support sample images and categories of the support sample images; A generating module, configured to generate a plurality of image pairs according to the image to be processed and the plurality of the supporting sample images; the image pairs include the image to be processed and the supporting sample images; A first input module is used to input the image pair to be processed into a feature extraction network and an attention mechanism network of an image classification model to obtain image features of the image to be processed in the image pair and supporting image features of supporting sample images in the image pair; The image classification model is trained based on the method described in any one of claims 1-2; A second input module is used to input the image features of the image to be processed in the image pair and the supporting image features of the supporting sample image in the image pair into the similarity calculation network in the image classification model to obtain the similarity between the image to be processed and the supporting sample image; The determination module is used to determine the category of the image to be processed according to the similarity between the image to be processed and the supporting sample image, and the category of the supporting sample image.
9. The device according to claim 8, in, The determination module is specifically used to: Selecting a target sample image from a plurality of the supporting sample images according to the similarity between the image to be processed and the supporting sample images; The category of the target sample image is determined as the category of the image to be processed.
10. The device according to claim 8 or 9, in, The category of the supporting sample image is the species to which the target object in the supporting sample image belongs; The category of the image to be processed is the species to which the target object in the image to be processed belongs.
11. An electronic device, include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can perform the method according to any one of claims 1 to 2; Alternatively, perform the method according to any one of claims 3 to 5.
12. A non-transitory computer-readable storage medium storing computer instructions, in, The computer instructions are used to enable the computer to execute the method according to any one of claims 1-2; or, to execute the method according to any one of claims 3-5.
