Image classification method, device, computer readable storage medium and electronic device

By performing block processing and adaptive feature extraction on images, the problem of high misjudgment rate in small sample image classification is solved and a more accurate classification effect is achieved.

CN114842236BActive Publication Date: 2024-09-10NORTHWESTERN POLYTECHNICAL UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210289446.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-22
Publication Date
2024-09-10
Estimated Expiration
2042-03-22

AI Technical Summary

Technical Problem

Existing small-sample image classification methods are easily affected by interference factors, resulting in misjudgments and poor classification effects. Especially when the number of samples is small, it is difficult for the model to learn class prototypes with good generalization performance.

Method used

By dividing the support set and query set images into blocks, the feature embedding network is used to extract target features, calculate adaptive feature vectors, and fit the class prototype based on iterative learning to reduce the influence of interference factors and improve the representation ability of the class prototype.

Benefits of technology

It effectively improves the accuracy of small sample image classification, reduces the misjudgment rate, and improves the classification effect, especially when the background is complex or the target structure changes greatly.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114842236B
    Figure CN114842236B
Patent Text Reader

Abstract

The present invention relates to an image classification method, device, computer-readable storage medium and electronic device. The method comprises: performing block processing on the support set image and the query set image respectively to obtain the support sample block image and the query sample block image; extracting the target features corresponding to the support sample block image and the target features corresponding to the query sample block image respectively based on the feature embedding network to obtain the feature vector corresponding to the support sample block image and the feature vector corresponding to the query sample block image; determining the adaptive feature vector corresponding to the support sample, and fitting the class prototype corresponding to the support sample based on the iterative learning method; classifying the query sample block image according to the feature vector corresponding to the query sample block image and the class prototype corresponding to the support sample. The present invention solves the technical problem that the small sample image classification method in the related art is easily affected by interference factors, and thus there is misjudgment and poor classification effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] In recent years, image classification tasks have achieved great results under the drive of big data under deep models. In some tasks, the classification accuracy of algorithms has exceeded that of humans. However, to achieve such excellent classification results, a large number of training samples are needed. In the fields of aerospace and medicine, it is undoubtedly difficult or almost impossible to obtain a large number of samples. Therefore, image classification methods based on small samples have become crucial. The goal of the small sample image classification task is to learn and fit a model with good generalization performance when the number of training set samples is small, so that the target classification task can be quickly completed when facing new targets.

[0003] In most existing metric-based small sample image classification methods, the K-shot support set sample representation usually uses the mean of the sample feature vector as the prototype representation of the category, and then performs distance measurement between the query set samples and the prototypes of each category in the support set to achieve sample classification. In fact, using the prototype obtained by the above method to perform classification tasks will make the samples more prone to misjudgment. For some images in the sample set that are occluded and the background area is larger than the target area, the calculated prototype will contain a lot of noise.

[0004] Therefore, for the K-shot task, it simply uses the mean of the support set embedding vector as the class prototype. On the one hand, it will lead to a large prototype representation deviation for some images with cluttered similar backgrounds and large changes in sample appearance and structure; on the other hand, it will cause the model to shift its focus from the most discriminative part of the target to other interference areas during the learning process.

[0005] The small sample image classification method in the above-mentioned related technologies is easily affected by interference factors, resulting in misjudgment and poor classification effect. No effective solution has been proposed yet. Summary of the invention

[0006] The embodiments of the present invention provide an image classification method, device, computer-readable storage medium and electronic device to at least solve the technical problem that the small sample image classification method in the related art is easily affected by interference factors, resulting in misjudgment and poor classification effect.

[0007] According to one aspect of an embodiment of the present invention, there is provided an image classification method, comprising: performing block processing on a support set image and a query set image respectively to obtain a support sample block image and a query sample block image; extracting target features corresponding to the support sample block image and target features corresponding to the query sample block image respectively based on a feature embedding network to obtain feature vectors corresponding to the support sample block image and feature vectors corresponding to the query sample block image, wherein the feature embedding network is used to extract features of a target image, and the target image comprises at least one of the following: the support sample block image and the query sample block image; determining an adaptive feature vector corresponding to the support sample according to the feature vector corresponding to the support sample block image and the feature vector corresponding to the query sample block image, and fitting a class prototype corresponding to the support sample based on an iterative learning method; and classifying the query sample block image according to the feature vector corresponding to the query sample block image and the class prototype corresponding to the support sample.

[0008] Optionally, the feature embedding network includes at least: a deep residual network and a global average pooling layer, wherein the deep residual network is used to extract initial features of the target image, and the global average pooling layer is used to perform global average pooling and position permutation operations on the initial features to obtain target features corresponding to the target image.

[0009] Optionally, the deep residual network includes four connected residual blocks, wherein each of the residual blocks includes three convolution blocks, each of the convolution blocks includes at least one convolution layer with a predetermined convolution kernel of X*X and a step size of Y, a normalization layer and an activation function, wherein X and Y are both positive integers.

[0010] Optionally, the adaptive feature vector corresponding to the support sample is determined according to the feature vector corresponding to the support sample block image and the feature vector corresponding to the query sample block image, including: performing distance measurement on the feature vector corresponding to the support sample block image and the feature vector corresponding to the query sample block image to obtain a distance matrix; determining a weight matrix between the support sample block image and the query sample block image; performing weighted processing on the distance matrix according to the weight matrix to obtain a correlation matrix; and obtaining the adaptive feature vector corresponding to the support sample according to the feature vector corresponding to the support sample block image and the correlation matrix.

[0011] Optionally, determining a weight matrix between the support sample block image and the query sample block image includes: determining a first matrix and a second matrix between the support sample block image and the query sample block image, wherein the first matrix is ​​obtained by calculating the dot product of the support sample block image and the query sample block image, and the second matrix is ​​obtained by calculating the dot product of the query sample block image and the support sample block image; determining a covariance matrix between the first matrix and the second matrix, wherein the trace of the covariance matrix is ​​used as the weight matrix.

[0012] Optionally, the class prototype corresponding to the supporting sample is expressed in the following manner: Among them, c s is the class prototype corresponding to the support sample, x i is the support sample, f() is the function mapping of the feature embedding network; R θ () is the mapping function of the class prototype learning module, θ is the learning parameter in the class prototype learning module, and K is the number of support samples in each category.

[0013] Optionally, the query sample block image is classified according to the feature vector corresponding to the query sample block image and the class prototype corresponding to the support sample, including: performing distance measurement on the feature vector corresponding to the query sample block image and the class prototype corresponding to the support sample to obtain a cosine distance; and determining the image category to which the query sample block image belongs according to the cosine distance.

[0014] According to another aspect of an embodiment of the present invention, an image classification device is also provided, comprising: a block processing module, used to perform block processing on a support set image and a query set image respectively, to obtain a support sample block image and a query sample block image; an extraction module, used to extract target features corresponding to the support sample block image and target features corresponding to the query sample block image respectively based on a feature embedding network, to obtain feature vectors corresponding to the support sample block image and feature vectors corresponding to the query sample block image, wherein the feature embedding network is used to extract features of a target image, and the target image comprises at least one of the following: the support sample block image and the query sample block image; a determination module, used to determine an adaptive feature vector corresponding to the support sample according to the feature vector corresponding to the support sample block image and the feature vector corresponding to the query sample block image, and to fit a class prototype corresponding to the support sample based on an iterative learning method; and a classification module, used to classify the query sample block image according to the feature vector corresponding to the query sample block image and the class prototype corresponding to the support sample.

[0015] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is further provided, wherein the computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute any one of the above-mentioned image classification methods.

[0016] According to another aspect of an embodiment of the present invention, an electronic device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to execute any one of the above-mentioned image classification methods through the computer program.

[0017] In an embodiment of the present invention, a support set image and a query set image are respectively subjected to block processing to obtain a support sample block image and a query sample block image; based on a feature embedding network, target features corresponding to the support sample block image and target features corresponding to the query sample block image are respectively extracted to obtain feature vectors corresponding to the support sample block image and feature vectors corresponding to the query sample block image, wherein the feature embedding network is used to extract features of the target image, and the target image includes at least one of the following: a support sample block image and a query sample block image; based on the feature vectors corresponding to the support sample block image and the feature vectors corresponding to the query sample block image, an adaptive feature vector corresponding to the support sample is determined, and a class prototype corresponding to the support sample is fitted based on an iterative learning method; based on the feature vectors corresponding to the query sample block image and the class prototype corresponding to the support sample, the query sample block image is classified, and the feature embedding network is used to respectively classify the query sample block image and the support sample block image. The target features corresponding to the support sample block image and the target features corresponding to the query sample block image are extracted to obtain the feature vectors corresponding to the support sample block image and the feature vectors corresponding to the query sample block image. Then, according to the feature vectors corresponding to the support sample block image and the feature vectors corresponding to the query sample block image, the adaptive feature vectors corresponding to the support sample are determined, and the class prototypes corresponding to the support sample are fitted based on an iterative learning method. Then, according to the feature vectors corresponding to the query sample block image and the class prototypes corresponding to the support sample, the query sample block image is classified, thereby achieving the purpose of reducing the influence of interference factors and obtaining prototypes with category relevance, thereby achieving the technical effect of effectively improving the representation ability of the class prototype for the sample and improving the accuracy of the classification of small sample images, thereby solving the technical problem that the classification method of small sample images in the related technology is easily affected by interference factors, resulting in misjudgment and poor classification effect. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] The drawings are only for the purpose of illustrating particular embodiments and are not to be considered limiting of the present invention. Like reference symbols denote like components throughout the drawings.

[0019] Figure 1is a flowchart of an image classification method according to an embodiment of the present invention;

[0020] Figure 2 is a flow chart of an image classification method according to an optional embodiment of the present invention;

[0021] Figure 3 is a data flow diagram of a feature embedding network according to an optional embodiment of the present invention;

[0022] Figure 4 is a schematic diagram of an adaptive prototype learning module according to an optional embodiment of the present invention;

[0023] Figure 5 is a schematic diagram of an image classification device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0024] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0025] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0026] Example 1

[0027] In order to solve the technical problem in the related art that the small sample image classification method is easily affected by interference factors, resulting in misjudgment and poor classification effect, according to an embodiment of the present invention, an embodiment of an image classification method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that here.

[0028] Figure 1 is a flowchart of an image classification method according to an embodiment of the present invention. Figure 1 As shown, the method comprises the following steps:

[0029] Step S102, performing block processing on the support set image and the query set image respectively to obtain a support sample block image and a query sample block image;

[0030] The above-mentioned supporting sample block images and query sample block images may also be referred to as supporting samples and query samples.

[0031] In an optional implementation, considering that embedding the entire image to represent the sample may make it difficult to obtain more representative feature vectors for some samples with complex backgrounds and missing complete target structures, the entire image is divided into blocks and randomly cropped. The above-mentioned entire image can be any image in the support set image or the query set image. In the specific implementation process, the support set image and the query set image can be divided into blocks and randomly cropped respectively, so as to obtain the support sample block image and the query sample block image.

[0032] Step S104, based on the feature embedding network, respectively extracting the target features corresponding to the support sample block image and the target features corresponding to the query sample block image, and obtaining the feature vector corresponding to the support sample block image and the feature vector corresponding to the query sample block image, wherein the feature embedding network is used to extract the features of the target image, and the target image includes at least one of the following: the support sample block image and the query sample block image;

[0033] In an optional implementation, the support sample block image and the query sample block image can all be input into the feature embedding network, and the feature embedding network extracts the target features of the target image, thereby obtaining the feature vector corresponding to the support sample block image and the feature vector corresponding to the query sample block image.

[0034] Step S106, determining the adaptive feature vector corresponding to the support sample according to the feature vector corresponding to the support sample block image and the feature vector corresponding to the query sample block image, and fitting the class prototype corresponding to the support sample based on an iterative learning method;

[0035] The class prototype corresponding to the above support samples can be expressed in the following way: Among them, c s To support the class prototype corresponding to the sample, x i is the support sample, f() is the function mapping of the feature embedding network; R θ () is the mapping function of the class prototype learning module, θ is the learning parameter in the class prototype learning module, that is, the prototype matrix, which is obtained through iterative learning, and K is the number of supporting samples in each category.

[0036] In an optional embodiment, an adaptive prototype learning network is used to obtain class prototypes corresponding to supporting samples, wherein the adaptive prototype learning network includes a tile mining module and a prototype learning module, the tile mining module is mainly used to obtain category-related adaptive tiles, and the prototype learning module is mainly used to use the enhanced tile feature representation of the former to learn class prototypes.

[0037] It should be noted that image segmentation can only enhance the model's discrimination of intra-class targets, while the discrimination of inter-class target images will increase the model's misjudgment due to the similar redundant background of target images of different classes. Therefore, developing a class correlation matrix for application in the image block mining module can effectively solve the above problem.

[0038] In an optional implementation, a block mining module is used to perform feature vector enhancement, and adaptive weights are given to different target images. The feature vectors corresponding to the weighted target images are used to fit the class prototypes corresponding to the supporting samples through iterative learning.

[0039] Step S108, classifying the query sample block image according to the feature vector corresponding to the query sample block image and the class prototype corresponding to the support sample.

[0040] In a specific implementation process, the category to which the query sample belongs can be determined by calculating the cosine distance between the feature vector corresponding to the query sample block image and the class prototype corresponding to each class of the support sample block image.

[0041] Through the above steps, the target features corresponding to the support sample block image and the target features corresponding to the query sample block image can be extracted respectively through the feature embedding network to obtain the feature vectors corresponding to the support sample block image and the feature vectors corresponding to the query sample block image. Then, according to the feature vectors corresponding to the support sample block image and the feature vectors corresponding to the query sample block image, the adaptive feature vector corresponding to the support sample is determined, and the class prototype corresponding to the support sample is fitted based on the iterative learning method. Then, according to the feature vectors corresponding to the query sample block image and the class prototype corresponding to the support sample, the query sample block image is classified, and the purpose of reducing the influence of interference factors and obtaining a prototype with category relevance is achieved, thereby achieving the technical effect of effectively improving the representation ability of the class prototype for the sample and improving the accuracy of the classification of small sample images, thereby solving the technical problem that the classification method of small sample images in the related technology is easily affected by interference factors, and thus there is misjudgment and poor classification effect.

[0042] It should be noted that the above image classification method can be applied to small sample image classification and can effectively improve the small sample image classification effect.

[0043] Optionally, the feature embedding network includes at least: a deep residual network and a global average pooling layer, wherein the deep residual network is used to extract the initial features of the target image, and the global average pooling layer is used to perform average global pooling and position permutation operations on the initial features to obtain the target features corresponding to the target image.

[0044] In an optional embodiment, a deep residual network is used as the backbone network to extract the initial features of the target image, and finally a layer of global average pooling is added to obtain the target features corresponding to the target image. The average global pooling can effectively reduce parameters and prevent model overfitting.

[0045] Optionally, the deep residual network includes four connected residual blocks, wherein each residual block contains three convolution blocks, each convolution block includes at least one convolution layer with a predetermined convolution kernel of X*X and a step size of Y, a normalization layer and an activation function, wherein X and Y are both positive integers.

[0046] It should be noted that the above-mentioned deep residual network includes but is not limited to the Resnet12 network, which will not be described one by one here. In addition, the values ​​of the above-mentioned X and Y can be set according to the needs of the application scenario.

[0047] In an optional implementation, a Resnet12 network can be used to extract the initial features of the target image, wherein the Resnet12 network is connected by four residual blocks, each residual block contains three convolution blocks, each convolution block contains a convolution layer with a convolution kernel of 3×3 and a step size of 1, a batch normalization layer, and a LeakyReLU activation function. After the target image passes through the Resnet12 network, a global average pooling layer is added to act on the initial features extracted by Resnet12, thereby obtaining the target features corresponding to the target image.

[0048] Optionally, based on the feature vector corresponding to the support sample block image and the feature vector corresponding to the query sample block image, an adaptive feature vector corresponding to the support sample is determined, including: performing distance measurement on the feature vector corresponding to the support sample block image and the feature vector corresponding to the query sample block image to obtain a distance matrix; determining a weight matrix between the support sample block image and the query sample block image; performing weighted processing on the distance matrix according to the weight matrix to obtain a correlation matrix; and obtaining an adaptive feature vector corresponding to the support sample according to the feature vector corresponding to the support sample block image and the correlation matrix.

[0049] In an optional implementation, the obtained feature vector P corresponding to the support sample block image and the feature vector Q corresponding to the query sample block image are distance-measured to obtain a distance matrix S:

[0050]

[0051] Among them, <·,·> is the cosine distance calculation, transpose() is the matrix dimension transformation, and The vectors after performing the bi-norm normalization operation on the support set sample feature vector P and the query set sample feature vector Q respectively;

[0052] In an optional implementation, the similarity of sample pairs is measured by calculating the cosine distance between sample feature vectors. n} and vector y={y1,y2,...,y n}, the cosine distance between them is:

[0053] In an optional implementation, the distance matrix S is weighted by a weight matrix to obtain a correlation matrix, and the correlation matrix is ​​multiplied by a feature vector corresponding to the support sample block image to obtain an adaptive feature vector corresponding to the support sample.

[0054] In the above-mentioned embodiment of the present invention, adaptive weights are given to different target images by scoring the contribution of the target images between classes and within classes.

[0055] Optionally, determining a weight matrix between the support sample block image and the query sample block image includes: determining a first matrix and a second matrix between the support sample block image and the query sample block image, wherein the first matrix is ​​obtained by calculating the dot product of the support sample block image and the query sample block image, and the second matrix is ​​obtained by calculating the dot product of the query sample block image and the support sample block image; determining a covariance matrix between the first matrix and the second matrix, wherein the trace of the covariance matrix is ​​used as the weight matrix.

[0056] In an optional implementation, the dot product between the support set and the query sample is calculated to obtain a first matrix W1, and the dot product between the support set and the support set sample is calculated from the perspective of the query set to obtain a second matrix W2; then the covariance matrix C between W2 and W1 is calculated, and the trace I of the covariance matrix is ​​taken as the weight matrix.

[0057] Optionally, the query sample block image is classified according to the feature vector corresponding to the query sample block image and the class prototype corresponding to the support sample, including: performing distance measurement on the feature vector corresponding to the query sample block image and the class prototype corresponding to the support sample to obtain a cosine distance; and determining the image category to which the query sample block image belongs according to the cosine distance.

[0058] In an optional embodiment, the above method may further include: model training, wherein the model training is divided into pre-training and meta-training. In pre-training, the sample in the target image is used to train the feature embedding network; in meta-training, the optimal pre-training model on the validation set is selected, and the pre-training network parameters are optimized again using the episode training mechanism with the data in the training set. Furthermore, the test sample is tested using the trained model, and the query set sample is inferred to which category of the support set the query set sample should be classified according to the distance metric based on the support set.

[0059] In an optional implementation, the category to which the query sample belongs is determined by calculating the cosine distance between the feature vector corresponding to the query sample block image and the class prototype corresponding to the support sample:

[0060]

[0061] in, is the feature vector corresponding to the query sample block image, c s The class prototype corresponding to the supporting sample.

[0062] An optional implementation manner of the present invention is described in detail below.

[0063] Figure 2 is a flowchart of an image classification method according to an optional embodiment of the present invention. Figure 2 As shown, it is mainly divided into: image segmentation, feature embedding, adaptive prototype learning and distance measurement. The following takes a small sample image classification task as an example to further illustrate the specific implementation steps of the present invention.

[0064] (1) Image segmentation: In order to reduce the loss of important local information of the sample during the learning process of the model, the images in the support set and query set are evenly divided into two parts and randomly cropped, and then the expanded data input features are embedded into the network fitting features.

[0065] (2) Feature embedding: Resnet12 is used as the backbone network to extract sample features. The Resnet12 network is connected by four residual blocks, each of which contains three convolution blocks. Each convolution block contains a convolution layer with a convolution kernel of 3×3 and a stride of 1, a batch normalization layer, and a LeakyReLU activation function. After the sample set passes through Resnet12, a global average pooling layer is added to act on the features extracted by Resnet12 to reduce parameters and prevent model overfitting.

[0066] Figure 3 is a data flow diagram of a feature embedding network according to an optional embodiment of the present invention, such as Figure 3As shown. In the 5-way5-shot image classification task, assuming that the query set has 2 samples, the input RGB image size is 84×84, and the original image is divided into 2 equal parts and 9 pieces are randomly cropped. The input size of the feature embedding network is I∈35×13×3×84×84, where the calculation of the first dimension of the input size is: the support set has 5 categories, each category has 5 samples for a total of 25, the query set has 2 samples for each category, and 5 categories have a total of 10 samples, so a total of 35 samples; the calculation of the second dimension is: divide it into 4 blocks evenly by 2 equal parts, randomly crop it for a total of 9 blocks, and expand 1 original image into 13 parts in total. The output feature map size of Resnet12 is T∈455×640×5×5. After global average pooling and position permutation operations, the output feature map size of the final embedding network is O∈35×640×13×1.

[0067] (3) Adaptive prototype learning: Figure 4 is a schematic diagram of an adaptive prototype learning module according to an optional embodiment of the present invention, such as Figure 4 As shown, the adaptive prototype learning module mainly includes patch mining and prototype learning.

[0068] ① Block mining, the specific steps are as follows:

[0069] Regarding the N-way K-shot image classification task with a query set of L samples, first, the feature vector of the support sample block image is P∈NK×H×W×M, and the feature vector of the query sample block image is Q∈NL×H×W×M, where H and W represent the output feature map dimensions, and M represents the number of blocks divided by the sample. The distance matrix S∈NK×NL×M×M is obtained by performing distance measurement on the support set embedding vector and the query set embedding vector. The distance matrix calculation formula is:

[0070]

[0071] Among them, <·,·> is the cosine distance calculation, transpose() is the matrix dimension transformation, and are the vectors after performing the bi-norm normalization operation on the support sample feature vector P and the query sample feature vector Q respectively.

[0072] It should be noted that N represents the number of categories and K represents the number of samples in each category.

[0073] The specific process of obtaining the distance matrix S is as follows:

[0074] 1) Take the vector P from the spatial position i (1≤i≤HW) of the support sample block image i ∈NK×M;

[0075] 2) Take the vector Q from the spatial position j (1≤j≤HW) of the query sample block image j ∈NL×M;

[0076] 3) For the position vector P i and Q i Implement normalization:

[0077]

[0078] 4) Local position S i ∈NK×NL×M is defined as:

[0079] Next, from the perspective of the support set, calculate the dot product with each sample in the query set to obtain the matrix W1∈NL×NK×M; from the perspective of the query set, calculate the dot product with each sample in the support set to obtain the matrix W2∈NK×NL×M. Then calculate the covariance matrix C∈NK×NK×M between W2 and W1, and take the trace of the covariance matrix I∈NK×M as the weight matrix; the calculation of the covariance matrix C is as follows:

[0080] 1) Take vector W from the spatial position i (1≤i≤M) of matrix W2 2i ∈NK×NL;

[0081] 2) Take vector W from the spatial position i (1≤i≤M) of matrix W1 1i ∈NL×NK;

[0082] 3) Calculate w at the middle position i 2i and w 1i The covariance matrix C between i ∈NK×NK:

[0083]

[0084] Finally, the calculated weight matrix I is added to the weighted distance matrix S to obtain the correlation matrix A. The correlation matrix is ​​then multiplied by the support set samples to obtain the support set adaptive patch feature representation P′∈NK×H×W×M.

[0085] In the tile mining module, instead of simply learning the importance of different tiles in a parameterized manner, multiple components are combined to complete category-dependent correlation calculations without using any additional parameters.

[0086] That is, by scoring the contribution of tiles between classes and within classes, adaptive weights are given to different tiles. This enables the current task to have better recognition and discrimination capabilities for samples, thereby allowing the model to enhance its anti-interference ability in irrelevant areas of the samples.

[0087] ②Prototype learning, the specific steps are as follows:

[0088] Based on the mean of the feature vector corresponding to the supporting sample block image, a residual term is added, and the prototype is calculated in a learnable way using the residual:

[0089]

[0090] Among them, x i is the training sample, f() is the function mapping of the feature embedding network; R θ () is the mapping function of the prototype learning module, and θ represents the learning parameters in the prototype module, that is, the prototype matrix. It should be noted that the above training samples can be support sample block images or query sample block images.

[0091] The main operations of prototype learning are:

[0092] 1) Get all sample feature vectors extracted by the feature embedding module and calculate the mean c of all samples of the same type s ′∈N×H×W;

[0093] 2) Construct a learnable matrix with dimension N×H×W Requested class prototype

[0094] 3) Through loss back propagation, iterative learning matrix The number of iterations is 200.

[0095] (4) Metric classification: The category to which the query sample belongs is determined by calculating the cosine distance between the query set sample feature vector and the class prototype corresponding to each class in the support set:

[0096]

[0097] (5) Model training: It is divided into pre-training and meta-training. In pre-training, the feature embedding network is trained with samples from the entire training set. No image segmentation is performed in the pre-training stage. The initial learning rate is selected as 0.1 and the batch size is 128. Stochastic gradient descent (SGD) is used to optimize the network with the standard cross entropy loss minimum. The network is trained for 200 epochs. At the end of pre-training, the classifier layer of the network is deleted.

[0098] In meta-training, the best pre-trained model on the validation set is selected, and the episode training mechanism is used, that is, in each task, 5-way 1-shot or 5-way 5-shot is sampled in the training set as the support set, and 15 instances that are not repeated in the support set samples are extracted from each class as the query set. One task is input in each iteration, the initial learning rate is set to 0.001, and 2000 episodic tasks (episodes) are learned.

[0099] (6) Test verification: Sampling the support set in the test set and queryset According to the support set, the distance metric is used to infer which category of the support set the query set sample should be classified into.

[0100] It should be noted that, compared with the existing small sample image classification method based on metric learning, the technical solution of the present invention has at least the following beneficial effects:

[0101] (1) Using a block mining model that does not rely on parameters, by giving different weights to the feature representation of the block image, the network is guided to learn the characteristics of the target area and reduce the interference of complex and redundant background on the representation of the sample. Secondly, the prototype learning module can also be used to increase the distance between the sample descriptions of different classes in small sample tasks, while having a more concentrated effect on the prototype representation of the sample features within the class.

[0102] (2) The effectiveness of the algorithm was verified through experiments. On the small sample learning benchmark datasets mini-ImageNet and CUB, the classification accuracy of the image classification method exceeded that of other existing technical methods, especially compared with the prototype network, the model performance was significantly improved.

[0103] The following experiments are used to illustrate the technical effects of the present invention:

[0104] The experimental data sets of the present invention are the public small sample learning benchmark data sets mini-ImageNet and CUB. Table 1 shows the accuracy of small sample image classification technology on the mini-ImageNet data set. In the experiment, the present invention and the comparison method are both implemented in Python 3.7 language.

[0105] Table 1 Accuracy of small sample image classification techniques on the mini-ImageNet dataset (%)

[0106]

[0107] As can be seen from Table 1, the method of the present invention has higher classification performance than the existing model based on metric learning method. From the experimental results of 5-way 1-shot and 5-way 5-shot of small sample classification standard, the classification accuracy of this method exceeds 9.54% and 7.94% compared with the initial prototype learning model. This is mainly because the idea of ​​image segmentation and the prototype learnable method enhance the model's ability to represent samples in complex backgrounds. Compared with the DeepEMD method that also uses image segmentation, our model can still achieve an overwhelming advantage. The model accuracy in 5-way 1-shot and 5-way5-shot tasks is improved by 0.77% and 1.83% respectively, which further proves the effectiveness of the present invention.

[0108] Experimental results show that the method provided by the present invention can effectively improve the classification effect of small sample images.

[0109] Example 2

[0110] According to another aspect of the embodiment of the present invention, there is also provided an image classification device. Figure 5 is a schematic diagram of an image classification device according to an embodiment of the present invention. Figure 5 As shown, the image classification device includes: a block processing module 52, an extraction module 54, a determination module 56 and a classification module 58. The image classification device is described in detail below.

[0111] The block processing module 52 is used to perform block processing on the support set image and the query set image respectively to obtain the support sample block image and the query sample block image; the extraction module 54 is connected to the block processing module 52 and is used to extract the target features corresponding to the support sample block image and the target features corresponding to the query sample block image respectively based on the feature embedding network to obtain the feature vector corresponding to the support sample block image and the feature vector corresponding to the query sample block image, wherein the feature embedding network is used to extract the features of the target image, and the target image includes at least one of the following: the support sample block image and the query sample block image; the determination module 56 is connected to the extraction module 54 and is used to determine the adaptive feature vector corresponding to the support sample according to the feature vector corresponding to the support sample block image and the feature vector corresponding to the query sample block image, and fit the class prototype corresponding to the support sample based on the iterative learning method; the classification module 58 is connected to the determination module 56 and is used to classify the query sample block image according to the feature vector corresponding to the query sample block image and the class prototype corresponding to the support sample.

[0112] It should be noted that the above-mentioned modules can be implemented by software or hardware. For example, for the latter, it can be implemented in the following ways: the above-mentioned modules can be located in the same processor; and / or the above-mentioned modules are located in different processors in any combination.

[0113] In the above embodiment, the image classification device can respectively extract the target features corresponding to the support sample block image and the target features corresponding to the query sample block image through the feature embedding network, and obtain the feature vector corresponding to the support sample block image and the feature vector corresponding to the query sample block image, and then determine the adaptive feature vector corresponding to the support sample according to the feature vector corresponding to the support sample block image and the feature vector corresponding to the query sample block image, and fit the class prototype corresponding to the support sample based on the iterative learning method, and then classify the query sample block image according to the feature vector corresponding to the query sample block image and the class prototype corresponding to the support sample, thereby achieving the purpose of reducing the influence of interference factors and obtaining a prototype with category relevance, thereby achieving the technical effect of effectively improving the representation ability of the class prototype for the sample and improving the accuracy of the classification of small sample images, and thus solving the technical problem that the small sample image classification method in the related technology is easily affected by interference factors, and thus there is misjudgment and poor classification effect.

[0114] It should be noted here that the above-mentioned block processing module 52, extraction module 54, determination module 56 and classification module 58 correspond to steps S102 to S108 in Example 1, and the examples and application scenarios implemented by the above-mentioned modules are the same as those of the corresponding steps, but are not limited to the contents disclosed in the above-mentioned Example 1.

[0115] Optionally, the feature embedding network includes at least: a deep residual network and a global average pooling layer, wherein the deep residual network is used to extract the initial features of the target image, and the global average pooling layer is used to perform global average pooling and position permutation operations on the initial features to obtain the target features corresponding to the target image.

[0116] Optionally, the deep residual network includes four connected residual blocks, each residual block includes three convolution blocks, each convolution block includes at least one convolution layer with a predetermined convolution kernel of X*X and a step size of Y, a normalization layer and an activation function, wherein X and Y are both positive integers.

[0117] Optionally, the above-mentioned determination module 56 includes: a first processing unit, used to perform distance measurement on the feature vector corresponding to the support sample block image and the feature vector corresponding to the query sample block image to obtain a distance matrix; a determination unit, used to determine the weight matrix between the support sample block image and the query sample block image; a second processing unit, used to perform weighted processing on the distance matrix according to the weight matrix to obtain a correlation matrix; a third processing unit, used to obtain an adaptive feature vector corresponding to the support sample based on the feature vector corresponding to the support sample block image and the correlation matrix.

[0118] Optionally, the above-mentioned determination unit includes: a first determination subunit, used to determine a first matrix and a second matrix between the support sample block image and the query sample block image, wherein the first matrix is ​​obtained by calculating the dot product of the support sample block image and the query sample block image, and the second matrix is ​​obtained by calculating the dot product of the query sample block image and the support sample block image; a second determination subunit, used to determine the covariance matrix between the first matrix and the second matrix, wherein the trace of the covariance matrix is ​​used as a weight matrix.

[0119] Optionally, the class prototype corresponding to the supporting sample is expressed in the following way: Among them, c s To support the class prototype corresponding to the sample, x i is the support sample, f() is the function mapping of the feature embedding network; R θ () is the mapping function of the class prototype learning module, θ is the learning parameter in the class prototype learning module, and K is the number of supporting samples in each category.

[0120] Optionally, the classification module 58 includes: a fourth processing unit, used to perform distance measurement on the feature vector corresponding to the query sample block image and the class prototype corresponding to the support sample to obtain the cosine distance; and a classification unit, used to determine the image category to which the query sample block image belongs based on the cosine distance.

[0121] Example 3

[0122] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is further provided, the computer-readable storage medium including a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute any one of the above-mentioned image classification methods.

[0123] Optionally, in this embodiment, the computer-readable storage medium may be located in any one of the computer terminals in a computer terminal group in a computer network, and / or located in any one of the mobile terminals in a mobile terminal group, and the computer-readable storage medium includes a stored program.

[0124] Optionally, when the program is running, the device where the computer-readable storage medium is located is controlled to perform the following functions: block processing is performed on the support set image and the query set image respectively to obtain a support sample block image and a query sample block image; based on the feature embedding network, the target features corresponding to the support sample block image and the target features corresponding to the query sample block image are respectively extracted to obtain a feature vector corresponding to the support sample block image and a feature vector corresponding to the query sample block image, wherein the feature embedding network is used to extract features of the target image, and the target image includes at least one of the following: a support sample block image and a query sample block image; according to the feature vector corresponding to the support sample block image and the feature vector corresponding to the query sample block image, an adaptive feature vector corresponding to the support sample is determined, and a class prototype corresponding to the support sample is fitted based on an iterative learning method; according to the feature vector corresponding to the query sample block image and the class prototype corresponding to the support sample, the query sample block image is classified.

[0125] Example 4

[0126] According to another aspect of an embodiment of the present invention, an electronic device is provided. The electronic device includes a memory and a processor. The memory stores a computer program. The processor is configured to execute any one of the above-mentioned image classification methods through the computer program.

[0127] In addition, the present invention also provides a computer program product, which, when executed on a data processing device, is suitable for executing a program that is initialized with the following method steps: performing block processing on a support set image and a query set image respectively to obtain a support sample block image and a query sample block image; extracting target features corresponding to the support sample block image and target features corresponding to the query sample block image respectively based on a feature embedding network to obtain feature vectors corresponding to the support sample block image and feature vectors corresponding to the query sample block image, wherein the feature embedding network is used to extract features of the target image, and the target image includes at least one of the following: a support sample block image and a query sample block image; determining an adaptive feature vector corresponding to the support sample based on the feature vector corresponding to the support sample block image and the feature vector corresponding to the query sample block image, and fitting a class prototype corresponding to the support sample based on an iterative learning method; and classifying the query sample block image based on the feature vector corresponding to the query sample block image and the class prototype corresponding to the support sample.

[0128] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0129] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0130] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units can be a logical function division. There may be other division methods in actual implementation. For example, multiple units or components 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 units or modules, which can be electrical or other forms.

[0131] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0132] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0133] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program codes.

[0134] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. An image classification method, characterized in that: include: The support set image and the query set image are divided into blocks to obtain support sample block images and query sample block images; Based on the feature embedding network, the target features corresponding to the support sample block image and the target features corresponding to the query sample block image are respectively extracted to obtain the feature vector corresponding to the support sample block image and the feature vector corresponding to the query sample block image, wherein the feature embedding network is used to extract the features of the target image, and the target image includes at least one of the following: the support sample block image and the query sample block image; According to the feature vector corresponding to the support sample block image and the feature vector corresponding to the query sample block image, the adaptive feature vector corresponding to the support sample is determined, and the class prototype corresponding to the support sample is fitted based on an iterative learning method; including: Performing distance measurement on the feature vectors corresponding to the support sample block images and the feature vectors corresponding to the query sample block images to obtain a distance matrix; Determining a weight matrix between the support sample block image and the query sample block image; comprising: Determine a first matrix and a second matrix between the support sample block image and the query sample block image, wherein the first matrix is ​​obtained by calculating the dot product of the support sample block image and the query sample block image, and the second matrix is ​​obtained by calculating the dot product of the query sample block image and the support sample block image; determining a covariance matrix between the first matrix and the second matrix, wherein a trace of the covariance matrix is ​​used as the weight matrix; Performing weighted processing on the distance matrix according to the weight matrix to obtain a correlation matrix; Obtaining an adaptive feature vector corresponding to the support sample according to the feature vector corresponding to the support sample block image and the correlation matrix; The query sample block image is classified according to the feature vector corresponding to the query sample block image and the class prototype corresponding to the support sample.

2. The method according to claim 1, characterized in that: The feature embedding network includes at least: a deep residual network and a global average pooling layer, wherein the deep residual network is used to extract the initial features of the target image, and the global average pooling layer is used to perform global average pooling and position permutation operations on the initial features to obtain the target features corresponding to the target image.

3. The method according to claim 2, characterized in that The deep residual network includes four connected residual blocks, each of which includes three convolution blocks, each of which includes at least one convolution layer with a predetermined convolution kernel of X*X and a step size of Y, a normalization layer and an activation function, wherein X and Y are both positive integers.

4. The method according to claim 1, characterized in that: The class prototype corresponding to the supporting sample is expressed in the following way: Among them, c s is the class prototype corresponding to the support sample, x i is the support sample, f() is the function mapping of the feature embedding network; R θ () is the mapping function of the class prototype learning module, θ is the learning parameter in the class prototype learning module, and K is the number of support samples in each category.

5. The method according to any one of claims 1 to 4, characterized in that: Classifying the query sample block image according to the feature vector corresponding to the query sample block image and the class prototype corresponding to the support sample, including: Performing distance measurement on the feature vector corresponding to the query sample block image and the class prototype corresponding to the support sample to obtain a cosine distance; The image category to which the query sample block image belongs is determined according to the cosine distance.

6. An image classification device, characterized in that: include: A block processing module is used to perform block processing on the support set image and the query set image to obtain a support sample block image and a query sample block image; An extraction module is used to extract target features corresponding to the support sample block image and the query sample block image respectively based on a feature embedding network to obtain a feature vector corresponding to the support sample block image and a feature vector corresponding to the query sample block image, wherein the feature embedding network is used to extract features of a target image, and the target image includes at least one of the following: the support sample block image and the query sample block image; A determination module, used to determine the adaptive feature vector corresponding to the support sample according to the feature vector corresponding to the support sample block image and the feature vector corresponding to the query sample block image, and fit the class prototype corresponding to the support sample based on an iterative learning method; comprising: Performing distance measurement on the feature vectors corresponding to the support sample block images and the feature vectors corresponding to the query sample block images to obtain a distance matrix; Determining a weight matrix between the support sample block image and the query sample block image; comprising: Determine a first matrix and a second matrix between the support sample block image and the query sample block image, wherein the first matrix is ​​obtained by calculating the dot product of the support sample block image and the query sample block image, and the second matrix is ​​obtained by calculating the dot product of the query sample block image and the support sample block image; determining a covariance matrix between the first matrix and the second matrix, wherein a trace of the covariance matrix is ​​used as the weight matrix; Performing weighted processing on the distance matrix according to the weight matrix to obtain a correlation matrix; Obtaining an adaptive feature vector corresponding to the support sample according to the feature vector corresponding to the support sample block image and the correlation matrix; The classification module is used to classify the query sample block image according to the feature vector corresponding to the query sample block image and the class prototype corresponding to the support sample.

7. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the image classification method according to any one of claims 1 to 5.

8. An electronic device, characterized in that: The method comprises a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to execute the image classification method described in any one of claims 1 to 5 through the computer program.