Instance segmentation method and system based on multi-scale features and contextual attention
By introducing multi-scale feature fusion and contextual attention aggregation technology into the instance segmentation model, the problem of low segmentation accuracy of small target objects is solved, and the model's detection ability and robustness for small targets are improved.
Patent Information
- Application Number
- CN202210333902.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-31
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2042-03-31
AI Technical Summary
Existing two-stage instance segmentation models have problems of missed detection and false detection in the segmentation of small target objects. This is mainly due to the fact that the pixels of small target objects are too small and the high-level semantic information is insufficient, resulting in low segmentation accuracy.
Using a method based on multi-scale feature fusion and contextual attention aggregation, by constructing a multi-scale feature fusion module and a contextual attention aggregation module, the representation of feature maps at different levels is enhanced, the representation ability of small target objects in feature maps is improved, and segmentation is improved. Accuracy.
The segmentation accuracy of large and medium targets is improved, while the segmentation accuracy of small target objects is significantly improved, the missed detection rate is reduced, and the robustness of the model is enhanced.
Smart Images

Figure CN114693930B
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of image processing and computer vision, and specifically relates to an instance segmentation method and system based on multi-scale features and contextual attention Background Art
[0002] In recent years, with the rapid development of artificial intelligence, more and more research has been conducted on machines replacing people to perform various tasks. Through artificial intelligence algorithms, machines can imitate various human behaviors and perform some repetitive and single tasks. However, there is still a certain gap in imitating more advanced and complex human behaviors. Computer vision tasks are one of the most important tasks here. Various work activities are carried out by imitating the human brain to perceive external information. Instance segmentation is a classic and challenging task in the field of computer vision, which aims to perform pixel-level calibration on objects of different categories and individuals in the image. The instance segmentation task requires not only to identify the category of the object, but also to clearly define the boundary and location of the object. Instance segmentation is widely used in unmanned driving, medical image analysis, security prevention and control, industrial sorting and other fields. Due to its wide applicability and industrial value, it has also attracted many domestic and foreign scholars to conduct research in this field. In order to better provide accurate and fine object masks for subsequent visual processing tasks (such as three-dimensional reconstruction, etc.), it is important to design instance segmentation model methods with higher segmentation accuracy, faster segmentation speed and better robustness in practical applications.
[0003] With the continuous research on target detection algorithms, the research progress of instance segmentation has also benefited from powerful target detectors. According to the actual target, it is divided into a single-stage instance segmentation model and a two-stage instance segmentation model. The former aims to achieve efficient real-time segmentation, while the latter hopes to use a more complex model to make the mask segmentation more accurate. The existing two-stage instance segmentation model can already achieve relatively accurate instance segmentation of target objects, but there are still some deficiencies in the segmentation of small target objects. The two-stage model relies on the features extracted by the backbone network for instance segmentation. For example, in Mask R-CNN, the feature pyramid network (FPN) is used to fuse the initial features extracted by the backbone, and the feature maps of the pyramid structure at different levels are used to detect and segment large targets (pixels greater than 96×96), medium targets (pixels between 32×32 and 96×96), and small targets (pixels less than 32×32). That is, the feature map with less semantics in the low level is used to detect smaller objects, and the feature map with more semantics in the high level is used to detect large objects. However, for small target objects, due to the small pixels and lack of high-level semantic information, they are usually missed and misdetected. Some existing methods for improving feature fusion do not focus on the difficulty of detecting and segmenting small target objects, but only enhance the high-level semantic information to the lower layers. Although the feature fusion representation is enhanced, it only brings more benefits to the segmentation of large target objects and ignores the targeted segmentation of small targets.
[0004] In order to solve the problem that small target objects in the two-stage model usually disappear in the high-level semantic information layer due to their small pixels, and the pixels of small target objects are almost negligible after convolution or pooling, which will lead to missed detection when other methods are not used, the present invention proposes an instance segmentation method based on multi-scale feature fusion and contextual attention aggregation. This method utilizes stronger multi-scale feature fusion and introduces a contextual attention mechanism, which not only enhances the representation of feature maps at different levels and improves the segmentation accuracy of large and medium targets, but also focuses on the representation of small targets in the feature maps, so that the segmentation accuracy of small targets is increased and the missed detection rate is reduced. Summary of the invention
[0005] The purpose of the present invention is to provide an instance segmentation method and system based on multi-scale features and contextual attention, which can not only improve the segmentation accuracy of large and medium targets, but also focus on small target objects and improve the segmentation performance of small targets.
[0006] To achieve the above object, the technical solution adopted by the present invention is: an instance segmentation method based on multi-scale features and contextual attention, comprising the following steps:
[0007] Step A: Perform data preprocessing including data enhancement and standardization on the images in the training set;
[0008] Step B: Construct a multi-scale feature fusion and contextual attention aggregation module, including a cascaded multi-scale feature fusion module and a contextual attention aggregation module, to enhance feature representation using a pyramid structure and focus on small target objects in the pyramid feature map;
[0009] Step C: Construct an instance segmentation network based on multi-scale feature fusion and contextual attention aggregation;
[0010] Step D: Use the images in the training set to train the instance segmentation network, generate instance segmentation results and calculate the loss function, back-propagate and optimize the parameters of the entire network to obtain a trained instance segmentation network;
[0011] Step E: Input the image to be processed into the trained instance segmentation network to obtain the instance segmentation result.
[0012] Furthermore, the step A specifically includes the following steps:
[0013] Step A1: Scale the images in the training set, and set the thresholds of image length and width to 2048 while keeping the aspect ratio unchanged; that is, scale the images according to the long side of the image and the threshold, ensuring that the long side and the short side do not exceed the threshold; then randomly flip all the scaled images with a flip ratio of 0.5 to achieve data enhancement;
[0014] Step A2: The enhanced image is standardized, and the standardized mean is [123.675, 116.28, 103.53] and the variance is [58.395, 57.12, 57.375]. Finally, the image is padded so that the length and width are divisible by 32. Each image has a corresponding label, and the label content is the bounding box and mask of each instance object in the image. The image label is processed synchronously while the image is scaled and data enhanced.
[0015] Furthermore, in step B, the implementation method of the multi-scale feature fusion module is as follows:
[0016] Step B101: The feature extraction module of the instance segmentation network extracts features from the input image to obtain four feature maps C1, C2, C3, and C4 from high-resolution layer to low-resolution layer, i.e., from low semantic information to high semantic information, and then inputs them into the multi-scale feature fusion module;
[0017] Step B102: The multi-scale feature fusion module performs a bilinear difference upsampling operation on the low-resolution feature map to obtain the C1 feature map. Figure 1The feature map of the sample resolution is concatenated to obtain M1, and then the number of channels of the M1 feature map is changed to N by 3×3 convolution. The specific formula is as follows:
[0018] M1=Conv 3×3 (Concat(C1, 2xUp(C2), 4xUp(C3), 8xUp(C4))),
[0019] Among them, Conv 3×3 is a 3×3 convolution, Concat is a feature concatenation operation, 2xUp means 2x upsampling, 4xUp and 8xUp mean 4x and 8x upsampling respectively;
[0020] Step B103: Construct a pyramid feature map structure; perform 3×3 convolution on M1 obtained in step B102 and downsample it by 2 times, and then perform 1×1 convolution with the initial feature map C2 to change the number of channels to N and perform element-by-element addition to obtain M2; similarly, M3 is obtained by performing element-by-element addition of M2 downsampled and the feature map C3 after 1×1 convolution, and M4 is obtained by performing element-by-element addition of M3 downsampled and the feature map C4 after l×1 convolution. The specific formula is as follows:
[0021] M i =Conv 3×3 (M i -1)+Conv 1×1 (C i ),
[0022] Among them, Conv 3×3 It is a 3×3 convolution with a stride of 2, Conv 1×1 It is a 1×1 convolution and the number of output channels is N, i=2, 3, 4;
[0023] Step B104: Downsample M4 by 2 times through a 3×3 convolution with a step size of 2 to obtain M5, thereby forming five feature maps M1, M2, M3, M4, and M5 of a pyramid structure.
[0024] Furthermore, in step B, the implementation method of the context attention aggregation module is as follows:
[0025] Step B201: The feature map M5 is subjected to a 3×3 convolution to obtain P5, which is a pyramid structure feature map of scale 5;
[0026] Step B202: fuse the feature maps of the two levels through the contextual attention aggregation module CAA; input the feature maps M4 and M5 into the fourth CCA module, use the high-level semantic information of the feature map M5 to enhance the context information in the feature map M4, and record the output of the fourth CAA module as M′4; M′4 is then convolved by 3×3 to obtain P4, which is a pyramid structure feature map of scale 4. The specific formula is as follows:
[0027] M′4=CAA4(M4,M5),
[0028] P4=Conv 3×3 (M′4),
[0029] Among them, CAA4 is the contextual attention aggregation module used in the fourth scale, Conv 3×3 It is a 3×3 convolution with a stride of 1 and N input and output channels.
[0030] Step B203: Input feature maps M3 and M′4 into the third CAA module to obtain M′3, and then obtain P3 through 3×3 convolution; similarly, M2 and M′3 pass through the second CAA module and then undergo 3×3 convolution to obtain feature map P2, and M1 and M′2 pass through the first CAA module and then undergo 3×3 convolution to obtain feature map P1; thus, the pyramid structure feature maps of the five scales of aggregated contextual attention are P1, P2, P3, P4, and P5 respectively; the specific formula of the above process is as follows:
[0031] M′ i =CAA i (M i , M′ i+1 ),
[0032] P i =Conv 3×3 (M′ i ),
[0033] Among them, CAA i The context attention aggregation module used for the i-th scale, Conv 3×3 It is a 3×3 convolution with a stride of 1, and the number of input and output channels is N, i=1, 2, 3.
[0034] Furthermore, the input of the contextual attention aggregation module is the feature map M of any two adjacent layers. i With M′ i+1 , for the penultimate layer, i.e. scale 4, use M i+1 Replace M' i+1 ;M i+1 and M′ i+1 For lower resolution and higher semantic layers, M iFor higher resolution and lower semantic layer; the feature map M′ i+1 After global average pooling, we get high-level attention. After 1×1 convolution, we change the number of channels to N and add M′ i+1 The feature map and feature map M after bilinear interpolation 2 times upsampling i , the three are added element by element to get the context feature C high , the specific formula is as follows:
[0035] C high =M i +2xUp(M′ i+1 )+Conv 1×1 (GAP(M′ i+1 )),
[0036] Among them, 2xUp means 2 times upsampling, Conv 1×1 is a 1×1 convolution with N output channels, and GAP is global average pooling;
[0037] The context feature C high After global average pooling, the context attention is obtained. After 1×1 convolution, the number of channels is changed to N, and the original input feature map M is obtained. i After 3×3 convolution, element-wise multiplication is performed to obtain the context attention C Atten , the specific formula is as follows:
[0038] C Atten =Conv 3×3 (M i )×Conv 1×1 (GAP(C high ))
[0039] Finally, C Atten With C high Add element by element to get the final context attention aggregation feature map M′ i , the specific formula is as follows:
[0040] M′ i =C Atten +C high .
[0041] Furthermore, in step C, the implementation method of the instance segmentation network based on multi-scale feature fusion and context attention aggregation is:
[0042] Step C1: Using the HRNet backbone network as the feature extraction module, the input image is subjected to feature extraction, and the extracted feature map is fed into the multi-scale feature fusion and contextual attention aggregation module;
[0043] Step C2: Use multi-scale feature fusion and context attention aggregation modules to strengthen feature representation, form a multi-scale pyramid structure, and then send it to the RPN subnetwork for region candidate proposal;
[0044] Step C3: Perform background and foreground binary classification prediction in the RPN subnetwork, and send the candidate region predicted as the foreground to the RoI Align pool to form a fixed-size region candidate box; finally, send the region candidate box to the RefineMask instance segmentation head and the RefineMask object detection head;
[0045] Step C4: Use the RefineMask instance segmentation head to segment the mask together with the fine-grained features generated by the multi-scale feature fusion and contextual attention aggregation modules to obtain the final instance segmentation result.
[0046] Furthermore, the step D specifically includes the following steps:
[0047] Step D1: Input the preprocessed training set images into the instance segmentation network to obtain the pyramid structure feature maps P1, P2, P3, P4, and P5 of 5 scales, and send them to the RPN network of RefineMask to generate a certain number of candidate regions. After classifying the positive samples, i.e. foreground objects, and the negative samples, i.e. background regions, RoI Align is used to convert the candidate regions into 7×7 size and then send them to the object detection head and instance segmentation head;
[0048] Step D2: The fine-grained features required in the instance segmentation head of RefineMask are generated by the obtained feature map P1 through a small semantic segmentation subnetwork consisting of four 3×3 convolutions; the object detection head and instance segmentation head of RefineMask are used to detect bounding boxes and segment masks;
[0049] Step D3: Calculate the bounding box loss, mask loss, and semantic loss of the fine-grained feature generation process; the total loss target is the sum of the three losses, and use the back-propagation method to calculate the gradients of each parameter in the instance segmentation network based on multi-scale feature fusion and contextual attention aggregation, and use the stochastic gradient descent method to update the parameters of the instance segmentation network.
[0050] Furthermore, the step E specifically includes the following steps:
[0051] Step E1: Input the image without label information into the trained instance segmentation network for processing;
[0052] Step E2: Use the object detection head to predict the bounding box of the foreground object in the image, and use the instance segmentation head to predict the mask result of each instance in the image; the result obtained by the instance segmentation head in the network is the final instance segmentation result.
[0053] The present invention also provides an instance segmentation system based on multi-scale features and contextual attention, including a memory, a processor, and computer program instructions stored in the memory and capable of being executed by the processor. When the processor executes the computer program instructions, the above-mentioned method steps can be implemented.
[0054] Compared with the prior art, the present invention has the following beneficial effects: it provides an instance segmentation method and system based on multi-scale features and contextual attention. The method is based on the HRNet backbone network, constructs a new multi-scale pyramid feature fusion, enhances the original feature representation in each layer, and can more strongly characterize the feature information in each layer; at the same time, it introduces an attention mechanism and constructs a contextual attention aggregation module. By integrating the attention of high-level semantic information, the lower layer can obtain more high-level semantic information representation, so that the segmentation accuracy of small targets is increased and the missed detection rate is reduced. The present invention can not only enhance the segmentation accuracy of large and medium targets, but also increase the segmentation accuracy of small targets and reduce the missed detection rate. It has strong practicality and broad application prospects. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] Figure 1 The present invention is a flowchart of a method implementation according to an embodiment of the present invention.
[0056] Figure 2 Schematic diagram of the structure of the entire instance segmentation network in an embodiment of the present invention.
[0057] Figure 3 It is a structural diagram of the multi-scale feature fusion and contextual attention aggregation module in an embodiment of the present invention.
[0058] Figure 4 It is a structural diagram of the context attention aggregation module in an embodiment of the present invention. DETAILED DESCRIPTION
[0059] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0060] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present application. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present application belongs.
[0061] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present application. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprise" and / or "include" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.
[0062] like Figure 1 As shown, this embodiment provides an instance segmentation method based on multi-scale features and contextual attention, comprising the following steps:
[0063] Step A: Perform data preprocessing including data augmentation and standardization on the images in the training set.
[0064] Step B: Construct a multi-scale feature fusion and contextual attention aggregation module, including a cascaded multi-scale feature fusion module and a contextual attention aggregation module, to enhance feature representation using a pyramid structure and focus on small target objects in the pyramid feature map.
[0065] Step C: Construct an instance segmentation network based on multi-scale feature fusion and contextual attention aggregation.
[0066] Step D: Use the images in the training set to train the instance segmentation network, generate instance segmentation results and calculate the loss function, back-propagate and optimize the parameters of the entire network to obtain a trained instance segmentation network.
[0067] Step E: Input the image to be processed into the trained instance segmentation network to obtain the instance segmentation result.
[0068] In this embodiment, the step A specifically includes the following steps:
[0069] Step A1: Scale the images in the training set, set the thresholds of image length and width to 2048 while keeping the aspect ratio unchanged; that is, scale the images according to the long side of the image and the threshold to ensure that neither the long side nor the short side exceeds the threshold; then randomly flip all the scaled images with a flip ratio of 0.5 to achieve data enhancement.
[0070] Step A2: The enhanced image is standardized, and the standardized mean is [123.675, 116.28, 103.53] and the variance is [58.395, 57.12, 57.375]. Finally, the image is padded so that the length and width are divisible by 32. Each image has a corresponding label, and the label content is the bounding box and mask of each instance object in the image. The image label is synchronously processed while the image is scaled and data enhanced.
[0071] Figure 3 Schematic diagram of the structure of the multi-scale feature fusion and contextual attention aggregation module in this embodiment. Figure 3 As shown in FIG. 1 , it includes a cascaded multi-scale feature fusion module and a context attention aggregation module. The implementation method of the multi-scale feature fusion module is as follows:
[0072] Step B101: The feature extraction module of the instance segmentation network extracts features from the input image to obtain four feature maps C1, C2, C3, and C4 from the high-resolution layer (low semantic information) to the low-resolution layer (high semantic information), and then inputs them into the multi-scale feature fusion module.
[0073] Step B102: The multi-scale feature fusion module performs a bilinear difference upsampling operation on the low-resolution feature map to obtain the C1 feature map. Figure 1 The feature map of the sample resolution is concatenated to obtain M1, and then the number of channels of the M1 feature map is changed to N by 3×3 convolution. The specific formula is as follows:
[0074] M1=Conv 3×3 (Concat(C1, 2xUp(C2), 4xUp(C3), 8xUp(C4))),
[0075] Among them, Conv 3×3 is a 3×3 convolution, Concat is a feature concatenation operation, 2xUp means 2x upsampling, 4xUp and 8xUp are 4x and 8x upsampling respectively.
[0076] Step B103: Construct a pyramid feature map structure; perform 3×3 convolution on M1 obtained in step B102 and downsample it by 2 times, and then perform 1×1 convolution with the initial feature map C2 to change the number of channels to N and perform element-by-element addition to obtain M2; similarly, M3 is obtained by performing element-by-element addition of M2 downsampled and the feature map C3 after 1×1 convolution, and M4 is obtained by performing element-by-element addition of M3 downsampled and the feature map C4 after 1×1 convolution. The specific formula is as follows:
[0077] M i =Conv 3×3 (M i-1 )+Conv 1×1 (C i ),
[0078] Among them, Conv 3×3 It is a 3×3 convolution with a stride of 2, Conv 1×1 It is a 1×1 convolution and the number of output channels is N, i=2, 3, 4.
[0079] Step B104: Downsample M4 by 2 times through a 3×3 convolution with a step size of 2 to obtain M5, thereby forming five feature maps M1, M2, M3, M4, and M5 of a pyramid structure.
[0080] The implementation of the contextual attention aggregation module is as follows:
[0081] Step B201: The feature map M5 is subjected to a 3×3 convolution to obtain P5, which is a pyramid structure feature map of scale 5.
[0082] Step B202: Through the context attention aggregation module (CAA), the feature maps of the two levels are fused; the feature maps M4 and M5 are input into the fourth CCA module, and the semantic information of the high-level feature map M5 is used to enhance the context information in the feature map M4. The output of the fourth CAA module is recorded as M′4; M′4 is then subjected to a 3×3 convolution to obtain P4, which is a pyramid structure feature map of scale 4. The specific formula is as follows:
[0083] M′4=CAA4(M4,M5),
[0084] P4=Conv 3×3 (M′4),
[0085] Among them, CAA4 is the contextual attention aggregation module used in the fourth scale, Conv 3×3 It is a 3×3 convolution with a stride of 1 and N input and output channels.
[0086] Step B203: Input feature maps M3 and M′4 into the third CAA module to obtain M′3, and then obtain P3 through 3×3 convolution; similarly, M2 and M′3 pass through the second CAA module and then undergo 3×3 convolution to obtain feature map P2, and M1 and M′2 pass through the first CAA module and then undergo 3×3 convolution to obtain feature map P1; thus, the pyramid structure feature maps of the five scales of aggregated contextual attention are P1, P2, P3, P4, and P5 respectively; the specific formula of the above process is as follows:
[0087] M′ i =CAA i (M i , M′ i+1 ),
[0088] P i =Conv 3×3 (M′ i ),
[0089] Among them, CAA i The context attention aggregation module used for the i-th scale, Conv3×3 It is a 3×3 convolution with a stride of 1, and the number of input and output channels is N, i=1, 2, 3.
[0090] The structure of the contextual attention aggregation module is as follows Figure 4 As shown. Figure 4 As shown, the input of the context attention aggregation module is the feature map M of any two adjacent layers. i With M′ i+1 , for the penultimate layer, i.e. scale 4, use M i+1 Replace M' i+1 ;M i+1 and M′ i+1 For lower resolution and higher semantic layers, M i For higher resolution and lower semantic layer; the feature map M′ i+1 After global average pooling, we get high-level attention. After 1×1 convolution, we change the number of channels to N and add M′ i+1 The feature map and feature map M after bilinear interpolation 2 times upsampling i , the three are added element by element to get the context feature C high , the specific formula is as follows:
[0091] C high =M i +2xUp(M′ i+1 )+Conv 1×1 (GAP(M′ i+1 )),
[0092] Among them, 2xUp means 2 times upsampling, Conv 1×1 is a 1×1 convolution with N output channels, and GAP is global average pooling.
[0093] The context feature C high The context attention is obtained through global average pooling (GAP), and after changing the number of channels to N through 1×1 convolution, it is compared with the original input feature map M i After 3×3 convolution, element-wise multiplication is performed to obtain the context attention C Atten , the specific formula is as follows:
[0094] C Atten =Conv 3×3 (M i )×Conv 1×1 (GAP(C high ))
[0095] Finally, C Atten With C high Add element by element to get the final context attention aggregation feature map M′i , the specific formula is as follows:
[0096] M′ i =C Atten +C high .
[0097] Figure 2 is a structural diagram of an instance segmentation network based on multi-scale feature fusion and contextual attention aggregation in this embodiment. Figure 2 As shown in the figure, the implementation method of the instance segmentation network based on multi-scale feature fusion and contextual attention aggregation is:
[0098] Step C1: Using the HRNet (High-Resolution Net) backbone network as the feature extraction module, feature extraction is performed on the input image, and the extracted feature map is sent to the multi-scale feature fusion and context attention aggregation module.
[0099] Step C2: Use multi-scale feature fusion and contextual attention aggregation modules to strengthen the feature representation and form a multi-scale pyramid structure, which is then sent to the RPN subnetwork for region candidate proposal.
[0100] Step C3: Perform background and foreground binary classification prediction in the RPN subnetwork, and send the candidate region predicted as the foreground to the RoI Align pool to form a fixed-size region candidate box; finally, send the region candidate box to the RefineMask instance segmentation head and the RefineMask object detection head.
[0101] Step C4: Use the RefineMask instance segmentation head to segment the mask together with the fine-grained features generated by the multi-scale feature fusion and contextual attention aggregation modules to obtain the final instance segmentation result.
[0102] In this embodiment, training the instance segmentation network specifically includes the following steps:
[0103] Step D1: Input the preprocessed images in the training set into the instance segmentation network to obtain the pyramid structure feature maps P1, P2, P3, P4, and P5 of 5 scales, and send them to the RPN network of RefineMask to generate a certain number of candidate regions. After classifying the positive samples (foreground objects) and negative samples (background areas), RoI Align is used to convert the candidate regions into 7×7 size and then send them to the object detection head and instance segmentation head.
[0104] Step D2: The fine-grained features required in the instance segmentation head of RefineMask are generated by the obtained feature map P1 through a small semantic segmentation subnetwork consisting of 4 3×3 convolutions; the object detection head and instance segmentation head of RefineMask are used to perform bounding box detection and mask segmentation.
[0105] Step D3: Calculate the bounding box loss, mask loss, and semantic loss of the fine-grained feature generation process; the total loss target is the sum of the three losses, and use the back-propagation method to calculate the gradients of each parameter in the instance segmentation network based on multi-scale feature fusion and contextual attention aggregation, and use the stochastic gradient descent (SGD) method to update the parameters of the instance segmentation network.
[0106] In this embodiment, the image to be processed is processed as follows:
[0107] Step E1: Input the image without label information into the trained instance segmentation network for processing
[0108] Step E2: Use the object detection head to predict the bounding box of the foreground object in the image, and use the instance segmentation head to predict the mask result of each instance in the image; the result obtained by the instance segmentation head in the network is the final instance segmentation result.
[0109] This embodiment also provides an instance segmentation system based on multi-scale features and contextual attention, including a memory, a processor, and computer program instructions stored in the memory and capable of being executed by the processor. When the processor executes the computer program instructions, the above-mentioned method steps can be implemented.
[0110] 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 in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0111] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0112] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0113] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0114] The above is only a preferred embodiment of the present invention, and does not limit the present invention in other forms. Any technician familiar with the profession may use the above disclosed technical content to change or modify it into an equivalent embodiment with equivalent changes. However, any simple modification, equivalent change and modification made to the above embodiment according to the technical essence of the present invention without departing from the technical solution of the present invention still belongs to the protection scope of the technical solution of the present invention.
Claims
1. An instance segmentation method based on multi-scale features and contextual attention, characterized in that: The following steps are involved: Step A: Perform data preprocessing including data enhancement and standardization on the images in the training set; Step B: Construct a multi-scale feature fusion and contextual attention aggregation module, including a cascaded multi-scale feature fusion module and a contextual attention aggregation module, to enhance feature representation using a pyramid structure and focus on small target objects in the pyramid feature map; Step C: Construct an instance segmentation network based on multi-scale feature fusion and contextual attention aggregation; Step D: Use the images in the training set to train the instance segmentation network, generate instance segmentation results and calculate the loss function, back-propagate and optimize the parameters of the entire network to obtain a trained instance segmentation network; Step E: Input the image to be processed into the trained instance segmentation network to obtain the instance segmentation result; In step B, the implementation method of the multi-scale feature fusion module is as follows: Step B101: The feature extraction module of the instance segmentation network extracts features from the input image to obtain four feature maps C1, C2, C3, and C4 from high-resolution layer to low-resolution layer, i.e., from low semantic information to high semantic information, and then inputs them into the multi-scale feature fusion module; Step B102: The multi-scale feature fusion module performs a bilinear difference upsampling operation on the low-resolution feature map to obtain a feature map with the same resolution as the C1 feature map, performs feature concatenation to obtain M1, and then uses a 3×3 convolution to change the number of channels of the M1 feature map to N. The specific formula is as follows: M1=Conv 3×3 (Concat(C1,2xUp(C2),4xUp(C3),8xUpC4))), Among them, Conv 3×3 is a 3×3 convolution, Concat is a feature concatenation operation, 2xUp means 2x upsampling, 4xUp and 8xUp mean 4x and 8x upsampling respectively; Step B103: Construct a pyramid feature map structure; perform 3×3 convolution on M1 obtained in step B102 and downsample it by 2 times, and then perform 1×1 convolution with the initial feature map C2 to change the number of channels to N and perform element-by-element addition to obtain M2; similarly, M3 is obtained by performing element-by-element addition of M2 downsampled and the feature map C3 after 1×1 convolution, and M4 is obtained by performing element-by-element addition of M3 downsampled and the feature map C4 after 1×1 convolution. The specific formula is as follows: M i =Conv 3×3 ((M i-1 )+Conv 1×1 (C i ), Among them, Conv 3×3 It is a 3×3 convolution with a stride of 2, Conv 1×1 It is a 1×1 convolution with N output channels, i=2,3,4; Step B104: downsample M4 by 2 times through a 3×3 convolution with a step size of 2 to obtain M5, thereby forming five feature maps M1, M2, M3, M4, and M5 of a pyramid structure; In step B, the implementation method of the context attention aggregation module is as follows: Step B201: The feature map M5 is subjected to a 3×3 convolution to obtain P5, which is a pyramid structure feature map of scale 5; Step B202: fuse the feature maps of the two levels through the contextual attention aggregation module CAA; input the feature maps M4 and M5 into the fourth CCA module, use the high-level semantic information of the feature map M5 to enhance the context information in the feature map M4, and record the output of the fourth CAA module as M′4; M′4 is then convolved by 3×3 to obtain P4, which is a pyramid structure feature map of scale 4. The specific formula is as follows: M′4=CAA4(M4,M5), P4=Conv 3×3 ((M′4), Among them, CAA4 is the contextual attention aggregation module used in the fourth scale, Conv 3×3 It is a 3×3 convolution with a stride of 1 and N input and output channels. Step B203: Input feature maps M3 and M′4 into the third CAA module to obtain M′3, and then obtain P3 through 3×3 convolution; similarly, M2 and M′3 pass through the second CAA module and then undergo 3×3 convolution to obtain feature map P2, and M1 and M′2 pass through the first CAA module and then undergo 3×3 convolution to obtain feature map P1; thus, the pyramid structure feature maps of the five scales of aggregated contextual attention are P1, P2, P3, P4, and P5 respectively; the specific formula of the above process is as follows: M′ i =CAA i (M i ,M′ i+1 ), P i =Conv 3×3 (M′ i ), Among them, CAA i The context attention aggregation module used for the i-th scale, Conv 3×3 It is a 3×3 convolution with a stride of 1, the number of input and output channels is N, i=1,2,3; The input of the contextual attention aggregation module is the feature map M of any two adjacent layers i With M′ i+1 , for the penultimate layer, i.e. scale 4, use M i+1 Replace M' i+1 ;M i+1 and M′ i+1 For lower resolution and higher semantic layers, M i For higher resolution and lower semantic layer; the feature map M′ i+1 After global average pooling, we get high-level attention. After 1×1 convolution, we change the number of channels to N and add M′ i+1 The feature map and feature map M after bilinear interpolation 2 times upsampling i , the three are added element by element to get the context feature C high , the specific formula is as follows: C high =M i +2xUp(M′ i+1 )+Conv 1×1 (GAP(M′ i+1 )), Among them, 2xUp means 2 times upsampling, Conv 1×1 is a 1×1 convolution with N output channels, and GAP is global average pooling; The context feature C high After global average pooling, the context attention is obtained. After 1×1 convolution, the number of channels is changed to N, and the original input feature map M is obtained. i After 3×3 convolution, element-wise multiplication is performed to obtain the context attention C Atten , the specific formula is as follows: C Atten =Conv 3×3 (M i )×Conv 1×1 (GAP(C high )) Finally, C Atten With C high Add element by element to get the final context attention aggregation feature map M' i , the specific formula is as follows: M’ i =C Atten +C high 。 2. The instance segmentation method based on multi-scale features and contextual attention according to claim 1, characterized in that: The step A specifically comprises the following steps: Step A1: Scale the images in the training set, and set the thresholds of image length and width to 2048 while keeping the aspect ratio unchanged; that is, scale the images according to the long side of the image and the threshold, ensuring that the long side and the short side do not exceed the threshold; then randomly flip all the scaled images with a flip ratio of 0.5 to achieve data enhancement; Step A2: The enhanced image is standardized, and the standardized mean is [123.675, 116.28, 103.53] and the variance is [58.395, 57.12, 57.375]. Finally, the image is padded so that the length and width are divisible by 32. Each image has a corresponding label, and the label content is the bounding box and mask of each instance object in the image. The image label is processed synchronously while the image is scaled and data enhanced.
3. The instance segmentation method based on multi-scale features and contextual attention according to claim 1, characterized in that: In step C, the implementation method of the instance segmentation network based on multi-scale feature fusion and context attention aggregation is: Step C1: Using the HRNet backbone network as the feature extraction module, the input image is subjected to feature extraction, and the extracted feature map is fed into the multi-scale feature fusion and contextual attention aggregation module; Step C2: Use multi-scale feature fusion and context attention aggregation modules to strengthen feature representation, form a multi-scale pyramid structure, and then send it to the RPN subnetwork for region candidate proposal; Step C3: Perform background and foreground binary classification prediction in the RPN subnetwork, and send the candidate region predicted as the foreground to RoIAlign pooling into a fixed-size region candidate box; finally, send the region candidate box to the RefineMask instance segmentation head and the RefineMask object detection head; Step C4: Use the RefineMask instance segmentation head to segment the mask together with the fine-grained features generated by the multi-scale feature fusion and contextual attention aggregation modules to obtain the final instance segmentation result.
4. The instance segmentation method based on multi-scale features and contextual attention according to claim 3, characterized in that: The step D specifically comprises the following steps: Step D1: Input the preprocessed training set images into the instance segmentation network to obtain the pyramid structure feature maps P1, P2, P3, P4, and P5 of 5 scales, and send them to the RPN network of RefineMask to generate a certain number of candidate regions. After classifying the positive samples, i.e. foreground objects, and the negative samples, i.e. background regions, RoIAlign is used to convert the candidate regions into 7×7 size and then send them to the object detection head and instance segmentation head; Step D2: The fine-grained features required in the instance segmentation head of RefineMask are generated by the obtained feature map P1 through a small semantic segmentation subnetwork consisting of four 3×3 convolutions; the object detection head and instance segmentation head of RefineMask are used to detect bounding boxes and segment masks; Step D3: Calculate the bounding box loss, mask loss, and semantic loss of the fine-grained feature generation process; the total loss target is the sum of the three losses, and use the back-propagation method to calculate the gradients of each parameter in the instance segmentation network based on multi-scale feature fusion and contextual attention aggregation, and use the stochastic gradient descent method to update the parameters of the instance segmentation network.
5. The instance segmentation method based on multi-scale features and contextual attention according to claim 4, characterized in that: The step E specifically comprises the following steps: Step E1: Input the image without label information into the trained instance segmentation network for processing; Step E2: Use the object detection head to predict the bounding box of the foreground object in the image, and use the instance segmentation head to predict the mask result of each instance in the image; the result obtained by the instance segmentation head in the network is the final instance segmentation result.
6. An instance segmentation system based on multi-scale features and contextual attention, characterized in that: The method comprises a memory, a processor, and computer program instructions stored in the memory and executable by the processor. When the processor executes the computer program instructions, the method steps as described in any one of claims 1 to 5 can be implemented.
