Visual relation extraction method based on global target perception
By introducing the global target perception module into the visual relationship extraction model, combined with the pre-trained visual model and the relationship prediction layer, the problem of ignoring global target information in the existing technology is solved, and the accuracy and semantic understanding of visual relationship extraction are improved.
Patent Information
- Application Number
- CN202410636051.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-22
- Publication Date
- 2024-08-23
AI Technical Summary
Existing visual relationship extraction methods ignore global target information when judging the relationship between targets, resulting in inaccurate and in-depth relationship reasoning and a lack of understanding of the scene context and overall structure.
Using the visual relationship extraction method based on global target perception, by building a visual relationship extraction model, including a pre-trained visual model, a global target perception module and a relationship prediction layer, extract image features and target features, build a global target feature matrix, and use global target perception The module enhances the feature matrix and inputs it into the relationship prediction layer for relationship prediction, and finally optimizes the model through the loss function.
It enhances the model's multi-hop target relationship reasoning ability, improves the accuracy of visual relationship extraction, provides richer semantic information and context, and can more accurately identify and explain the types of relationships between objects.
Smart Images

Figure CN118537640A
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of deep learning and image processing, and in particular to a visual relationship extraction method based on global target perception. Background Art
[0002] The input of visual relationship extraction is an image and the location of the target in the image, and the output is a label or category that describes the relationship between objects. The goal of visual relationship extraction is to automatically obtain and understand the relationship between objects from an image, thereby providing a richer and deeper understanding of the image content. This task is of great significance in many applications, such as visual question answering, image description generation, image search, and intelligent decision-making.
[0003] Existing visual relationship extraction methods often only use the information of the pair of targets when judging the relationship between targets, while ignoring the information of other targets. In fact, by perceiving the global target, we can better understand the context and overall structure of the scene, and provide more accurate and meaningful information for visual relationship extraction. Perceiving the global target helps to reason about the relationship. Through the global analysis of the entire scene, the potential relationship between objects can be inferred. For example, there is a basketball scene in the image. After perceiving the global targets such as basketball, players and baskets, it can be inferred that there may be a relationship between the player and the basketball for shooting. Perceiving the global target can provide richer semantic information for visual relationship extraction. Understanding the overall target and structure in the scene can provide more context and meaning for relationship extraction. This helps to more accurately identify and explain the types of relationships between objects, such as spatial relationships (in, above, below), behavioral relationships (eat, hit, look), etc. Therefore, enabling the model to perceive the global target is an explorable direction to improve model performance. Summary of the invention
[0004] The present invention aims to solve at least one of the technical problems existing in the prior art. To this end, the present invention discloses a visual relationship extraction method based on global target perception. The method can identify the relationship between targets in an image. Compared with the existing methods, the method innovatively proposes a global target perception module, which enables the model to aggregate information of different target pairs, and can comprehensively consider other global target pairs when judging the relationship between targets, thereby enhancing the multi-hop target relationship reasoning ability of the model and improving the accuracy of visual relationship extraction.
[0005] The objective of the present invention is to achieve a visual relationship extraction method based on global target perception through the following technical solution, the method comprising:
[0006] Step 1: Build a visual relationship extraction model, including a pre-trained visual model, a global object perception module, and a relationship prediction layer;
[0007] Step 2: Use the pre-trained visual model to extract image features;
[0008] Step 3, obtain the feature representation of all targets based on the image features and target area annotations;
[0009] Step 4, construct a global target feature matrix;
[0010] Step 5, using the global target perception module to enhance the global target feature matrix;
[0011] Step 6: Input the enhanced global target feature matrix into the relationship prediction layer to predict the relationship between targets;
[0012] Step 7: Calculate the relationship extraction loss function, use the relationship extraction loss function to optimize the visual relationship extraction model, and use the optimized visual relationship extraction model to perform visual relationship extraction.
[0013] Specifically, the method of extracting image features using a pre-trained visual model includes the following steps:
[0014] The input image is represented as Use the pre-trained visual model to extract the visual features of the input image. The expression is:
[0015] F img =ResNet(x)
[0016] in, Represents the visual features of the image, W and H represent the width and height of the image, d represents the hidden layer dimension of ResNet, and s represents the downsampling multiple of ResNet.
[0017] Specifically, the method of obtaining feature representations of all targets based on image features and target area annotations includes the following steps:
[0018] According to the target area annotation, the target position is represented as the coordinates of the rectangular box (x i ,y i ,w i ,h i ), where i represents the index of the target, x i and i Indicates the coordinates of the upper left corner of the rectangular box, w i and h i Indicates the width and height of the rectangular box;
[0019] Use the ROIAlign algorithm to map the target area annotation to the space of image features to obtain the visual feature map of the target, which is expressed as:
[0020]
[0021] in, represents the visual feature map of the i-th target, d represents the hidden layer dimension of ResNet, and s o Indicates the output size of ROIAlign;
[0022] Adaptively pool the visual feature map of the i-th target to obtain the feature representation of the i-th target, which is expressed as:
[0023]
[0024] in, Represents the feature representation of the i-th target;
[0025] Visual features are extracted for each target to obtain feature representations of all targets:
[0026]
[0027] in, represents the feature representation of all targets, and n represents the number of targets.
[0028] Specifically, the construction of the global target feature matrix includes the following steps:
[0029] Construct an n×n matrix A and calculate the expression for the element in the i-th row and j-th column:
[0030]
[0031] Among them, A represents the global target feature matrix, W a and b a is a learnable parameter, represents the feature representation of the i-th target, Represents the feature representation of the j-th target.
[0032] Furthermore, the method of enhancing the global target feature matrix using the global target perception module comprises the following steps:
[0033] Input the global target feature matrix into UNet to obtain the enhanced global target feature matrix, which is expressed as:
[0034] A′=UNet(A)
[0035] Among them, A′ represents the enhanced global target feature matrix.
[0036] The step of inputting the enhanced global target feature matrix into the relationship prediction layer to predict the relationship between targets includes the following steps:
[0037] Each element in the enhanced global target feature matrix is input into the relationship prediction layer to obtain the predicted relationship probability vector, which is expressed as:
[0038] p ij =softmax(W o A′ ij +b o )
[0039] Among them, p ij Represents the predicted relationship probability vector between the i-th target and the j-th target, A′ ij represents the element of the i-th row and j-th column of the enhanced global target feature matrix A′, W o and b o is a learnable parameter and softmax is an activation function.
[0040] Furthermore, the calculation of the relationship extraction loss function, optimizing the visual relationship extraction model using the relationship extraction loss function, and performing visual relationship extraction using the optimized visual relationship extraction model includes the following steps:
[0041] Step 701, calculate the relationship prediction loss between the i-th target and the j-th target, the expression is:
[0042]
[0043] Among them, L ij represents the relationship prediction loss between the i-th target and the j-th target, p ijk Represents the relationship probability vector p between the predicted i-th target and the j-th target ij The kth element of ij Indicates the relationship between the i-th target and the j-th target, which is a p ij One-hot vectors of the same dimension, q ijk Indicates q ij The kth element of , when the relationship between the i-th target and the j-th target is the m-th type q ijm=1 ;
[0044] Step 702, calculate the relationship extraction loss function, the expression is:
[0045]
[0046] Among them, L represents the relationship extraction loss function, L ij Represents the relationship prediction loss between the i-th target and the j-th target;
[0047] Step 703: According to the relationship extraction loss function L, the pre-trained visual model, the global object perception module and the relationship prediction layer are trained using the Adam optimizer until the relationship extraction loss function converges to obtain the trained model parameters.
[0048] Compared with the existing methods, the advantages of the method of the present invention are: this technology provides a visual relationship extraction method based on global target perception. This method innovatively proposes a global target perception module, which enables the model to aggregate the information of global targets and comprehensively consider other global target pairs when judging the relationship between targets. Through global analysis of the entire scene, the model's multi-hop target relationship reasoning ability is enhanced, thereby improving the accuracy of visual relationship extraction. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] Figure 1 A schematic diagram of a flow chart of an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0050] In order to make the purpose, technical solution and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0051] 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.
[0052] In this example, we assume that we want to build an autonomous driving system. In this system, visual relationship extraction can be used to analyze the relationship between traffic participants in road scenes, such as vehicles, pedestrians, and traffic lights. This helps the autonomous driving system better understand and predict the behavior of other traffic participants and improve driving safety. For the task of visual relationship extraction, a visual relationship extraction method based on global object perception is used.
[0053] Therefore, if Figure 1 As shown, a visual relationship extraction method based on global target perception includes:
[0054] Step 1: Build a visual relationship extraction model, including a pre-trained visual model, a global object perception module, and a relationship prediction layer;
[0055] Step 2: Use the pre-trained visual model to extract image features;
[0056] Step 3, obtain the feature representation of all targets based on the image features and target area annotations;
[0057] Step 4, construct a global target feature matrix;
[0058] Step 5, using the global target perception module to enhance the global target feature matrix;
[0059] Step 6: Input the enhanced global target feature matrix into the relationship prediction layer to predict the relationship between targets;
[0060] Step 7: Calculate the relationship extraction loss function, use the relationship extraction loss function to optimize the visual relationship extraction model, and use the optimized visual relationship extraction model to perform visual relationship extraction.
[0061] The method of extracting image features using a pre-trained visual model includes the following steps:
[0062] The input image is represented as Use the pre-trained visual model to extract the visual features of the input image. The expression is:
[0063] F img =ResNet(x)
[0064] in, Represents the visual features of the image, W and H represent the width and height of the image, d represents the hidden layer dimension of ResNet, and s represents the downsampling multiple of ResNet.
[0065] ResNet is a deep residual network designed to solve the gradient vanishing and gradient exploding problems in deep neural network training, making it possible to train deeper neural networks.
[0066] ResNet builds a network structure by introducing residual modules. Each residual module contains a skip connection, which directly passes the input to the output layer, while adding one or more convolutional layers and activation functions in the middle. This skip connection allows information to be directly transmitted in the network, avoiding information loss and degradation, thereby alleviating the problem of gradient disappearance.
[0067] The method of obtaining feature representations of all targets based on image features and target area annotations includes the following steps:
[0068] According to the target area annotation, the target position is represented as the coordinates of the rectangular box (x i ,y i ,w i ,h i ), where i represents the index of the target, x i and i Indicates the coordinates of the upper left corner of the rectangular box, w i and h i Indicates the width and height of the rectangular box;
[0069] Use the ROIAlign algorithm to map the target area annotation to the space of image features to obtain the visual feature map of the target, which is expressed as:
[0070]
[0071] in, represents the visual feature map of the i-th target, d represents the hidden layer dimension of ResNet, and s o Indicates the output size of ROIAlign;
[0072] ROIAlign is a commonly used operation in object detection and instance segmentation tasks. The purpose of ROIAlign is to solve the problem of information loss and inaccuracy that may be caused when using the region of interest pooling operation.
[0073] The traditional ROI pooling operation divides the irregular ROI into fixed-size grids, and performs maximum or average pooling in each grid to obtain a fixed-size feature representation. However, this division and pooling method may cause the loss of fine structure of information, especially in small objects or high-resolution images.
[0074] ROIAlign solves this problem through interpolation operations. It performs bilinear interpolation in each grid to map the coordinates on the feature map to the exact coordinates on the ROI. Specifically, ROIAlign divides the ROI into small sub-regions and calculates the interpolation weights in each sub-region. Then, the pixels on the feature map are interpolated according to the weights to obtain the feature representation on the ROI.
[0075] Adaptively pool the visual feature map of the i-th target to obtain the feature representation of the i-th target, which is expressed as:
[0076]
[0077] in, Represents the feature representation of the i-th target;
[0078] Visual features are extracted for each target to obtain feature representations of all targets:
[0079]
[0080] in, represents the feature representation of all targets, and n represents the number of targets.
[0081] The construction of the global target feature matrix comprises the following steps:
[0082] Construct an n×n matrix A and calculate the expression for the element in the i-th row and j-th column:
[0083]
[0084] Among them, A represents the global target feature matrix, W a and b a is a learnable parameter, represents the feature representation of the i-th target, Represents the feature representation of the j-th target.
[0085] The method of using the global target perception module to enhance the global target feature matrix comprises the following steps:
[0086] Input the global target feature matrix into UNet to obtain the enhanced global target feature matrix, which is expressed as:
[0087] A′=UNet(A)
[0088] Among them, A′ represents the enhanced global target feature matrix.
[0089] The encoder part of UNet consists of a series of convolutional layers and pooling layers, which are used to gradually reduce the spatial resolution of the input image and extract high-level abstract features. The decoder part gradually restores the spatial resolution of the feature map to its original size through upsampling (deconvolution) operations, and combines it with the feature maps from the corresponding levels of the encoder for fusion. This jump connection design enables the network to utilize a combination of shallow and deep features, thereby better preserving detail information in segmentation tasks.
[0090] The step of inputting the enhanced global target feature matrix into the relationship prediction layer to predict the relationship between targets includes the following steps:
[0091] Each element in the enhanced global target feature matrix is input into the relationship prediction layer to obtain the predicted relationship probability vector, which is expressed as:
[0092] p ij =softmax(W o A′ ij +b o )
[0093] Among them, p ij Represents the predicted relationship probability vector between the i-th target and the j-th target, A′ ij represents the element of the i-th row and j-th column of the enhanced global target feature matrix A′, W o and b o is a learnable parameter and softmax is an activation function.
[0094] The calculating of the relation extraction loss function, optimizing the visual relation extraction model with the relation extraction loss function, and performing visual relation extraction with the optimized visual relation extraction model comprises the following steps:
[0095] Step 701, calculate the relationship prediction loss between the i-th target and the j-th target, the expression is:
[0096]
[0097] Among them, L ij represents the relationship prediction loss between the i-th target and the j-th target, P ijk Represents the relationship probability vector p between the predicted i-th target and the j-th target ij The kth element of ij Indicates the relationship between the i-th target and the j-th target, which is a p ij One-hot vectors of the same dimension, q ijk Indicates q ij The kth element of , when the relationship between the i-th target and the j-th target is the m-th type q ijm=1 ;
[0098] Step 702, calculate the relationship extraction loss function, the expression is:
[0099]
[0100] Among them, L represents the relationship extraction loss function, L ij Represents the relationship prediction loss between the i-th target and the j-th target;
[0101] Step 703: According to the relationship extraction loss function L, the pre-trained visual model, the global object perception module and the relationship prediction layer are trained using the Adam optimizer until the relationship extraction loss function converges to obtain the trained model parameters.
[0102] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
Claims
1. A visual relationship extraction method based on global target perception, characterized in that: The method comprises: Step 1: Build a visual relationship extraction model, including a pre-trained visual model, a global object perception module, and a relationship prediction layer; Step 2: Use the pre-trained visual model to extract image features; Step 3, obtain the feature representation of all targets based on the image features and target area annotations; Step 4, construct a global target feature matrix; Step 5, using the global target perception module to enhance the global target feature matrix; Step 6: Input the enhanced global target feature matrix into the relationship prediction layer to predict the relationship between targets; Step 7: Calculate the relationship extraction loss function, use the relationship extraction loss function to optimize the visual relationship extraction model, and use the optimized visual relationship extraction model to perform visual relationship extraction.
2. The visual relationship extraction method based on global object perception according to claim 1 is characterized in that: The method of extracting image features using a pre-trained visual model includes the following steps: The input image is represented as Use the pre-trained visual model to extract the visual features of the input image. The expression is: F img =ResNet(x) in, Represents the visual features of the image, W and H represent the width and height of the image, d represents the hidden layer dimension of ResNet, and s represents the downsampling multiple of ResNet.
3. The visual relationship extraction method based on global object perception according to claim 2 is characterized in that: The method of obtaining feature representations of all targets based on image features and target area annotations includes the following steps: According to the target area annotation, the target position is represented as the coordinates of the rectangular box (x i ,y i ,w i ,h i ), where i represents the index of the target, x i and i Indicates the coordinates of the upper left corner of the rectangular box, w i and h i Indicates the width and height of the rectangular box; Use the ROIAlign algorithm to map the target area annotation to the space of image features to obtain the visual feature map of the target, which is expressed as: in, represents the visual feature map of the i-th target, s o Indicates the output size of ROIAlign; Adaptively pool the visual feature map of the i-th target to obtain the feature representation of the i-th target, which is expressed as: in, represents the feature representation of the i-th target, and AdaptivePooling represents the adaptive pooling operation; Visual features are extracted for each target to obtain feature representations of all targets: in, represents the feature representation of all targets, and n represents the number of targets.
4. The method for extracting visual relationships based on global object perception according to claim 3, characterized in that: The construction of the global target feature matrix comprises the following steps: Construct an n×n matrix A and calculate the expression for the element in the i-th row and j-th column: Among them, A represents the global target feature matrix, W a and b a is a learnable parameter, represents the feature representation of the i-th target, Represents the feature representation of the j-th target.
5. The method for extracting visual relationships based on global object perception according to claim 4, characterized in that: The method of using the global target perception module to enhance the global target feature matrix comprises the following steps: Input the global target feature matrix into UNet to obtain the enhanced global target feature matrix, which is expressed as: A′=UNet(A) Among them, A′ represents the enhanced global target feature matrix.
6. The method for extracting visual relationships based on global object perception according to claim 5, characterized in that: The step of inputting the enhanced global target feature matrix into the relationship prediction layer to predict the relationship between targets includes the following steps: Each element in the enhanced global target feature matrix is input into the relationship prediction layer to obtain the predicted relationship probability vector, which is expressed as: p ij =softmax(W o A′ ij +b o ) Among them, p ij Represents the predicted relationship probability vector between the i-th target and the j-th target, A′ ij represents the element of the i-th row and j-th column of the enhanced global target feature matrix A′, W o and b o is a learnable parameter and softmax is an activation function.
7. The method for extracting visual relations based on global object perception according to claim 6, characterized in that: The calculating of the relation extraction loss function, optimizing the visual relation extraction model with the relation extraction loss function, and performing visual relation extraction with the optimized visual relation extraction model comprises the following steps: Step 701, calculate the relationship prediction loss between the i-th target and the j-th target, the expression is: Among them, L ij represents the relationship prediction loss between the i-th target and the j-th target, p ijk Represents the relationship probability vector p between the predicted i-th target and the j-th target ij The kth element of ij Indicates the relationship between the i-th target and the j-th target, which is a p ij One-hot vectors of the same dimension, q ijk Indicates q ij The kth element of , when the relationship between the i-th target and the j-th target is the m-th type Step 702, calculate the relationship extraction loss function, the expression is: Among them, L represents the relationship extraction loss function, L ij Represents the relationship prediction loss between the i-th target and the j-th target; Step 703: According to the relationship extraction loss function L, the pre-trained visual model, the global object perception module and the relationship prediction layer are trained using the Adam optimizer until the relationship extraction loss function converges to obtain the trained model parameters.
