Image semantic segmentation method, device and computer-readable storage medium
By dividing the original image into image blocks and processing the down-sampled rough image in the semantic segmentation model, the connection between the image blocks and the rough image is established, which solves the problem of loss of detailed information and inconsistent results in image semantic segmentation, and improves improve the accuracy of semantic segmentation.
Patent Information
- Application Number
- CN202210435267.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-24
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2042-04-24
AI Technical Summary
In the process of image semantic segmentation, in the existing technology, due to the reduction of resolution or the lack of connection between image blocks, detailed information is lost or the semantic segmentation results are inconsistent, which affects the accuracy.
Divide the original image into image blocks of preset sizes and down-sampled rough images, process them in the semantic segmentation model through the pooling branch and spatial information extraction branch, establish the connection between the image blocks and the rough image, and perform global averaging. Pooling, matrix multiplication, and convolution operations are performed to determine the semantic segmentation results, and the final results are stitched based on image patch locations.
It improves the accuracy of image semantic segmentation, avoids the ambiguity of the semantic segmentation results of image blocks and the inconsistency between the final splicing information and the original image, and ensures the accurate classification of pixels.
Smart Images

Figure CN114581671B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing, and in particular to a method, system and device for semantic segmentation of an image. Background Art
[0002] Semantic segmentation is an important step in image processing and computer vision technology. Semantic segmentation is to classify each pixel in the image into the category corresponding to the pixel, such as classifying the pixels of a vehicle into the category of a vehicle. Before semantic segmentation of an image, because semantic segmentation is limited by the computing performance of the processor hardware, the existing technology usually uses the following two methods to process images with larger resolutions:
[0003] 1. Downsample the original resolution image to a low-resolution image and then perform semantic segmentation. Since this method will reduce the resolution of the image, some detailed content information in the original image will be lost, resulting in inaccurate semantic segmentation of the image.
[0004] 2. Divide the original resolution image into multiple image blocks of equal size, perform semantic segmentation on these image blocks one by one, and finally stitch together the semantic segmentation results of each image block to complete the semantic segmentation of the original resolution image. Although this method does not lose some detailed content information in the original image, since there is no connection between the image blocks, the semantic segmentation results of each image block will be ambiguous, making the information in the final spliced image inconsistent with the information in the original image. For example, if a car in the original image is divided into multiple image blocks, after semantic segmentation of these image blocks, in the semantic segmentation results of each image block, there may be a situation where the pixels belonging to the vehicle are not classified into the vehicle category. Summary of the invention
[0005] The purpose of the present invention is to provide a method, device and computer-readable storage medium for semantic segmentation of an image, which can establish a connection between each image block and a rough image, avoid ambiguity in the semantic segmentation results of the image blocks, and further avoid inconsistency between the information in the final spliced image and the information in the original image, accurately classify pixels belonging to a certain category into the category, and ultimately improve the accuracy of image semantic segmentation.
[0006] In order to solve the above technical problems, the present invention provides a semantic segmentation method of an image, comprising:
[0007] When an original image is obtained, an image block and a rough image of the original image are obtained; wherein the image block is any one of N image blocks of preset sizes obtained by cutting the original image into the image block, and the rough image is an image of the preset size obtained by downsampling the original image, where N is an integer not less than 2;
[0008] Obtaining a first feature map of the image block after the convolution operation and a coarse feature map of the coarse image after the convolution operation; upsampling an image of a portion of the coarse feature map that is the same as the image of the image block to obtain a second feature map of the preset size;
[0009] Input the first feature map and the second feature map into a pooling branch and a spatial information extraction branch; in the pooling branch, perform global average pooling on the first feature map and the second feature map, and perform matrix multiplication on the first feature map and the second feature map after pooling to obtain an auxiliary first feature map corresponding to the first feature map and an auxiliary second feature map corresponding to the second feature map; in the spatial information extraction branch, perform global average pooling and maximum pooling on the first feature map and the second feature map after pooling, and perform a first preset number of convolution operations on the first feature map and the second feature map after pooling to obtain a third feature map; perform dot multiplication on the first feature map and the second feature map with the third feature map to obtain a fourth feature map and a fifth feature map;
[0010] Performing a convolution operation for a second preset number of times on a sixth feature map obtained by connecting the first feature map, the second feature map, the auxiliary first feature map, the auxiliary second feature map, the fourth feature map, and the fifth feature map to obtain a seventh feature map;
[0011] The semantic segmentation result of the image block is determined based on the seventh feature map; the semantic segmentation results of each image block are spliced according to the position of each image block in the original image to obtain the semantic segmentation result of the original image.
[0012] Preferably, performing global average pooling on the first feature map and the second feature map, and performing matrix multiplication on the pooled first feature map and the second feature map, comprising:
[0013] Performing global average pooling on the h dimension of the first feature map and the second feature map to obtain an h-dimensional feature map of the first feature map and an h-dimensional feature map of the second feature map;
[0014] Performing global average pooling on the w dimensions of the first feature map and the second feature map to obtain a w-dimensional feature map of the first feature map and a w-dimensional feature map of the second feature map;
[0015] Performing matrix multiplication on the w-dimensional feature map and the h-dimensional feature map of the first feature map to obtain the auxiliary first feature map;
[0016] Matrix multiplication is performed on the w-dimensional feature map and the h-dimensional feature map of the second feature map to obtain the auxiliary second feature map.
[0017] Preferably, global average pooling and maximum pooling are performed on both the first feature map and the second feature map, and a first preset number of convolution operations are performed on the first feature map and the second feature map after pooling, including:
[0018] Connecting the first feature map and the second feature map after pooling to obtain a first connected feature map;
[0019] Performing a convolution operation on the first connection feature map using n convolution layers with different convolution kernel sizes to obtain n convolutional first connection feature maps, where n is an integer not less than 2;
[0020] Connecting the first convolution feature maps to obtain a second convolution feature map;
[0021] A convolution operation is performed on the second connected feature map to obtain the third feature map.
[0022] Preferably, upsampling the image of the same portion of the coarse feature map as the image of the image block comprises:
[0023] Using the position of the image block in the original image and the ROIAlign function, obtaining a coarse feature block in the coarse feature map that has the same position area as the image block;
[0024] The coarse feature block is upsampled to obtain a second feature map of the preset size.
[0025] Preferably, performing a second preset number of convolution operations on the sixth feature map includes:
[0026] Performing a convolution operation on the sixth feature map using m convolution layers with the same convolution kernels to obtain a preliminary feature map, where m is an integer not less than 2;
[0027] The preliminary feature map is convolved using two convolution layers with different convolution kernels, and the two feature maps obtained by the convolution are connected to obtain the seventh feature map.
[0028] Preferably, splicing the semantic segmentation results of each image block according to the position of each image block in the original image includes:
[0029] Determine the coordinate points of four vertices of each of the image blocks in a preset coordinate system of the original image, where the horizontal axis of the preset coordinate system is the X axis and the vertical axis is the Y axis;
[0030] Determining an image portion in the original image corresponding to the image block based on coordinates of four vertices of the image block;
[0031] The semantic segmentation results of the image blocks are spliced according to the image parts in the original image corresponding to the image blocks.
[0032] Preferably, obtaining a first feature map of the image block after the convolution operation and a coarse feature map of the coarse image after the convolution operation, upsampling an image of a portion of the coarse feature map that is the same as the image of the image block to obtain a second feature map of the preset size includes:
[0033] Inputting the image block and the rough image into the HRNetV2+OCR model;
[0034] In the HRNetV2+OCR model, a convolution operation is performed on the image block and the rough image to obtain a first feature map and the rough feature map, and an image of the same portion of the rough feature map as the image of the image block is upsampled to obtain a second feature map of the preset size.
[0035] Preferably, determining the semantic segmentation result of the image block based on the seventh feature map includes:
[0036] Performing a convolution operation on the seventh feature map to obtain the convolved seventh feature map;
[0037] An Argmax operation is performed on the seventh feature map after the convolution operation to obtain a semantic segmentation result of the image block.
[0038] The present application also provides a semantic segmentation device for an image, comprising:
[0039] Memory for storing computer programs;
[0040] A processor is used to implement the steps of the above-mentioned method for semantic segmentation of an image when executing the computer program.
[0041] The present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the image semantic segmentation method as described above are implemented.
[0042] The present invention provides a method, device and computer-readable storage medium for semantic segmentation of an image, and relates to the field of semantic segmentation. The method comprises: dividing an original image into image blocks of preset sizes and downsampling the original image to a coarse image of preset sizes; for each image block, inputting the obtained coarse image and the image block into a semantic segmentation model together to obtain the semantic segmentation results of each image block; splicing the semantic segmentation results of the image blocks according to the positions of the image blocks on the original image to obtain the final segmentation results of the original image. The semantic segmentation model includes a pooling branch and a spatial information extraction branch, which can establish a connection between each image block and the coarse image, avoid ambiguity in the semantic segmentation results of the image blocks, and further avoid the information in the final spliced image being inconsistent with the information in the original image, accurately classify the pixels belonging to a certain category into the category, and finally improve the accuracy of image semantic segmentation. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the prior art and the drawings required for use in the embodiments are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0044] Figure 1 A flowchart of a method for semantic segmentation of an image provided in this application;
[0045] Figure 2 A schematic diagram of downsampling and segmentation processing of an original image provided in this application;
[0046] Figure 3 A schematic diagram of the structure of a semantic segmentation network model provided in this application;
[0047] Figure 4 A schematic diagram of the structure of an image semantic segmentation device provided in this application. DETAILED DESCRIPTION
[0048] The core of the present invention is to provide a method, system and device for semantic segmentation of images, which can establish a connection between each image block and the rough image, avoid ambiguity in the semantic segmentation results of the image blocks, and thus avoid inconsistency between the information in the final spliced image and the information in the original image, accurately classify the pixels belonging to a certain category into the category, and ultimately improve the accuracy of image semantic segmentation.
[0049] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0050] Please refer to Figure 1 , Figure 1 The present invention provides a method for semantic segmentation of an image, the method comprising:
[0051] S1: when an original image is obtained, an image block and a rough image of the original image are obtained; wherein the image block is any one of N image blocks of preset sizes obtained by cutting the original image into the image block, and the rough image is an image of the preset size obtained by downsampling the original image, where N is an integer not less than 2;
[0052] S2: Obtain a first feature map of the image block after the convolution operation and a coarse feature map of the coarse image after the convolution operation; upsample the image of the same portion of the coarse feature map as the image of the image block to obtain a second feature map of a preset size;
[0053] S3: Input the first feature map and the second feature map into the pooling branch and the spatial information extraction branch; in the pooling branch, perform global average pooling on the first feature map and the second feature map, and perform matrix multiplication on the pooled first feature map and the second feature map to obtain an auxiliary first feature map corresponding to the first feature map and an auxiliary second feature map corresponding to the second feature map; in the spatial information extraction branch, perform global average pooling and maximum pooling on the first feature map and the second feature map, and perform a first preset number of convolution operations on the pooled first feature map and the second feature map to obtain a third feature map; perform dot multiplication on the first feature map and the second feature map with the third feature map to obtain a fourth feature map and a fifth feature map;
[0054] S4: performing a convolution operation for a second preset number of times on a sixth feature map obtained by connecting the first feature map, the second feature map, the auxiliary first feature map, the auxiliary second feature map, the fourth feature map, and the fifth feature map to obtain a seventh feature map;
[0055] S5: Determine the semantic segmentation result of the image block based on the seventh feature map; splice the semantic segmentation results of each image block according to the position of each image block in the original image to obtain the semantic segmentation result of the original image.
[0056] When semantic segmentation is performed on an image, the effect of semantic segmentation will be affected by the original resolution of the image and the processing performance of the processor that performs semantic segmentation on the image. The prior art often downsamples the original image into a low-resolution image and then performs semantic segmentation, or divides the original image into multiple image blocks and then performs semantic segmentation on the image blocks one by one. If the original image is downsampled into a low-resolution image, some detail information in the original image will be lost, making the result of semantic segmentation inaccurate. For example, if the original image is a circuit board inside a device, after it is downsampled into a low-resolution image, a small component such as a capacitor may be lost because the image becomes blurred; if the original image is divided into multiple image blocks, it is equivalent to these image blocks themselves being a complete image, and there is no connection between the image blocks, so the semantic segmentation results of these image blocks may be wrong. For example, if an image of a poster is divided into multiple image blocks, the content of one of the image blocks is only the pure color part of the background. It can be seen that it is difficult to determine what category the image block belongs to, that is, the semantic segmentation result of the image block may not classify the category of the image block into the poster.
[0057] After the original image is segmented and downsampled, the resolution of the original image is assumed to be H*W. The resolution of the downsampled rough image can be preset to be h*w. The original image can be segmented into N image blocks of size h*w. For example, when H is X times h and W is Y times w, the number of image blocks obtained by segmentation is X*Y. Then, any image block and the rough image are convolved, and they can be input into a rough segmentation model for convolution. The rough segmentation model can be any neural network model that can achieve this function. In the training phase, the original images in the data set are used for training, and data augmentation strategies such as random cropping, rotation, and flipping are used for data expansion. Then, the data is normalized to the h*w resolution for training to obtain the network weights of the rough segmentation model. In the testing phase, the trained weights are fixed, and the image block and the rough image are input into the neural network model. When obtaining the second feature map, since the rough image is equivalent to a reduced version of the original image, and the image block is equivalent to a part of the original image, it is necessary to take out the image equivalent to the part in the rough image and then enlarge it to the h*w size. Please refer to Figure 2 , Figure 2 A schematic diagram of downsampling and segmentation of an original image provided by the present application. If the image block is the image of the upper left corner of the 16 image blocks into which the original image is segmented, the image of the same part of the upper left corner of the rough image needs to be upsampled to h*w size. The sizes of the first feature map and the second feature map finally obtained are both (c, h, w), where c is the number of categories that the image may belong to, h is the height of the image, and w is the width of the image.
[0058] Then input the first feature map and the second feature map into the two branches, please refer to Figure 3 , Figure 3 A structural diagram of a semantic segmentation network model provided for this application, the box in the center is a spatial information extraction branch, and the pooling branches are located on the upper and lower sides of the spatial information extraction branch. In the pooling branch, global average pooling is performed on the image according to its resolution to obtain feature maps in various dimensions; in the spatial information extraction branch, global average pooling and multiple convolution operations are performed to obtain feature maps corresponding to image blocks and rough images after spatial information enhancement. Finally, the multiple feature maps obtained by the two branches are connected (concatenation), and the connected feature maps are subjected to multiple convolution operations to fine-tune them. The results of the refined prediction are required for any image block. The above steps need to be performed, and finally the semantic segmentation results of N image blocks can be obtained, and then the semantic segmentation results are spliced according to the positions of these image blocks in the original image to obtain the final semantic segmentation results of the original image.
[0059] It should also be noted that when training the network of this solution, the network layer weights of our pooling branch and spatial information extraction branch are randomly initialized using Gaussian distribution. First, the general segmentation model is trained. After the training is completed, the weight parameters of the general segmentation model are fixed, and then the fine-tuning network is trained based on the general segmentation model. In the initial 20 epoch training, the learning rate is set to 0.001, and then 30 epoch training is performed, at this time the learning rate is adjusted to 0.0001. In addition, all training is completed under the Pytorch framework and can be run on Ubuntu 16.04 system and Tesla V100s.
[0060] In summary, the original image is divided into image blocks of preset sizes and the original image is downsampled to a coarse image of preset sizes; for each image block, the obtained coarse image and the image block are input into the semantic segmentation model together to obtain the semantic segmentation results of each image block; the semantic segmentation results of the image blocks are spliced according to the positions of the image blocks on the original image to obtain the final segmentation results. The semantic segmentation model includes a pooling branch and a spatial information extraction branch, which can establish a connection between each image block and the coarse image, avoid ambiguity in the semantic segmentation results of the image blocks, and thus avoid inconsistency between the information in the final spliced image and the information in the original image, accurately classify the pixels belonging to a certain category into that category, and finally improve the accuracy of image semantic segmentation.
[0061] Based on the above embodiments:
[0062] As a preferred embodiment, global average pooling is performed on the first feature map and the second feature map, and matrix multiplication is performed on the pooled first feature map and the second feature map, including:
[0063] Performing global average pooling on the h dimension of the first feature map and the second feature map to obtain an h-dimensional feature map of the first feature map and an h-dimensional feature map of the second feature map;
[0064] Performing global average pooling on the w dimension of the first feature map and the second feature map to obtain a w-dimensional feature map of the first feature map and a w-dimensional feature map of the second feature map;
[0065] Performing matrix multiplication on the w-dimensional feature map and the h-dimensional feature map of the first feature map to obtain an auxiliary first feature map;
[0066] Matrix multiplication is performed on the w-dimensional feature map and the h-dimensional feature map of the second feature map to obtain an auxiliary second feature map.
[0067] In order to accurately obtain the auxiliary first feature map and the auxiliary second feature map, in this application, for the first feature map, its size is (c, h, w), where c is the number of categories that the first feature map is predicted to be classified into, and h and w are the height and width of the first feature map, respectively. When performing global average pooling on the first feature map, in order to avoid errors in the pooling results and slow pooling speed caused by a large number of parameters involved in the calculation at the same time, the two dimensions of the first feature map can be globally average pooled first, and then combined to obtain the final auxiliary first feature map. Specifically, global average pooling is performed on both the h dimension and the w dimension of the first feature map, and a feature map of size (c, 1, w) can be obtained in the h dimension, and a feature map of size (c, h, 1) can be obtained in the w dimension. Finally, the two feature maps are multiplied by matrix multiplication, and the formula is as follows: F A =M{Avgpool(h,1),Avgpool(1,w)}, where F A is the auxiliary first feature map, M is matrix multiplication, Avgpool(h, 1) represents the global average pooling operation on the feature map in the w dimension, and Avgpool(1, w) represents the global average pooling operation on the feature map in the h dimension. Based on this, an auxiliary first feature map of size (c, h, w) can be output, and the auxiliary second feature map is determined in the same way. By first performing global average pooling on different dimensions and then performing matrix multiplication on the pooling results, the auxiliary first feature map and the auxiliary second feature map can be accurately obtained.
[0068] As a preferred embodiment, global average pooling and maximum pooling are performed on both the first feature map and the second feature map, and a first preset number of convolution operations are performed on the pooled first feature map and the second feature map, including:
[0069] Connecting the pooled first feature map and the second feature map to obtain a first connected feature map;
[0070] Performing a convolution operation on the first connection feature map using n convolution layers with different convolution kernel sizes to obtain the first connection feature map after n convolutions, where n is an integer not less than 2;
[0071] Connect the first connected feature maps after each convolution to obtain a second connected feature map;
[0072] The second connected feature map is convolved to obtain the third feature map.
[0073] In order to obtain a third feature map with stronger feature information, after pooling the first feature map and the second feature map twice, a global average pooling feature map and a maximum pooling feature map corresponding to the first feature map and the second feature map will be obtained, that is, a total of 4 feature maps of size (1, h, w) are obtained, and these 4 feature maps are connected to obtain the first connected feature map. After obtaining the first connection feature map, n convolutional layers with different convolution kernel sizes are used to perform convolution operations on the first connection feature map. For example, when n is 3, convolutional layers with convolution kernel sizes of 3*3, 5*5 and 7*7 can be used to perform convolution operations on the first connection feature map, and three first convolutional feature maps of size (1, h, w) are obtained. Since the smaller the convolution kernel, the more the convolution layer can focus on the smaller object part in the first connection feature map, and the larger the convolution kernel, the more the convolution layer can focus on the larger object part in the first connection feature map, the first connection feature map is convolved by using N convolutional layers with different convolution kernel sizes, and then the three convolutional first feature maps are connected to obtain a second connection feature map of size (3, h, w). The convolutional layer with a convolution kernel size of 3*3 is used to convolve the second connection feature map, and a third feature map of size (1, h, w) can be obtained. Since it has undergone multiple convolution operations with various convolution kernel sizes, the feature information of the obtained third feature map is stronger.
[0074] As a preferred embodiment, upsampling the image of the same portion of the image block in the coarse feature map includes:
[0075] Using the position of the image block in the original image and the ROIAlign function, a coarse feature block in the coarse feature map having the same position area as the image block is obtained;
[0076] The coarse feature block is upsampled to obtain a second feature map of a preset size.
[0077] In order to facilitate the establishment of connections between image blocks, in this application, it is considered that if there is no connection between image blocks, the categories of pixels in the image blocks may be incorrectly classified. For example, after an image containing a car is divided into multiple image blocks, the pixels in these image blocks cannot be classified as the same car. Since the coarse feature map is equivalent to a small-size, low-pixel version of the original image, it has the connection between each pixel of the original image, so the coarse feature map can be used to establish connections between image blocks. The image in the coarse feature map that is the same part as the image of the image block refers to the image portion of the original image occupied by the image block, and then the image portion is upsampled to obtain a second feature map of the same size as the image block. For example, if the original image is an image of a vehicle and its surrounding environment, assuming that the size of the original image is 100 pixels * 100 pixels, the original image is downsampled to obtain a 10 * 10 pixel coarse image, and the original image is block processed to obtain 100 image blocks of 10 pixels * 10 pixels, and one of the image blocks is exactly the image of the right front wheel tire and its surrounding parts of the vehicle. According to the position information of the image block, the ROIAlign (Region of Interest alignment) function is used to obtain the image of the right front wheel tire and its surrounding parts of the vehicle in the coarse feature map, and then it is normalized and upsampled to obtain a second feature map with a size of 10 pixels * 10 pixels. Since the second feature map has a connection between itself and other pixels in the coarse feature map, it can be known that the second feature map represents the right front wheel tire and its surrounding parts of the vehicle. Based on this, it is convenient for the image block to subsequently establish a connection between itself and other image blocks.
[0078] As a preferred embodiment, performing a convolution operation on the sixth feature map for a second preset number of times includes:
[0079] Perform a convolution operation on the sixth feature map using m convolution layers with the same convolution kernels to obtain a preliminary feature map, where m is an integer not less than 2;
[0080] The preliminary feature map is convolved using two convolution layers with different convolution kernels, and the two feature maps obtained by the convolution are connected to obtain the seventh feature map.
[0081] In order to improve the accuracy of semantic segmentation, in this application, after obtaining the sixth feature map, it is necessary to perform a second preset number of convolution operations to improve the segmentation effect of the object edge, and obtain a seventh feature map with obvious object edges and clear object boundary segmentation. Specifically, the sixth feature map is obtained by connecting the first feature map, the second feature map, the auxiliary first feature map, the auxiliary second feature map, the fourth feature map and the fifth feature map, a total of 6 feature maps, and the sizes of these feature maps are (c, h, w), and the size of the obtained sixth feature map is (6*c, h, w). The sixth feature map is input into a convolution layer with a convolution kernel size of 3*3 for convolution operation, and the result is then entered into a convolution layer with a convolution kernel size of 3*3 for convolution operation to obtain a feature map of (128, h, w). At this time, in order to adjust the depth of the network and increase the dimension of the feature map, a three-layer convolution layer with a convolution kernel of {1*1, 3*3, 1*1} and a convolution layer with a convolution kernel of 1*1 are used to perform a convolution operation on the feature map of (128, h, w), and then the two are connected to obtain the seventh feature map, the size of which is (256, h, w). The seventh feature map has a stronger network expression ability than the sixth feature map, which makes the subsequent semantic segmentation more accurate.
[0082] In order to further improve the segmentation effect of object edges, the above convolutional layer can be trained. Please refer to Figure 3 , Figure 3 A schematic diagram of the structure of a semantic segmentation network model provided in this application can be trained using a boundary loss function such as a cross entropy loss function. Figure 3 The dotted box in the upper right corner is the boundary loss function. First, the Laplace transform is used to transform the true semantic label of the data set to obtain the true label of the boundary. Then the seventh feature map is input into a convolution layer with a convolution kernel size of 3*3 to obtain a boundary prediction map of size (1,h,w). The loss function is: Among them, y i is the predicted value of each pixel in the seventh feature map, y i~ is the corresponding boundary true label, h and w are the height and width of the seventh feature map, L edge is the boundary loss. In addition, since boundary loss usually only occurs in the training phase, it is not necessary to predict the boundaries of the image separately in practical applications. In addition, during training, the network layer weights can also be randomly initialized using Gaussian distribution.
[0083] As a preferred embodiment, the semantic segmentation results of each image block are spliced according to the position of each image block in the original image, including:
[0084] Determine the coordinate points of the four vertices of each image block in a preset coordinate system of the original image, where the horizontal axis of the preset coordinate system is the X axis and the vertical axis is the Y axis;
[0085] Determine the image portion in the original image corresponding to the image block based on the coordinates of the four vertices of the image block;
[0086] The semantic segmentation results of the image blocks are spliced according to the image parts in the original image corresponding to each image block.
[0087] In order to correctly stitch the semantic segmentation results of each image block, in this application, it is first necessary to confirm the position of each image block in the original image. The preset coordinate system can use the pixel points of the original image as the numerical interval of the coordinate axis. After the original image is divided into N image blocks, each image block has 4 vertices. By determining the coordinates of these 4 vertices, it is possible to determine that the image block corresponds to the image part in the original image, and finally the semantic segmentation result of the image block is used as the semantic segmentation result of the image part in the original image corresponding to the image block. For example, the size of the original image is 200 pixels * 200 pixels, and the coordinates of the upper right corner vertex of the original image in the coordinate system are (200, 200). If the original image is divided into 4 image blocks of 100 pixels * 100 pixels, and the coordinates of the 4 vertices of one of the image blocks are (0, 0), (0, 100), (100, 0) and (100, 100), then through the coordinate information of the 4 vertices of this image block, it can be determined that the image block corresponds to the lower left corner image part of the original image or the image of the lower half of the left half. Finally, the semantic segmentation result of the image block is used as the semantic segmentation result of the lower left corner image part of the original image, and the steps for the other three image blocks are the same. Based on this, the semantic segmentation results of each image block can be spliced into the image part of the original image corresponding to the image block, and the combination is the semantic segmentation result of the original image.
[0088] As a preferred embodiment, obtaining a first feature map of an image block after a convolution operation and a coarse feature map of a coarse image after a convolution operation includes:
[0089] Send both the image patch and the rough image to the HRNetV2+OCR model;
[0090] In the HRNetV2+OCR model, convolution operations are performed on the image block and the coarse image to obtain the first feature map and the coarse feature map.
[0091] In order to obtain the first feature map and the rough feature map, in this application, when extracting features from image blocks and rough images, in order to improve the accuracy of feature extraction, the HRNetV2+OCR (High-Resolution Network version2+Object-contextual representations) model is used as a model for feature extraction. HRNetV2 can maintain the high-resolution representation of the image during the entire feature extraction process to avoid the image resolution reduction caused by the convolution operation, which leads to ambiguity in the final semantic segmentation result. OCR can calculate the relationship weight between each pixel in the image and other pixels in the image, and then superimpose it with the original features in the image, so that the feature information of the first feature map and the rough feature map is more obvious, and the accuracy of semantic segmentation is improved. When training the HRNetV2+OCR model, the ImageNet data set is used to provide relevant data, and images in multiple image data sets can be trained. These images can be expanded by random cropping, rotation, flipping and other data enhancement steps, and then these images are normalized to a preset size to train the HRNetV2+OCR model.
[0092] As a preferred embodiment, determining the semantic segmentation result of the image block based on the seventh feature map includes:
[0093] Performing a convolution operation on the seventh feature map to obtain a convolved seventh feature map;
[0094] Perform the Argmax operation on the seventh feature map after the convolution operation to obtain the semantic segmentation result of the image block.
[0095] In order to obtain accurate semantic segmentation results, in the present application, since the output first feature map and the second feature map are adjusted through multiple convolution operations, the image semantic information characteristics of the seventh feature map are stronger. After obtaining the seventh feature map, as long as the seventh feature map is subjected to a convolution operation with a convolution kernel of 3*3 and then an Argmax (arguments of the maxima, maximum point set) operation is performed once, the accurate semantic segmentation result of the seventh feature map can be obtained, and the semantic segmentation result is a semantic segmentation image block of size (1, h, w).
[0096] Please refer to Figure 4 , Figure 4 A semantic segmentation device for an image provided in this application includes:
[0097] A memory 21, used for storing computer programs;
[0098] The processor 22 is used to implement the steps of the above-mentioned method for semantic segmentation of an image when executing a computer program.
[0099] For a detailed introduction to an image semantic segmentation device provided in the present application, please refer to the above-mentioned embodiment of the image semantic segmentation method, and the present application will not go into details here.
[0100] The present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the image semantic segmentation method as described above are implemented.
[0101] For a detailed introduction to a computer-readable storage medium provided in the present application, please refer to the embodiment of the semantic segmentation method of the above-mentioned image, and the present application will not go into details here.
[0102] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0103] It should also be noted that, in this specification, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.
Claims
1. A semantic segmentation method for an image, characterized in that: include: When an original image is obtained, an image block and a rough image of the original image are obtained; wherein the image block is any one of N image blocks of preset sizes obtained by cutting the original image into the image block, and the rough image is an image of the preset size obtained by downsampling the original image, where N is an integer not less than 2; Obtaining a first feature map of the image block after the convolution operation and a coarse feature map of the coarse image after the convolution operation; upsampling an image of a portion of the coarse feature map that is the same as the image of the image block to obtain a second feature map of the preset size; Input the first feature map and the second feature map into a pooling branch and a spatial information extraction branch; in the pooling branch, perform global average pooling on the first feature map and the second feature map, and perform matrix multiplication on the first feature map and the second feature map after pooling to obtain an auxiliary first feature map corresponding to the first feature map and an auxiliary second feature map corresponding to the second feature map; in the spatial information extraction branch, perform global average pooling and maximum pooling on the first feature map and the second feature map after pooling, and perform a first preset number of convolution operations on the first feature map and the second feature map after pooling to obtain a third feature map; perform dot multiplication on the first feature map and the second feature map with the third feature map to obtain a fourth feature map and a fifth feature map; Performing a convolution operation for a second preset number of times on a sixth feature map obtained by connecting the first feature map, the second feature map, the auxiliary first feature map, the auxiliary second feature map, the fourth feature map, and the fifth feature map to obtain a seventh feature map; The semantic segmentation result of the image block is determined based on the seventh feature map; the semantic segmentation results of each image block are spliced according to the position of each image block in the original image to obtain the semantic segmentation result of the original image.
2. The method for semantic segmentation of an image according to claim 1, wherein: Performing global average pooling on the first feature map and the second feature map, and performing matrix multiplication on the first feature map and the second feature map after the pooling, including: Performing global average pooling on the h dimension of the first feature map and the second feature map to obtain an h-dimensional feature map of the first feature map and an h-dimensional feature map of the second feature map; Performing global average pooling on the w dimensions of the first feature map and the second feature map to obtain a w-dimensional feature map of the first feature map and a w-dimensional feature map of the second feature map; Performing matrix multiplication on the w-dimensional feature map and the h-dimensional feature map of the first feature map to obtain the auxiliary first feature map; Matrix multiplication is performed on the w-dimensional feature map and the h-dimensional feature map of the second feature map to obtain the auxiliary second feature map.
3. The method for semantic segmentation of an image according to claim 1, wherein: Performing global average pooling and maximum pooling on both the first feature map and the second feature map, and performing a first preset number of convolution operations on the first feature map and the second feature map after pooling, including: Connecting the first feature map and the second feature map after pooling to obtain a first connected feature map; Performing a convolution operation on the first connection feature map using n convolution layers with different convolution kernel sizes to obtain n convolutional first connection feature maps, where n is an integer not less than 2; Connecting the first convolution feature maps to obtain a second convolution feature map; A convolution operation is performed on the second connected feature map to obtain the third feature map.
4. The method for semantic segmentation of an image according to claim 1, wherein: Upsampling the image of the same portion of the coarse feature map as the image of the image block, comprising: Using the position of the image block in the original image and the ROIAlign function, obtaining a coarse feature block in the coarse feature map that has the same position area as the image block; The coarse feature block is upsampled to obtain a second feature map of the preset size.
5. The method for semantic segmentation of an image according to claim 1, wherein: Performing a second preset number of convolution operations on the sixth feature map includes: Performing a convolution operation on the sixth feature map using m convolution layers with the same convolution kernels to obtain a preliminary feature map, where m is an integer not less than 2; The preliminary feature map is convolved using two convolution layers with different convolution kernels, and the two feature maps obtained by the convolution are connected to obtain the seventh feature map.
6. The method for semantic segmentation of an image according to claim 1, wherein: The semantic segmentation results of each image block are spliced according to the position of each image block in the original image, including: Determine the coordinate points of four vertices of each of the image blocks in a preset coordinate system of the original image, where the horizontal axis of the preset coordinate system is the X axis and the vertical axis is the Y axis; Determine the image portion of the original image corresponding to the image block based on the coordinates of the four vertices of the image block; The semantic segmentation results of the image blocks are spliced according to the image parts in the original image corresponding to the image blocks.
7. The method for semantic segmentation of an image according to claim 1, wherein: Acquiring a first feature map of the image block after the convolution operation and a coarse feature map of the coarse image after the convolution operation, upsampling an image of a portion of the coarse feature map that is the same as the image of the image block to obtain a second feature map of the preset size, including: Inputting the image block and the rough image into the HRNetV2+OCR model; In the HRNetV2+OCR model, a convolution operation is performed on the image block and the rough image to obtain a first feature map and the rough feature map, and an image of the same portion of the rough feature map as the image of the image block is upsampled to obtain a second feature map of the preset size.
8. The method for semantic segmentation of an image according to any one of claims 1 to 7, characterized in that: Determining a semantic segmentation result of the image block based on the seventh feature map includes: Performing a convolution operation on the seventh feature map to obtain the convolved seventh feature map; An Argmax operation is performed on the seventh feature map after the convolution operation to obtain a semantic segmentation result of the image block.
9. A semantic segmentation device for an image, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the method for semantic segmentation of an image as described in any one of claims 1 to 8 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method for semantic segmentation of an image as described in any one of claims 1 to 8 are implemented.
