Convolution and self-attention mixed image feature extraction method, device and equipment
Through the hybrid image feature extraction method of convolution and self-attention, combined with local and global feature extraction, the problem of poor image feature extraction effect in the existing technology is solved, the accuracy and stability of image feature extraction are improved, and it is suitable for complex images. Processing of data.
Patent Information
- Application Number
- CN202410920294.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-10
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2044-07-10
AI Technical Summary
Existing image feature extraction methods cannot effectively obtain the global information of objects in target detection and semantic segmentation tasks, resulting in detection bias and poor recognition accuracy and robustness.
A hybrid image feature extraction method of convolution and self-attention is used to process image data through N×N convolution layers and 1×1 convolution layers, and combine local self-attention and global self-attention modules to extract local and global features. and fuse them to obtain more comprehensive image features.
It improves the accuracy and stability of image feature extraction, especially when the object scale changes greatly, it can maintain better detection results and enhance the understanding and processing capabilities of complex image data.
Smart Images

Figure CN118570491A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to a convolution and self-attention mixed image feature extraction method, device and equipment. Background Art
[0002] In object detection and semantic segmentation tasks, image feature extraction is the most important step. In the past, most image feature extraction algorithms were mainly based on the improvement of traditional manual features such as gradient histogram, color, texture, etc. Although these algorithms have a fast running speed, their recognition accuracy is not high and their robustness is also poor.
[0003] Convolutional neural networks use convolution kernels to perform sliding feature extraction on images, focusing only on local information of the image. By stacking multiple convolutional layers, convolutional neural networks can extract different levels of features of input image data layer by layer. This hierarchical feature extraction method enables the model to better understand and process complex image data. However, it is actually impossible to obtain global receptive field information simply by stacking multiple convolutional layers. In visual tasks such as target detection, it is impossible to obtain all information about the object (especially large objects), which causes detection bias.
[0004] Therefore, the current image feature extraction method has the technical problem of poor image feature extraction effect. Summary of the invention
[0005] In view of this, the purpose of the present invention is to provide a convolution and self-attention mixed image feature extraction method, device and equipment to solve the technical problem of poor image feature extraction effect in the prior art.
[0006] In order to solve the above technical problems, the present invention provides a convolution and self-attention mixed image feature extraction method, comprising:
[0007] The input image data is processed using an N×N convolution layer and a 1×1 convolution layer to obtain convolution processing data;
[0008] Using a local self-attention module to extract local features from the input image data to obtain local features;
[0009] Performing fusion processing on the local features and the convolution processing data to obtain fused data;
[0010] Using a global self-attention module to extract global features from the fused data and the convolution processing data to obtain global features;
[0011] The global features and the local features are fused to obtain fused image features.
[0012] Optionally, after extracting local features from the input image data using the local self-attention module to obtain local features, the method further includes:
[0013] Using an N×N convolutional layer to perform convolution processing on the local features and the fused data to obtain fused local data;
[0014] Accordingly, the global feature and the local feature are fused to obtain a fused image feature, including:
[0015] The global feature and the fused local data are fused to obtain the fused image feature.
[0016] Optionally, the fusing the local features and the convolution processing data to obtain fused data includes:
[0017] Performing fusion processing on the local features and the convolution processing data to obtain initial fusion data;
[0018] The initial fused data is randomly shuffled to obtain the fused data.
[0019] Optionally, after fusing the local feature and the convolution processing data to obtain fused data, the method further includes:
[0020] Dividing the fused data into two parts to obtain first fused data and second fused data;
[0021] Correspondingly, the global self-attention module is used to extract global features from the fused data and the convolution processing data to obtain global features; and the global features are fused with the local features to obtain fused image features, including:
[0022] Using the global self-attention module to extract global features from the first fused data and the convolution processing data to obtain the global features;
[0023] Processing the local feature and the second fused data using an N×N convolutional layer to obtain a convolutional local feature;
[0024] The convolution local feature and the global feature are fused to obtain the fused image feature.
[0025] Optionally, after fusing the global feature and the local feature to obtain a fused image feature, the method further includes:
[0026] The fused image features are processed using a 1×1 convolutional layer to obtain final fused image features.
[0027] Optionally, the process of extracting local features includes:
[0028] Performing a window equalization operation on the input image data to obtain equalized data, and performing self-attention QKV matrix calculation on the equalized data to obtain corresponding target equalized data;
[0029] Performing reorganization and recovery processing on the target equally divided data to obtain reorganized input image data;
[0030] The reorganized input image data is divided into three parts, and enters three fully connected layers with output dimensions d for data calculation respectively, to obtain feature matrices Q, K and V respectively, and then these three feature matrices are calculated according to the local self-attention formula to obtain the local features.
[0031] Optionally, after fusing the global feature and the local feature to obtain a fused image feature, the method further includes:
[0032] The fused image features are input into a target detection model or a semantic segmentation model for feature analysis to obtain a target processing result.
[0033] The present application also provides a convolution and self-attention mixed image feature extraction device, comprising:
[0034] A convolution processing module, used for processing input image data using an N×N convolution layer and a 1×1 convolution layer to obtain convolution processing data;
[0035] A local feature extraction module, used to extract local features from the input image data using a local self-attention module to obtain local features;
[0036] An information crossover module, used for fusing the local features and the convolution processing data to obtain fused data;
[0037] A global feature extraction module, used for performing global feature extraction on the fused data and the convolution processing data using a global self-attention module to obtain global features;
[0038] The local and global fusion module is used to fuse the global features with the local features to obtain fused image features.
[0039] The present application also provides a convolution and self-attention mixed image feature extraction device, comprising:
[0040] Memory for storing computer programs;
[0041] A processor is used to implement the steps of the above-mentioned convolution and self-attention mixed image feature extraction method when executing the computer program.
[0042] The present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned convolution and self-attention mixed image feature extraction method are implemented.
[0043] It can be seen that the present invention processes the input image data using N×N convolutional layers and 1×1 convolutional layers to obtain convolution processing data; uses a local self-attention module to extract local features of the input image data to obtain local features; fuses the local features and the convolution processing data to obtain fused data; uses a global self-attention module to extract global features of the fused data and the convolution processing data to obtain global features; fuses the global features and the local features to obtain fused image features. The present application extracts features by cross-processing the input image data in two methods, which not only takes advantage of the convolution's focus on local subtle features, but also combines the ability of self-attention to capture long-distance dependent information, thereby improving the image feature extraction effect. This can maintain good stability for some specific scenarios, such as industrial defect detection, when the object scale changes too much.
[0044] In addition, the present invention also provides a convolution and self-attention mixed image feature extraction device, equipment and computer-readable storage medium, which also have the above-mentioned beneficial effects. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0046] Figure 1 A flow chart of a convolution and self-attention hybrid image feature extraction method provided by an embodiment of the present invention;
[0047] Figure 2 A flowchart of a convolution and self-attention hybrid image feature extraction method provided by an embodiment of the present invention;
[0048] Figure 3 A schematic diagram of the overall structure of a convolution and self-attention hybrid image feature extraction method provided by an embodiment of the present invention;
[0049] Figure 4 An example diagram of a flow chart of calculation of a local self-attention block provided in an embodiment of the present invention;
[0050] Figure 5An example diagram of a process of self-attention calculation provided by an embodiment of the present invention;
[0051] Figure 6 A schematic diagram of the structure of a convolution and self-attention hybrid image feature extraction device provided by an embodiment of the present invention;
[0052] Figure 7 A structural schematic diagram of a convolution and self-attention hybrid image feature extraction device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0053] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution 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 are within the scope of protection of the present invention.
[0054] The self-attention mechanism can directly calculate the dependency between any two positions in the input sequence, thereby effectively capturing long-distance dependency information and understanding the image content through global information. However, self-attention lacks spatial inductive bias and is insensitive to position information. This is not friendly to visual tasks such as target detection and cannot accurately locate objects.
[0055] Convolutional neural networks use convolution kernels to perform sliding feature extraction on images, focusing only on local information of the image. By stacking multiple convolutional layers, convolutional neural networks can extract different levels of features of the input image layer by layer. This hierarchical feature extraction method enables the model to better understand and process complex image data. However, it is actually impossible to obtain global receptive field information simply by stacking multiple convolutional layers. In visual tasks such as target detection, it is impossible to obtain all information about the object (especially large objects), which causes detection bias.
[0056] Therefore, the current image feature extraction cannot achieve the comprehensive extraction of all information and local information, resulting in poor image feature extraction effect.
[0057] Please refer to Figure 1 , Figure 1 A flow chart of a convolution and self-attention hybrid image feature extraction method provided by an embodiment of the present invention. The method may include:
[0058] S101, processing the input image data using an N×N convolution layer and a 1×1 convolution layer to obtain convolution processing data.
[0059] The execution subject of this embodiment is any electronic device. This embodiment does not limit the specific N×N convolution layer. For example, the N×N convolution layer in this embodiment may be a 3×3 convolution layer; or the N×N convolution layer in this embodiment may be a 6×6 convolution layer.
[0060] S102, using the local self-attention module to extract local features of the input image data to obtain local features.
[0061] The local self-attention module in this embodiment is a neural network module for extracting local features of an image. It captures local structural information in the image by calculating the relationship between each pixel and other pixels in the input image.
[0062] It should be further explained that, in order to improve the effect of image feature extraction, after the local self-attention module is used to extract local features from the input image data to obtain local features, it can also include: using an N×N convolution layer to perform convolution processing on the local features and the fused data to obtain fused local data; correspondingly, fusing the global features with the local features to obtain fused image features can include: fusing the global features with the fused local data to obtain fused image features. This embodiment performs convolution processing on the local features and the fused data to obtain fused local data, so that the information extraction is more comprehensive, thereby improving the effect of image feature extraction.
[0063] It should be further explained that, in order to improve the effect of local feature extraction, the process of local feature extraction may include:
[0064] S1021, performing a window equalization operation on the input image data to obtain equalized data, and performing self-attention QKV matrix calculation on the equalized data to obtain corresponding target equalized data;
[0065] S1022, performing reorganization and recovery processing on the target equally divided data to obtain reorganized input image data;
[0066] S1023, divide the reorganized input image data into three parts, respectively enter three fully connected layers with output dimensions d for data calculation, and obtain feature matrices Q, K and V respectively, and then these three feature matrices are calculated according to the local self-attention formula; wherein, the calculation formula of local self-attention is used to characterize the relationship between the self-attention calculation result and d, Q, K and V, Q represents query, K represents key, V represents value, which correspond to Q, K and V in the figure respectively, and d represents the output dimension of the fully connected layer.
[0067] The local feature extraction in this embodiment has a larger receptive field than the convolution layer, which can make up for the problem of limited receptive field of the convolution layer, so that the model can pay attention to more global image information. Compared with global feature extraction, the amount of calculation is smaller. The global self-attention module performs QKV matrix calculation on the entire image, while the local self-attention module will first divide the image into equal parts (if the image resolution cannot be divided equally, it is necessary to fill the pixels around the image with 0 to make the length or width of the image divisible by 2), and then perform QKV matrix calculation in these small blocks. This improves the effect of local feature extraction.
[0068] S103, fusing the local features and the convolution processing data to obtain fused data.
[0069] It should be further explained that, in order to improve the fusion effect, the above-mentioned fusing the local features and the convolution processing data to obtain the fused data may include: fusing the local features and the convolution processing data to obtain the initial fused data; and randomly shuffling the initial fused data to obtain the fused data. This embodiment breaks the comfort zone of the model during the training process by performing a random shuffling operation, thereby improving the fusion effect.
[0070] It should be further explained that in order to improve the effect of fusing global features and local features, after the above-mentioned fusing of local features and convolution processing data to obtain fused data, it can also include: dividing the fused data into two parts to obtain first fused data and second fused data; correspondingly, using the global self-attention module to extract global features from the fused data and the convolution processing data to obtain global features; fusing the global features and the local features to obtain fused image features, which can include: using the global self-attention module to extract global features from the first fused data and the convolution processing data to obtain global features; processing the local features and the second fused data using an N×N convolution layer to obtain convolution local features; fusing the convolution local features with the global features to obtain fused image features. This embodiment divides the fused data into two parts, thereby fusing them with the global features and the local features respectively, thereby improving the effect of fusing the global features and the local features.
[0071] S104, using the global self-attention module to extract global features from the fused data and the convolution processing data to obtain global features.
[0072] The global self-attention module in this embodiment is an efficient neural network component designed to improve the performance of deep networks in image processing tasks.
[0073] S105, fusing the global features and the local features to obtain fused image features.
[0074] It should be further explained that, in order to reduce channel processing, after the global features and local features are fused to obtain fused image features, the following may be included: using a 1×1 convolution layer to process the fused image features to obtain the final fused image features. This embodiment uses a 1×1 convolution layer to interact between channels and perform dimensionality reduction and channel processing (for example, there are 64 feature maps after fusion, and after dimensionality reduction by a 1×1conv convolution layer, 32 feature maps are obtained) to reduce the amount of subsequent calculations.
[0075] It should be further explained that in order to improve the accuracy of feature analysis, the global features and local features are
[0076] After the features are fused to obtain fused image features, the method may further include: inputting the fused image features into a target detection model or a semantic segmentation model for feature analysis to obtain a target processing result. This embodiment improves the accuracy of feature analysis by performing feature analysis after cross-processing of global features and local features.
[0077] A convolution and self-attention hybrid image feature extraction method provided by an embodiment of the present invention may include: S101, processing input image data using N×N convolution layers and 1×1 convolution layers to obtain convolution processing data; S102, extracting local features from the input image data using a local self-attention module to obtain local features; S103, fusing local features and convolution processing data to obtain fused data; S104, extracting global features from the fused data and convolution processing data using a global self-attention module to obtain global features; S105, fusing global features and local features to obtain fused image features. Compared with the current inability to simultaneously take into account local features and global features, the present application extracts features by cross-processing the input image data in two methods, which not only takes into account the advantages of convolution focusing on local subtle features, but also combines the ability of self-attention to capture long-distance dependent information, thereby improving the image feature extraction effect, which can maintain good stability for some specific scenarios, such as industrial defect detection, when the object scale changes too much. Moreover, this embodiment performs convolution processing on local features and fused data to obtain fused local data, so that information extraction is more comprehensive, thereby improving the effect of image feature extraction; and, the local feature extraction in this embodiment has a larger receptive field than the convolution layer, which can make up for the problem of limited receptive field of the convolution layer, so that the model can pay attention to more global image information, and the amount of calculation is smaller than that of global feature extraction; and, this embodiment breaks the comfort zone of the model during the training process by performing a random shuffle operation, thereby improving the fusion effect; and, this embodiment divides the fused data into two parts, thereby fusing them with global features and local features respectively, thereby improving the effect of fusing global features and local features; and, this embodiment uses a 1×1 convolution layer to interact between channels and perform dimensionality reduction and channel reduction processing to reduce the subsequent amount of calculation; and, this embodiment performs feature analysis after cross-processing of global features and local features, thereby improving the accuracy of feature analysis.
[0078] In order to make the present invention easier to understand, please refer to Figure 2 , Figure 2 A flow chart of a convolution and self-attention hybrid image feature extraction method provided in an embodiment of the present invention may specifically include:
[0079] S201, input image data into path 1 and path 2 respectively.
[0080] The present invention is a hybrid image feature extraction method based on convolution and self-attention. The method combines the local feature extraction of convolution with the global feature extraction of self-attention. The image data will be continuously cross-processed in the structure of the present invention to mine the potential information of the image data that is useful for the current task. This has important semantics for improving the robustness of the deep learning feature extraction model. For ease of understanding, please refer to Figure 3 , Figure 3 A schematic diagram of the overall structure of a convolution and self-attention mixed image feature extraction provided in an embodiment of the present invention corresponds to a convolution and self-attention mixed image feature extraction method. The input feature data of this embodiment can be one or more two-dimensional images, and the output is a feature map group after layer-by-layer feature extraction. The feature map group can be input into the decoder of the target detection or semantic segmentation model for final feature analysis to complete a specific visual task. The input image data in this embodiment will be input into path 1 and path 2 respectively.
[0081] S202, the data in path 1 will pass through a convolution layer with a convolution window size of 3×3, a 1×1 convolution layer, and a 1×1 convolution layer in sequence to obtain convolution processing data, and the convolution processing data will be input into path 3 and path 5.
[0082] The data of the path 1 part in this embodiment will pass through a convolution layer with a convolution window size of 3×3 (representing the length and width of the window), that is, 3×3conv in the figure, for extracting local features, and a 1×1conv convolution layer for integrating local information and information interaction between channels (or multiple feature maps). The output of the 1×1conv convolution layer will enter path 3 and path 5 respectively.
[0083] S203, the data in path 2 will enter a local self-attention block for feature extraction. After the local self-attention calculation is completed, the result will be input into path 4 and path 6.
[0084] In this embodiment, the data in path 2 will enter a local self-attention block for feature extraction. The design of this module is mainly based on the following two points: 1. Compared with the convolution layer, the local self-attention module has a larger receptive field, which can make up for the problem of limited receptive field of the convolution layer, so that the model can pay attention to more global image information; 2. Compared with the global self-attention module, the local self-attention module has less computational complexity. The global self-attention module performs QKV matrix calculation on the entire image, while the local self-attention module will first divide the image into 4 equal parts (if the image resolution cannot be divided into 4 equal parts, it is necessary to add 0 pixels around the image to make the length or width of the image divisible by 2), and then perform QKV matrix calculation in these 4 small blocks. The calculation process of the local self-attention block is as follows Figure 4 As shown, Figure 4This is an example diagram of a calculation process of a local self-attention block provided by an embodiment of the present invention. The input will first undergo a window splitting operation to split the input into A, B, C, and D without overlap. Then, these four blocks will perform self-attention QKV matrix calculations to obtain A', B', C', and D', and then A', B', C', and D' will be calculated according to Figure 2 The position of is reorganized into the input. The calculation process of self-attention is as follows Figure 5 As shown, Figure 5 This is an example flow chart of self-attention calculation provided by an embodiment of the present invention, where T represents transposition. The input is the split window data, which is then divided into three parts and enters three fully connected layers (fully connected layer_1, fully connected layer_2, and fully connected layer_3) with an output dimension of d for data calculation, respectively, to obtain feature matrices Q, K, and V, respectively, and then these three feature matrices are calculated according to the self-attention formula. The calculation formula of self-attention is used to characterize the relationship between the self-attention calculation results and d, Q, K, and V. Q represents query, K represents key, and V represents value, which correspond to Q, K, and V in the figure, respectively, and d represents the output dimension of the fully connected layer. In the present invention, d is 64 (it can also be 32, 128, 356, etc.). After the local self-attention calculation is completed, the results will be input into path 4 and path 6.
[0085] S204, the data of path 3 and path 4 will enter the channel splicing layer for data fusion and channel random shuffling operation, and then the result will be divided into two equal parts to obtain part_1 and part_2.
[0086] In this embodiment, the data of path 3 and path 4 will enter the channel splicing layer (or other data fusion methods) for data fusion. In order to reduce the risk of overfitting of the model during training and prevent the model from being more biased towards the data of the convolution or self-attention layer, the present invention adds a channel random shuffling operation after the channel splicing layer to break the comfort zone of the model during training, and then divide the result into two equal parts to obtain part_1 and part_2.
[0087] S205, the data of part_1 and the data of path 5 will be sent to the global self-attention module for self-attention QKV calculation.
[0088] In this embodiment, the data of part_1 and the data of path 5 are sent to the global self-attention module for self-attention QKV calculation. The global self-attention module is used here mainly to obtain the global receptive field information, so that the model can mine global image features based on the information of the entire image.
[0089] S206, the data of part_2 will be sent to the 3×3 convolution layer together with the data of path 6 for local information extraction.
[0090] In this embodiment, the data of part_2 is sent to the 3×3conv convolution layer together with the data of path 6 for local information extraction. The input of the global self-attention block mainly comes from the data after convolution processing, and the input data of the second 3×3conv convolution layer mainly comes from the data after self-attention layer processing. This method of cross-feature extraction of data helps to reduce the negative impact caused by the defects of convolution and self-attention, while giving play to their respective advantages, that is, to learn from each other.
[0091] S207, the results after the global self-attention module and the second 3×3 convolutional layer are calculated will continue to be fused by adding pixels one by one, and the data after feature fusion will be integrated into a 1×1 convolutional layer for channel interaction and dimensionality reduction and channel reduction processing to obtain a feature extraction map.
[0092] In this embodiment, the results after the global self-attention module and the second 3×3conv convolutional layer are calculated will continue to be fused by pixel-by-pixel addition. The result brings together local micro information and global macro information. The data after feature fusion will be integrated into a 1×1conv convolutional layer for channel interaction and dimensionality reduction and channel reduction processing (for example, there are 64 feature maps after fusion, and after dimensionality reduction by the 1×1conv convolutional layer, 32 feature maps are obtained) to reduce the subsequent calculation amount.
[0093] S208, input the feature extraction map into the decoder of the target detection or semantic segmentation model for final feature analysis.
[0094] The feature extraction graph in this embodiment is used for decoding operations in a framework of target detection or semantic segmentation to complete specific visual tasks.
[0095] The embodiment of the present invention is an image feature extraction method that mixes convolution and self-attention, which has the following advantages: better robustness and stronger feature extraction capability. When designing the present invention, the respective advantages and disadvantages of the current mainstream deep learning feature extraction methods, convolution and self-attention mechanisms, are analyzed, and image data is cross-processed in the two methods for feature extraction. This not only takes advantage of the convolution's focus on local subtle features, but also combines the ability of self-attention to capture long-distance dependent information. This can maintain good stability for some specific scenarios, such as industrial defect detection, when the object scale changes too much.
[0096] The following is an introduction to the convolution and self-attention mixed image feature extraction device provided by an embodiment of the present invention. The convolution and self-attention mixed image feature extraction device described below and the convolution and self-attention mixed image feature extraction method described above can be referenced to each other.
[0097] Please refer to Figure 6 , Figure 6 A structural schematic diagram of a convolution and self-attention hybrid image feature extraction device provided by an embodiment of the present invention may include:
[0098] The convolution processing module 100 is used to process the input image data using an N×N convolution layer and a 1×1 convolution layer to obtain convolution processing data;
[0099] A local feature extraction module 200 is used to extract local features from the input image data using a local self-attention module to obtain local features;
[0100] An information cross-module 300 is used to fuse the local features and the convolution processing data to obtain fused data;
[0101] A global feature extraction module 400 is used to extract global features from the fused data and the convolution processing data using a global self-attention module to obtain global features;
[0102] The local and global fusion module 500 is used to fuse the global features and the local features to obtain fused image features.
[0103] Further, based on the above embodiment, the above convolution and self-attention mixed image feature extraction device may also include:
[0104] A fused local data determination module, used for performing convolution processing on the local features and the fused data using an N×N convolution layer to obtain fused local data;
[0105] Accordingly, the local and global fusion module 500 may include:
[0106] The local and global fusion unit is used to fuse the global feature with the fused local data to obtain the fused image feature.
[0107] Further, based on any of the above embodiments, the above information cross-connect module 300 may include:
[0108] An initial fusion unit, used for fusing the local features and the convolution processing data to obtain initial fused data;
[0109] The random shuffling processing unit is used to perform random shuffling processing on the initial fused data to obtain the fused data.
[0110] Further, based on any of the above embodiments, the above convolution and self-attention mixed image feature extraction device may also include:
[0111] A division module, used for dividing the fused data into two parts to obtain first fused data and second fused data;
[0112] Accordingly, the global feature extraction module 400 and the local and global fusion module 500 may include:
[0113] A global feature extraction unit, configured to perform global feature extraction on the first fused data and the convolution processing data using the global self-attention module to obtain the global feature;
[0114] A convolution local feature determination unit, configured to process the local feature and the second fused data using an N×N convolution layer to obtain a convolution local feature;
[0115] A fusion unit is used to fuse the convolution local feature and the global feature to obtain the fused image feature.
[0116] Further, based on any of the above embodiments, the above convolution and self-attention mixed image feature extraction device may also include:
[0117] The final fused image feature determination module is used to process the fused image features using a 1×1 convolutional layer to obtain the final fused image features.
[0118] Further, based on any of the above embodiments, the local feature extraction module 200 may include:
[0119] An equal division processing unit is used to perform a window equal division operation on the input image data to obtain equal division data, and perform self-attention QKV matrix calculation on the equal division data to obtain corresponding target equal division data;
[0120] A reorganization unit, used for performing reorganization and recovery processing on the target equally divided data to obtain reorganized input image data;
[0121] The self-attention calculation unit is used to divide the reorganized input image data into three parts, respectively enter three fully connected layers with output dimensions d for data calculation, and obtain feature matrices Q, K and V respectively. Then these three feature matrices are calculated according to the local self-attention formula to obtain the local features.
[0122] Further, based on any of the above embodiments, the above convolution and self-attention mixed image feature extraction device may also include:
[0123] The feature analysis module is used to input the fused image features into a target detection model or a semantic segmentation model for feature analysis to obtain a target processing result.
[0124] It should be noted that the order of the modules and units in the above-mentioned convolution and self-attention mixed image feature extraction device can be changed before or after without affecting the logic.
[0125] The convolution and self-attention mixed image feature extraction device provided in an embodiment of the present invention may include: a convolution processing module 100, used to process input image data using an N×N convolution layer and a 1×1 convolution layer to obtain convolution processing data; a local feature extraction module 200, used to extract local features of the input image data using a local self-attention module to obtain local features; an information intersection module 300, used to fuse the local features and the convolution processing data to obtain fused data; a global feature extraction module 400, used to extract global features of the fused data and the convolution processing data using a global self-attention module to obtain global features; a local and global fusion module 500, used to fuse the global features with the local features to obtain fused image features. Compared with the current method that cannot take into account both local features and global features at the same time, this application extracts features by cross-processing the input image data in two methods. It not only takes advantage of the convolution's focus on local subtle features, but also combines the ability of self-attention to capture long-distance dependent information, thereby improving the image feature extraction effect. This is for some specific scenarios, such as industrial defect detection, when the object scale changes too much, it can maintain good stability. Moreover, this embodiment performs convolution processing on local features and fused data to obtain fused local data, so that information extraction is more comprehensive, thereby improving the effect of image feature extraction; and, the local feature extraction in this embodiment has a larger receptive field than the convolution layer, which can make up for the problem of limited receptive field of the convolution layer, so that the model can pay attention to more global image information, and the amount of calculation is smaller than that of global feature extraction; and, this embodiment breaks the comfort zone of the model during the training process by performing a random shuffle operation, thereby improving the fusion effect; and, this embodiment divides the fused data into two parts, thereby fusing them with global features and local features respectively, thereby improving the effect of fusing global features and local features; and, this embodiment uses a 1×1 convolution layer to interact between channels and perform dimensionality reduction and channel reduction processing to reduce the subsequent amount of calculation; and, this embodiment performs feature analysis after cross-processing of global features and local features, thereby improving the accuracy of feature analysis.
[0126] A convolution and self-attention mixed image feature extraction device provided by an embodiment of the present invention is introduced below. The convolution and self-attention mixed image feature extraction device described below and the convolution and self-attention mixed image feature extraction method described above can be referenced to each other.
[0127] Please refer to Figure 7 , Figure 7 A structural schematic diagram of a convolution and self-attention hybrid image feature extraction device provided by an embodiment of the present invention may include:
[0128] A memory 10, used for storing computer programs;
[0129] The processor 20 is used to execute a computer program to implement the above-mentioned convolution and self-attention mixed image feature extraction method.
[0130] The memory 10 , the processor 20 , and the communication interface 30 all communicate with each other via a communication bus 40 .
[0131] In the embodiment of the present invention, the memory 10 is used to store one or more programs, and the program may include program code, and the program code includes computer operation instructions. In the embodiment of the present invention, the memory 10 may store programs for implementing the following functions:
[0132] The input image data is processed using an N×N convolution layer and a 1×1 convolution layer to obtain convolution processing data;
[0133] Using a local self-attention module to extract local features from the input image data to obtain local features;
[0134] The local features and the convolution processing data are fused to obtain fused data;
[0135] Use the global self-attention module to extract global features from the fused data and convolutional processed data to obtain global features;
[0136] The global features and local features are fused to obtain fused image features.
[0137] In a possible implementation, the memory 10 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function, etc.; the data storage area may store data created during use.
[0138] In addition, the memory 10 may include a read-only memory and a random access memory, and provide instructions and data to the processor. A portion of the memory may also include an NVRAM. The memory stores an operating system and operating instructions, executable modules or data structures, or a subset thereof, or an extended set thereof, wherein the operating instructions may include various operating instructions for implementing various operations. The operating system may include various system programs for implementing various basic tasks and processing hardware-based tasks.
[0139] The processor 20 may be a central processing unit (CPU), an application specific integrated circuit, a digital signal processor, a field programmable gate array or other programmable logic device, a microprocessor or any conventional processor, etc. The processor 20 may call a program stored in the memory 10 .
[0140] The communication interface 30 may be an interface of a communication module, and is used to connect to other devices or systems.
[0141] Of course, it should be noted that Figure 7 The structure shown does not constitute a limitation on the convolution and self-attention mixed image feature extraction device in the embodiment of the present invention. In practical applications, the convolution and self-attention mixed image feature extraction device may include Figure 7 More or fewer components than shown, or combinations of certain components.
[0142] The computer-readable storage medium provided in an embodiment of the present invention is introduced below. The computer-readable storage medium described below and the convolution and self-attention mixed image feature extraction method described above can be referenced to each other.
[0143] The present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned convolution and self-attention mixed image feature extraction method are implemented.
[0144] The computer-readable storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0145] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0146] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0147] Finally, it should be noted that, in this article, relationships such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprises" or any other variations are intended to cover non-exclusive inclusion, so that a process, method, article or device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.
[0148] The above is a detailed introduction to the convolution and self-attention mixed image feature extraction method, device and equipment provided by the present invention. This article uses specific examples to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for general technical personnel in this field, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A convolution and self-attention hybrid image feature extraction method, characterized in that: include: The input image data is processed using an N×N convolution layer and a 1×1 convolution layer to obtain convolution processing data; Using a local self-attention module to extract local features from the input image data to obtain local features; Performing fusion processing on the local features and the convolution processing data to obtain fused data; Using a global self-attention module to extract global features from the fused data and the convolution processing data to obtain global features; The global features and the local features are fused to obtain fused image features.
2. The convolution and self-attention hybrid image feature extraction method according to claim 1, characterized in that: After extracting local features from the input image data using the local self-attention module to obtain local features, the method further includes: Using an N×N convolutional layer to perform convolution processing on the local features and the fused data to obtain fused local data; Accordingly, the global feature and the local feature are fused to obtain a fused image feature, including: The global feature and the fused local data are fused to obtain the fused image feature.
3. The convolution and self-attention hybrid image feature extraction method according to claim 1, characterized in that: The step of fusing the local features and the convolution processing data to obtain fused data includes: Performing fusion processing on the local features and the convolution processing data to obtain initial fusion data; The initial fused data is randomly shuffled to obtain the fused data.
4. The convolution and self-attention hybrid image feature extraction method according to claim 1, characterized in that: After fusing the local features and the convolution processing data to obtain fused data, the method further includes: Dividing the fused data into two parts to obtain first fused data and second fused data; Correspondingly, the global self-attention module is used to extract global features from the fused data and the convolution processing data to obtain global features; and the global features are fused with the local features to obtain fused image features, including: Using the global self-attention module to extract global features from the first fused data and the convolution processing data to obtain the global features; Processing the local feature and the second fused data using an N×N convolutional layer to obtain a convolutional local feature; The convolution local feature and the global feature are fused to obtain the fused image feature.
5. The convolution and self-attention hybrid image feature extraction method according to any one of claims 1 to 4, characterized in that: After fusing the global feature and the local feature to obtain a fused image feature, the method further includes: The fused image features are processed using a 1×1 convolutional layer to obtain final fused image features.
6. The convolution and self-attention hybrid image feature extraction method according to any one of claims 1 to 4, characterized in that: The process of local feature extraction includes: Performing a window equalization operation on the input image data to obtain equalized data, and performing self-attention QKV matrix calculation on the equalized data to obtain corresponding target equalized data; Performing reorganization and recovery processing on the target equally divided data to obtain reorganized input image data; The reorganized input image data is divided into three parts, and enters three fully connected layers with output dimensions d for data calculation respectively, to obtain feature matrices Q, K and V respectively, and then these three feature matrices are calculated according to the local self-attention formula to obtain the local features.
7. The convolution and self-attention hybrid image feature extraction method according to claim 1, characterized in that: After fusing the global feature and the local feature to obtain a fused image feature, the method further includes: The fused image features are input into a target detection model or a semantic segmentation model for feature analysis to obtain a target processing result.
8. A convolution and self-attention hybrid image feature extraction device, characterized in that: include: A convolution processing module, used for processing input image data using an N×N convolution layer and a 1×1 convolution layer to obtain convolution processing data; A local feature extraction module, used to extract local features from the input image data using a local self-attention module to obtain local features; An information crossover module, used for fusing the local features and the convolution processing data to obtain fused data; A global feature extraction module, used for performing global feature extraction on the fused data and the convolution processing data using a global self-attention module to obtain global features; The local and global fusion module is used to fuse the global features with the local features to obtain fused image features.
9. A convolution and self-attention hybrid image feature extraction device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the convolution and self-attention mixed image feature extraction method as described in any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the convolution and self-attention mixed image feature extraction method as described in any one of claims 1 to 7 are implemented.
