Image sentiment analysis method and device based on feature pyramid and attention mechanism

By introducing feature pyramid and attention mechanism into image sentiment analysis, integrating features at different levels and improving the quality of feature maps, it solves the problems of difficulty in weighing feature importance and information loss in traditional methods, and improves the accuracy of image sentiment analysis.

CN118537631APending Publication Date: 2024-08-23XIAMEN UNIV OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410580597.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-11
Publication Date
2024-08-23

AI Technical Summary

Technical Problem

In the process of feature extraction and sentiment analysis of traditional image sentiment analysis methods, it is difficult to weigh the importance of features at different levels. The convolution operation leads to the reduction of feature map size and the loss of local details and spatial location information, which affects the effect of sentiment analysis.

Method used

An image sentiment analysis method based on feature pyramid and attention mechanism is used, convolution preprocessing is performed through the ResNet50 model, and bottom-up and top-down processing are performed in combination with the feature pyramid module to generate multiple intermediate feature maps and perform attention on Channel and spatial attention processing are performed in the mechanism module to improve the quality and effectiveness of feature maps.

Benefits of technology

It effectively integrates features at different levels, improves the expression of semantic information, enhances the expressive ability of features, solves the problems of multi-scale information fusion and loss of local detail information, and improves the accuracy and effect of image emotion analysis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118537631A
    Figure CN118537631A
Patent Text Reader

Abstract

According to the image sentiment analysis method and device based on the feature pyramid and the attention mechanism, sentiment analysis is carried out on the image, information conveyed by the image can be deeply understood, and then the requirements of people in the aspects of visual content understanding and interaction are better met. The method is improved on the basis of a ResNet50 model, and a multi-scale feature map is integrated in the ResNet50 model by using a feature pyramid module, so that the accuracy of image sentiment analysis is improved. Attention to key features is enhanced by introducing a CBAM attention module. The model combines a channel attention mechanism and a space attention mechanism to capture important channel and space information in an image. In conclusion, the image sentiment analysis model based on the feature pyramid and the attention mechanism has certain accuracy and reliability in the aspects of feature extraction and sentiment analysis.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image sentiment analysis, and in particular to an image sentiment analysis method and device based on a feature pyramid and an attention mechanism. Background Art

[0002] With the rapid development and application of Internet technology, more and more people express their opinions, share emotions and record their lives on social media. A large number of pictures or emoticons are circulated among different users. Compared with text, images contain more abstract information, and the analysis of images has attracted close attention from researchers. In today's digital age, the explosive growth of image data has enabled people to easily capture, share and disseminate a large amount of image content. However, it is not enough to rely solely on the image itself for information understanding, because the emotional and emotional information contained in the image is crucial to fully understand and interpret the image.

[0003] Image sentiment analysis can help computer systems better understand the emotions expressed by people or scenes in images, thereby improving intelligent recognition capabilities and further promoting the development of human-computer interaction technology. Secondly, by analyzing users' emotional responses to advertising images, advertising design and marketing strategies can be optimized to improve advertising effectiveness and user appeal. In addition, image sentiment analysis can also be applied to the medical and health fields to assist in diagnosis and treatment, as well as to identify abnormal emotions in security monitoring and provide early warning of potential security risks. Therefore, in-depth research on image sentiment analysis will not only help enrich artificial intelligence application scenarios and improve the intelligence level of computer systems, but also bring more convenience and possibilities to people's lives and work.

[0004] Most traditional image sentiment analysis methods perform sentiment analysis by extracting underlying features such as color, texture, and shape of images. In recent years, due to the fact that deep neural networks can automatically extract image features, many researchers have turned to using convolutional neural networks to extract image sentiment features. There is a method that combines a spatial attention mechanism module with a fully convolutional network to extract image regional features, then uses a residual network to extract the overall image features, fuses the two features through dot products, and finally performs sentiment classification; a method that extracts image salient target features, face targets, and overall features through feature pyramids, improved VGG models, and fine-tuned convolutional neural networks, and classifies features according to different fusion strategies; and a method that adds a visual attention mechanism module to the CNN sentiment analysis framework for the first time, considers the salient targets of the image as sentiment prior knowledge, corrects the region of visual attention learning, and makes up for the deficiency of learning emotions from the self-attention mechanism.

[0005] Among them, the traditional deep convolutional neural network gradually extracts abstract features of the image from the bottom layer to the top layer. However, features at different levels may have different importance for sentiment analysis tasks. In addition, the convolution operation will cause the size of the feature map to gradually decrease, resulting in the loss of local details and spatial location information.

[0006] In view of this, this application is filed. Summary of the invention

[0007] The present invention provides an image sentiment analysis method and device based on feature pyramid and attention mechanism, which can at least partially improve the above problems.

[0008] To achieve the above object, the present invention adopts the following technical solutions: An image sentiment analysis method based on feature pyramid and attention mechanism, comprising: Obtain an input image to be analyzed, and use the ResNet50 module of the trained sentiment analysis model to perform convolution operation preprocessing on the input image to be analyzed; Inputting the preprocessed feature maps of different levels into the feature pyramid module of the sentiment analysis model, performing bottom-up processing and top-down processing respectively, and generating multiple intermediate feature maps; The intermediate feature map is used as input and transmitted to the attention mechanism module of the sentiment analysis model, and is first processed by the channel attention mechanism and then by the spatial attention mechanism to obtain a processed feature map; According to the processed feature map, an image sentiment analysis result corresponding to the input image to be analyzed is obtained.

[0009] Preferably, before using the ResNet50 module of the trained sentiment analysis model to perform convolution operation preprocessing on the input image to be analyzed, it also includes: Obtain a traditional ResNet50 model, and combine the feature pyramid structure and the attention mechanism structure on the basis of the ResNet50 model as a basic model; The basic model is pre-trained using a preset ImageNet dataset to obtain a trained sentiment analysis model, wherein the sentiment analysis model consists of a ResNet50 module, a feature pyramid module and an attention mechanism structure module, the ResNet50 module consists of a convolutional layer conv1, a convolutional layer conv2, a convolutional layer conv3, a convolutional layer conv4, a convolutional layer conv5, and repeated residual blocks in the convolutional layer.

[0010] Preferably, the pre-processed input image to be analyzed is input into the feature pyramid module of the sentiment analysis model, and bottom-up processing and top-down processing are performed respectively to generate multiple intermediate feature maps, specifically: When it is judged that it is in the bottom-up process, the input image to be analyzed passes through the convolution layer conv2, convolution layer conv3, convolution layer conv4, and convolution layer conv5 from the bottom to the top in the sentiment analysis model in sequence, and a plurality of feature maps {C2, C3, C4, C5} with different abstraction levels are obtained, wherein the feature map C2 contains low-level texture information, the feature map C5 contains high-level semantic information, and each of the feature maps represents the feature representation of the input image to be analyzed at different levels; When it is determined that it is in the top-down process, a 1x1 convolution operation is applied to the top-most feature map C5 to generate an intermediate feature map M5 with a higher level than the feature map C5; The intermediate feature map M5 is restored to the same size as the feature map C4 through upsampling operation, and the intermediate feature map M4 is obtained by 1x1 convolution operation; The intermediate feature map M4 is restored to the same size as the feature map C3 through upsampling operation, and the intermediate feature map M3 is obtained by 1x1 convolution operation. The calculation formula is:

[0011]

[0012]

[0013] A 3×3 convolution is added to each intermediate feature map, and the corresponding feature maps C2, C3, C4, and C5 generate a feature map set {P2, P3, P4, P5} of the same size.

[0014] Preferably, the intermediate feature map is used as input and transmitted to the attention mechanism module of the sentiment analysis model, and the channel attention mechanism is first processed, and then the spatial attention mechanism is processed to obtain the processed feature map, specifically: The input intermediate feature map is set as the input feature map F, and the input feature map F is input into the channel attention CAM module to obtain the channel attention map; Multiply the channel attention map by the input feature map F to obtain the first feature map ; Input the first feature map F' into the spatial attention SAM module to obtain a spatial attention map; The spatial attention map is combined with the first feature map Multiply to get the final input feature map , the calculation formula is:

[0015]

[0016]

[0017]

[0018]

[0019] in, Represented as element-by-element matrix multiplication, is the number of channels of the feature map, is the height of the feature map, is the width of the feature map.

[0020] Preferably, the input feature map F is input into the channel attention CAM module to obtain a channel attention map, specifically: Perform maximum pooling and average pooling on the input feature map F to obtain the channel attention maximum pooling result And channel attention average pooling results ; The channel attention is maximized pooled And channel attention average pooling results Input into the multi-layer perceptron MLP for learning and generate the corresponding one-dimensional channel attention features; The one-dimensional channel attention features are summed, and the summed results are mapped through the Sigmord activation function to update the channel attention feature vector , the calculation formula is:

[0021]

[0022] in, represents the Sigmord activation function, and Represent average pooling and maximum pooling respectively, and They are all weights of the multi-layer perceptron MLP; According to the channel attention feature vector , and obtain the channel attention map.

[0023] Preferably, the first feature map F' is input into the spatial attention SAM module to obtain a spatial attention map, specifically: Perform maximum pooling and average pooling on the input feature map F to obtain the spatial attention maximum pooling result And spatial attention average pooling results ; The spatial attention maximum pooling result And the spatial attention average pooling result Splicing is performed according to the channels to generate the splicing result, where the dimension of the input feature map F is ; The convolution operation is performed on the concatenated result to generate a convolution result, where the dimension of the input feature map F is ; The convolution result is processed by an activation function to generate a two-dimensional spatial attention feature. , the calculation formula is:

[0024]

[0025] in, represents a convolution operation with a filter size of 7×7, Indicates feature fusion; According to the two-dimensional spatial attention feature , and obtain the spatial attention map.

[0026] The present invention also provides an image sentiment analysis device based on feature pyramid and attention mechanism, which comprises: The ResNet unit is used to obtain an input image to be analyzed, and use the ResNet50 module of the trained sentiment analysis model to perform convolution operation preprocessing on the input image to be analyzed; A feature pyramid unit is used to input the preprocessed feature maps of different levels into the feature pyramid module of the sentiment analysis model, perform bottom-up processing and top-down processing respectively, and generate multiple intermediate feature maps; An attention mechanism unit, used to take the intermediate feature map as input, transmit it to the attention mechanism module of the sentiment analysis model, first perform channel attention mechanism processing, and then perform spatial attention mechanism processing to obtain a processed feature map; The analysis result generating unit is used to obtain the image sentiment analysis result corresponding to the input image to be analyzed according to the processed feature map.

[0027] Preferably, the feature pyramid unit is specifically used for: When it is judged that it is in the bottom-up process, the input image to be analyzed passes through the convolution layer conv2, convolution layer conv3, convolution layer conv4, and convolution layer conv5 from the bottom to the top in the sentiment analysis model in sequence, and a plurality of feature maps {C2, C3, C4, C5} with different abstraction levels are obtained, wherein the feature map C2 contains low-level texture information, the feature map C5 contains high-level semantic information, and each of the feature maps represents the feature representation of the input image to be analyzed at different levels; When it is determined that it is in the top-down process, a 1x1 convolution operation is applied to the top-most feature map C5 to generate an intermediate feature map M5 with a higher level than the feature map C5; The intermediate feature map M5 is restored to the same size as the feature map C4 through upsampling operation, and the intermediate feature map M4 is obtained by 1x1 convolution operation; The intermediate feature map M4 is restored to the same size as the feature map C3 through upsampling operation, and the intermediate feature map M3 is obtained by 1x1 convolution operation. The calculation formula is:

[0028]

[0029]

[0030] A 3×3 convolution is added to each intermediate feature map, and the corresponding feature maps C2, C3, C4, and C5 generate a feature map set {P2, P3, P4, P5} of the same size.

[0031] Preferably, the attention mechanism unit is specifically used for: The input intermediate feature map is set as the input feature map F, and the input feature map F is input into the channel attention CAM module to obtain the channel attention map; Multiply the channel attention map by the input feature map F to obtain the first feature map ; Input the first feature map F' into the spatial attention SAM module to obtain a spatial attention map; The spatial attention map is combined with the first feature map Multiply to get the final input feature map , the calculation formula is:

[0032]

[0033]

[0034]

[0035]

[0036] in, Represented as element-by-element matrix multiplication, is the number of channels of the feature map, is the height of the feature map, is the width of the feature map.

[0037] In summary, the image sentiment analysis method based on feature pyramid and attention mechanism proposes an image sentiment analysis model based on feature pyramid and attention mechanism, and adds feature pyramid and attention mechanism to the ResNet50 model. The feature pyramid network is used to integrate feature maps of different levels to improve the expression of semantic information, and solves the problem of multi-scale information fusion in target detection or semantic segmentation. The feature pyramid upsamples and fuses feature maps from different levels of ResNet to generate feature maps with higher resolution and richer semantic information. The channel attention mechanism and the spatial attention mechanism are applied to the feature pyramid to further improve the model's attention to features. The channel attention mechanism helps the model better capture the correlation information between different channels, thereby enhancing the expressiveness of features; the spatial attention mechanism helps the model focus more on important areas in space, improving the quality and effectiveness of feature maps. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 It is a flowchart of an image sentiment analysis method based on feature pyramid and attention mechanism provided by the first embodiment of the present invention; Figure 2 1. It is a schematic diagram of an image sentiment analysis model process of an image sentiment analysis method based on feature pyramid and attention mechanism provided by the first embodiment of the present invention; Figure 3 It is a schematic diagram of the basic structure of the residual block of the image sentiment analysis method based on the feature pyramid and attention mechanism provided by the first embodiment of the present invention; Figure 4 Schematic diagram of the network structure of the image sentiment analysis method based on feature pyramid and attention mechanism provided by the first embodiment of the present invention; Figure 5 1 is a schematic diagram of a feature pyramid network structure of an image sentiment analysis method based on a feature pyramid and an attention mechanism provided by a first embodiment of the present invention; Figure 6 It is a schematic diagram of a top-down intermediate feature calculation method of an image sentiment analysis method based on a feature pyramid and an attention mechanism provided by a first embodiment of the present invention; Figure 7Schematic diagram of a CBAM attention module of an image sentiment analysis method based on a feature pyramid and an attention mechanism provided by a first embodiment of the present invention; Figure 8 Schematic diagram of a channel attention mechanism model of an image sentiment analysis method based on a feature pyramid and an attention mechanism provided by the first embodiment of the present invention; Fig. 9 is a schematic diagram of a spatial attention mechanism module of an image sentiment analysis method based on a feature pyramid and an attention mechanism provided by a first embodiment of the present invention; Fig.10 is a diagram of an example of a data set provided by the first embodiment of the present invention; Fig.11 is a sample diagram of experimental results provided by the first embodiment of the present invention; Fig.12 This is a sample picture of the model evaluation provided by the first embodiment of the present invention. Fig.13 It is a module schematic diagram of an image sentiment analysis device based on feature pyramid and attention mechanism provided by the second embodiment of the present invention. DETAILED DESCRIPTION

[0039] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0040] As shown in the reference figure, the first embodiment of the present invention discloses an image sentiment analysis method based on a feature pyramid and an attention mechanism, which can be executed by an image sentiment analysis device (hereinafter referred to as an analysis device), and in particular, by one or more processors in the analysis device to implement the following method: S101, obtaining an input image to be analyzed, and performing convolution operation preprocessing on the input image to be analyzed using a ResNet50 module of a trained sentiment analysis model; Preferably, before using the ResNet50 module of the trained sentiment analysis model to perform convolution operation preprocessing on the input image to be analyzed, it also includes: Obtain a traditional ResNet50 model, and combine the feature pyramid structure and the attention mechanism structure on the basis of the ResNet50 model as a basic model; The basic model is pre-trained using a preset ImageNet dataset to obtain a trained sentiment analysis model, wherein the sentiment analysis model consists of a ResNet50 module, a feature pyramid module and an attention mechanism structure module, the ResNet50 module consists of a convolutional layer conv1, a convolutional layer conv2, a convolutional layer conv3, a convolutional layer conv4, a convolutional layer conv5, and repeated residual blocks in the convolutional layer.

[0041] In this embodiment, a sentiment analysis model based on a neural network is constructed. The ResNet50 model pre-trained on the ImageNet dataset is selected as the sentiment analysis model to verify the effectiveness of the model in this paper. The structure is as follows: Figure 2 As shown. The ResNet residual network model is a deep neural network model based on the idea of ​​cross-connection and with the residual block structure as the basic component. Its structure includes convolutional layer, residual block, global average pooling layer and fully connected layer. The network is composed of convolutional layer conv1, convolutional layer conv2, conv3, conv4, conv5 in sequence. The convolutional layer is composed of repeated residual blocks. ResNet avoids the degradation problem of deep convolutional neural network through residual connection in residual block and reduces the training time of the model. The structure of residual block is shown in Figure 3 As shown in the figure. After the input undergoes five convolution operations, it undergoes an average pooling operation, and finally the Softmax classifier outputs the probability of each category. Through the idea of ​​residual learning, ResNet50 can learn feature representation more deeply, avoid the gradient vanishing problem, and improve model performance and accuracy.

[0042] S102, inputting the preprocessed feature maps of different levels into the feature pyramid module of the sentiment analysis model, performing bottom-up processing and top-down processing respectively, and generating a plurality of intermediate feature maps; Specifically, step S102 includes: when it is determined that it is in a bottom-up process, the input image to be analyzed passes through the convolution layer conv2, convolution layer conv3, convolution layer conv4, and convolution layer conv5 from the bottom to the top in the sentiment analysis model in sequence, and obtains a plurality of feature maps {C2, C3, C4, C5} with different abstraction levels, wherein the feature map C2 contains low-level texture information, the feature map C5 contains high-level semantic information, and each of the feature maps represents the feature representation of the input image to be analyzed at different levels; When it is determined that it is in the top-down process, a 1x1 convolution operation is applied to the top-most feature map C5 to generate an intermediate feature map M5 with a higher level than the feature map C5; The intermediate feature map M5 is restored to the same size as the feature map C4 through upsampling operation, and the intermediate feature map M4 is obtained by 1x1 convolution operation; The intermediate feature map M4 is restored to the same size as the feature map C3 through upsampling operation, and the intermediate feature map M3 is obtained by 1x1 convolution operation. The calculation formula is:

[0043]

[0044]

[0045] A 3×3 convolution is added to each intermediate feature map, and the corresponding feature maps C2, C3, C4, and C5 generate a feature map set {P2, P3, P4, P5} of the same size.

[0046] Feature Pyramid Network (FPN) is a neural network structure used to handle multi-scale object detection and segmentation tasks. The design of this network is inspired by a key problem: how to effectively capture object information at different scales in deep neural networks to achieve accurate target detection and segmentation. FPN solves this problem by establishing a feature pyramid, which enables the network to understand images at different scales and improve the detection performance of multi-scale objects. FPN consists of two parts, bottom-up and top-down, as well as lateral connections. The structure is as follows Figure 5 shown.

[0047] In this embodiment, in the bottom-up process, after the input image passes through the convolutional layers from the bottom to the top (such as conv2, conv3, conv4, conv5), a series of feature map representations {C2, C3, C4, C5} with different levels of abstraction are obtained, where C2 contains lower-level texture information and C5 contains higher-level semantic information. These feature maps represent the feature representation of the image at different levels.

[0048] In the top-down process, a 1x1 convolution operation is first applied to the top-level feature map C5 to generate a higher-level intermediate feature map M5, which helps to enhance semantic information and reduce the number of channels. Then, M5 is restored to the same size as C4 through an upsampling operation, and a 1x1 convolution operation is used to obtain the intermediate feature map M4. The calculation process is as follows: Figure 6 Similarly, M4 is reduced to the same size as C3, and M3 is obtained. This process can be expressed as:

[0049]

[0050]

[0051] Finally, a 3×3 convolution is added to each intermediate feature map, and the corresponding {C2, C3, C4, C5} generates a feature map set of the same size {P2, P3, P4, P5}. By combining bottom-up and top-down feature transfer, FPN can effectively fuse information at different scales and improve the model's detection performance for multi-scale objects. In addition, lateral connections also help feature sharing and information flow between different levels, further enhancing the network's representation ability and accuracy. Overall, the introduction of FPN provides an effective and powerful method for solving multi-scale object detection and segmentation tasks, enabling the model to achieve better performance in complex scenarios.

[0052] S103, taking the intermediate feature map as input, transmitting it to the attention mechanism module of the sentiment analysis model, first performing channel attention mechanism processing, and then performing spatial attention mechanism processing, to obtain a processed feature map; Specifically, step S103 includes: setting the input intermediate feature map as the input feature map F, inputting the input feature map F into the channel attention CAM module, and obtaining a channel attention map; Multiply the channel attention map by the input feature map F to obtain the first feature map ; Input the first feature map F' into the spatial attention SAM module to obtain a spatial attention map; The spatial attention map is combined with the first feature map Multiply to get the final input feature map , the calculation formula is:

[0053]

[0054]

[0055]

[0056]

[0057] in, Represented as element-by-element matrix multiplication, is the number of channels of the feature map, is the height of the feature map, is the width of the feature map.

[0058] Preferably, the input feature map F is input into the channel attention CAM module to obtain a channel attention map, specifically: Perform maximum pooling and average pooling on the input feature map F to obtain the channel attention maximum pooling result And channel attention average pooling results ; The channel attention is maximized pooled And channel attention average pooling results Input into the multi-layer perceptron MLP for learning and generate the corresponding one-dimensional channel attention features; The one-dimensional channel attention features are summed, and the summed results are mapped through the Sigmord activation function to update the channel attention feature vector , the calculation formula is:

[0059]

[0060] in, represents the Sigmord activation function, and Represent average pooling and maximum pooling respectively, and They are all weights of the multi-layer perceptron MLP; According to the channel attention feature vector , and obtain the channel attention map.

[0061] Preferably, the first feature map F' is input into the spatial attention SAM module to obtain a spatial attention map, specifically: Perform maximum pooling and average pooling on the input feature map F to obtain the spatial attention maximum pooling result And spatial attention average pooling results ; The spatial attention maximum pooling result And the spatial attention average pooling result Splicing is performed according to the channels to generate the splicing result, where the dimension of the input feature map F is ; The convolution operation is performed on the concatenated result to generate a convolution result, where the dimension of the input feature map F is ; The convolution result is processed by an activation function to generate a two-dimensional spatial attention feature. , the calculation formula is:

[0062]

[0063] in, represents a convolution operation with a filter size of 7×7, Indicates feature fusion; According to the two-dimensional spatial attention feature , and obtain the spatial attention map.

[0064] The attention mechanism is a mechanism that imitates the working mode of human vision or auditory system, which is used to enhance the ability of neural network to process input data. By introducing the attention mechanism, the neural network can learn to assign different weights to different parts of the input data, so as to pay more attention to the information that is more important to the current task. The basic principle of the attention mechanism is to dynamically adjust the degree of attention of the model to these parts according to the different parts of the input data. Specifically, through the learned weight distribution, the model can assign different attention weights at different time steps or spatial positions to better capture the key information in the input data.

[0065] In this embodiment, the CBAM attention module is used, which combines the channel attention mechanism and the spatial attention mechanism to enhance the attention and learning ability of the deep neural network on feature representation. The model can simultaneously consider the feature correlation of the channel dimension and the spatial dimension, and improve the capture and representation of important features. The model structure is as follows Figure 7 As shown in Figure 2, a CBAM module consists of two sub-modules: the channel attention module (CAM) and the spatial attention module (SAM), which allocate attention in the channel and space dimensions respectively.

[0066] The input intermediate feature map is set to , which is input into the CAM module to obtain the channel attention map, and then Multiply to get Then Input into the SAM module to obtain the spatial attention map, which is combined with Multiply to get the final input feature map . The formula calculation can be expressed as:

[0067]

[0068]

[0069]

[0070]

[0071] in, is the intermediate feature map, Represented as element-by-element matrix multiplication, for Combined with the feature map obtained by the CAM module, Represents the feature map obtained by the SAM module, is the number of channels of the feature map, is the height of the feature map, is the width of the feature map.

[0072] In this embodiment, the role of the channel attention mechanism is to dynamically adjust the weights between channels according to the importance of each channel in the input feature map, so that the network can better capture the key features of the data. The structure of the channel attention mechanism is as follows Figure 8 As shown in Figure 2, when calculating the channel attention feature, the input feature map is first subjected to maximum pooling and average pooling to obtain and , and then send the obtained maximum pooling and average pooling results to the multilayer perceptron (MLP) for learning, respectively generate the corresponding one-dimensional channel attention features, and finally sum the results output by the multilayer perceptron, and then process them through the mapping of the Sigmord function to obtain the final channel attention feature vector The calculation formula of channel attention feature can be expressed as:

[0073]

[0074] Where: represents the Sigmord activation function, and represents average pooling and maximum pooling, and is the weight of MLP.

[0075] In this embodiment, the spatial attention mechanism can enhance the model's modeling ability for spatial structured data, improve the model's performance and representation ability, and also help improve the model's interpretability and robustness. The structure of the spatial attention mechanism is as follows: Fig. 9 When calculating the spatial attention mechanism, we first perform maximum pooling and average pooling on the input feature map to obtain: and , then the results of maximum pooling and average pooling are concatenated according to the channel, and the dimension of the feature map is Finally, the convolution operation is performed on the concatenated result to obtain the feature map dimension , and then generate two-dimensional spatial attention features through activation function processing The calculation formula of spatial attention features can be expressed as:

[0076]

[0077] Where: represents the Sigmord activation function, represents a convolution operation with a filter size of 7×7, Indicates feature fusion.

[0078] S104, obtaining an image sentiment analysis result corresponding to the input image to be analyzed according to the processed feature map.

[0079] In this embodiment, the experimental environment is adopted: processor AMD Ryzen R9 7945HX, main frequency 2.50GHZ, the experiment is run based on Python3.9's deep learning framework Pytorch, the development tool is PyCharm, the GPU is NVIDIAGeForce RTX4060, and the video memory capacity is 8GB. The image sentiment analysis method based on feature pyramid and attention mechanism is analyzed.

[0080] The experimental data set comes from the image sentiment analysis data set annotated by AMT: Twitter I data set. The Twitter I data set is a two-category data set, including two categories of positive and negative emotions, and is classified by sentiment polarity annotation by five AMT employees. There are 769 images in the positive sentiment category and 500 images in the negative sentiment category. There are three types of sentiment polarity annotations for each image, namely "all agree", "at least 4 people agree", and "at least 3 people agree". The data set is randomly divided into 80% for training and 20% for testing. The data set example is shown in the figure below. Fig.10 shown.

[0081] The experimental evaluation index is the image sentiment classification accuracy (Accuracy, Acc). The classification accuracy indicates the ratio of the number of samples correctly predicted by the model to the total number of samples, that is, the number of correctly classified samples divided by the total number of samples. The expression is as follows:

[0082] Among them, Total is the total number of samples in the test set, and N is the number of samples with correct label prediction in the test set.

[0083] In order to prove that the model in the present invention is effective for image sentiment analysis tasks, in the training process, in order to prevent overfitting, the input image is randomly cropped in size and aspect ratio, then scaled to 224x224 pixels, and randomly flipped horizontally, so as to expand the data set, and the network is optimized using the stochastic gradient descent algorithm, the learning rate is set to 0.001, the batch size is set to 32, the model uses the L2 paradigm to prevent overfitting, and the weight decay is 0.0005. It is compared with some existing models to verify the effectiveness of the present invention: (1) PCNN: A CNN architecture for visual sentiment analysis. The model experiments with large-scale weakly labeled training data for learning, predicts visual sentiment labels through two convolutional layers and several fully connected layers, and uses progressive training strategies and domain transfer strategies to fine-tune the neural network.

[0084] (2) AlexNet: A deep convolutional neural network model. Compared with previous neural network models, AlexNet has a deeper and wider network structure. It contains 5 convolutional layers and 3 fully connected layers, a total of 8 layers, of which the 1st, 2nd and 5th layers are fully connected layers.

[0085] (3) VGG16: A classic deep convolutional neural network architecture consisting of 13 convolutional layers and 3 fully connected layers. It was first pre-trained on the ImageNet dataset and then fine-tuned using the emotional image dataset.

[0086] (4) ResNet50: A deep neural network architecture that is a variant of the residual network. The residual module is introduced to solve the problems of gradient vanishing and gradient exploding in deep neural networks through direct connections across layers. These direct connections allow information to be passed directly from one layer to subsequent layers, which helps alleviate the gradient vanishing problem during network training, making the network easier to optimize and allowing for training of deeper network structures.

[0087] The present invention uses accuracy as an indicator to measure the performance of the model. The accuracy results of each model on the data set are shown in Table 1. Fig.11 The correct and incorrectly classified examples using the proposed model are given. In the Twitter I dataset, the accuracy of the proposed model is slightly higher than that of other traditional models. This shows that the feature pyramid and attention mechanism are helpful in solving the loss of local details and spatial position information.

[0088] Table 1 Comparison of experimental results of different models

[0089] At the same time, in order to further evaluate the effectiveness of the proposed model, a comparative experiment was conducted with the traditional model ResNet50, which currently has better performance. During the evaluation process, some image samples with obvious emotional labels were selected, such as Fig.12 As shown in the figure. The subjective evaluation of these image samples has received extensive participation, and a total of 50 people from different ages, genders and backgrounds were invited. Including teenagers, adults and the elderly, as well as men and women, participated in the subjective evaluation. In order to ensure the accuracy and authority of the evaluation, a voting mechanism was adopted to allow more people to participate in the evaluation process, so as to obtain more objective and comprehensive results. This example shows that the model in this paper can correctly classify the image samples that the ResNet50 model cannot accurately classify. Through this comparative experiment, the effectiveness of the model of this invention in the image sentiment analysis task is further confirmed, which provides strong support for future related research.

[0090] Table 2. Image sentiment labeling voting table

[0091] In summary, the present invention improves on the traditional ResNet50 model. The network structure is as follows Figure 4 As shown in the figure. A feature pyramid structure is introduced to integrate feature maps from different stages and extract features of different scales. This helps the model better capture multi-scale information. Specifically, the feature pyramid module consists of a series of convolutional layers to extract features of different scales. It receives feature maps from different stages and converts them to the same number of output channels through convolution operations. Before the final output, a global average pooling layer is used to convert the feature map into a fixed-length feature vector. This helps to reduce the number of parameters and improve the generalization ability of the model. In addition, a channel attention mechanism is introduced after the output of the ResNet50 module. This mechanism obtains the importance weight of each channel through learning, thereby enhancing the information interaction and feature representation ability between different channels. Specifically, the channel attention module contains an average pooling layer and a maximum pooling layer, as well as two convolutional layers and a Sigmord activation function. The channel attention weight is obtained by performing average pooling and maximum pooling operations on the input feature map, and then processed by a series of convolutional layers and activation functions, and then the weight is limited to between 0 and 1 by the Sigmord function.

[0092] At the same time, the spatial attention mechanism is also introduced after the output of the ResNet50 module. This mechanism obtains the importance weight of each spatial position by learning, thereby enhancing the information attention and feature extraction capabilities between different spatial positions. Specifically, the spatial attention module contains a convolutional layer and a Sigmord activation function. It performs average pooling and maximum pooling operations on the input feature map and splices the two together. Then, it is processed through the convolutional layer and the Sigmord function to obtain the spatial attention weight. Similarly, the weight is limited to between 0 and 1.

[0093] In short, with the rapid development of social media such as Twitter and Weibo, image sentiment analysis has received more and more attention. The present invention proposes an image sentiment analysis model based on attention mechanism and feature pyramid. The attention mechanism is added to solve the problem of not being able to flexibly weight or adjust different tasks according to features at different levels. The feature pyramid network is introduced to solve the problem of not being able to effectively capture feature information at different scales, semantics and space. The deep feature map has high semantic features, and the shallow feature map contains multiple detail features. The feature map fused by the feature pyramid network contains both deep high semantic features and shallow detail features. The experimental results show that the model proposed by the present invention has certain effectiveness compared with the traditional model. In the future, in-depth research will be carried out in the study of sentiment classification of multimodal data such as images, text or speech, hoping to achieve a more comprehensive sentiment understanding effect.

[0094] See also Fig.13 The second embodiment of the present invention further provides an image sentiment analysis device based on feature pyramid and attention mechanism, which includes: ResNet unit 201, used to obtain an input image to be analyzed, and use the ResNet50 module of the trained sentiment analysis model to perform convolution operation preprocessing on the input image to be analyzed; A feature pyramid unit 202 is used to input the preprocessed feature graphs of different levels into the feature pyramid module of the sentiment analysis model, perform bottom-up processing and top-down processing respectively, and generate multiple intermediate feature graphs; An attention mechanism unit 203 is used to take the intermediate feature map as input and transmit it to the attention mechanism module of the sentiment analysis model, first perform channel attention mechanism processing, and then perform spatial attention mechanism processing to obtain a processed feature map; The analysis result generating unit 204 is used to obtain the image sentiment analysis result corresponding to the input image to be analyzed according to the processed feature map.

[0095] Preferably, the feature pyramid unit 202 is specifically used for: When it is judged that it is in the bottom-up process, the input image to be analyzed passes through the convolution layer conv2, convolution layer conv3, convolution layer conv4, and convolution layer conv5 from the bottom to the top in the sentiment analysis model in sequence, and a plurality of feature maps {C2, C3, C4, C5} with different abstraction levels are obtained, wherein the feature map C2 contains low-level texture information, the feature map C5 contains high-level semantic information, and each of the feature maps represents the feature representation of the input image to be analyzed at different levels; When it is determined that it is in the top-down process, a 1x1 convolution operation is applied to the top-most feature map C5 to generate an intermediate feature map M5 with a higher level than the feature map C5; The intermediate feature map M5 is restored to the same size as the feature map C4 through upsampling operation, and the intermediate feature map M4 is obtained by 1x1 convolution operation; The intermediate feature map M4 is restored to the same size as the feature map C3 through upsampling operation, and the intermediate feature map M3 is obtained by 1x1 convolution operation. The calculation formula is:

[0096]

[0097]

[0098] A 3×3 convolution is added to each intermediate feature map, and the corresponding feature maps C2, C3, C4, and C5 generate a feature map set {P2, P3, P4, P5} of the same size.

[0099] Preferably, the attention mechanism unit 203 is specifically used for: The input intermediate feature map is set as the input feature map F, and the input feature map F is input into the channel attention CAM module to obtain the channel attention map; Multiply the channel attention map by the input feature map F to obtain the first feature map ; Input the first feature map F' into the spatial attention SAM module to obtain a spatial attention map; The spatial attention map is combined with the first feature map Multiply to get the final input feature map , the calculation formula is:

[0100]

[0101]

[0102]

[0103]

[0104] in, Represented as element-by-element matrix multiplication, is the number of channels of the feature map, is the height of the feature map, is the width of the feature map.

[0105] The above is a preferred embodiment of the present invention. It should be pointed out that a person skilled in the art can make several improvements and modifications without departing from the principle of the present invention. These improvements and modifications are also considered to be within the scope of protection of the present invention.

Claims

1. An image sentiment analysis method based on feature pyramid and attention mechanism, characterized in that: include: Obtain an input image to be analyzed, and use the ResNet50 module of the trained sentiment analysis model to perform convolution operation preprocessing on the input image to be analyzed; Inputting the preprocessed feature maps of different levels into the feature pyramid module of the sentiment analysis model, performing bottom-up processing and top-down processing respectively, and generating multiple intermediate feature maps; The intermediate feature map is used as input and transmitted to the attention mechanism module of the sentiment analysis model, and is first processed by the channel attention mechanism and then by the spatial attention mechanism to obtain a processed feature map; According to the processed feature map, an image sentiment analysis result corresponding to the input image to be analyzed is obtained.

2. The image sentiment analysis method based on feature pyramid and attention mechanism according to claim 1, characterized in that: Before using the ResNet50 module of the trained sentiment analysis model to perform convolution operation preprocessing on the input image to be analyzed, the method further includes: Obtain a traditional ResNet50 model, and combine the feature pyramid structure and the attention mechanism structure on the basis of the ResNet50 model as a basic model; The basic model is pre-trained using a preset ImageNet dataset to obtain a trained sentiment analysis model, wherein the sentiment analysis model consists of a ResNet50 module, a feature pyramid module and an attention mechanism structure module, the ResNet50 module consists of a convolutional layer conv1, a convolutional layer conv2, a convolutional layer conv3, a convolutional layer conv4, a convolutional layer conv5, and repeated residual blocks in the convolutional layer.

3. The image sentiment analysis method based on feature pyramid and attention mechanism according to claim 1, characterized in that: The preprocessed feature maps of different levels are input into the feature pyramid module of the sentiment analysis model, and are processed bottom-up and top-down respectively to generate multiple intermediate feature maps, specifically: When it is judged that it is in the bottom-up process, the input image to be analyzed passes through the convolution layer conv2, convolution layer conv3, convolution layer conv4, and convolution layer conv5 from the bottom to the top in the sentiment analysis model in sequence, and a plurality of feature maps {C2, C3, C4, C5} with different abstraction levels are obtained, wherein the feature map C2 contains low-level texture information, the feature map C5 contains high-level semantic information, and each of the feature maps represents the feature representation of the input image to be analyzed at different levels; When it is determined that it is in the top-down process, a 1x1 convolution operation is applied to the top-most feature map C5 to generate an intermediate feature map M5 with a higher level than the feature map C5; The intermediate feature map M5 is restored to the same size as the feature map C4 through upsampling operation, and the intermediate feature map M4 is obtained by 1x1 convolution operation; The intermediate feature map M4 is restored to the same size as the feature map C3 through upsampling operation, and the intermediate feature map M3 is obtained by 1x1 convolution operation. The calculation formula is: A 3×3 convolution is added to each intermediate feature map, and the corresponding feature maps C2, C3, C4, and C5 generate a feature map set {P2, P3, P4, P5} of the same size.

4. The image sentiment analysis method based on feature pyramid and attention mechanism according to claim 1, characterized in that: The intermediate feature map is used as input and transmitted to the attention mechanism module of the sentiment analysis model. The channel attention mechanism is first processed, and then the spatial attention mechanism is processed to obtain the processed feature map, which is specifically: The input intermediate feature map is set as the input feature map F, and the input feature map F is input into the channel attention CAM module to obtain the channel attention map; Multiply the channel attention map by the input feature map F to obtain the first feature map ; Input the first feature map F' into the spatial attention SAM module to obtain a spatial attention map; The spatial attention map is combined with the first feature map Multiply to get the final input feature map , the calculation formula is: in, Represented as element-by-element matrix multiplication, is the number of channels of the feature map, is the height of the feature map, is the width of the feature map.

5. The image sentiment analysis method based on feature pyramid and attention mechanism according to claim 4 is characterized in that: Input the input feature map F into the channel attention CAM module to obtain the channel attention map, which is: Perform maximum pooling and average pooling on the input feature map F to obtain the channel attention maximum pooling result And channel attention average pooling results ; The channel attention is maximized pooled And channel attention average pooling results Input into the multi-layer perceptron MLP for learning and generate the corresponding one-dimensional channel attention features; The one-dimensional channel attention features are summed, and the summed results are mapped through the Sigmord activation function to update the channel attention feature vector , the calculation formula is: in, represents the Sigmord activation function, and Represent average pooling and maximum pooling respectively, and They are all weights of the multi-layer perceptron MLP; According to the channel attention feature vector , and obtain the channel attention map.

6. The image sentiment analysis method based on feature pyramid and attention mechanism according to claim 5, characterized in that: The first feature map F' is input into the spatial attention SAM module to obtain a spatial attention map, which is specifically: Perform maximum pooling and average pooling on the input feature map F to obtain the spatial attention maximum pooling result And spatial attention average pooling results ; The spatial attention maximum pooling result And the spatial attention average pooling result Splicing is performed according to the channels to generate the splicing result, where the dimension of the input feature map F is ; The convolution operation is performed on the concatenated result to generate a convolution result, where the dimension of the input feature map F is ; The convolution result is processed by an activation function to generate a two-dimensional spatial attention feature. , the calculation formula is: in, represents a convolution operation with a filter size of 7×7, Indicates feature fusion; According to the two-dimensional spatial attention feature , and obtain the spatial attention map.

7. An image sentiment analysis device based on feature pyramid and attention mechanism, characterized in that: include: The ResNet unit is used to obtain an input image to be analyzed, and use the ResNet50 module of the trained sentiment analysis model to perform convolution operation preprocessing on the input image to be analyzed; A feature pyramid unit is used to input the preprocessed feature maps of different levels into the feature pyramid module of the sentiment analysis model, perform bottom-up processing and top-down processing respectively, and generate multiple intermediate feature maps; An attention mechanism unit, used to take the intermediate feature map as input, transmit it to the attention mechanism module of the sentiment analysis model, first perform channel attention mechanism processing, and then perform spatial attention mechanism processing to obtain a processed feature map; The analysis result generating unit is used to obtain the image sentiment analysis result corresponding to the input image to be analyzed according to the processed feature map.

8. The image sentiment analysis device based on feature pyramid and attention mechanism according to claim 7, characterized in that: The feature pyramid unit is specifically used for: When it is judged that it is in the bottom-up process, the input image to be analyzed passes through the convolution layer conv2, convolution layer conv3, convolution layer conv4, and convolution layer conv5 from the bottom to the top in the sentiment analysis model in sequence, and a plurality of feature maps {C2, C3, C4, C5} with different abstraction levels are obtained, wherein the feature map C2 contains low-level texture information, the feature map C5 contains high-level semantic information, and each of the feature maps represents the feature representation of the input image to be analyzed at different levels; When it is determined that it is in the top-down process, a 1x1 convolution operation is applied to the top-most feature map C5 to generate an intermediate feature map M5 with a higher level than the feature map C5; The intermediate feature map M5 is restored to the same size as the feature map C4 through upsampling operation, and the intermediate feature map M4 is obtained by 1x1 convolution operation; The intermediate feature map M4 is restored to the same size as the feature map C3 through upsampling operation, and the intermediate feature map M3 is obtained by 1x1 convolution operation. The calculation formula is: A 3×3 convolution is added to each intermediate feature map, and the corresponding feature maps C2, C3, C4, and C5 generate a feature map set {P2, P3, P4, P5} of the same size.

9. The image sentiment analysis device based on feature pyramid and attention mechanism according to claim 7, characterized in that: The attention mechanism unit is specifically used for: The input intermediate feature map is set as the input feature map F, and the input feature map F is input into the channel attention CAM module to obtain the channel attention map; Multiply the channel attention map by the input feature map F to obtain the first feature map ; Input the first feature map F' into the spatial attention SAM module to obtain a spatial attention map; The spatial attention map is combined with the first feature map Multiply to get the final input feature map , the calculation formula is: in, Represented as element-by-element matrix multiplication, is the number of channels of the feature map, is the height of the feature map, is the width of the feature map.