A semantic segmentation method, system and electronic device
By adding branch networks and feature fusion modules to the BiSeNet model, combining edge, shallow and semantic features, and optimizing the loss function, the problem of low semantic segmentation accuracy in the existing technology is solved, and the state detection of the railway catenary cotter pin is significantly improved. Semantic segmentation accuracy.
Patent Information
- Application Number
- CN202111049819.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-08
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2041-09-08
AI Technical Summary
The existing semantic segmentation model has low semantic segmentation accuracy in the detection of the cotter pin status of the railway catenary, and it is difficult to obtain rich semantic information, which affects subsequent research.
Add a branch network to the BiSeNet model to restore the edge part of the picture, combine the spatial branch network and the context branch network, extract edge features, shallow features and semantic features through the feature fusion module and attention recovery module, and optimize the loss function to improve semantic segmentation accuracy.
By extracting rich edge, shallow and semantic features, the semantic segmentation accuracy is significantly improved and the model's recognition ability of the image to be segmented is improved.
Smart Images

Figure CN114119971B
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of railway contact network cotter pin state detection, and in particular to a semantic segmentation method, system and electronic equipment. Background Art
[0002] To identify the state of a component, it is necessary to separate the component area from the background area. However, in practice, the following problems are often encountered, for example, when the target to be detected does not have obvious features in the image, or the target is difficult to distinguish from the background. In recent years, with the substantial improvement of computer computing power, methods based on deep learning have made great progress, and it has become possible to extract the target area using deep learning methods.
[0003] Among them, in the process of extracting the target area, the semantic segmentation models used are mainly divided into deep semantic segmentation models based on candidate regions and deep semantic segmentation models based on full convolution. The semantic segmentation method based on candidate regions needs to generate a large number of candidate regions. This process takes a lot of time and memory space, and the segmentation effect is often not as good as the semantic segmentation model based on full convolution. As the name suggests, the deep semantic segmentation model based on full convolution is composed entirely of convolutional layers and does not contain fully connected layers. The main ones are FCN, SegNet, and UNet.
[0004] Commonly used models include the BiSeNet model, which consists of a dual-branch network. When processing images with neural networks, different depths correspond to different levels of semantic features. The shallow network has a high resolution and contains more detailed features, while the deep network has a low resolution and contains more semantic features. However, for semantic segmentation, both spatial information and semantic features are important. Therefore, in order to obtain rich semantic information without losing too much spatial information, BiSeNet proposes a dual-branch semantic segmentation model. The first branch is a spatial network, which obtains a feature map of 1 / 8 the size of the input image through three convolutions. The second branch is a context network, which has a larger receptive field by residually connecting a deep backbone network. Finally, the features of the two branches are fused through a feature fusion module to obtain the final semantic segmentation map.
[0005] However, most of the above models have low semantic segmentation accuracy and cannot obtain rich semantic information, which greatly affects subsequent research. Summary of the invention
[0006] In view of the shortcomings of the prior art in that the semantic segmentation accuracy is low and rich semantic information cannot be obtained, the present invention provides a semantic segmentation method, system and electronic device, which, while solving the above-mentioned shortcomings, also achieves the purpose of extracting edge information of an image, and obtains the final semantic segmentation map by processing the edge features, shallow features and semantic features of the image.
[0007] The technical means of a semantic segmentation method provided by the present invention are as follows:
[0008] Get the image to be segmented;
[0009] The image to be segmented is input into the trained semantic segmentation model to obtain the final semantic segmentation map.
[0010] The beneficial effects of a semantic segmentation method of the present invention are as follows:
[0011] The semantic information contained in the image to be segmented can be obtained by using the trained semantic segmentation model. Based on the above solution, a semantic segmentation method of the present invention can also be improved as follows.
[0012] The process of acquiring the trained semantic segmentation model includes:
[0013] Get the image to be trained;
[0014] Add a branch network to BiSeNet to obtain an improved semantic segmentation model, wherein the branch network is used to restore the edge part of the image to be trained and output the edge features of the image to be trained, the context branch network in the BiSeNet is used to output the semantic features of the image to be trained, and the space branch network in the BiSeNet is used to output the shallow features of the image to be trained;
[0015] Input the edge features, the semantic features and the shallow features into the feature fusion module in the BiSeNet to obtain an initial semantic segmentation map of the image to be trained, perform an upsampling operation on the initial semantic segmentation map to obtain a final semantic segmentation map of the image to be trained, and train the improved semantic segmentation model to obtain a trained semantic segmentation model;
[0016] The network structure of the branch network is the same as the network structure of the context branch network.
[0017] The beneficial effects of adopting the above further scheme are: in the process of training the semantic segmentation model, the shallow features of the image to be trained are obtained through the spatial network branch in BiSeNet, which can retain the rich spatial information of the image to be trained; the rich semantic information of the image to be trained can be obtained through the context network branch in BiSeNet; the edge part of the image to be trained can be restored through the added network branch, and the edge features of the image to be trained can be obtained. Through the added network branch, the deep network not only combines the features of the shallow network, but also extracts more features through the shallow features, obtains richer semantic information, and improves the accuracy of semantic segmentation to a certain extent.
[0018] Furthermore, the semantic feature includes a first semantic feature and a second semantic feature.
[0019] The process of the context branch network outputting the first semantic feature and the second semantic feature of the image to be trained includes:
[0020] Through a downsampling operation, a first feature map of a first preset size and a second feature map of a second preset size of the image to be trained are obtained at different depths of the context branch network; using an attention recovery module of the context branch network, a first semantic feature of the image to be trained is obtained according to the first feature map, and a second semantic feature of the image to be trained is obtained according to the second feature map;
[0021] The edge feature includes a first edge feature and a second edge feature,
[0022] The process of the branch network outputting the first edge feature and the second edge feature of the image to be trained includes:
[0023] Through the downsampling operation, a third feature map of a third preset size and a fourth feature map of a fourth preset size of the image to be trained are respectively obtained at different depths of the branch network; using the attention recovery module of the branch network, a first edge feature of the image to be trained is obtained according to the third feature map, and a second edge feature of the image to be trained is obtained according to the fourth feature map.
[0024] Furthermore, it also includes:
[0025] Based on the improved semantic segmentation model, an improved loss function is obtained, and the improved loss function is: loss = L seg +L edge ;
[0026] Among them, L seg =β1CE(C1,y t )+β2CE(C2,y t )+β3CE(y,yt ), L seg is the segmentation loss caused by the context branch network, C1 is the first semantic feature of the image to be trained, C2 is the second semantic feature of the image to be trained, y is the final semantic segmentation map corresponding to the image to be trained, and y t is the preset semantic segmentation map corresponding to the image to be trained, CE(C1, y t ) is C1 and y t The cross entropy between CE(C2,y t ) is C2 and y t The cross entropy between CE(y,y t ) are y and y t The cross entropy between
[0027] L edge =α1BCE(E1,E T )+α2BCE(E2,E T ), L edge is the edge loss caused by the branch network, E1 is the first edge feature of the image to be trained, E2 is the second edge feature of the image to be trained, and E T is the edge map corresponding to the preset semantic segmentation map, BCE(E1, E T ) is E1 and E T The second-class cross entropy between E2 and E T ) is E2 and E T The second-class cross entropy between ;
[0028] Both α1 and α2 are greater than β1, β2 and β3.
[0029] The beneficial effect of adopting the above further scheme is: the input data of the feature fusion module in the semantic segmentation model is further clarified, the features obtained by the context branch network at different depths are respectively used through the attention recovery module to obtain the corresponding semantic segmentation features, and the features obtained by the added branch network at different depths are respectively used through the attention recovery module to obtain the corresponding edge features. Based on this, in order to enable different branches of the network to handle different tasks, different weights are set for output results of different depths in the loss function.
[0030] Furthermore, α1=2.5, α2=5, β1=2, β2=0.5, β3=1.
[0031] The beneficial effect of adopting the above further scheme is that through different weights, the features recovered by the shallow layer of the network have less influence in the loss function, while the features recovered by the deep network have greater influence in the loss function. edgeThe larger values of α1 and α2 are because the value calculated by the second-class cross entropy is generally much smaller than the cross entropy, so the influence of marginal loss on the loss function is increased by multiplying by a larger weight.
[0032] A technical solution of a semantic segmentation system of the present invention is as follows:
[0033] Includes acquisition unit and semantic segmentation unit;
[0034] The acquisition unit is used to acquire the image to be segmented;
[0035] The semantic segmentation unit is used to input the image to be segmented into a trained semantic segmentation model to obtain a final semantic segmentation map.
[0036] The beneficial effects of a semantic segmentation system of the present invention are as follows:
[0037] Through the trained semantic segmentation model, the semantic information contained in the image to be segmented is obtained.
[0038] Based on the above technical solution, a semantic segmentation system of the present invention can also be improved as follows.
[0039] Furthermore, the acquisition unit is also used to acquire the image to be trained;
[0040] The semantic segmentation unit is specifically used for:
[0041] Add a branch network to BiSeNet to obtain an improved semantic segmentation model, wherein the branch network is used to restore the edge part of the image to be trained and output the edge features of the image to be trained, the context branch network in the BiSeNet is used to output the semantic features of the image to be trained, and the space branch network in the BiSeNet is used to output the shallow features of the image to be trained;
[0042] Input the edge features, the semantic features and the shallow features into the feature fusion module in the BiSeNet to obtain an initial semantic segmentation map of the image to be trained, perform an upsampling operation on the initial semantic segmentation map to obtain a final semantic segmentation map of the image to be trained, and train the improved semantic segmentation model to obtain a trained semantic segmentation model;
[0043] The network structure of the branch network is the same as the network structure of the context branch network.
[0044] The beneficial effects of adopting the above further scheme are: in the process of training the semantic segmentation model, the shallow features of the image to be trained are obtained through the spatial network branch in BiSeNet, which can retain the rich spatial information of the image to be trained; the rich semantic information of the image to be trained can be obtained through the context network branch in BiSeNet; the edge part of the image to be trained can be restored through the added network branch, and the edge features of the image to be trained can be obtained. Through the added network branch, the deep network not only combines the features of the shallow network, but also extracts more features through the shallow features, obtains richer semantic information, and improves the accuracy of semantic segmentation to a certain extent.
[0045] Furthermore, the semantic feature includes a first semantic feature and a second semantic feature, the edge feature includes a first edge feature and a second edge feature, and the first processing unit is specifically configured to:
[0046] Through a downsampling operation, a first feature map of a first preset size and a second feature map of a second preset size of the image to be trained are obtained at different depths of the context branch network; using an attention recovery module of the context branch network, a first semantic feature of the image to be trained is obtained according to the first feature map, and a second semantic feature of the image to be trained is obtained according to the second feature map;
[0047] Through the downsampling operation, a third feature map of a third preset size and a fourth feature map of a fourth preset size of the image to be trained are respectively obtained at different depths of the branch network; using the attention recovery module of the branch network, a first edge feature of the image to be trained is obtained according to the third feature map, and a second edge feature of the image to be trained is obtained according to the fourth feature map.
[0048] Further, it also includes a design unit;
[0049] The design unit is used to design an improved loss function based on the improved semantic segmentation model.
[0050] The improved loss function is: loss = L seg +L edge ;
[0051] Among them, L seg =β1CE(C1,y t )+β2CE(C2,y t )+β3CE(y,y t ), L seg is the segmentation loss caused by the context branch network, C1 is the first semantic feature of the image to be trained, C2 is the second semantic feature of the image to be trained, y is the final semantic segmentation map corresponding to the image to be trained, and yt is the preset semantic segmentation map corresponding to the image to be trained, CE(C1, y t ) is C1 and y t The cross entropy between CE(C2,y t ) is C2 and y t The cross entropy between CE(y,y t ) are y and y t The cross entropy between
[0052] L edge =α1BCE(E1,E T )+α2BCE(E2,E T ), L edge is the edge loss caused by the branch network, E1 is the first edge feature of the image to be trained, E2 is the second edge feature of the image to be trained, and E T is the edge map corresponding to the preset semantic segmentation map, BCE(E1, E T ) is E1 and E T The second-class cross entropy between E2 and E T ) is E2 and E T The second-class cross entropy between ;
[0053] Both α1 and α2 are greater than β1, β2 and β3.
[0054] The beneficial effect of adopting the above further scheme is: the input data of the feature fusion module in the semantic segmentation model is further clarified, the features obtained by the context branch network at different depths are respectively used through the attention recovery module to obtain the corresponding semantic segmentation features, and the features obtained by the added branch network at different depths are respectively used through the attention recovery module to obtain the corresponding edge features. Based on this, in order to enable different branches of the network to handle different tasks, different weights are set for output results of different depths in the loss function.
[0055] Furthermore, α1=2.5, α2=5, β1=2, β2=0.5, β3=1.
[0056] The beneficial effect of adopting the above further scheme is that through different weights, the features recovered by the shallow layer of the network have less influence in the loss function, while the features recovered by the deep network have greater influence in the loss function. edge The larger values of α1 and α2 are because the value calculated by the second-class cross entropy is generally much smaller than the cross entropy, so the influence of marginal loss on the loss function is increased by multiplying by a larger weight.
[0057] The technical solution of an electronic device of the present invention is as follows:
[0058] The method comprises a memory, a processor and a program stored in the memory and running on the processor, wherein when the processor executes the program, the steps of a semantic segmentation method described in any one of the above items are implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0060] Figure 1 A schematic diagram of the steps of a semantic segmentation method according to an embodiment of the present invention;
[0061] Figure 2 Schematic diagram of the architecture of a semantic segmentation model according to an embodiment of the present invention;
[0062] Figure 3 A schematic diagram of the loss curve of the semantic segmentation model including the split pin image and the change of the mIoU value of the validation set in an embodiment of the present invention;
[0063] Figure 4 A schematic diagram of the loss variation trend of a semantic segmentation model including a cotter pin image trained in an embodiment of the present invention;
[0064] Figure 5 It is a schematic diagram of the average accuracy change trend of the semantic segmentation model trained with the cotter pin image in an embodiment of the present invention;
[0065] Figure 6 A structural diagram of a semantic segmentation system according to an embodiment of the present invention;
[0066] Figure 7 The figure is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0067] like Figure 1 As shown, a semantic segmentation method according to an embodiment of the present invention comprises the following steps:
[0068] S1, obtain the image to be segmented;
[0069] S2. Input the image to be segmented into a trained semantic segmentation model to obtain a final semantic segmentation map.
[0070] Specifically, the architecture diagram of the semantic segmentation model is as follows Figure 2 The process of obtaining the trained semantic segmentation model includes:
[0071] Get the image to be trained;
[0072] Add a branch network to BiSeNet to obtain an improved semantic segmentation model, wherein the branch network is used to restore the edge part of the image to be trained and output the edge features of the image to be trained, the context branch network in the BiSeNet is used to output the semantic features of the image to be trained, and the space branch network in the BiSeNet is used to output the shallow features of the image to be trained;
[0073] Input the edge features, the semantic features and the shallow features into the feature fusion module in the BiSeNet to obtain an initial semantic segmentation map of the image to be trained, perform an upsampling operation on the initial semantic segmentation map to obtain a final semantic segmentation map of the image to be trained, and train the improved semantic segmentation model to obtain a trained semantic segmentation model;
[0074] The network structure of the branch network is the same as the network structure of the context branch network.
[0075] Generally, an eight-fold upsampling operation is used, and adaptive adjustments can also be made according to actual conditions.
[0076] Specifically, the Feature Fusion Module (FFM) in BiSeNet is used to integrate features from the spatial branch network and the context branch network. In the semantic segmentation model of this solution, the feature fusion module needs to integrate features from the spatial branch network, the context branch network, and the added branch network. The network structures of the added branch network and the context branch network are both built based on ResNet18. Through ResNet18, the semantic segmentation model needs to learn less content and is easier to learn. This further reduces the complexity of network training in the semantic segmentation model and improves efficiency.
[0077] Specifically, the process of obtaining a trained semantic segmentation model includes the following steps:
[0078] Step 1: Create a semantic segmentation dataset, which is a large number of original images used to train and test the semantic segmentation model, as well as labeled images for verification;
[0079] Specifically, the process of obtaining the labeled image is: processing the original image through target detection, and using Labelme software to mark the target area in the original image after target detection, obtaining the json file corresponding to the original image after target detection, and processing the json file through Labelme software to obtain the labeled image corresponding to the original image after target detection.
[0080] Step 2: Train the semantic segmentation model, save the model with the highest verification accuracy, and save the final model after training is completed.
[0081] Taking the example of obtaining a semantic segmentation map containing a cotter pin image, the process of training the semantic segmentation model is as follows:
[0082] 1. Make a segmentation dataset
[0083] Since the pixel area of the cotter pin region is relatively small, generally about 100*100, in order to facilitate the marking and segmentation of data, the image size is adjusted to 512*512. In addition, the data is gamma corrected to improve the data contrast, and then the labelme software is used to create the data set.
[0084] The images of the located split pin area are used as a data set, with a total of 802 images, which are divided into training set, validation set, and test set in a ratio of 8:1:1. The training set and validation set are used to train the semantic segmentation model. The performance of the current iteration model is verified during the training process, and the test set is used to evaluate the model after the training is completed. The split pin area is divided into the head and tail areas, and the split pin semantic segmentation data set is produced using polygon annotation, where the green area of the label is the split pin head, and the red area is the split pin tail.
[0085] 2. Training semantic segmentation model
[0086] The maximum number of iterations was set to 500, the learning rate was 0.01, and the momentum and weight decay were configured to 0.9 and 0.0001 respectively. The experiment used a GTX2080 graphics card. During the training process, the model with the highest verification accuracy was always saved, and the final model was saved after the training was completed.
[0087] The training process is recorded by tensorboard, and the loss curve and the mIoU value change process of the validation set are as follows Figure 3 As shown, the change trend of loss and average accuracy is as follows Figure 4 and Figure 5 shown.
[0088] When training reaches 150 times, the training loss and mIoU value basically converge. The final mIoU value on the validation set is 87.3%, the prediction accuracy is 97.3%, and the loss drops to 0.182. mIoU is the average intersection-over-union ratio, that is, the IoU value is calculated on each category, and the calculation formula is: The accuracy is the ratio of the number of correctly predicted pixels to the total number of pixels.
[0089] Among them, n is the number of categories, the true value TP: the predicted value is 1, the true value is 1; the false positive value FP: the predicted value is 1, the true value is 0; the false negative value (FN): the predicted value is 0, the true value is 1.
[0090] Preferably, the semantic feature includes a first semantic feature and a second semantic feature.
[0091] The process of the context branch network outputting the first semantic feature and the second semantic feature of the image to be trained includes:
[0092] Through a downsampling operation, a first feature map of a first preset size and a second feature map of a second preset size of the image to be trained are obtained at different depths of the context branch network; using an attention recovery module of the context branch network, a first semantic feature of the image to be trained is obtained according to the first feature map, and a second semantic feature of the image to be trained is obtained according to the second feature map;
[0093] The edge feature includes a first edge feature and a second edge feature,
[0094] The process of the branch network outputting the first edge feature and the second edge feature of the image to be trained includes:
[0095] Through the downsampling operation, a third feature map of a third preset size and a fourth feature map of a fourth preset size of the image to be trained are respectively obtained at different depths of the branch network; using the attention recovery module of the branch network, a first edge feature of the image to be trained is obtained according to the third feature map, and a second edge feature of the image to be trained is obtained according to the fourth feature map.
[0096] Generally, by downsampling at different depths of the context branch network, feature maps of sizes 1 / 4, 1 / 8, 1 / 16, and 1 / 32 of the image to be trained are obtained in turn, and the features of sizes 1 / 16 and 1 / 32 are respectively passed through the Attention Refinement Module (ARM) to obtain the semantic features of the branch at the corresponding depth; by downsampling at different depths of the added branch network, feature maps of sizes 1 / 4, 1 / 8, 1 / 16, and 1 / 32 of the image to be trained are obtained in turn, and the features of sizes 1 / 16 and 1 / 32 are respectively passed through the Attention Refinement Module to obtain the edge features of the branch at the corresponding depth.
[0097] Preferably, it also includes:
[0098] Based on the improved semantic segmentation model, an improved loss function is obtained, and the improved loss function is: loss = L seg +L edge ;
[0099] Among them, L seg =β1CE(C1,y t )+β2CE(C2,y t )+β3CE(y,y t ), L seg is the segmentation loss caused by the context branch network, C1 is the first semantic feature of the image to be trained, C2 is the second semantic feature of the image to be trained, y is the final semantic segmentation map corresponding to the image to be trained, and y t is the preset semantic segmentation map corresponding to the image to be trained, CE(C1, y t ) is C1 and y t The cross entropy between CE(C2,y t ) is C2 and y t The cross entropy between CE(y,y t ) are y and y t The cross entropy between
[0100] L edge =α1BCE(E1,E T )+α2BCE(E2,E T ), L edge is the edge loss caused by the branch network, E1 is the first edge feature of the image to be trained, E2 is the second edge feature of the image to be trained, and E T is the edge map corresponding to the preset semantic segmentation map, BCE(E1, E T ) is E1 and E T The second-class cross entropy between E2 and E T ) is E2 and E T The second-class cross entropy between ;
[0101] Both α1 and α2 are greater than β1, β2 and β3.
[0102] Specifically, in the process of training the improved semantic segmentation model, the label image produced is the preset semantic segmentation map, and the edge map corresponding to the preset semantic segmentation map is the edge contour map obtained according to the label image. The purpose of training is to make the difference between the final semantic segmentation map output by the improved semantic segmentation model and the preset semantic segmentation map smaller and smaller.
[0103] Preferably, α1=2.5, α2=5, β1=2, β2=0.5, β3=1.
[0104] In the above embodiments, although the steps are numbered S1, S2, etc., these are only specific embodiments given in the present application. Those skilled in the art may adjust the execution order of S1, S2, etc. according to actual conditions, which is also within the scope of protection of the present invention. It can be understood that in some embodiments, some or all of the above embodiments may be included.
[0105] A semantic segmentation system 100 according to an embodiment of the present invention is as follows: Figure 6 As shown, it includes an acquisition 110 and a semantic segmentation unit 120;
[0106] The acquisition unit 110 is used to acquire the image to be segmented;
[0107] The semantic segmentation unit 120 is used to input the image to be segmented into a trained semantic segmentation model to obtain a final semantic segmentation map.
[0108] Preferably, the acquisition unit is further used to acquire the image to be trained;
[0109] The semantic segmentation unit is specifically used for:
[0110] Add a branch network to BiSeNet to obtain an improved semantic segmentation model, wherein the branch network is used to restore the edge part of the image to be trained and output the edge features of the image to be trained, the context branch network in the BiSeNet is used to output the semantic features of the image to be trained, and the space branch network in the BiSeNet is used to output the shallow features of the image to be trained;
[0111] Input the edge features, the semantic features and the shallow features into the feature fusion module in the BiSeNet to obtain an initial semantic segmentation map of the image to be trained, perform an upsampling operation on the initial semantic segmentation map to obtain a final semantic segmentation map of the image to be trained, and train the improved semantic segmentation model to obtain a trained semantic segmentation model;
[0112] The network structure of the branch network is the same as the network structure of the context branch network.
[0113] Preferably, the semantic feature includes a first semantic feature and a second semantic feature, the edge feature includes a first edge feature and a second edge feature, and the first processing unit is specifically configured to:
[0114] Through a downsampling operation, a first feature map of a first preset size and a second feature map of a second preset size of the image to be trained are obtained at different depths of the context branch network; using an attention recovery module of the context branch network, a first semantic feature of the image to be trained is obtained according to the first feature map, and a second semantic feature of the image to be trained is obtained according to the second feature map;
[0115] Through the downsampling operation, a third feature map of a third preset size and a fourth feature map of a fourth preset size of the image to be trained are respectively obtained at different depths of the branch network; using the attention recovery module of the branch network, a first edge feature of the image to be trained is obtained according to the third feature map, and a second edge feature of the image to be trained is obtained according to the fourth feature map.
[0116] Preferably, it further comprises a design unit;
[0117] The design unit is used to design an improved loss function based on the improved semantic segmentation model.
[0118] The improved loss function is: loss = L seg +L edge ;
[0119] Among them, L seg =β1CE(C1,y t )+β2CE(C2,y t )+β3CE(y,y t ), L seg is the segmentation loss caused by the context branch network, C1 is the first semantic feature of the image to be trained, C2 is the second semantic feature of the image to be trained, y is the final semantic segmentation map corresponding to the image to be trained, and y t is the preset semantic segmentation map corresponding to the image to be trained, CE(C1, y t ) is C1 and y t The cross entropy between CE(C2,y t ) is C2 and y t The cross entropy between CE(y,y t ) are y and y t The cross entropy between
[0120] L edge =α1BCE(E1,E T )+α2BCE(E2,E T ), L edge is the edge loss caused by the branch network, E1 is the first edge feature of the image to be trained, E2 is the second edge feature of the image to be trained, and E Tis the edge map corresponding to the preset semantic segmentation map, BCE(E1, E T ) is E1 and E T The second-class cross entropy between E2 and E T ) is E2 and E T The second-class cross entropy between ;
[0121] Both α1 and α2 are greater than β1, β2 and β3.
[0122] Preferably, α1=2.5, α2=5, β1=2, β2=0.5, β3=1.
[0123] like Figure 7 As shown, an electronic device 200 of an embodiment of the present invention includes a memory 210, a processor 220, and a program 230 stored in the memory and running on the processor. When the processor 220 executes the program 230, it implements part or all of the steps in any one of the above-mentioned semantic segmentation method embodiments.
[0124] The electronic device can be any electronic product for user human-computer interaction, such as a personal computer, a tablet computer, a personal digital assistant (PDA), an interactive network television (IPTV), an intelligent wearable device, etc., and the above-mentioned parameters and steps in an electronic device of the present invention can refer to the parameters and steps in an embodiment of a method for monitoring data above, and will not be repeated here.
[0125] The electronic device may also include a network device and / or a user device, wherein the network device includes but is not limited to a single network server, a server group consisting of multiple network servers, or a cloud consisting of a large number of hosts or network servers based on cloud computing.
[0126] The network where the electronic device is located includes but is not limited to the Internet, a wide area network, a metropolitan area network, a local area network, a virtual private network (VPN, Virtual Private Network), etc.
[0127] The reader should understand that in the description of this specification, the description with reference to the terms "first embodiment", "second embodiment", "example", "specific example", or "some examples" means that the specific features, structures or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine different embodiments or examples described in this specification and the features of different embodiments or examples without contradiction.
[0128] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and units can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0129] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed.
[0130] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiments of the present invention.
[0131] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0132] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0133] It should also be understood that in the embodiments of the present invention, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0134] The above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.
Claims
1. A semantic segmentation method, characterized in that: include: Get the image to be segmented; Input the image to be segmented into a trained semantic segmentation model to obtain a final semantic segmentation map; The process of obtaining the trained semantic segmentation model includes: Get the image to be trained; Add a branch network to BiSeNet to obtain an improved semantic segmentation model, wherein the branch network is used to restore the edge part of the image to be trained and output the edge features of the image to be trained, the context branch network in the BiSeNet is used to output the semantic features of the image to be trained, and the space branch network in the BiSeNet is used to output the shallow features of the image to be trained; Input the edge features, the semantic features and the shallow features into the feature fusion module in the BiSeNet to obtain an initial semantic segmentation map of the image to be trained, perform an upsampling operation on the initial semantic segmentation map to obtain a final semantic segmentation map of the image to be trained, and train the improved semantic segmentation model to obtain a trained semantic segmentation model; The network structure of the branch network is the same as the network structure of the context branch network, and the network structure of the branch network and the network structure of the context branch network are built based on ResNet18; The semantic features include a first semantic feature and a second semantic feature. The process of the context branch network outputting the first semantic feature and the second semantic feature of the image to be trained includes: Through a downsampling operation, a first feature map of a first preset size and a second feature map of a second preset size of the image to be trained are obtained at different depths of the context branch network; using an attention recovery module of the context branch network, a first semantic feature of the image to be trained is obtained according to the first feature map, and a second semantic feature of the image to be trained is obtained according to the second feature map; The edge feature includes a first edge feature and a second edge feature, The process of the branch network outputting the first edge feature and the second edge feature of the image to be trained includes: Through the downsampling operation, a third feature map of a third preset size and a fourth feature map of a fourth preset size of the image to be trained are respectively obtained at different depths of the branch network; using the attention recovery module of the branch network, a first edge feature of the image to be trained is obtained according to the third feature map, and a second edge feature of the image to be trained is obtained according to the fourth feature map.
2. A semantic segmentation method according to claim 1, characterized in that: Also includes: Based on the improved semantic segmentation model, an improved loss function is obtained, and the improved loss function is: loss = L seg +L edge ; Among them, L seg =β1CE(C1,y t )+β2CE(C2,y t )+β3CE(y,y t ), L seg is the segmentation loss caused by the context branch network, C1 is the first semantic feature of the image to be trained, C2 is the second semantic feature of the image to be trained, y is the final semantic segmentation map corresponding to the image to be trained, and y t is the preset semantic segmentation map corresponding to the image to be trained, CE(C1,y t ) is C1 and y t The cross entropy between CE(C2,y t ) is C2 and y t The cross entropy between CE(y,y t ) are y and y t The cross entropy between L edge =α1BCE(E1,E T )+α2BCE(E2,E T ), L edge is the edge loss caused by the branch network, E1 is the first edge feature of the image to be trained, E2 is the second edge feature of the image to be trained, and E T is the edge map corresponding to the preset semantic segmentation map, BCE(E1,E T ) is E1 and E T The second-class cross entropy between E2, E T ) is E2 and E T The second-class cross entropy between ; Both α1 and α2 are greater than β1, β2 and β3.
3. A semantic segmentation method according to claim 2, characterized in that: α1=2.5、α2=5、β1=2、β2=0.5、β3=1。 4. A semantic segmentation system, characterized in that: Includes acquisition unit and semantic segmentation unit; The acquisition unit is used to acquire the image to be segmented; The semantic segmentation unit is used to input the image to be segmented into a trained semantic segmentation model to obtain a final semantic segmentation map; Wherein, the acquisition unit is also used to acquire the image to be trained; The semantic segmentation unit is specifically used for: Add a branch network to BiSeNet to obtain an improved semantic segmentation model, wherein the branch network is used to restore the edge part of the image to be trained and output the edge features of the image to be trained, the context branch network in the BiSeNet is used to output the semantic features of the image to be trained, and the space branch network in the BiSeNet is used to output the shallow features of the image to be trained; Input the edge features, the semantic features and the shallow features into the feature fusion module in the BiSeNet to obtain an initial semantic segmentation map of the image to be trained, perform an upsampling operation on the initial semantic segmentation map to obtain a final semantic segmentation map of the image to be trained, and train the improved semantic segmentation model to obtain a trained semantic segmentation model; The network structure of the branch network is the same as the network structure of the context branch network, and the network structure of the branch network and the network structure of the context branch network are built based on ResNet18; The semantic feature includes a first semantic feature and a second semantic feature, the edge feature includes a first edge feature and a second edge feature, and further includes a first processing unit, wherein the first processing unit is specifically configured to: Through the downsampling operation, a first feature map of a first preset size and a second feature map of a second preset size of the image to be trained are obtained at different depths of the context branch network respectively; using the attention recovery module of the context branch network, a first semantic feature of the image to be trained is obtained according to the first feature map, and a second semantic feature of the image to be trained is obtained according to the second feature map; through the downsampling operation, a third feature map of a third preset size and a fourth feature map of a fourth preset size of the image to be trained are obtained at different depths of the branch network respectively; using the attention recovery module of the branch network, a first edge feature of the image to be trained is obtained according to the third feature map, and a second edge feature of the image to be trained is obtained according to the fourth feature map.
5. A semantic segmentation system according to claim 4, characterized in that: Also includes design units; The design unit is used to design an improved loss function based on the improved semantic segmentation model. The improved loss function is: loss = L seg +L edge ; Among them, L seg =β1CE(C1,y t )+β2CE(C2,y t )+β3CE(y,y t ), L seg is the segmentation loss caused by the context branch network, C1 is the first semantic feature of the image to be trained, C2 is the second semantic feature of the image to be trained, y is the final semantic segmentation map corresponding to the image to be trained, and y t is the preset semantic segmentation map corresponding to the image to be trained, CE(C1,y t ) is C1 and y t The cross entropy between CE(C2,y t ) is C2 and y t The cross entropy between CE(y,y t ) are y and y t The cross entropy between L edge =α1BCE(E1,E T )+α2BCE(E2,E T ), L edge is the edge loss caused by the branch network, E1 is the first edge feature of the image to be trained, E2 is the second edge feature of the image to be trained, and E T is the edge map corresponding to the preset semantic segmentation map, BCE(E1,E T ) is E1 and E T The second-class cross entropy between E2, E T ) is E2 and E T The second-class cross entropy between ; Both α1 and α2 are greater than β1, β2 and β3.
6. An electronic device comprising a memory, a processor, and a program stored in the memory and running on the processor, characterized in that: When the processor executes the program, the steps of a semantic segmentation method as described in any one of claims 1 to 3 are implemented.
Citation Information
Patent Citations
Portrait semantic analysis method based on aggregation excitation context pyramid
CN112396063A
Soil effective aggregate classification and identification method based on deep convolutional neural network
CN112651440A
Method and apparatus for semantic segmentation and depth completion using a convolutional neural network
US20210174513A1
