Image feature extraction method, device, storage medium and computer equipment
By dividing the image to be processed into sub-images and extracting feature vectors of clear sub-images, the problem of low feature extraction accuracy of unclear images in the prior art is solved, and higher feature extraction accuracy is achieved.
Patent Information
- Application Number
- CN202210026806.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-11
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2042-01-11
AI Technical Summary
It is difficult for the existing technology to ensure the accuracy of feature extraction when processing unclear or incomplete images. Especially when cropped or mosaic images are encountered in actual business scenarios, feature extraction constructed using clear and complete images The model cannot effectively support feature extraction.
By dividing the picture to be processed into multiple sub-pictures, a clear target sub-picture is determined, and a preset picture feature extraction model is used to extract the feature vector of the target sub-picture, and the position information of the sub-picture in the picture to be processed is combined to calculate the picture to be processed. The third image feature vector to improve feature extraction accuracy.
It effectively avoids the difficulty of feature extraction of unclear images by building a clear and complete image model, improves the accuracy of image feature extraction, and is suitable for processing various incomplete or unclear images.
Smart Images

Figure CN114387450B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information technology, and in particular to a method, device, storage medium and computer equipment for extracting image features. Background Art
[0002] Image feature extraction is a basic task in natural language processing. Image feature extraction provides a basis for subsequent natural language processing. Therefore, efficient and accurate image feature extraction is of great significance to natural language processing.
[0003] At present, feature extraction models are usually built using clear and complete images, and image features are extracted based on the built feature extraction models. However, in actual business scenarios, images are often incomplete or unclear, such as cropped images or mosaic images. As a result, feature extraction models built using clear and complete images are difficult to support feature extraction of unclear or incomplete images, and the accuracy of image feature extraction cannot be guaranteed. Summary of the invention
[0004] The present invention provides a method, device, storage medium and computer equipment for extracting image features, which are mainly capable of improving the accuracy of image feature extraction.
[0005] According to a first aspect of the present invention, there is provided a method for extracting image features, comprising:
[0006] Get the images to be processed in actual business scenarios;
[0007] Divide the image to be processed into multiple sub-images, and determine a clear target sub-image from the multiple sub-images, wherein the clear target sub-image is an image that is not damaged, not mosaiced, and has a pixel value greater than a preset pixel value;
[0008] Inputting the target sub-image into a preset image feature extraction model to perform feature extraction, and obtaining a first image feature vector corresponding to the target sub-image;
[0009] Based on the first picture feature vector and the position information of the plurality of sub-pictures in the picture to be processed, determining a second picture feature vector corresponding to the remaining sub-pictures after removing the target sub-picture from the plurality of sub-pictures;
[0010] Based on the first picture feature vector and the second picture feature vector, a third picture feature vector corresponding to the picture to be processed is determined.
[0011] According to a second aspect of the present invention, there is provided a device for extracting image features, comprising:
[0012] An acquisition unit, used to acquire the image to be processed in the actual business scenario;
[0013] A segmentation unit, used to segment the to-be-processed picture into a plurality of sub-pictures, and determine a clear target sub-picture from the plurality of sub-pictures, wherein the clear target sub-picture is a picture that is not damaged, not mosaiced, and has a pixel value greater than a preset pixel value;
[0014] An extraction unit, configured to input the target sub-image into a preset image feature extraction model for feature extraction, and obtain a first image feature vector corresponding to the target sub-image;
[0015] A first determining unit, configured to determine, based on the first picture feature vector and position information of the plurality of sub-pictures in the picture to be processed, a second picture feature vector corresponding to a remaining sub-picture after removing the target sub-picture from the plurality of sub-pictures;
[0016] The second determining unit is used to determine a third picture feature vector corresponding to the picture to be processed based on the first picture feature vector and the second picture feature vector.
[0017] According to a third aspect of the present invention, there is provided a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the following steps:
[0018] Get the images to be processed in actual business scenarios;
[0019] Divide the image to be processed into multiple sub-images, and determine a clear target sub-image from the multiple sub-images, wherein the clear target sub-image is an image that is not damaged, not mosaiced, and has a pixel value greater than a preset pixel value;
[0020] Inputting the target sub-image into a preset image feature extraction model to perform feature extraction, and obtaining a first image feature vector corresponding to the target sub-image;
[0021] Based on the first picture feature vector and the position information of the plurality of sub-pictures in the picture to be processed, determining a second picture feature vector corresponding to the remaining sub-pictures after removing the target sub-picture from the plurality of sub-pictures;
[0022] Based on the first picture feature vector and the second picture feature vector, a third picture feature vector corresponding to the picture to be processed is determined.
[0023] According to a fourth aspect of the present invention, there is provided a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the following steps are implemented:
[0024] Get the images to be processed in actual business scenarios;
[0025] Divide the image to be processed into multiple sub-images, and determine a clear target sub-image from the multiple sub-images, wherein the clear target sub-image is an image that is not damaged, not mosaiced, and has a pixel value greater than a preset pixel value;
[0026] Inputting the target sub-image into a preset image feature extraction model to perform feature extraction, and obtaining a first image feature vector corresponding to the target sub-image;
[0027] Based on the first picture feature vector and the position information of the plurality of sub-pictures in the picture to be processed, determining a second picture feature vector corresponding to the remaining sub-pictures after removing the target sub-picture from the plurality of sub-pictures;
[0028] Based on the first picture feature vector and the second picture feature vector, a third picture feature vector corresponding to the picture to be processed is determined.
[0029] According to a method, device, storage medium and computer equipment for extracting image features provided by the present invention, compared with the current method of using a clear and complete image to build a feature extraction model and extracting image features based on the built feature extraction model, the present invention obtains an image to be processed in an actual business scenario; divides the image to be processed into multiple sub-images, and determines a clear target sub-image from the multiple sub-images, wherein the clear target sub-image is an image that is not damaged, not mosaiced, and has a pixel value greater than a preset pixel value; inputs the target sub-image into a preset image feature extraction model for feature extraction, and obtains a first image feature vector corresponding to the target sub-image; and determines, based on the first image feature vector and the position information of the multiple sub-images in the image to be processed, to remove the target sub-image from the multiple sub-images. The second picture feature vector corresponding to the remaining sub-picture after the slice is processed; based on the first picture feature vector and the second picture feature vector, the third picture feature vector corresponding to the picture to be processed is determined, thereby by segmenting the picture to be processed, determining a clear target sub-picture in the picture to be processed, and extracting the first picture feature vector corresponding to the target sub-picture, and at the same time, based on the first picture feature vector and the position information of the multiple sub-pictures in the picture to be processed, the second picture feature vector corresponding to the remaining sub-pictures in the multiple sub-pictures is determined, and finally based on the first picture feature vector and the second picture feature vector, the third picture feature vector corresponding to the picture to be processed is determined, which can avoid the situation where the feature extraction model constructed by using a clear and complete picture extracts features for unclear pictures, thereby improving the accuracy of picture feature extraction. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0031] Figure 1 A flow chart of a method for extracting image features provided by an embodiment of the present invention is shown;
[0032] Figure 2 Another method for extracting image features according to an embodiment of the present invention is shown in the flowchart;
[0033] Figure 3 A schematic diagram of the structure of a picture feature extraction device provided by an embodiment of the present invention is shown;
[0034] Figure 4 A schematic diagram showing the structure of another image feature extraction device provided by an embodiment of the present invention is shown;
[0035] Figure 5 A schematic diagram of the physical structure of a computer device provided by an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0036] The present invention will be described in detail below with reference to the accompanying drawings and in combination with embodiments. It should be noted that the embodiments and features in the embodiments of the present application can be combined with each other without conflict.
[0037] At present, a feature extraction model is constructed using clear and complete images, and image features are extracted based on the constructed feature extraction model. However, since images in actual business scenarios are often incomplete or unclear, the feature extraction model constructed using clear and complete images is difficult to support feature extraction of unclear or incomplete images, and the extraction accuracy of image features cannot be guaranteed.
[0038] In order to solve the above problems, the embodiment of the present invention provides a method for extracting image features, such as Figure 1 As shown, the method includes:
[0039] 101. Obtain the images to be processed in actual business scenarios.
[0040] Among them, the images to be processed in actual business scenarios include mosaic images, cropped images, etc.
[0041] For the embodiment of the present invention, in order to overcome the defect of low accuracy of image feature extraction in the prior art, the embodiment of the present invention divides the image to be processed into multiple sub-images, and determines a clear target sub-image from the multiple sub-images. At the same time, the first image feature vector corresponding to the target sub-image is extracted using the image feature extraction model, and based on the first image feature vector and the position information corresponding to the multiple sub-images, the second image feature vector corresponding to the remaining sub-images in the multiple sub-images is determined. Finally, based on the first image feature vector and the second image feature vector, the third image feature vector corresponding to the image to be processed is determined, thereby avoiding the situation where the feature extraction model constructed using clear and complete images is difficult to support feature extraction for unclear or incomplete images, and improving the accuracy of image feature extraction. The embodiment of the present invention is mainly applied to the scene of extracting image features. The execution subject of the embodiment of the present invention is a device or equipment capable of extracting image features, which can be specifically set on the client or server side.
[0042] Specifically, there are a large number of pictures to be processed in actual business scenarios. By downloading cropped or mosaicked pictures on the Internet, the pictures to be processed can also be obtained from the picture database. After obtaining the pictures to be processed, the pictures to be processed are divided into multiple sub-pictures, and a clear target sub-picture is determined from the multiple sub-pictures. At the same time, the target sub-picture is input into a preset picture feature extraction model for feature extraction to obtain a first picture feature vector corresponding to the target sub-picture. Then, based on the first picture feature vector and the position information of the multiple sub-pictures in the picture to be processed, the second picture feature vector corresponding to the remaining sub-pictures in the multiple sub-pictures is determined. Finally, based on the first picture feature vector and the second picture feature vector, the third picture feature vector corresponding to the picture to be processed is determined, thereby improving the accuracy of picture feature extraction.
[0043] 102. Divide the image to be processed into multiple sub-images, and determine a clear target sub-image from the multiple sub-images, wherein the clear target sub-image is an image that is not damaged, not mosaiced, and has a pixel value greater than a preset pixel value.
[0044] The sizes of the multiple sub-pictures may be the same or different. For the embodiment of the present invention, if the sizes of the multiple sub-pictures are the same, the image to be processed is divided into multiple sub-pictures, and the number of the multiple sub-pictures is as follows:
[0045]
[0046] Among them, N is the number of sub-pictures, a is the length corresponding to the sub-picture, b is the width corresponding to the sub-picture, H is the length corresponding to the image to be processed, and W is the width corresponding to the image to be processed. After the image to be processed is divided into multiple sub-pictures, a clear target sub-picture is determined among the multiple sub-pictures. The target sub-picture is a picture that has not been mosaiced or damaged. The number of clear target sub-pictures can be 1 or more, and this application does not make specific restrictions. After determining a clear target sub-picture, the target sub-picture is input into a preset image feature extraction model for feature extraction to obtain a first image feature vector corresponding to the target sub-picture, and based on the first image feature vector and the position information of the multiple sub-pictures in the image to be processed, the second image feature vector corresponding to the remaining sub-pictures in the multiple sub-pictures is determined. Finally, based on the first image feature vector and the second image feature vector, the third image feature vector corresponding to the image to be processed is determined to ensure the accuracy of image feature extraction.
[0047] 103. Input the target sub-image into a preset image feature extraction model to perform feature extraction, and obtain a first image feature vector corresponding to the target sub-image.
[0048] Among them, the preset image feature extraction model can specifically be a preset encoder.
[0049] For the embodiment of the present invention, after determining a clear target sub-picture in the picture to be processed, the target sub-picture is input into a preset encoder for feature extraction to obtain a first picture feature vector corresponding to the target sub-picture, and based on the first picture feature vector and the position information of the multiple sub-pictures in the picture to be processed, the second picture feature vector corresponding to the remaining sub-pictures in the multiple sub-pictures is determined, and finally based on the first picture feature vector and the second picture feature vector, the third picture feature vector corresponding to the picture to be processed is determined. This can avoid the situation where a feature extraction model constructed using a clear and complete picture is used to extract features from an unclear picture, thereby improving the accuracy of picture feature extraction.
[0050] 104. Determine, based on the first picture feature vector and position information of the multiple sub-pictures in the picture to be processed, a second picture feature vector corresponding to the remaining sub-pictures after removing the target sub-picture from the multiple sub-pictures.
[0051] Among them, the position information can specifically be the position order of multiple sub-pictures in the picture to be processed. According to the order of the multiple sub-pictures from left to right and from top to bottom in the picture to be processed, the multiple sub-pictures are encoded as 1, 2, 3, etc. in sequence, thereby determining the position information of the multiple sub-pictures in the picture to be processed, wherein the position information includes the position information corresponding to the target sub-picture.
[0052] For the embodiment of the present invention, after determining the first image feature vector corresponding to the target sub-image, in order to determine the third image feature vector corresponding to the image to be processed, it is first necessary to determine the second image feature vectors corresponding to the remaining sub-images except the target sub-image in the multiple sub-images. Based on this, the method is to determine the position information of the multiple sub-images in the image to be processed, and based on the first image feature vector corresponding to the target sub-image and the position information of the multiple sub-images in the image to be processed, determine the second image feature vectors corresponding to the remaining sub-images in the multiple sub-images. Finally, based on the first image feature vector and the second image feature vector, determine the third image feature vector corresponding to the image to be processed. This can avoid the situation where the feature extraction model constructed using a clear and complete image is used to extract features from an unclear image, thereby improving the accuracy of image feature extraction.
[0053] 105. Determine a third picture feature vector corresponding to the picture to be processed based on the first picture feature vector and the second picture feature vector.
[0054] For the embodiment of the present invention, after obtaining the first image feature vector corresponding to the target sub-image in the image to be processed and the second image feature vector corresponding to the remaining sub-images, the first image feature vector and the second image feature vector are finally added to obtain the third image feature vector corresponding to the image to be processed. Thus, by segmenting the image to be processed, a clear target sub-image in the image to be processed is determined, and the first image feature vector corresponding to the target sub-image is extracted. At the same time, based on the first image feature vector and the position information of the multiple sub-images in the image to be processed, the second image feature vector corresponding to the remaining sub-images after removing the target sub-image from the multiple sub-images is determined. Finally, based on the first image feature vector and the second image feature vector, the third image feature vector corresponding to the image to be processed is determined. This can avoid the situation where a feature extraction model constructed using a clear and complete image is used to extract features from an unclear image, thereby improving the accuracy of image feature extraction.
[0055] According to a method for extracting image features provided by the present invention, compared with the current method of using a clear and complete image to build a feature extraction model and extracting image features based on the built feature extraction model, the present invention obtains an image to be processed in an actual business scenario; divides the image to be processed into multiple sub-images, and determines a clear target sub-image from the multiple sub-images, wherein the clear target sub-image is an image that is not damaged, not mosaiced, and has a pixel value greater than a preset pixel value; inputs the target sub-image into a preset image feature extraction model for feature extraction, and obtains a first image feature vector corresponding to the target sub-image; and determines the remaining sub-images after removing the target sub-image from the multiple sub-images based on the first image feature vector and the position information of the multiple sub-images in the image to be processed. a second picture feature vector corresponding to the slice; based on the first picture feature vector and the second picture feature vector, determining the third picture feature vector corresponding to the picture to be processed, thereby segmenting the picture to be processed, determining a clear target sub-picture in the picture to be processed, and extracting the first picture feature vector corresponding to the target sub-picture, and at the same time determining the second picture feature vectors corresponding to the remaining sub-pictures in the multiple sub-pictures based on the first picture feature vector and the position information of the multiple sub-pictures in the picture to be processed, and finally determining the third picture feature vector corresponding to the picture to be processed based on the first picture feature vector and the second picture feature vector, which can avoid the situation where the feature extraction model constructed by using a clear and complete picture extracts features for unclear pictures, thereby improving the accuracy of picture feature extraction.
[0056] Further, in order to better illustrate the above process of extracting image features, as a refinement and extension of the above embodiment, the embodiment of the present invention provides another method for extracting image features, such as Figure 2 As shown, the method includes:
[0057] 201. Obtain the image to be processed in the actual business scenario.
[0058] Specifically, the image database contains a large number of images that have been mosaiced or damaged in actual business scenarios. In order to obtain the image feature vector corresponding to the image to be processed, the image to be processed can be obtained from the image database, and the image to be processed can be segmented to obtain multiple sub-images corresponding to the image to be processed, and a clear target sub-image can be determined among the multiple sub-images. Thereafter, the target sub-image is input into a preset image feature extraction model for feature extraction to obtain a first image feature vector corresponding to the target sub-image, and based on the first image feature vector and the corresponding position information of the multiple sub-images in the image to be processed, the second image feature vector corresponding to the remaining sub-images in the multiple sub-images is determined, and finally, based on the first image feature vector and the second image feature vector, the third image feature vector corresponding to the image to be processed is determined.
[0059] 202. Divide the image to be processed into multiple sub-images, and determine a clear target sub-image from the multiple sub-images, wherein the clear target sub-image is an image that is not damaged, not mosaiced, and has a pixel value greater than a preset pixel value.
[0060] Specifically, first determine the number of segmentations, and then segment the image to be processed based on the number of segmentations. For example, if the number of segmentations is determined to be 25, the image to be processed can be divided into 5 parts horizontally and then divided into 5 parts vertically. After the image to be processed is cut according to the number of segmentations, a plurality of sub-images can be obtained, and a fresh target sub-image is determined among the plurality of sub-images. The target sub-image is then input into a preset image feature extraction model for feature extraction to obtain a first image feature vector corresponding to the target sub-image. At the same time, based on the first image feature vector and the position information of the plurality of sub-images in the image to be processed, the second image feature vector corresponding to the remaining sub-images in the plurality of sub-images is determined. Finally, based on the first image feature vector and the second image feature vector, the third image feature vector corresponding to the image to be processed is determined.
[0061] 203. Determine a pixel matrix corresponding to the target sub-picture.
[0062] Specifically, the target sub-image is converted into a pixel matrix. If the image to be processed is a color image, the target sub-image is converted into an RGB pixel matrix of a×b×c, wherein a is the length of the matrix, b is the width of the matrix, and c is the number of channels of the matrix. The pixel value at each position in the pixel matrix is a value between 0 and 255. In order to reduce the amount of calculation of the model, each pixel value needs to be divided by 255, that is, the pixel matrix is normalized so that the size of each pixel value is between 0 and 1, so that the normalized pixel matrix corresponding to the target sub-image can be obtained, and based on the normalized pixel matrix, the fourth image feature vector corresponding to the target sub-image is determined, and then the fourth image feature vector is input into a preset image feature extraction model for feature extraction to obtain the first image feature vector corresponding to the target sub-image. At the same time, based on the first image feature vector and the position information of the multiple sub-images in the image to be processed, the second image feature vectors corresponding to the remaining sub-images in the multiple sub-images are determined, and finally based on the first image feature vector and the second image feature vector, the third image feature vector corresponding to the image to be processed is determined.
[0063] 204. Transversely splice the pixels in each row in the pixel matrix to obtain a fourth image feature vector corresponding to the target sub-image.
[0064] Specifically, after determining the pixel matrix corresponding to the target sub-image, each row of pixels in the pixel matrix is horizontally spliced using the reshape function to obtain a feature vector of the first preset dimension corresponding to the target sub-image. For example, if the dimension of the normalized pixel matrix is P×P×C, where C represents the number of channels of the pixel matrix corresponding to the target sub-image, the reshape function is used to convert the matrix of dimension P×P×C into a vector of dimension P2C. This method can be used to obtain a feature vector of the first preset dimension corresponding to the target sub-image. Furthermore, in order to meet the accuracy of feature extraction by the preset feature extraction model, it is also necessary to convert the feature vector of the first preset dimension into a feature vector of the second preset dimension, that is, the fourth image feature vector. The specific conversion formula is as follows:
[0065] Y=WX
[0066] Among them, X is a feature vector of a first preset dimension, W is a matrix of [c, X], c represents a value of a second preset dimension, and through the multiplication operation between the above matrix and the vector, the feature vector of the first preset dimension can be converted into a feature vector of a second preset dimension, that is, a fourth image feature vector. In this application, in order to use a preset image feature extraction model to extract the first image feature vector corresponding to the target sub-image, the second preset dimension can be set to 1024, and then the feature vector of the first preset dimension corresponding to the target sub-image is finally converted into a fourth image feature vector of 1024 dimensions, and the fourth image feature vector corresponding to the target sub-image is input into the preset image feature extraction model for feature extraction to obtain the first image feature vector corresponding to the target sub-image, and based on the first image feature vector and the position information of the multiple sub-images in the image to be processed, the second image feature vectors corresponding to the remaining sub-images in the multiple sub-images are determined, and finally based on the first image feature vector and the second image feature vector, the third image feature vector corresponding to the image to be processed is determined.
[0067] 205. Input the fourth picture feature vector into the preset picture feature extraction model to perform feature extraction, and obtain a first picture feature vector corresponding to the target sub-picture.
[0068] Among them, the preset image feature extraction model can be specifically a preset encoder, which includes an attention layer and a feedforward neural network layer. The output of the attention layer is used as the input of the feedforward neural network layer. The attention layer includes multiple attention subspaces, that is, the attention layer in the present application adopts a multi-head attention mechanism. Furthermore, in order to improve the accuracy of image feature extraction, 24 preset encoders connected in series are used in the present application to extract the features of the target sub-image. Each encoder is connected end to end, and the output of the previous encoder is used as the input of the next encoder to extract the feature vector in the target sub-image.
[0069] For an embodiment of the present invention, before the target sub-picture is input into a preset encoder, in order to improve the accuracy of feature vector extraction by the preset encoder, it is necessary to pre-train the preset encoder. Based on this, the method includes: obtaining a sample picture in an actual business scenario, and an actual sample picture feature vector corresponding to the sample picture; dividing the sample picture into multiple sample sub-pictures, and determining a clear target sample sub-picture from the multiple sample sub-pictures; inputting the target sample sub-picture into an initial picture feature extraction model for feature extraction to obtain a first sample picture feature vector corresponding to the target sample sub-picture; determining a second sample picture feature vector corresponding to the sample picture based on the first sample picture feature vector and the position information of the multiple sample sub-pictures in the sample picture respectively; constructing a loss function corresponding to the initial picture feature extraction model based on the actual sample picture feature vector corresponding to the sample picture and the second sample picture feature vector; training the initial picture feature extraction model based on the loss function to construct the preset picture feature extraction model.
[0070] Specifically, firstly, a sample image in an actual business scenario is obtained, and the sample image is segmented to obtain a plurality of sample sub-images. A clear target sample sub-image is determined among the plurality of sample sub-images, and the clear target sample sub-image is input into an initial image feature extraction model for feature extraction to obtain a first sample image feature vector corresponding to the target sample sub-image. Then, based on the first sample image feature vector and the position information of the plurality of sample sub-images in the sample image, a third sample image feature vector corresponding to the remaining sample sub-images in the plurality of sample sub-images is determined. Finally, based on the first sample image feature vector and the third sample image feature vector, a second sample image feature vector corresponding to the sample image is determined. Based on the actual sample image feature vector and the second sample image feature vector corresponding to the sample image, a loss function corresponding to the initial image feature extraction model is constructed. The specific method for constructing the loss function includes: calculating the differences between each vector at the same position in the actual sample image feature vector and the second sample image feature vector; and constructing the loss function corresponding to the initial image feature extraction model by calculating the sum of the squares of each vector difference.
[0071] Specifically, after determining the actual sample image feature vector and the second sample image feature vector corresponding to the sample image, calculate each vector difference at the same position in the actual sample image feature vector and the second sample image feature vector, then square and sum the vector differences to obtain, that is, calculate the root mean square error corresponding to the initial image feature extraction model, and by calculating the root mean square error, construct the loss function corresponding to the initial image feature extraction model. The specific formula for calculating the root mean square error is as follows:
[0072]
[0073] Among them, Z represents the root mean square error, u1, u2....ur represent each vector in the second sample image feature vector, v1, v2....vr represent each vector in the actual sample image feature vector, and r represents the number of vectors corresponding to the actual sample image feature vector. After constructing the loss function corresponding to the initial image feature extraction model according to the above formula, the initial image feature extraction model is trained based on the loss function until the minimum loss function value appears, and based on the model parameters corresponding to the minimum loss function value, the preset image feature extraction model, that is, the preset encoder in the embodiment of the present invention, is constructed.
[0074] Furthermore, after obtaining a preset encoder with better performance through training, it is necessary to extract the first picture feature vector corresponding to the target sub-picture based on the encoder. Based on this, step 205 specifically includes: inputting the fourth picture feature vector into the different attention subspaces in the attention layer for feature extraction to obtain the fifth picture feature vector of the target sub-picture in the different attention subspaces; multiplying the fifth picture feature vector of the target sub-picture in the different attention subspaces by the weights corresponding to the different attention subspaces and summing them to obtain the attention layer output vector corresponding to the target sub-picture; adding the attention layer output vector and the fourth picture feature vector to obtain the sixth picture feature vector corresponding to the target sub-picture; inputting the sixth picture feature vector into the feedforward neural network layer for feature extraction to obtain the first picture feature vector corresponding to the target sub-picture.
[0075] Specifically, the fourth image feature vector is input into different attention subspaces in the attention layer of the first encoder for feature extraction to obtain a fifth image feature vector of the target sub-image in the different attention subspaces, wherein the specific process of obtaining the fifth image feature vector of the target sub-image in the different attention subspaces is to determine the query vector, key vector and value vector of the target sub-image in the different attention subspaces according to the fourth image feature vector, and multiply the query vector of the first target sub-image in the target sub-image in the different attention subspaces with the key vector of the target sub-image in the different attention subspaces to obtain the attention score of the target sub-image for the first target sub-image in the different attention subspaces, and at the same time, multiply the attention score of the target sub-image in different attention subspaces and the key vector and sum them to obtain the fifth image feature vector of the first target sub-image in the different attention space, wherein the first target sub-image can be any image in the target sub-image, thereby obtaining the fifth image feature vector corresponding to the target sub-image.
[0076] Furthermore, the fifth image feature vector of the target sub-image in the different attention subspaces is multiplied and summed with the weights in the different attention subspaces to obtain the output vector of the attention layer in the first encoder. At the same time, the output vector of the attention layer is added to the residual of the fourth image feature vector to obtain the sixth image feature vector corresponding to the target sub-image. The sixth image feature vector is then input into the feedforward neural network layer to obtain the output vector of the feedforward neural network layer. The output vector of the feedforward neural network layer is then added to the input vector of the feedforward neural network layer, i.e., the residual of the sixth image feature vector, to obtain the output vector of the first encoder. Because in the embodiment of the present invention, The 24 encoders are connected in series, so the output vector of the first encoder is input into the second encoder for feature extraction to obtain the output vector of the second encoder, and the output vector of the previous encoder is used as the input vector of the next encoder, and finally the output vector of the last encoder is determined as the first picture feature vector corresponding to the target sub-picture, and based on the first picture feature vector and the position information of multiple sub-pictures in the picture to be processed, the second picture feature vector corresponding to the remaining sub-pictures in the multiple sub-pictures is determined, and finally based on the first picture feature vector and the second picture feature vector, the third picture feature vector corresponding to the picture to be processed is determined.
[0077] 206. Determine, based on the first picture feature vector and the position information of the multiple sub-pictures in the picture to be processed, a second picture feature vector corresponding to the remaining sub-pictures after removing the target sub-picture from the multiple sub-pictures.
[0078] For the embodiment of the present invention, after determining the first picture feature vector corresponding to the target sub-picture, it is necessary to determine the second picture feature vector corresponding to the remaining sub-pictures in the multiple sub-pictures based on the first picture feature vector and the position information of the multiple sub-pictures in the picture to be processed. Based on this, step 206 specifically includes: inputting the first picture feature vector and the position information of the multiple sub-pictures in the picture to be processed into a preset decoder to extract the feature vector, and obtaining the second picture feature vector corresponding to the remaining sub-pictures in the multiple sub-pictures after removing the target sub-picture.
[0079] Specifically, the preset decoder has the same structure as the preset encoder. An embodiment of the present invention uses 6 preset decoders connected in series end to end, and inputs the first picture feature vector and the position information of the multiple sub-pictures in the picture to be processed into the first preset decoder for feature extraction to obtain the output vector of the first preset decoder, and inputs the output vector of the first preset decoder into the second preset decoder for feature extraction, so that the output vector of the previous decoder is used as the input vector of the next decoder, and the output vector of the last decoder is determined as the second picture feature vector corresponding to the remaining sub-pictures in the multiple sub-pictures, and finally, based on the first picture feature vector and the second picture feature vector, the third picture feature vector corresponding to the picture to be processed is determined.
[0080] 207. Determine a third picture feature vector corresponding to the picture to be processed based on the first picture feature vector and the second picture feature vector.
[0081] For this embodiment of the present invention, in order to determine the third picture feature vector corresponding to the picture to be processed, step 207 specifically includes: determining a first weight coefficient corresponding to the first picture feature vector and a second weight coefficient corresponding to the second picture feature vector; based on the first weight coefficient and the second weight coefficient, adding the first picture feature vector to the second picture feature vector to obtain the third picture feature vector corresponding to the picture to be processed.
[0082] Specifically, first, a first weight coefficient corresponding to the first picture feature vector and a second weight coefficient corresponding to the second picture feature vector are respectively determined, and the first weight coefficient and the first picture feature vector are multiplied to obtain a first product. At the same time, the second weight coefficient and the second picture feature vector are multiplied to obtain a second product. Finally, the first product and the second product are added to obtain a third picture feature vector corresponding to the picture to be processed.
[0083] According to another image feature extraction method provided by the present invention, compared with the current method of using a clear and complete image to build a feature extraction model and extracting image features based on the built feature extraction model, the present invention obtains a to-be-processed image in an actual business scenario; divides the to-be-processed image into multiple sub-images, and determines a clear target sub-image from the multiple sub-images, wherein the clear target sub-image is an image that is not damaged, not mosaiced, and has a pixel value greater than a preset pixel value; inputs the target sub-image into a preset image feature extraction model for feature extraction, and obtains a first image feature vector corresponding to the target sub-image; and determines the remaining sub-images after removing the target sub-image from the multiple sub-images based on the first image feature vector and the position information of the multiple sub-images in the to-be-processed image. a second picture feature vector corresponding to the slice; based on the first picture feature vector and the second picture feature vector, determining the third picture feature vector corresponding to the picture to be processed, thereby segmenting the picture to be processed, determining a clear target sub-picture in the picture to be processed, and extracting the first picture feature vector corresponding to the target sub-picture, and at the same time determining the second picture feature vectors corresponding to the remaining sub-pictures in the multiple sub-pictures based on the first picture feature vector and the position information of the multiple sub-pictures in the picture to be processed, and finally determining the third picture feature vector corresponding to the picture to be processed based on the first picture feature vector and the second picture feature vector, which can avoid the situation where the feature extraction model constructed by using a clear and complete picture extracts features for unclear pictures, thereby improving the accuracy of picture feature extraction.
[0084] Further, as Figure 1 The specific implementation of the present invention provides a device for extracting image features, such as Figure 3 As shown, the device includes: an acquisition unit 31, a segmentation unit 32, an extraction unit 33, a first determination unit 34 and a second determination unit 35.
[0085] The acquisition unit 31 may be used as an acquisition unit to acquire a to-be-processed picture in an actual business scenario.
[0086] The segmentation unit 32 can be used to segment the image to be processed into multiple sub-images, and determine a clear target sub-image from the multiple sub-images, wherein the clear target sub-image is an image that is not damaged, not mosaiced, and has a pixel value greater than a preset pixel value.
[0087] The extraction unit 33 may be used to input the target sub-image into a preset image feature extraction model to perform feature extraction, and obtain a first image feature vector corresponding to the target sub-image.
[0088] The first determination unit 34 may be configured to determine, based on the first image feature vector and position information of the plurality of sub-images in the image to be processed, a second image feature vector corresponding to the remaining sub-images after removing the target sub-image from the plurality of sub-images.
[0089] The second determining unit 35 may be configured to determine a third picture feature vector corresponding to the picture to be processed based on the first picture feature vector and the second picture feature vector.
[0090] In a specific application scenario, in order to input the target sub-image into a preset image feature extraction model for feature extraction, a first image feature vector corresponding to the target sub-image is obtained, such as Figure 4 As shown, the extraction unit 33 includes a determination module 331 , a splicing module 332 and an extraction module 333 .
[0091] The determination module 331 may be used to determine a pixel matrix corresponding to the target sub-picture.
[0092] The stitching module 332 may be used to stitch the rows of pixels in the pixel matrix horizontally to obtain a fourth image feature vector corresponding to the target sub-image.
[0093] The extraction module 333 may be used to input the fourth image feature vector into the preset image feature extraction model for feature extraction to obtain the first image feature vector corresponding to the target sub-image.
[0094] In a specific application scenario, in order to input the fourth image feature vector into the preset image feature extraction model for feature extraction and obtain the first image feature vector corresponding to the target sub-image, the extraction module 333 includes an extraction sub-module, a summation sub-module, and an addition sub-module.
[0095] The extraction submodule can be used to input the fourth image feature vector into different attention subspaces in the attention layer for feature extraction, and obtain the fifth image feature vector of the target sub-image in the different attention subspaces.
[0096] The summation submodule can be used to multiply and sum the fifth image feature vector of the target sub-image in the different attention subspaces with the weights corresponding to the different attention subspaces to obtain the attention layer output vector corresponding to the target sub-image.
[0097] The addition submodule can be used to add the attention layer output vector and the fourth image feature vector to obtain a sixth image feature vector corresponding to the target sub-image.
[0098] The extraction submodule can be specifically used to input the sixth image feature vector into the feedforward neural network layer for feature extraction to obtain the first image feature vector corresponding to the target sub-image.
[0099] In a specific application scenario, in order to train and construct the preset image feature extraction model, the device also includes a construction unit 36.
[0100] The acquisition unit 31 may also be used to acquire sample images in actual business scenarios and actual sample image feature vectors corresponding to the sample images.
[0101] The segmentation unit 32 may also be configured to segment the sample image into a plurality of sample sub-images, and determine a clear target sample sub-image from the plurality of sample sub-images.
[0102] The extraction unit 33 may also be used to input the target sample sub-image into an initial image feature extraction model to perform feature extraction, and obtain a first sample image feature vector corresponding to the target sample sub-image.
[0103] The second determining unit 35 may also be configured to determine a second sample picture feature vector corresponding to the sample picture based on the first sample picture feature vector and position information of the plurality of sample sub-pictures in the sample picture.
[0104] The construction unit 36 may be configured to construct a loss function corresponding to the initial image feature extraction model based on the actual sample image feature vector corresponding to the sample image and the second sample image feature vector.
[0105] The construction unit 36 may be specifically configured to train the initial image feature extraction model based on the loss function to construct the preset image feature extraction model.
[0106] In a specific application scenario, in order to construct the loss function corresponding to the initial image feature extraction model, the construction unit 36 includes a calculation module 361 and a construction module 362 .
[0107] The calculation module 361 may be used to calculate each vector difference at the same position between the actual sample image feature vector and the second sample image feature vector.
[0108] The construction module 362 can be used to construct a loss function corresponding to the initial image feature extraction model by calculating the sum of squares of the vector differences.
[0109] In a specific application scenario, in order to determine the second image feature vector corresponding to the remaining sub-images in the multiple sub-images based on the first image feature vector and the position information of the multiple sub-images in the image to be processed, the first determination unit 34 can be specifically used to input the first image feature vector and the position information of the multiple sub-images in the image to be processed into a preset decoder to extract the feature vector, so as to obtain the second image feature vector corresponding to the remaining sub-images in the multiple sub-images.
[0110] In a specific application scenario, in order to determine the third image feature vector corresponding to the image to be processed based on the first image feature vector and the second image feature vector, the second determination unit 35 can be specifically used to determine the first weight coefficient corresponding to the first image feature vector and the second weight coefficient corresponding to the second image feature vector; based on the first weight coefficient and the second weight coefficient, the first image feature vector is added to the second image feature vector to obtain the third image feature vector corresponding to the image to be processed.
[0111] It should be noted that for other corresponding descriptions of the functional modules involved in the image feature extraction device provided in the embodiment of the present invention, reference can be made to Figure 1 The corresponding description of the method shown will not be repeated here.
[0112] Based on the above Figure 1 The method shown, accordingly, an embodiment of the present invention also provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, the following steps are implemented: obtaining a picture to be processed in an actual business scenario; dividing the picture to be processed into multiple sub-pictures, and determining a clear target sub-picture from the multiple sub-pictures, wherein the clear target sub-picture is a picture that is not damaged, not mosaiced, and has a pixel value greater than a preset pixel value; inputting the target sub-picture into a preset picture feature extraction model for feature extraction, and obtaining a first picture feature vector corresponding to the target sub-picture; based on the first picture feature vector and the position information of the multiple sub-pictures in the picture to be processed, determining a second picture feature vector corresponding to the remaining sub-pictures after removing the target sub-picture from the multiple sub-pictures; based on the first picture feature vector and the second picture feature vector, determining a third picture feature vector corresponding to the picture to be processed.
[0113] Based on the above Figure 1 The method shown and Figure 3 The embodiment of the device shown in the figure, the embodiment of the present invention also provides a physical structure diagram of a computer device, such as Figure 5As shown, the computer device includes: a processor 41, a memory 42, and a computer program stored in the memory 42 and executable on the processor, wherein the memory 42 and the processor 41 are both arranged on a bus 43, and the processor 41 implements the following steps when executing the program: obtaining a picture to be processed in an actual business scenario; dividing the picture to be processed into a plurality of sub-pictures, and determining a clear target sub-picture from the plurality of sub-pictures, wherein the clear target sub-picture is a picture that is not damaged, not mosaiced, and has a pixel value greater than a preset pixel value; inputting the target sub-picture into a preset picture feature extraction model for feature extraction, and obtaining a first picture feature vector corresponding to the target sub-picture; determining a second picture feature vector corresponding to the remaining sub-pictures after removing the target sub-picture from the plurality of sub-pictures based on the first picture feature vector and the position information of the plurality of sub-pictures in the picture to be processed; and determining a third picture feature vector corresponding to the picture to be processed based on the first picture feature vector and the second picture feature vector.
[0114] Through the technical solution of the present invention, the present invention obtains a picture to be processed in an actual business scenario; divides the picture to be processed into multiple sub-pictures, and determines a clear target sub-picture from the multiple sub-pictures, wherein the clear target sub-picture is a picture that is not damaged, not mosaiced, and has a pixel value greater than a preset pixel value; inputs the target sub-picture into a preset picture feature extraction model for feature extraction to obtain a first picture feature vector corresponding to the target sub-picture; based on the first picture feature vector and the position information of the multiple sub-pictures in the picture to be processed, determines the second picture feature vector corresponding to the remaining sub-pictures in the multiple sub-pictures; based on the first picture feature vector and the second picture feature vector, determines the The third picture feature vector corresponding to the picture to be processed is obtained, thereby segmenting the picture to be processed, determining a clear target sub-picture in the picture to be processed, and extracting the first picture feature vector corresponding to the target sub-picture, and at the same time determining the second picture feature vector corresponding to the remaining sub-pictures after removing the target sub-picture from the multiple sub-pictures based on the first picture feature vector and the position information of the multiple sub-pictures in the picture to be processed, and finally determining the third picture feature vector corresponding to the picture to be processed based on the first picture feature vector and the second picture feature vector, which can avoid the situation where the feature extraction model constructed by using a clear and complete picture is used to extract features from an unclear picture, thereby improving the accuracy of picture feature extraction.
[0115] Obviously, those skilled in the art should understand that the above modules or steps of the present invention can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, and optionally, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order than here, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.
[0116] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for extracting image features, characterized in that: include: Get the images to be processed in actual business scenarios; Divide the image to be processed into multiple sub-images, and determine a clear target sub-image from the multiple sub-images, wherein the clear target sub-image is an image that is not damaged, not mosaiced, and has a pixel value greater than a preset pixel value; Inputting the target sub-image into a preset image feature extraction model to perform feature extraction, and obtaining a first image feature vector corresponding to the target sub-image; Based on the first picture feature vector and the position information of the plurality of sub-pictures in the picture to be processed, determining a second picture feature vector corresponding to the remaining sub-pictures after removing the target sub-picture from the plurality of sub-pictures; Determine a third picture feature vector corresponding to the picture to be processed based on the first picture feature vector and the second picture feature vector; The step of determining a third picture feature vector corresponding to the picture to be processed based on the first picture feature vector and the second picture feature vector includes: Determine a first weight coefficient corresponding to the first picture feature vector and a second weight coefficient corresponding to the second picture feature vector; Based on the first weight coefficient and the second weight coefficient, the first picture feature vector is added to the second picture feature vector to obtain a third picture feature vector corresponding to the picture to be processed.
2. The method according to claim 1, characterized in that The step of inputting the target sub-picture into a preset picture feature extraction model to perform feature extraction to obtain a first picture feature vector corresponding to the target sub-picture includes: Determine a pixel matrix corresponding to the target sub-picture; Transversely splicing the pixels in each row in the pixel matrix to obtain a fourth picture feature vector corresponding to the target sub-picture; The fourth image feature vector is input into the preset image feature extraction model for feature extraction to obtain the first image feature vector corresponding to the target sub-image.
3. The method according to claim 2, characterized in that The preset picture feature extraction model is a preset encoder, the preset encoder includes an attention layer and a feedforward neural network layer, and the fourth picture feature vector is input into the preset picture feature extraction model for feature extraction to obtain the first picture feature vector corresponding to the target sub-picture, including: Inputting the fourth picture feature vector into different attention subspaces in the attention layer for feature extraction, to obtain a fifth picture feature vector of the target sub-picture in the different attention subspaces; Multiplying the fifth picture feature vector of the target sub-picture in the different attention sub-spaces by the weights corresponding to the different attention sub-spaces and summing them up to obtain an attention layer output vector corresponding to the target sub-picture; Adding the attention layer output vector and the fourth picture feature vector to obtain a sixth picture feature vector corresponding to the target sub-picture; The sixth picture feature vector is input into the feed-forward neural network layer for feature extraction to obtain the first picture feature vector corresponding to the target sub-picture.
4. The method according to claim 1, characterized in that: Before inputting the target sub-picture into a preset picture feature extraction model to extract features and obtain a first picture feature vector corresponding to the target sub-picture, the method further includes: Obtaining sample images in actual business scenarios and actual sample image feature vectors corresponding to the sample images; Splitting the sample image into a plurality of sample sub-images, and determining a clear target sample sub-image from the plurality of sample sub-images; Inputting the target sample sub-image into an initial image feature extraction model to perform feature extraction, and obtaining a first sample image feature vector corresponding to the target sample sub-image; Determine a second sample picture feature vector corresponding to the sample picture based on the first sample picture feature vector and position information of the plurality of sample sub-pictures in the sample picture respectively; Based on the actual sample picture feature vector corresponding to the sample picture and the second sample picture feature vector, constructing a loss function corresponding to the initial picture feature extraction model; The initial image feature extraction model is trained based on the loss function to construct the preset image feature extraction model.
5. The method according to claim 4, characterized in that The constructing a loss function corresponding to the initial picture feature extraction model based on the actual sample picture feature vector corresponding to the sample picture and the second sample picture feature vector includes: Calculating each vector difference at the same position between the actual sample image feature vector and the second sample image feature vector; By calculating the sum of squares of the vector differences, a loss function corresponding to the initial image feature extraction model is constructed.
6. The method according to claim 1, characterized in that The determining, based on the first picture feature vector and the position information of the plurality of sub-pictures in the picture to be processed, a second picture feature vector corresponding to the remaining sub-pictures after removing the target sub-picture from the plurality of sub-pictures comprises: The first picture feature vector and the position information of the multiple sub-pictures in the picture to be processed are respectively input into a preset decoder to extract the feature vector, and a second picture feature vector corresponding to the remaining sub-pictures after removing the target sub-picture from the multiple sub-pictures is obtained.
7. A device for extracting image features, characterized in that: include: An acquisition unit, used to acquire the image to be processed in the actual business scenario; A segmentation unit, used to segment the to-be-processed picture into a plurality of sub-pictures, and determine a clear target sub-picture from the plurality of sub-pictures, wherein the clear target sub-picture is a picture that is not damaged, not mosaiced, and has a pixel value greater than a preset pixel value; An extraction unit, configured to input the target sub-image into a preset image feature extraction model to perform feature extraction, and obtain a first image feature vector corresponding to the target sub-image; A first determining unit, configured to determine, based on the first picture feature vector and position information of the plurality of sub-pictures in the picture to be processed, a second picture feature vector corresponding to a remaining sub-picture after removing the target sub-picture from the plurality of sub-pictures; A second determining unit, configured to determine a third picture feature vector corresponding to the picture to be processed based on the first picture feature vector and the second picture feature vector; The second determination unit is used to determine a first weight coefficient corresponding to the first picture feature vector and a second weight coefficient corresponding to the second picture feature vector; based on the first weight coefficient and the second weight coefficient, the first picture feature vector is added to the second picture feature vector to obtain a third picture feature vector corresponding to the picture to be processed.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
