Cable image segmentation method and device based on block category coding
By using the block category encoding method in the cable image segmentation technology, the correlation between cable blocks is optimized, and the problem of incomplete cable segmentation in the prior art is solved, thereby achieving higher segmentation accuracy and completeness.
Patent Information
- Application Number
- CN202411836240.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-13
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2044-12-13
AI Technical Summary
Existing cable image segmentation techniques fail to fully consider the correlation between image blocks, resulting in incomplete cable segmentation.
Using a block category encoding method, the image data is encoded into block features through a semantic segmentation encoder and a decoder, and the block encoding module is used to convert the semantic category label into block category labels to construct a correlation matching loss function to optimize the correlation between cable blocks.
Improves the correlation between cable blocks, improves the integrity of cable segmentation, and improves the accuracy of cable image segmentation.
Smart Images

Figure CN119339084B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing, and in particular to a cable image segmentation method and device based on block category coding. Background Art
[0002] Cable image segmentation technology is an important technology in power grid automation maintenance and drone obstacle avoidance. However, because the commonly used cable image segmentation loss function does not fully consider the correlation between image blocks, it often leads to incomplete cable segmentation. In practice, due to the standardization of cable production, its color and texture are highly similar in a local range. Therefore, how to improve the correlation optimization between cable blocks has become one of the difficulties of existing cable image segmentation technology. Summary of the invention
[0003] The purpose of this application is to propose a cable image segmentation method and device based on block category coding in response to the above-mentioned technical problems.
[0004] In a first aspect, the present invention provides a cable image segmentation method based on block category coding, comprising the following steps:
[0005] Obtain image data with pixel-level semantic category labels and construct cable segmentation training data;
[0006] Constructing a cable image segmentation model and a block coding module, the cable image segmentation model includes a semantic segmentation encoder and a semantic segmentation decoder, using cable segmentation training data and the block coding module to train the cable image segmentation model, inputting image data in the cable segmentation training data into the semantic segmentation encoder to obtain block features, inputting the block features into the semantic segmentation decoder to obtain semantic category probabilities, constructing a semantic segmentation loss function based on the semantic category probabilities and the semantic category labels, inputting the semantic category labels into the block coding module to obtain block category labels, constructing a correlation matching loss function based on the semantic category probabilities and the block category labels, calculating a total loss function based on the semantic segmentation loss function and the correlation matching loss function, training the cable image segmentation model based on the total loss function to obtain a trained cable image segmentation model;
[0007] The image to be segmented is obtained and input into a trained cable image segmentation model to obtain the semantic category probability corresponding to the image to be segmented, and the cable area and non-cable area in the image to be segmented are determined according to the semantic category probability corresponding to the image to be segmented.
[0008] Preferably, the image data in the cable segmentation training data is input into a semantic segmentation encoder to obtain block features, specifically including:
[0009] The block characteristics are calculated using the following formula:
[0010] x = Encoder (img);
[0011] in, Represents each image data in a batch of B image data, Represents a set of real numbers. The cable segmentation training data contains a batch of B image data. Each image data has 3 channels, a height of H, and a width of W. Encoder represents the function corresponding to the semantic segmentation encoder. Indicates that each image data in a batch of B images has a block feature with C channels, h height, and w width.
[0012] Preferably, the block features are input into a semantic segmentation decoder to obtain semantic category probabilities, and a semantic segmentation loss function is constructed based on the semantic category probabilities and semantic category labels, specifically including:
[0013] The semantic category probability is calculated using the following formula:
[0014] y = Decoder(x);
[0015] in, It represents the block features with C channels, h height and w width corresponding to each image data in a batch of B images. Decoder represents the function corresponding to the semantic segmentation decoder. Represents the semantic category probability of each image data with a height of H and a width of W in a batch of B images;
[0016] The cross entropy loss function is used to calculate the loss value of the semantic category probability and the semantic category label at each spatial position, as shown in the following formula:
[0017]
[0018] Among them, CEL is the semantic segmentation loss function, L s Represents the value of the semantic segmentation loss function, is the semantic category label, Indicates the label value of the spatial position of the semantic category label of the b-th image data in a batch of B images, y b,i,j Represents the probability value of the spatial position at height i and width j in the semantic category probability of the b-th image data in a batch of B image data.
[0019] Preferably, the semantic category label is input into the block encoding module to obtain the block category label, a relevance matching loss function is constructed based on the semantic category probability and the block category label, and a total loss function is calculated based on the semantic segmentation loss function and the relevance matching loss function, specifically including:
[0020] The semantic category label is converted into the block category label using the following formula:
[0021]
[0022] in, Represents the block category label of the bth image data in a batch of B image data The spatial position in the label value is at a height of p and a width of q. When the label value is 1, it means that the block contains the cable area. When the label value is 0, it means that the block does not contain the cable area. max means taking out the maximum value in the input data.
[0023] Indicates the semantic category label GT of the bth image data from a batch of B images. s The height in arrive In the range, the width is arrive All label values in the range, H and W represent the height and width of the semantic category label, and h and w represent the height and width of the block category label;
[0024] The correlation matching loss function is calculated using the following formula:
[0025]
[0026] Among them, ED represents the correlation matching loss function, L r Represents the value of the correlation matching loss function, Represents the block category label of the bth image data in a batch of B image data The spatial position in the label value is at a height of s and a width of t. Represents the block category label of the bth image data in a batch of B image data The spatial position in the label value is m in height and n in width, x b,c,s,t Represents the feature value of the cth channel in the block feature x of the bth image data in a batch of B images, at a height of s and a width of t. b,c,m,n Represents the feature value of the c-th channel in the block feature x of the b-th image data in a batch of B image data at a spatial position of m and width n;
[0027] The total loss function L is calculated using the following formula:
[0028] L=L s +L r ;
[0029] Among them, L sRepresents the numerical value of the semantic segmentation loss function.
[0030] Preferably, the semantic segmentation encoder includes a ResNet-50 network, the semantic segmentation decoder includes a feature pyramid network, and the block encoding module includes a maximum pooling layer.
[0031] Preferably, determining the cable area and the non-cable area in the image to be segmented according to the semantic category probability corresponding to the image to be segmented specifically includes:
[0032] When the probability value of one of the spatial positions of the semantic category probability corresponding to the image to be segmented is greater than or equal to the threshold, the spatial position is regarded as a cable area; when the probability value of one of the spatial positions of the semantic category probability corresponding to the image to be segmented is less than the threshold, the spatial position is regarded as a non-cable area.
[0033] In a second aspect, the present invention provides a cable image segmentation device based on block category coding, comprising:
[0034] A training data construction module, configured to obtain image data with pixel-level semantic category labels and construct cable segmentation training data;
[0035] A model building module is configured to build a cable image segmentation model and a block coding module, wherein the cable image segmentation model includes a semantic segmentation encoder and a semantic segmentation decoder, the cable image segmentation model is trained using cable segmentation training data and the block coding module, image data in the cable segmentation training data is input into the semantic segmentation encoder to obtain block features, the block features are input into the semantic segmentation decoder to obtain semantic category probabilities, a semantic segmentation loss function is constructed based on the semantic category probabilities and the semantic category labels, the semantic category labels are input into the block coding module to obtain block category labels, a correlation matching loss function is constructed based on the semantic category probabilities and the block category labels, a total loss function is calculated based on the semantic segmentation loss function and the correlation matching loss function, the cable image segmentation model is trained based on the total loss function to obtain a trained cable image segmentation model;
[0036] The segmentation module is configured to obtain the image to be segmented and input the trained cable image segmentation model to obtain the semantic category probability corresponding to the image to be segmented, and determine the cable area and non-cable area in the image to be segmented according to the semantic category probability corresponding to the image to be segmented.
[0037] In a third aspect, the present invention provides an electronic device comprising one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any implementation manner in the first aspect.
[0038] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in any implementation manner in the first aspect.
[0039] In a fifth aspect, the present invention provides a computer program product, comprising a computer program, which, when executed by a processor, implements the method described in any implementation manner in the first aspect.
[0040] Compared with the prior art, the present invention has the following beneficial effects:
[0041] (1) The cable image segmentation method based on block category coding proposed in the present invention constructs a cable image segmentation model. In the cable image segmentation model, the image data is encoded into block features by a semantic segmentation encoder, and the block features are decoded into semantic category probabilities by a semantic segmentation decoder to calculate the semantic segmentation loss function; secondly, a block coding module is constructed to convert the semantic category labels into block category labels and find all the cable blocks in the image; thirdly, a correlation matching loss function is constructed to reduce the Euclidean distance between the cable block features to enhance the correlation between the cable blocks and improve the integrity of the cable segmentation.
[0042] (2) The cable image segmentation method based on block category coding proposed in the present invention is based on the high similarity of cable materials in different scenarios, and uses Euclidean distance to optimize the correlation between cable image data, ultimately improving the accuracy of cable image segmentation. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be 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 paying creative work.
[0044] Figure 1 A schematic flow chart of a cable image segmentation method based on block category coding according to an embodiment of the present application;
[0045] Figure 2 A schematic diagram of a training process of a cable image segmentation model of a cable image segmentation method based on block category coding according to an embodiment of the present application;
[0046] Figure 3 A schematic diagram of a cable image segmentation device based on block category coding according to an embodiment of the present application;
[0047] Figure 4 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0048] In order to make the purpose, technical scheme and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0049] Figure 1 A cable image segmentation method based on block category coding provided by an embodiment of the present application is shown, comprising the following steps:
[0050] S1, obtain image data with pixel-level semantic category labels and construct cable segmentation training data.
[0051] Specifically, image data with semantic category labels are obtained as cable segmentation training data. The semantic category labels are at the pixel level, and each pixel position in each image data corresponds to a label value of the semantic category label. The image data is obtained after data preprocessing and data enhancement. The data preprocessing is specifically: the height of the image data is uniformly adjusted to H, and the width is uniformly adjusted to W. The data enhancement methods include random horizontal flipping and random cropping.
[0052] S2, constructing a cable image segmentation model and a block coding module, the cable image segmentation model includes a semantic segmentation encoder and a semantic segmentation decoder, using cable segmentation training data and the block coding module to train the cable image segmentation model, inputting the image data in the cable segmentation training data into the semantic segmentation encoder to obtain block features, inputting the block features into the semantic segmentation decoder to obtain semantic category probabilities, constructing a semantic segmentation loss function based on the semantic category probabilities and semantic category labels, inputting the semantic category labels into the block coding module to obtain block category labels, constructing a relevance matching loss function based on the semantic category probabilities and block category labels, calculating a total loss function based on the semantic segmentation loss function and the relevance matching loss function, training the cable image segmentation model based on the total loss function to obtain a trained cable image segmentation model.
[0053] In a specific embodiment, the semantic segmentation encoder includes a ResNet-50 network, the semantic segmentation decoder includes a feature pyramid network, and the block encoding module includes a maximum pooling layer.
[0054] In a specific embodiment, the image data in the cable segmentation training data is input into a semantic segmentation encoder to obtain block features, specifically including:
[0055] The block characteristics are calculated using the following formula:
[0056] x = Encoder(img);
[0057] in, Represents each image data in a batch of B image data, Represents a set of real numbers. The cable segmentation training data contains a batch of B image data. Each image data has 3 channels, a height of H, and a width of W. Encoder represents the function corresponding to the semantic segmentation encoder. Indicates that each image data in a batch of B images has a block feature with C channels, h height, and w width.
[0058] In a specific embodiment, the block features are input into a semantic segmentation decoder to obtain semantic category probabilities, and a semantic segmentation loss function is constructed based on the semantic category probabilities and semantic category labels, specifically including:
[0059] The semantic category probability is calculated using the following formula:
[0060] y = Decoder(x);
[0061] in, It represents the block features with C channels, h height and w width corresponding to each image data in a batch of B images. Decoder represents the function corresponding to the semantic segmentation decoder. Represents the semantic category probability of each image data with a height of H and a width of W in a batch of B images;
[0062] The cross entropy loss function is used to calculate the loss value of the semantic category probability and the semantic category label at each spatial position, as shown in the following formula:
[0063]
[0064] Among them, CEL is the semantic segmentation loss function, L s Represents the value of the semantic segmentation loss function, is the semantic category label, Indicates the label value of the spatial position of the semantic category label of the b-th image data in a batch of B images, y b,i,j Represents the probability value of the spatial position at height i and width j in the semantic category probability of the b-th image data in a batch of B image data.
[0065] Specifically, refer to Figure 2In the embodiment of the present application, the ResNet-50 network is selected as the semantic segmentation encoder, which gradually increases the number of channels of the input data, gradually reduces the height and width, and finally encodes the B-part image data into block features with the number of channels of B, the height of h, and the width of w. In the embodiment of the present application, the feature pyramid network (FPN) is selected as the semantic segmentation decoder, which gradually reduces the number of channels of the input data, gradually increases the height and width, and finally decodes the B-part block features into the semantic category probabilities with the height of B and the width of W. The larger the probability value of a spatial position in the semantic category probability, the greater the probability that the spatial position is a cable area; the semantic segmentation loss function uses cross entropy loss to calculate the loss value of the semantic category probability and the semantic category label at each spatial position.
[0066] In a specific embodiment, the semantic category label is input into the block encoding module to obtain the block category label, a relevance matching loss function is constructed based on the semantic category probability and the block category label, and a total loss function is calculated based on the semantic segmentation loss function and the relevance matching loss function, which specifically includes:
[0067] The semantic category label is converted into the block category label using the following formula:
[0068]
[0069] in, Represents the block category label of the bth image data in a batch of B image data The spatial position in the label value is at a height of p and a width of q. When the label value is 1, it means that the block contains the cable area. When the label value is 0, it means that the block does not contain the cable area. max means taking out the maximum value in the input data.
[0070] Indicates the semantic category label GT of the bth image data from a batch of B images. s The height in arrive In the range, the width is arrive All label values in the range, H and W represent the height and width of the semantic category label, and h and w represent the height and width of the block category label;
[0071] The correlation matching loss function is calculated using the following formula:
[0072]
[0073] Among them, ED represents the correlation matching loss function, L r Represents the value of the correlation matching loss function, Represents the block category label of the bth image data in a batch of B image data The spatial position in the label value is at a height of s and a width of t. Represents the block category label of the bth image data in a batch of B image data The spatial position in the label value is m in height and n in width, x b,c,s,t Represents the feature value of the cth channel in the block feature x of the bth image data in a batch of B images, at a height of s and a width of t. b,c,m,n Represents the feature value of the c-th channel in the block feature x of the b-th image data in a batch of B image data at a spatial position of m and width n;
[0074] The total loss function L is calculated using the following formula:
[0075] L=L s +L r ;
[0076] Among them, L s Represents the numerical value of the semantic segmentation loss function.
[0077] Specifically, the embodiment of the present application uses the maximum pooling layer as a block encoding module, and uses the maximum pooling layer to convert semantic category labels into block category labels to find all cable blocks in the image data. That is to say, each spatial position in the image data is divided into several blocks, and the maximum value of the label value of the semantic category label of all spatial positions in the block is used as the block category label of the block. For example, if the label values of the semantic category labels of each spatial position in one block are 1, 1, 0, 1 respectively, then the block category label of the block is 1, and the label values of the semantic category labels of each spatial position in another block are 0, 0, 0, 0 respectively, then the block category label of the block is 0.
[0078] Furthermore, a correlation matching loss function is constructed through block features and block category labels to reduce the Euclidean distance between cable block features, so as to improve the correlation between cable blocks and improve the integrity of cable segmentation. The correlation matching loss function calculates the Euclidean distance between block features of all cable areas and the Euclidean distance between block features of non-cable areas. The sum of the two types of Euclidean distances is used as the correlation matching loss function. In the training of the cable image segmentation model, the correlation matching loss function will be subjected to stochastic gradient descent, thereby reducing the Euclidean distance between cable blocks and improving the correlation between cable blocks. In addition, the semantic segmentation loss function is also subjected to stochastic gradient descent. Therefore, the correlation matching loss function and the semantic segmentation loss function are added to obtain the total loss function, and the total loss function is subjected to stochastic gradient descent to complete the training of the cable image segmentation model.
[0079] S3, obtaining the image to be segmented and inputting it into a trained cable image segmentation model to obtain the semantic category probability corresponding to the image to be segmented, and determining the cable area and non-cable area in the image to be segmented according to the semantic category probability corresponding to the image to be segmented.
[0080] In a specific embodiment, determining the cable area and the non-cable area in the image to be segmented according to the semantic category probability corresponding to the image to be segmented specifically includes:
[0081] When the probability value of one of the spatial positions of the semantic category probability corresponding to the image to be segmented is greater than or equal to the threshold, the spatial position is regarded as a cable area; when the probability value of one of the spatial positions of the semantic category probability corresponding to the image to be segmented is less than the threshold, the spatial position is regarded as a non-cable area.
[0082] Specifically, the trained cable image segmentation model is used to infer the image to be segmented, and the semantic category probability output by the semantic segmentation decoder is used as the classification basis. When the probability value of the semantic category probability of a certain spatial position is greater than or equal to 0.5, the spatial position is regarded as a cable area. When the probability value of the semantic category probability of a certain spatial position is less than 0.5, the spatial position is regarded as a non-cable area.
[0083] Further references Figure 3 As an implementation of the methods shown in the above figures, the present application provides an embodiment of a cable image segmentation device based on block category coding, and the device embodiment is similar to Figure 1 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0084] The embodiment of the present application provides a cable image segmentation device based on block category coding, comprising:
[0085] A training data construction module 1 is configured to obtain image data with pixel-level semantic category labels and construct cable segmentation training data;
[0086] The model construction module 2 is configured to construct a cable image segmentation model and a block coding module. The cable image segmentation model includes a semantic segmentation encoder and a semantic segmentation decoder. The cable image segmentation model is trained using the cable segmentation training data and the block coding module. The image data in the cable segmentation training data is input into the semantic segmentation encoder to obtain block features. The block features are input into the semantic segmentation decoder to obtain semantic category probabilities. A semantic segmentation loss function is constructed based on the semantic category probabilities and the semantic category labels. The semantic category labels are input into the block coding module to obtain block category labels. A correlation matching loss function is constructed based on the semantic category probabilities and the block category labels. A total loss function is calculated based on the semantic segmentation loss function and the correlation matching loss function. The cable image segmentation model is trained based on the total loss function to obtain a trained cable image segmentation model.
[0087] The segmentation module 3 is configured to obtain the image to be segmented and input the trained cable image segmentation model to obtain the semantic category probability corresponding to the image to be segmented, and determine the cable area and non-cable area in the image to be segmented according to the semantic category probability corresponding to the image to be segmented.
[0088] Figure 4 Schematic diagram of the hardware structure of the electronic device provided by the embodiment of the present invention. Figure 4 As shown, the electronic device of this embodiment includes: a processor 401 and a memory 402; wherein the memory 402 is used to store computer-executable instructions; the processor 401 is used to execute the computer-executable instructions stored in the memory to implement the various steps performed by the electronic device in the above embodiment. For details, please refer to the relevant description in the above method embodiment.
[0089] Optionally, the memory 402 may be independent or integrated with the processor 401 .
[0090] When the memory 402 is independently provided, the electronic device further includes a bus 403 for connecting the memory 402 and the processor 401 .
[0091] The embodiment of the present invention further provides a computer storage medium, in which computer execution instructions are stored. When the processor 401 executes the computer execution instructions, the above method is implemented.
[0092] The embodiment of the present invention further provides a computer program product, including a computer program. When the computer program is executed by the processor 401, the above method is implemented.
[0093] In the embodiments provided by the present invention, 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 modules is only a logical function division, and there may be other division methods in actual implementation, such as multiple modules can be combined or integrated into another system, or some features can be ignored or not executed. Another point, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.
[0094] The modules described as separate components may or may not be physically separated, and the components shown as modules 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 modules may be selected according to actual needs to implement the solution of this embodiment.
[0095] In addition, each functional module in each embodiment of the present invention may be integrated into one processing unit, each module may exist physically separately, or two or more modules may be integrated into one unit. The unit formed by the above modules may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0096] The above-mentioned integrated module implemented in the form of a software function module can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, including a number of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor 401 to perform some steps of the methods of various embodiments of the present application.
[0097] It should be understood that the processor 401 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or the processor 401 may be any conventional processor 401, etc. The steps of the method disclosed in the invention may be directly embodied in the hardware processor 401 for execution, or may be executed by a combination of hardware and software modules in the processor 401.
[0098] The memory 402 may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk memory, and may also be a USB flash drive, a mobile hard disk, a read-only memory, a magnetic disk, or an optical disk.
[0099] The bus 403 may be an Industry Standard Architecture (ISA), a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus 403 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus 403 in the drawings of the present application is not limited to only one bus 403 or one type of bus 403.
[0100] The above storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The storage medium can be any available medium that can be accessed by a general or special purpose computer.
[0101] An exemplary storage medium is coupled to the processor 401, so that the processor 401 can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor 401. The processor 401 and the storage medium can be located in an application specific integrated circuit (ASIC). Of course, the processor 401 and the storage medium can also exist as discrete components in an electronic device or a main control device.
[0102] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.
[0103] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A cable image segmentation method based on block category coding, characterized in that: The following steps are involved: Obtain image data with pixel-level semantic category labels and construct cable segmentation training data; A cable image segmentation model and a block coding module are constructed, wherein the cable image segmentation model includes a semantic segmentation encoder and a semantic segmentation decoder, the cable image segmentation model is trained using the cable segmentation training data and the block coding module, the image data in the cable segmentation training data is input into the semantic segmentation encoder to obtain block features, the block features are input into the semantic segmentation decoder to obtain semantic category probabilities, a semantic segmentation loss function is constructed based on the semantic category probabilities and semantic category labels, the semantic category labels are input into the block coding module to obtain block category labels, and the semantic category labels are converted into the block category labels using the following formula: in, Represents the block category label of the bth image data in a batch of B image data The spatial position in the label value is at a height of p and a width of q. When the label value is 1, it means that the block contains the cable area. When the label value is 0, it means that the block does not contain the cable area. max means taking out the maximum value in the input data. Indicates the semantic category label GT of the bth image data from a batch of B images. s The height of arrive In the range, the width is arrive All label values in the range, H and W represent the height and width of the semantic category label, and h and w represent the height and width of the block category label; A relevance matching loss function is constructed based on the semantic category probability and the block category label, and the relevance matching loss function is calculated using the following formula: Among them, ED represents the correlation matching loss function, L r Represents the value of the correlation matching loss function, Represents the block category label of the bth image data in a batch of B image data The spatial position in the label value is at a height of s1 and a width of t. Represents the block category label of the bth image data in a batch of B image data The spatial position in the label value is m in height and n in width, x b,c,s1,t Represents the feature value of the cth channel in the block feature x of the bth image data in a batch of B images, at a height of s1 and a width of t. b,c,m,n Representing a feature value of a spatial position on the cth channel in a block feature x of the bth image data in a batch of B image data at a height of m and a width of n; calculating a total loss function according to the semantic segmentation loss function and the correlation matching loss function, and training the cable image segmentation model based on the total loss function to obtain a trained cable image segmentation model; The image to be segmented is obtained and input into the trained cable image segmentation model to obtain the semantic category probability corresponding to the image to be segmented, and the cable area and non-cable area in the image to be segmented are determined according to the semantic category probability corresponding to the image to be segmented.
2. The cable image segmentation method based on block category coding according to claim 1 is characterized in that: The image data in the cable segmentation training data is input into the semantic segmentation encoder to obtain block features, specifically including: The block characteristics are calculated using the following formula: x = Encoder (img); in, Represents each image data in a batch of B image data, represents a set of real numbers. The cable segmentation training data includes a batch of B image data. Each image data has 3 channels, a height of H, and a width of W. Encoder represents the function corresponding to the semantic segmentation encoder. Indicates that each image data in a batch of B images has a block feature with C channels, h height, and w width.
3. The cable image segmentation method based on block category coding according to claim 1, characterized in that: Inputting the block features into the semantic segmentation decoder to obtain semantic category probabilities, and constructing a semantic segmentation loss function based on the semantic category probabilities and semantic category labels, specifically including: The semantic category probability is calculated using the following formula: y = Decoder(x); in, It represents the block features with C channels, h height and w width corresponding to each image data in a batch of B images. Decoder represents the function corresponding to the semantic segmentation decoder. Represents the semantic category probability of each image data with a height of H and a width of W in a batch of B images; The cross entropy loss function is used to calculate the loss value of the semantic category probability and the semantic category label at each spatial position, as shown in the following formula: Among them, CEL is the semantic segmentation loss function, L s Represents the value of the semantic segmentation loss function, is the semantic category label, Indicates the label value of the spatial position of the semantic category label of the b-th image data in a batch of B images, y b,i,j Represents the probability value of the spatial position at height i and width j in the semantic category probability of the b-th image data in a batch of B image data.
4. The cable image segmentation method based on block category coding according to claim 1, characterized in that: The total loss function is calculated according to the semantic segmentation loss function and the correlation matching loss function, specifically including: The total loss function L is calculated using the following formula: L=L s +L r ; Among them, L s Represents the numerical value of the semantic segmentation loss function.
5. The cable image segmentation method based on block category coding according to claim 1, characterized in that: The semantic segmentation encoder includes a ResNet-50 network, the semantic segmentation decoder includes a feature pyramid network, and the block encoding module includes a maximum pooling layer.
6. The cable image segmentation method based on block category coding according to claim 1, characterized in that: Determining the cable area and the non-cable area in the image to be segmented according to the semantic category probability corresponding to the image to be segmented specifically includes: When the probability value of one of the spatial positions of the semantic category probability corresponding to the image to be segmented is greater than or equal to a threshold, the spatial position is regarded as a cable area; when the probability value of one of the spatial positions of the semantic category probability corresponding to the image to be segmented is less than the threshold, the spatial position is regarded as a non-cable area.
7. A cable image segmentation device based on block category coding, characterized in that: include: A training data construction module, configured to obtain image data with pixel-level semantic category labels and construct cable segmentation training data; The model building module is configured to build a cable image segmentation model and a block coding module, wherein the cable image segmentation model includes a semantic segmentation encoder and a semantic segmentation decoder, the cable image segmentation model is trained using the cable segmentation training data and the block coding module, the image data in the cable segmentation training data is input into the semantic segmentation encoder to obtain block features, the block features are input into the semantic segmentation decoder to obtain semantic category probabilities, a semantic segmentation loss function is built based on the semantic category probabilities and semantic category labels, the semantic category labels are input into the block coding module to obtain block category labels, and the semantic category labels are converted into the block category labels using the following formula: in, Represents the block category label of the bth image data in a batch of B image data The spatial position in the label value is at a height of p and a width of q. When the label value is 1, it means that the block contains the cable area. When the label value is 0, it means that the block does not contain the cable area. max means taking out the maximum value in the input data. Indicates the semantic category label GT of the bth image data from a batch of B images. s The height of arrive In the range, the width is arrive All label values in the range, H and W represent the height and width of the semantic category label, and h and w represent the height and width of the block category label; A relevance matching loss function is constructed based on the semantic category probability and the block category label, and the relevance matching loss function is calculated using the following formula: Among them, ED represents the correlation matching loss function, L r Represents the value of the correlation matching loss function, Represents the block category label of the bth image data in a batch of B image data The spatial position in the label value is at a height of s1 and a width of t. Represents the block category label of the bth image data in a batch of B image data The spatial position in the label value is m in height and n in width, x b,c,s1,t Represents the feature value of the cth channel in the block feature x of the bth image data in a batch of B images, at a height of s1 and a width of t. b,c,m,n Representing a feature value of a spatial position on the cth channel in a block feature x of the bth image data in a batch of B image data at a height of m and a width of n; calculating a total loss function according to the semantic segmentation loss function and the correlation matching loss function, and training the cable image segmentation model based on the total loss function to obtain a trained cable image segmentation model; The segmentation module is configured to obtain the image to be segmented and input the trained cable image segmentation model to obtain the semantic category probability corresponding to the image to be segmented, and determine the cable area and non-cable area in the image to be segmented according to the semantic category probability corresponding to the image to be segmented.
8. An electronic device comprising: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Remote sensing image semantic segmentation method based on shared convolution kernel and boundary loss function
CN115035295A
Small sample semantic segmentation method and system based on background information mining
CN117409413A