An electrical secondary drawing component detection method and device based on a structure perception mechanism and a medium
By embedding a structure-aware attention module and a structural consistency loss function into the YOLOv5 detection algorithm, the problem of detecting small-sized, densely arranged, and complex-background component symbols in electrical drawings is solved, achieving high-precision and robust automatic detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- GUIZHOU POWER GRID CO LTD
- Filing Date
- 2026-01-05
- Publication Date
- 2026-05-01
AI Technical Summary
Electrical drawings contain a large number of small, densely arranged component symbols with complex backgrounds, posing a significant challenge to automatic detection. Existing technologies struggle to effectively identify and distinguish them.
An improved detection algorithm based on YOLOv5 is adopted, embedding a structure-aware attention module (SAAM) and a structural consistency loss function. By enhancing local texture and modeling global strip structures, structurally sensitive features of drawings are extracted. Combining local details and global structural features, the model's response capability to small, edge-blurred components is improved.
It significantly improves the accuracy and robustness of component inspection on electrical drawings, reduces false detection and false negative rates, achieves high-precision identification, adapts to complex scenarios, and has fast inspection efficiency and low-cost deployment efficiency.
Smart Images

Figure CN121458716B_ABST
Abstract
Description
A method, equipment, and medium for detecting electrical secondary drawing components based on structure perception mechanism. Technical Field
[0001] This invention relates to the field of component testing technology in drawings, specifically to a method, equipment, and medium for testing electrical secondary drawing components based on a structure perception mechanism. Background Technology
[0002] Electrical secondary schematic diagrams use standard symbols, text labels, and lines to express the control logic and connection relationships of various components in a power system, serving as crucial technical documents for power design and operation and maintenance. In recent years, deep learning technology has been widely applied to the field of schematic diagram information extraction, achieving certain results in text detection and symbol recognition. However, the component symbols in electrical secondary schematic diagrams are characterized by dense small targets, complex structures, and strong background interference, leading to the following challenges for general target detection models: First, the symbols are small in size and have weak features, making them easily ignored by the network during detection; second, the tight spacing between symbols and the intertwined lines blur the target boundaries; third, the diagrams contain a large number of semantically meaningless background lines (such as table grids and wires), which can easily interfere with and mislead model recognition.
[0003] Component symbols on drawings are often aligned along conductors, and groups of components may be arranged in regular arrays. Symbols and their text labels often have relatively fixed positional relationships. Currently, information extraction from electrical drawings takes into account the visual appearance features of the target and some contextual information to varying degrees, but the utilization of the structural prior knowledge unique to the drawings is still insufficient.
[0004] Electrical drawings contain numerous small, densely packed component symbols against complex backgrounds, posing a significant challenge to automatic detection. To address this issue, this invention embeds a novel Structure-Aware Attention Module (SAAM) into the multi-scale feature extraction stage of the You Only Look Once version 5 (YOLOv5) network. SAAM extracts structurally sensitive features of the drawings through local texture enhancement and global banded structure modeling, thereby improving the model's responsiveness to small, edge-blurred components. Simultaneously, a structural consistency enhancement loss function is designed, incorporating the spatial arrangement patterns of components into the training objective. A spatial structural consistency constraint is proposed to guide the detection boxes in learning typical symbol arrangement patterns, significantly improving localization accuracy and detection robustness. The proposed method outperforms the original YOLOv5 and other baseline models in both small target detection accuracy and anti-interference capability, effectively alleviating the three major challenges of small symbol size, dense arrangement, and strong background interference, achieving high-precision automatic detection of components in electrical drawings. Summary of the Invention
[0005] In view of the above-mentioned problems, the present invention is proposed.
[0006] Therefore, the technical problem solved by this invention is: how to solve the problem that electrical drawings contain a large number of small, densely arranged component symbols with complex backgrounds, which pose a great challenge to automatic detection.
[0007] To address the aforementioned technical problems, this invention provides the following technical solution: a method for detecting components in electrical secondary drawings based on a structure-aware mechanism, comprising: acquiring electrical secondary drawings; performing unified rasterization and preprocessing on the electrical secondary drawings to obtain preprocessed electrical secondary drawings; constructing an electrical secondary drawing component detection model, with the preprocessed electrical secondary drawings as input and the class probability, confidence level, and bounding box parameters for each target as output; and during the training phase of the electrical secondary drawing component detection model, selecting nodes and connection rules to construct a structure graph, and constructing a loss function based on the structure graph.
[0008] As a preferred embodiment of the electrical secondary drawing component detection method based on structure-aware mechanism described in this invention, the construction of the electrical secondary drawing component detection model includes: designing a detection architecture based on YOLOv5; extracting multi-scale features from the backbone network and embedding structure-aware attention modules at each scale to fuse local details and global structure; performing cross-scale fusion through the neck pyramid and introducing efficient multi-scale attention to improve feature consistency; and outputting class probability, confidence, and bounding box parameters from the detection head at each scale.
[0009] As a preferred embodiment of the electrical secondary drawing component detection method based on structure-aware mechanism described in this invention, the step of extracting multi-scale features from the backbone network and embedding a structure-aware attention module at each scale includes: the structure-aware attention module is embedded in the multi-scale feature layer of the backbone network to process the input feature map and output an attention weight map with structure-aware characteristics; the structure-aware attention module includes a local detail enhancement path and a global structure-aware path; the local detail enhancement path design includes a multi-scale convolutional filter with multiple convolutional kernels and introduces dilated convolution to expand the receptive field, and each convolution is followed by batch normalization and activation function, and by fusing the responses of multi-scale convolutions pixel by pixel, local detail features of emphasized symbol edges and texture change regions are obtained.
[0010] As a preferred embodiment of the electrical secondary drawing component detection method based on the structure-aware mechanism described in this invention, the global structure-aware path includes averaging the input feature map by channel dimensions to obtain a spatial feature map, represented as follows:
[0011]
[0012] in, In spatial location The channel average value, For width index, For height indexing, For channel index, This represents the total number of channels in the feature map. For the first Each channel is in The feature values at the given location are then subjected to strip global pooling along the height and width directions, respectively, to obtain one-dimensional horizontal and vertical features, represented as follows:
[0013]
[0014] in, The horizontal band-like feature indicates the first The average of the overall activation intensity of the column; For column indexes; The vertical band-like feature indicates the first The average of the overall activation distribution of the row; For row index; The width of the feature map; The feature map height; In spatial location The channel average value; In spatial location The channel average value; by expanding it to a two-dimensional space and adding it element-wise, the global structural features are obtained, represented as:
[0015]
[0016] in, For global structural feature maps in The value of ; The response obtained after applying a one-dimensional convolution and nonlinear mapping to the horizontal band-shaped features; The response obtained after applying a one-dimensional convolution and nonlinear mapping to the vertical band-shaped features; This is the Sigmoid activation function.
[0017] This preferred solution introduces channel averaging, strip global pooling, and one-dimensional convolution operations into the global structure perception path, which can effectively capture the row and column arrangement patterns of symbols in electrical secondary drawings. This allows the model to not only rely on local textures during detection but also to identify the overall layout pattern of symbols, thereby enhancing the perception ability of densely arranged and grouped symbols and improving the stability of detection results.
[0018] As a preferred embodiment of the electrical secondary drawing component detection method based on structure perception mechanism described in this invention, the fusion of local details and global structure includes adding and fusing local detail features and global structure features, and generating a final attention weight map through an activation function, as shown below:
[0019]
[0020] in, For attention weights, For local detail features, The input feature map is represented as a global structural feature map; the attention weight map performs element-wise weighting on the input feature map, and outputs an enhanced feature map, represented as:
[0021]
[0022] in, For element-wise multiplication, For the enhanced feature map, This is the input feature map.
[0023] As a preferred embodiment of the component detection method for electrical secondary drawings based on a structure-aware mechanism described in this invention, the step of selecting nodes and connection rules to construct a structure graph during the training phase of the component detection model for electrical secondary drawings includes: taking the geometric centers of all symbols on the electrical secondary drawings as nodes of the graph; establishing undirected edges between nodes based on actual electrical connection relationships, layout alignment, and adjacency relationships; the criteria for establishing edges include: if there is a direct electrical connection relationship between symbols, then an edge is connected between the corresponding nodes; if symbols have an alignment relationship in the layout of the drawing, then an edge is connected between the nodes; and symbol nodes belonging to the same logical functional module and spatially adjacent are connected by edges.
[0024] As a preferred embodiment of the electrical secondary drawing component detection method based on structure perception mechanism described in this invention, the construction loss function includes: constructing an overall structure loss and an overall training loss based on the structure diagram; the overall structure loss is expressed as:
[0025]
[0026] in, This represents a node in the structure diagram. Representing nodes in the structure diagram Another node that has a structural relationship This is a structural diagram. For overall structural loss, For nodes The prediction box, For nodes The prediction box, For nodes truth box, For nodes truth box, For relative distance loss, For alignment direction loss, For topology connectivity loss, The weight hyperparameters for the relative distance loss are... The weight hyperparameters for the alignment direction loss are... The weight hyperparameters for the topology connectivity loss are: The overall training loss is expressed as:
[0027]
[0028] in, As a result of overall training losses, For classifying losses, To regress the loss, The weights for structural consistency loss, This represents the loss of structural consistency.
[0029] This preferred solution constructs an overall structural loss and optimizes it in conjunction with classification loss and regression loss. It can simultaneously take into account the symbol recognition accuracy and the rationality of the global layout during the training process. It not only ensures the accurate detection of individual symbols, but also improves the spatial consistency between detection boxes, making the detection results more in line with the design specifications of electrical secondary drawings.
[0030] As a preferred embodiment of the electrical secondary drawing component detection method based on structure perception mechanism described in this invention, the structural consistency loss includes the difference between the spatial relationship between predicted boxes and the true symbolic relationship, expressed as:
[0031]
[0032] in, This represents the number of edges in the structure.
[0033] The present invention provides a computer device, including a memory and a processor, wherein the memory stores a computer program, characterized in that the processor executes the computer program to implement the steps of the described method for detecting electrical secondary drawing components based on a structure-aware mechanism.
[0034] The present invention provides a computer-readable storage medium having a computer program stored thereon, characterized in that, when the computer program is executed by a processor, it implements the steps of the described method for detecting electrical secondary drawing components based on a structure-aware mechanism.
[0035] The beneficial effects of this invention are as follows: Addressing the shortcomings of traditional image recognition algorithms in their poor robustness to electrical component symbols, this invention employs an improved detection algorithm based on YOLOv5. Considering the diverse types and similar outlines of components in electrical drawings, the algorithm can accurately distinguish between various components, significantly reducing false positives and false negatives, and achieving high-precision recognition. It boasts fast detection efficiency and rapid inference speed, meeting the real-time analysis needs of power scenarios. Through professional data augmentation, it adapts to complex scenarios such as aging drawings and dense layouts, exhibiting excellent small target detection performance and enhancing model robustness. Furthermore, it features a smaller model size and higher deployment efficiency, and requires only a small amount of labeled data for training, resulting in low cost and high practicality. Attached Figure Description
[0036] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0037] Figure 1 is a flowchart of an electrical secondary drawing component detection method based on a structure perception mechanism provided by an embodiment of the present invention.
[0038] Figure 2 is a schematic diagram of the overall framework of the electrical secondary drawing component detection model of an electrical secondary drawing component detection method based on structure perception mechanism provided in an embodiment of the present invention.
[0039] Figure 3 is a diagram of the structure-aware attention module of an electrical secondary drawing component detection method based on a structure-aware mechanism provided in an embodiment of the present invention.
[0040] Figure 4 is a structural diagram of electrical secondary drawing components according to an embodiment of the present invention, which is a method for detecting electrical secondary drawing components based on a structure perception mechanism. Detailed Implementation
[0041] To make the above-mentioned objects, features, and advantages of the present invention more apparent and understandable, specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the protection scope of the present invention.
[0042] Example 1, referring to Figure 1, is an embodiment of the present invention. This embodiment provides a method for detecting electrical secondary drawing components based on a structure-aware mechanism, including:
[0043] S1. Collect electrical secondary drawings, perform unified rasterization and preprocessing on the electrical secondary drawings to obtain preprocessed electrical secondary drawings.
[0044] S2. Construct a component detection model for electrical secondary drawings. The input is the preprocessed electrical secondary drawings, and the output is the category probability, confidence level, and bounding box parameters for each target.
[0045] S3. During the training phase of the electrical secondary drawing component detection model, select nodes and connection rules to construct a structure diagram, and construct a loss function based on the structure diagram.
[0046] It should be noted that by introducing a symbolic structure relationship graph during the training phase of the detection model and combining it with structural consistency loss for joint optimization, this invention can explicitly constrain the spatial relationship between predicted boxes. This enables the detection results to not only have high target recognition accuracy but also conform to the actual design logic of electrical secondary drawings, effectively reducing false detections and missed detections caused by complex backgrounds or dense symbols, thereby improving the overall accuracy and stability of the detection.
[0047] Example 2, referring to Figures 2-4, is an embodiment of the present invention. Based on the previous embodiment, it provides a method for detecting electrical secondary drawing components based on a structure-aware mechanism, including:
[0048] Furthermore, in step S1, electrical secondary drawings are collected, and the electrical secondary drawings are uniformly rasterized and preprocessed to obtain preprocessed electrical secondary drawings.
[0049] Perform unified rasterization and preprocessing on electrical secondary drawings in CAD / PDF / image formats.
[0050] Furthermore, in step S2, an electrical secondary drawing component detection model is constructed. The input is the preprocessed electrical secondary drawing, and the output is the category probability, confidence level, and bounding box parameters for each target.
[0051] The entire model is an improvement on the YOLOv5 detection architecture, comprising two core components: embedded SAAM and the introduction of structural alignment enhancement loss. The input drawing image is processed by a backbone feature extraction network to extract multi-scale feature pyramids. During feature extraction, the feature maps at each scale are fused with the structural information of the drawing through SAAM, resulting in enhanced features more sensitive to small targets. The detection head generates component candidate bounding boxes based on these features. During model training, a structural alignment enhancement loss is added to the traditional object detection loss, making the predicted bounding boxes more spatially consistent with the arrangement patterns of real symbols.
[0052] Multi-scale features are extracted from the backbone network and SAAM is embedded at each scale to fuse local details with global row and column structures; cross-scale fusion is performed through the neck pyramid, and efficient multi-scale attention is introduced to improve feature consistency; the detection head at each scale outputs class probability, confidence and bounding box parameters.
[0053] This invention proposes an improved backbone network structure for component detection in electrical secondary drawings. As shown in the figure, the input drawing image is first subjected to initial convolution and layer-by-layer downsampling to obtain feature maps at five scales: 1 / 2, 1 / 4, 1 / 8, 1 / 16, and 1 / 32. SAAM is embedded during feature extraction at each scale to enhance the perception of local texture details and global row and column structures of symbols, thereby better distinguishing small, dense symbols that are easily confused with the background. The multi-scale features output by the backbone network are further input to the feature pyramid and path aggregation module, achieving cross-scale fusion through upsampling, convolution, and feature concatenation. An efficient multi-scale attention mechanism is introduced to improve the consistency and discriminative power between features at different scales. Finally, detection heads are set at the 1 / 4, 1 / 8, and 1 / 16 scales respectively, outputting the class probability, target confidence, and bounding box parameters for each candidate target. This backbone network differs from traditional general backbones (such as ResNet and CSPDarknet) by combining SAAM and a multi-scale attention mechanism, specifically designed for the characteristics of small, dense, and regularly arranged symbols in electrical secondary drawings. The overall framework is shown in Figure 2. The neck pyramid is the C3 neck module in Figure 2.
[0054] Addressing the challenges of small, densely packed symbols and components in electrical drawings, whose blurred outlines easily blend into the background, this invention proposes SAAM, which significantly enhances the model's ability to perceive symbolic components at the feature level and suppresses interference from complex backgrounds. SAAM's design philosophy combines two parallel pathways: local detail enhancement and global structure perception. It selectively weights the input feature map to highlight the spatial structural features of symbolic entities in the drawing. This lightweight module can be flexibly embedded into various stages of YOLOv5's multi-scale feature pyramid, providing more accurate feature representations.
[0055] As shown in Figure 3, SAAM uses input feature maps embedded in the multi-scale feature layers of the backbone network. ,in, For the number of channels, For feature map height, The width of the feature map. For the set of real numbers, Element-wise addition refers to adding corresponding elements of two vectors or matrices with the same shape one by one, while maintaining the same shape in the result; this process is then applied to output an attention weight map with structure-aware characteristics. .
[0056] SAAM includes local detail enhancement pathways and global structure awareness pathways.
[0057] The local detail enhancement pathway aims to capture fine-grained texture and edge information in symbol component regions. It employs multi-scale convolutional filters with 1×1, 3×3, and 5×5 kernels, and introduces dilated convolutions to expand the receptive field, capturing more local texture details. Each convolution is followed by batch normalization and a ReLU activation function to enhance feature representation stability and non-linearity. By fusing the responses of multi-scale convolutions pixel-by-pixel, local detail features emphasizing symbol edges and texture abrupt changes are obtained. This pathway can amplify the texture signal of small target symbols, highlighting symbol edges and texture abrupt changes on the feature map.
[0058] Let the input feature map be The four parallel branches are represented as follows:
[0059]
[0060]
[0061]
[0062]
[0063] in, This is a local detail branch feature map obtained from a convolutional layer with a kernel size of 1×1. It is the ReLU activation function. For batch normalization operations, This is a convolutional layer with a kernel size of 1×1. For the input feature map, This is a local detail branch feature map obtained from a convolutional layer with a kernel size of 3×3. This is a convolutional layer with a kernel size of 3×3. This is a convolutional layer with a kernel size of 5×5. This is a convolutional layer with a kernel size of 5×5. expansion rate The local detail branch feature map obtained from the dilated convolutional layer. expansion rate Hollow convolution.
[0064] Let the fusion weights of the four branches be learnable parameters, represented using softmax normalization:
[0065]
[0066] in, For the first The fusion weights of each branch; For branch index variables; For the first The learnable weight parameters of each branch are updated through the backpropagation algorithm to learn the optimal learnable weight parameters for each branch. This is the summation index in normalization, used to traverse all branches; This is a branch of dilated convolution; For the first Learnable weight parameters for each branch.
[0067] Local detail blending features:
[0068]
[0069] in, This is a local detail fusion feature map after fusing the features of the four branches.
[0070] The residual connection yields the final local detail feature representation as follows:
[0071]
[0072] in, These are local detail features.
[0073] In the local detail enhancement pathway of this invention, the input feature map extracts fine-grained features through parallel multi-scale convolutional branches. Specifically, four convolutional branches are designed: a 1×1 convolutional branch for channel remixing and fine-grained information capture; a 3×3 convolutional branch for extracting basic edge and texture features; a 5×5 convolutional branch for covering a wider local region; and a dilated convolutional branch, which uses 3×3 convolution with a dilation rate of 2 to expand the receptive field while maintaining resolution, capturing sparse structural information around small symbols. Each convolutional branch is connected to batch normalization and a nonlinear activation function after the convolution operation to enhance the stability of feature representation and nonlinear representation capability. Subsequently, the outputs of the four branches are fused at pixel-wise positions: in one implementation, learnable weights are set for each branch and normalized to obtain a weighted sum of pixel-wise fused features; in another implementation, the outputs of each branch are concatenated along the channel dimension and then compressed to the original number of channels through a 1×1 convolution to achieve pixel-wise information aggregation. The fused features are then residually connected to the input features, and a channel attention mechanism can be optionally introduced to further enhance the response of the symbol region. The resulting local detail features can highlight the edges and texture abrupt changes of the symbol, significantly enhance the model's ability to perceive small target symbols, and suppress background noise interference.
[0074] The global structure perception pathway is responsible for extracting the macroscopic layout features of the drawing symbols. First, the input feature map is averaged along the channel dimensions to obtain the spatial feature map:
[0075]
[0076] in, In spatial location The channel average value, For width index, For height indexing, For channel indexing, This represents the total number of channels in the feature map. For the first Each channel is in The eigenvalue at that location.
[0077] Perform strip global pooling along the height and width directions respectively to obtain one-dimensional horizontal and vertical features:
[0078]
[0079] in, For horizontal band features, indexed by column. Let be the independent variable, representing the th . The average activation intensity of the entire column (along the vertical direction); For column indexes; Vertical band features, indexed by row Let be the independent variable, representing the th . The average of the overall (horizontal) activation distribution of the row; For row index; The width of the feature map; The feature map height; In spatial location The channel average value; In spatial location The average value of the channels.
[0080] One-dimensional convolution and non-linear activation functions are used to process the features in the two directions mentioned above, respectively, to further extract the correlation between adjacent rows or columns, obtain enhanced directional features, and capture the spatial relationships of neighboring regions of rows and columns. Global structural features are obtained by expanding to a two-dimensional space and adding them element-wise.
[0081]
[0082] in, For global structural feature maps in The value of ; The response obtained after applying a one-dimensional convolution and nonlinear mapping to the horizontal band-shaped features is... Take the value corresponding to the row / column at that position after broadcasting; The response obtained after applying a one-dimensional convolution and nonlinear mapping to vertical band-shaped features is at the position. Take the value corresponding to the row / column at that position after broadcasting; This is the Sigmoid activation function. This pathway can capture the overall distribution pattern of the rows and columns where the symbols are located. For example, when the symbols are arranged horizontally or vertically along the wire, they will form obvious strip patterns in the feature map.
[0083] Local detail features are added to and fused with global structural features, and the final attention weight map is generated using the Sigmoid function.
[0084]
[0085] in, For attention weights, For local detail features, This refers to global structural features.
[0086] The attention weight map performs element-wise weighting on the input feature map and outputs an enhanced feature map:
[0087]
[0088] in, The enhanced feature map; Input feature map; For element-wise multiplication, for a homogeneous tensor at each position Multiplication, specifically element-wise multiplication, refers to multiplying corresponding elements of two vectors or matrices of the same shape one by one, resulting in a vector or matrix of the same shape. Enhanced SAAM organically integrates the local details of the symbol with global layout information, strengthening the feature response of the target region while suppressing background patterns unrelated to the symbol.
[0089] The SAAM structure is lightweight and flexible, and can be embedded in parallel at the multi-scale feature fusion layers of YOLOv5. After introducing SAAM into electrical drawing inspection, the network's ability to perceive small and dense symbols is significantly improved, and false detections caused by background interference are effectively reduced, providing more accurate feature representations for subsequent detection heads.
[0090] Furthermore, in step S3, during the training phase of the electrical secondary drawing component detection model, nodes and connection rules are selected to construct a structure diagram, and a loss function is constructed based on the structure diagram.
[0091] In addition to enhancing structural information at the feature level, spatial structural relationships between symbols are introduced into the training objectives as additional supervision. Traditional object detection loss functions only focus on the prediction accuracy of individual boxes, neglecting the global arrangement patterns between targets. However, in actual electrical secondary drawings, as shown in Figure 4, component symbols often follow certain design rules and arrangement patterns: devices in the same circuit are often aligned along the same horizontal or vertical direction; groups of components may be arranged in a matrix; and symbols with electrical connections are usually spatially adjacent or arranged at specific angles. If the model can explicitly learn these structural priors, it will help improve the accuracy and stability of the detection results.
[0092] Specifically, this invention defines a structural relationship diagram to depict the spatial relationships between symbols. The geometric centers of all symbols on the drawing are used as nodes in the diagram, and undirected edges are established between these nodes based on actual electrical connections, layout alignment, and adjacency. The criteria for edge establishment include: if there is a direct electrical connection between symbols, an edge is connected between the corresponding nodes; if symbols have a clear alignment relationship in the drawing layout, an edge is connected between the nodes; and symbols belonging to the same logical functional module and spatially adjacent are also connected by edges. Through these principles, a structural diagram that clearly reflects the layout of symbols on the drawing is constructed. The introduction of the structural diagram provides a theoretical basis for loss function design.
[0093] Based on the aforementioned symbolic structure diagram, a structural consistency loss function is proposed to explicitly optimize the spatial rationality of the detection results. The original training objectives of YOLOv5 include classification loss. (Handling object confidence and category) and regression loss The regression loss typically uses the Generalized Intersection over Union (GIoU) to optimize the bounding box coordinates, expressed as:
[0094]
[0095]
[0096] in, For classification loss; The set of positive sample predictions; The number of positive samples; Index for positive samples; For the first The positive sample in the th... Truth value on class; The total number of categories; An index for the classification categories; This represents the predicted probability of the corresponding category after the sigmoid function; For regression loss; For GIoU loss; The region of the prediction box; The region defined by the true bounding box; The smallest enclosing region, capable of simultaneously containing and The smallest set; The difference between sets; In the outer region, it belongs to But not belonging to Part of the area.
[0097] Based on this, a structural consistency loss is defined to measure the difference between the spatial relationships between predicted boxes and the true symbolic relationships, and it is added to the overall loss function:
[0098]
[0099] in, For structural consistency loss, The number of structural edges; This represents a node in the structure diagram. Representing nodes in the structure diagram Another node that has a structural relationship This represents a pair of nodes in the structure graph. This is a structural diagram; For nodes The prediction box, For nodes The prediction box; For nodes truth box, For nodes The truth box; The overall structural loss function measures the difference between the spatial relationships between predicted boxes and the true symbolic relationships, and is defined in three dimensions:
[0100] Relative distance loss encourages the distance relationships between predicted boxes to align with the distance relationships between ground truth symbols, preventing predicted boxes from becoming overly clustered or overly scattered.
[0101]
[0102] in, For relative distance loss, To obtain the center point coordinates of the bounding boxes, this loss makes the spacing between the predicted boxes as close as possible to the actual layout, which helps to maintain the relative positional relationship of the symbols.
[0103] Alignment loss occurs when symbols are strictly aligned along horizontal or vertical lines on a drawing, requiring the prediction frames to maintain the same orientation. Alignment is constrained by measuring the directional angle of the line connecting the centers of the prediction frames.
[0104]
[0105] in, For alignment direction loss, For the prediction center in Relative displacement on the axis For the prediction center in Relative displacement on the axis For the true center Relative displacement on the axis For the true center The relative displacement on the axis encourages the predicted boxes to align with the actual layout, thereby improving the consistency of the detection box arrangement.
[0106] For topological connectivity loss, for symbol pairs with clear connectivity, it encourages the angles of the connections between predicted boxes to be consistent with the angles of the connections between true symbols, reducing bias in connectivity. Cosine loss based on the angle difference is used.
[0107]
[0108] in, For topology connectivity loss, To predict the direction angle of the line connecting the centers, The direction angle of the line connecting the true centers ensures that the predicted boxes of the connecting symbols have the correct spatial relationship.
[0109] In actual training, the overall structural loss is constructed by combining the above sub-loss terms using a weighted summation method:
[0110]
[0111] in, For overall structural loss, The weight hyperparameters for the relative distance loss are... The weight hyperparameters for the alignment direction loss are... The weight hyperparameters for the topology connectivity loss; To control the magnitude of the loss contribution in each dimension, preheating and normalization are performed first. After 1-2 training epochs, calculate the mean of the three sub-losses, use their reciprocals as initial values, and normalize them so that the sum of the three weight hyperparameters is 1. Then, using this initial value as the center, perform a small-range grid or Bayesian search on the validation set, selecting the combination that minimizes the validation loss as the final result. .
[0112] During model training, this structural loss is applied only to predicted bounding box pairs that have correctly matched the ground truth symbols, preventing errors caused by background interference. The overall training loss is a weighted sum of the structural loss and the traditional object detection loss:
[0113]
[0114] in, This represents an overall training loss. The weights for structural consistency loss are gradually increased during the training process, starting from a relatively low value initially, to ensure basic detection capabilities before finely adjusting the layout structure.
[0115] From a mechanistic perspective, structural consistency loss guides the model to output position predictions that better conform to the design rules of the drawings through explicit spatial relationship constraints. It reduces false detections caused by interference from background lines or adjacent symbols, and makes the arrangement of detection boxes more closely match the actual drawing layout, thereby significantly improving the positioning accuracy and consistency of symbols.
[0116] Example 3 is an embodiment of the present invention, which provides a method for detecting electrical secondary drawing components based on a structure perception mechanism. In order to verify the beneficial effects of the present invention, scientific demonstration is carried out through experiments.
[0117] Step 1: Experimental environment and model configuration.
[0118] To verify the effectiveness of the proposed method, extensive experiments were conducted on a self-constructed electrical drawing symbol dataset. The experimental hardware environment consisted of an NVIDIA RTX 3080 GPU with 16GB of video memory. The proposed method was implemented using a Python-based tensor and dynamic computation graph deep learning framework. During training, a stochastic gradient descent optimizer was used, with an initial learning rate of 0.001, momentum of 0.9, weight decay of 0.0005, and a batch size of 16. The model training iterated for 120 training epochs, and after each training epoch, metrics such as average accuracy were monitored on the validation set. When the validation set performance showed no improvement for several consecutive training epochs, an early stopping strategy was adopted. To ensure fairness in the evaluation results, all comparison models were trained under the same hardware environment and training hyperparameter settings.
[0119] Step 2: Dataset Construction and Evaluation Metrics.
[0120] Currently, there is a lack of publicly available datasets for detecting symbols on electrical secondary circuit drawings. This invention constructs a dedicated dataset based on actual engineering data for model training and evaluation. The data sources cover typical secondary circuit drawings from multiple engineering units, and also include some publicly available electrical diagrams from the internet. A total of 500 drawings were ultimately compiled, covering various drawing styles and symbol distribution characteristics.
[0121] These drawings were uniformly converted to PNG format with a resolution of approximately 300 DPI and manually annotated using an image annotation tool (LabelImg). The annotations included the category of each component symbol and its precise location box in the drawing. The annotation work strictly adhered to national and industry standards for graphic symbols of secondary equipment in power systems. To enhance the model's ability to identify common components, 12 typical symbol categories were defined: circuit breakers, disconnect switches, relay coils, relay contacts, knife switches, fuses, transformers, pushbuttons, indicator lights, terminals, grounding symbols, and other auxiliary components. The entire dataset contains approximately 8000 symbol instances, with hundreds of samples for each symbol category.
[0122] All drawings were divided into training and testing sets at an 8:2 ratio to ensure the representativeness and generalizability of the test drawings during the evaluation process. Three commonly used metrics were used for model evaluation: precision, recall, and mean average precision (mAP). In the detection evaluation, the Common Objects in Context (COCO) evaluation criteria were selected, using mAP@0.5 and mAP@0.5:0.95. mAP@0.5 indicates that a predicted bounding box with an Intersection over Union (IoU) greater than 0.5 is considered correct, reflecting basic detection capabilities; mAP@0.5:0.95 is the average precision across multiple IoU thresholds, providing a more rigorous evaluation of localization accuracy. In addition, the report provides precision, recall, and average precision for each class, as well as average precision for small (area less than 32×32 pixels), medium (area between 32×32 pixels and 96×96 pixels), and large (area greater than 96×96 pixels) targets. This detailed analysis of the model's performance on different categories and scales of symbols, along with a focus on detection speed and resource consumption, is intended to validate the model's practicality.
[0123] Step 3: Data Augmentation.
[0124] To enhance the robustness and generalization ability of the model in complex electrical drawing environments, this invention introduces multiple data augmentation strategies during the training phase to simulate the variations that drawings may exhibit in real-world scenarios. First, considering that drawing symbols may be placed in arbitrary orientations, random rotations in 90° increments, along with horizontal and vertical flips, are employed to broaden the sample distribution of symbols at different angles. Furthermore, addressing the issue of small target symbols in drawings being easily lost during overall drawing scaling, overlapping block cropping is used to divide the original large image into local regions for training. This is supplemented by a mosaic data augmentation stitching strategy, randomly stitching together blocks from different original drawings to break the original circuit background pattern and reduce the model's dependence on specific layouts.
[0125] Building upon this foundation, a further method for generating synthetic drawings was designed: background fragments from real drawings, such as grid patterns and blank backgrounds, were selected, and multiple individual symbol icons were randomly pasted onto them. Lines were then drawn in random directions to simulate loop structures, supplemented with noise perturbations to enhance realism. This process constructs new symbol combinations and layouts, expanding the structural diversity of the training data. By combining these multi-dimensional data augmentation techniques, the model's adaptability to symbol deformation, background interference, and structural diversity was significantly improved, providing a solid foundation for feature generalization in component detection within actual engineering drawings.
[0126] Step 4: Experimental Analysis.
[0127] To comprehensively verify the effectiveness of the proposed structure-aware detection method, this invention selected mainstream object detection models such as YOLOv5 small (You Only Look Once version 5 small, YOLOv5s), YOLOX small (You Only Look Once X small, YOLOX-S), Faster Region-based Convolutional Neural Network (Faster R-CNN), and Retina Network (RetinaNet) as baselines on a unified test set, maintaining the same training configuration and evaluation metrics. Table 1 summarizes the performance of each model under core performance metrics such as precision, recall, mAP@0.5, mAP@0.5:0.95, and F1 score. The results show that the proposed method achieves 91.6% mAP@0.5, which is 5.2 percentage points higher than YOLOv5s' 86.4%, and significantly better than YOLOX-S's 88.0% and Faster R-CNN's 83.7%. Even at the more stringent mAP@0.5:0.95 metric, the method of this invention also achieved 63.5%, which is 2 percentage points higher than YOLOv5s, demonstrating stronger detection accuracy and positioning consistency.
[0128] In terms of anti-interference performance, background noise in electrical drawings mainly comes from dense wires, table frames, and text structures. As shown in Table 1, a comparative analysis of the false detection rate and false negative rate of each model shows that the false detection rate of the method in this invention is 5.3%, far lower than the 11.4% of YOLOv5s. Common false detection scenarios, such as misidentifying cross-connections as symbols and misidentifying annotation boxes as terminals, are significantly reduced after introducing SAAM and structural consistency loss. This is attributed to the structural awareness mechanism's constraint on unreasonable boxes and its ability to understand the contextual structural relationships. At the same time, the false negative rate of the method in this invention is 4.1%, which is also better than the 7.8% of YOLOv5s. Even when symbols are blurred or occluded, the structural constraint mechanism can still infer the existence of the target through the relationship between adjacent symbols, further improving the overall detection integrity.
[0129] Table 1 Comparison of Experimental Results of Mainstream Detection Models
[0130]
[0131] To further evaluate the adaptability of the method in multi-class symbol detection, Table 2 shows the model's recognition results for 12 typical electrical components. As can be seen from the table, the method of this invention achieves a balance between high precision and high recall in most target categories, demonstrating good overall performance. For small targets with high precision requirements, such as fuses and buttons, the model achieves 100% precision and a recall rate exceeding 0.98, demonstrating its advantage in micro-target detection. For symbols with simple shapes but easily interfered with by background interference such as wiring, such as circuit breakers and disconnect switches, good recognition performance is still achieved, verifying the model's effective filtering ability of redundant information.
[0132] Table 2 Model Parameters and Accuracy Evaluation
[0133]
[0134] Further analysis from the perspective of target size reveals that the method of this invention has a significant advantage for small symbols with an area less than 32×32 pixels. Table 3 shows that in small target detection, the average accuracy of the method of this invention reaches 78.9%, which is about 10 percentage points higher than YOLOv5s, and the recall rate is also improved by about 12 percentage points. This indicates that SAAM effectively enhances the feature representation ability of small targets, achieving stable detection even in complex backgrounds. For medium and large targets, the differences between models are small, but the method of this invention still has certain advantages in terms of detection accuracy and stability, demonstrating good scale generalization ability.
[0135] Table 3 Detection performance on targets of different scales
[0136]
[0137] Regarding inference efficiency, although the method of this invention introduces SAAM and structural consistency loss, the total number of model parameters is approximately 18M, only about 2M more than YOLOv5s, and it remains lightweight overall. Real-world testing shows that on a medium-complexity GPU platform, the method of this invention processes an A3 drawing image containing approximately 20 elements in an average of 120ms, achieving an inference frame rate of 8.3FPS, meeting the requirements for real-time performance and deployment efficiency in practical engineering applications.
[0138] In summary, the experiments fully validated the effectiveness of the proposed structure-aware detection method. In terms of detection accuracy, anti-interference capability, and positioning accuracy, the proposed method significantly outperforms the original YOLOv5 and other comparative models. This highlights the value of integrating prior structural information from electrical drawings into the target detection framework.
[0139] Step 5: Ablation experiment.
[0140] To evaluate the independent effects of SAAM and structural consistency loss, a series of ablation experiments were designed to compare the changes in model performance under different configurations. The baseline model was a YOLOv5s without any improvements: SAAM was removed and replaced with ordinary convolutional layers of equal parameters, and only classification and regression losses were used during training, without structural consistency loss. This baseline achieved an mAP@0.5 of 86.4% on the test set. Based on this, SAAM and structural consistency loss were added separately for comparison:
[0141] SAAM only: SAAM is embedded at the end of each multi-scale feature layer in YOLOv5s, but structural consistency loss is not used during training. Experimental results show that the model with SAAM only improves mAP@0.5 to approximately 89%, nearly 3 percentage points higher than the baseline, with particularly significant improvements in recall for small targets and an average precision improvement of approximately 8 percentage points. Simultaneously, background false positives are reduced, indicating that SAAM effectively enhances feature extraction capabilities, especially greatly aiding in the detection of small symbols.
[0142] Adding only structural consistency loss: Structural consistency loss is added to the baseline YOLOv5s training, but SAAM is not used; that is, structural information is only guided by the loss and not fused at the feature layer. In this case, the model with only structural consistency loss increases mAP@0.5 to approximately 87%, a slight increase of 1 percentage point compared to the baseline. More importantly, there is a significant improvement in localization accuracy and faster training convergence speed. This indicates that structural consistency loss mainly improves bounding box prediction, making the predicted boxes more closely match the arrangement of the true symbols, but because it does not enhance feature representation, the improvement in model recall is relatively limited.
[0143] Simultaneous use of SAAM and structural consistency loss: the combined model achieved an mAP@0.5 of 91.6%, a 5.2 percentage point improvement over the baseline, and nearly 6 percentage points improvement on the stringent metric of mAP@0.5: 0.95. The complete model achieved best performance across all symbol classes, especially in highly dense symbol regions, minimizing errors while maintaining high recall. This indicates that SAAM and structural consistency loss work synergistically: SAAM provides a better candidate base for subsequent box predictions, while structural consistency loss further adjusts and optimizes the positions of these candidate boxes and suppresses unreasonable detections that do not conform to structural priors, as shown in Table 4.
[0144] Table 4 Ablation Experiment Results
[0145]
[0146] Ablation experiments show that SAAM and structural consistency loss each significantly contribute to performance improvement, with the combination of the two yielding the best results: SAAM increases the detection rate of small target symbols and reduces background false detections, while structural consistency loss improves positioning accuracy and result consistency. The ablation results validate the effectiveness and complementarity of the proposed modules, further demonstrating the effectiveness of incorporating prior knowledge of the drawing structure into the detection framework.
[0147] Example 4 is an embodiment of the present invention, which provides an electrical secondary drawing component inspection device and medium based on a structure-sensing mechanism, including:
[0148] This embodiment also provides an electronic device applicable to a method for detecting electrical secondary drawing components based on a structure-aware mechanism, comprising: a memory and a processor; the memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions to implement the method for detecting electrical secondary drawing components based on a structure-aware mechanism as proposed in the above embodiment.
[0149] This embodiment also provides a storage medium storing a computer program that, when executed by a processor, implements a method for detecting electrical secondary drawing components based on a structure-aware mechanism as proposed in the above embodiments.
[0150] The storage medium proposed in this embodiment belongs to the same inventive concept as the method for detecting electrical secondary drawing components based on structure perception mechanism proposed in the above embodiments. Technical details not described in detail in this embodiment can be found in the above embodiments, and this embodiment has the same beneficial effects as the above embodiments.
[0151] Based on the above description of the implementation methods, those skilled in the art can clearly understand that the present invention can be implemented using software and necessary general-purpose hardware, and of course, it can also be implemented using hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory, hard disk, or optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods of the various embodiments of the present invention.
[0152] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.
Claims
1. A method for detecting electrical secondary drawing components based on a structure-sensing mechanism, characterized in that: The process includes: collecting electrical secondary drawings; performing unified rasterization and preprocessing on the electrical secondary drawings to obtain preprocessed electrical secondary drawings; constructing a component detection model for the electrical secondary drawings, taking the preprocessed electrical secondary drawings as input and outputting the class probability, confidence score, and bounding box parameters for each target; during the training phase of the component detection model for the electrical secondary drawings, selecting nodes and connection rules to construct a structure graph, and constructing a loss function based on the structure graph; the construction of the component detection model for the electrical secondary drawings includes designing a detection architecture based on YOLOv5; extracting multi-scale features from the backbone network and embedding structure-aware attention modules at each scale to fuse local details and global structure; Cross-scale fusion is performed via the neck pyramid, and efficient multi-scale attention is introduced to improve feature consistency; The detection head at each scale outputs class probability, confidence score, and bounding box parameters. The extraction of multi-scale features from the backbone network and embedding a structure-aware attention module at each scale includes: the structure-aware attention module is embedded in the multi-scale feature layer of the backbone network to process the input feature map and output an attention weight map with structure-aware characteristics; the structure-aware attention module includes a local detail enhancement path and a global structure-aware path; by introducing channel averaging, striped global pooling, and one-dimensional convolution operations in the global structure-aware path, it can effectively capture the row and column arrangement patterns of symbols in electrical secondary drawings, enabling the model to not only rely on local textures during detection but also recognize the overall layout rules of symbols; the local detail enhancement path captures fine-grained texture and edge information of symbol component regions; the local detail enhancement path design includes multi-scale convolutional filters with multiple convolutional kernels and introduces dilated convolution to expand the receptive field; each convolution is followed by batch normalization and an activation function; by fusing the responses of multi-scale convolutions pixel-by-pixel, local detail features emphasizing symbol edges and texture abrupt changes are obtained; the construction of the loss function includes: constructing an overall structure loss and an overall training loss based on the structure map; the overall structure loss is expressed as... in, This represents a node in the structure diagram. Representing nodes in the structure diagram Another node with a structural relationship. This is a structural diagram. For overall structural loss, For nodes The prediction box, For nodes The prediction box, For nodes truth box, For nodes truth box, For relative distance loss, For alignment direction loss, For topology connectivity loss, The weight hyperparameters for the relative distance loss are... The weight hyperparameters for the alignment direction loss are... Let be the weight hyperparameters of the topology connectivity loss; the overall training loss is expressed as . in, As a result of overall training losses, For classifying losses, To regress the loss, The weights for structural consistency loss, The structural consistency loss is defined as follows: The structural consistency loss includes a measure of the difference between the spatial relationships between predicted boxes and the true symbolic relationships, expressed as... in, This represents the number of edges in the structure.
2. The method for detecting electrical secondary drawing components based on a structure-sensing mechanism as described in claim 1, characterized in that: The global structure-aware pathway includes averaging the input feature map along its channel dimensions to obtain a spatial feature map, represented as follows: in, In spatial location The channel average value, For width index, For height indexing, For channel index, This represents the total number of channels in the feature map. For the first Each channel is in The feature values at the given location are then subjected to strip global pooling along the height and width directions, respectively, to obtain one-dimensional horizontal and vertical features, denoted as follows: in, The horizontal band-like feature indicates the first The average of the overall activation intensity of the column; For column indexes; The vertical band-like feature indicates the first The average of the overall activation distribution of the row; For row index; The width of the feature map; The feature map height; In spatial location The channel average value; In spatial location The channel average value; by expanding to a two-dimensional space and adding element-wise, the global structural features are obtained, represented as, in, For global structural feature maps in The value of ; The response obtained after applying a one-dimensional convolution and nonlinear mapping to the horizontal band-shaped features; The response obtained after applying a one-dimensional convolution and nonlinear mapping to the vertical band-shaped features; This is the Sigmoid activation function.
3. The method for detecting electrical secondary drawing components based on a structure-sensing mechanism as described in claim 2, characterized in that: The fusion of local details and global structure includes adding and fusing local detail features and global structural features, and generating a final attention weight map through an activation function, as shown below. in, For attention weights, For local detail features, The input feature map is represented as a global structural feature map; the attention weight map performs element-wise weighting on the input feature map, and outputs an enhanced feature map, represented as follows. in, For element-wise multiplication, For the enhanced feature map, This is the input feature map.
4. The method for detecting electrical secondary drawing components based on a structure-sensing mechanism as described in claim 3, characterized in that: In the training phase of the component detection model for electrical secondary drawings, the selection of nodes and connection rules to construct a structure diagram includes: taking the geometric center of all symbols on the electrical secondary drawings as nodes of the diagram; establishing undirected edges between nodes based on actual electrical connection relationships, layout alignment, and adjacency relationships; the criteria for establishing edges include: if there is a direct electrical connection between symbols, then an edge is connected between the corresponding nodes; if symbols have an alignment relationship in the drawing layout, then an edge is connected between the nodes; and symbol nodes belonging to the same logical functional module and spatially adjacent are connected by edges.
5. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the electrical secondary drawing component detection method based on the structure perception mechanism according to any one of claims 1 to 4.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the electrical secondary drawing component detection method based on the structure perception mechanism as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Cloth flaw detection method and system based on MAC-YOLO
CN120976097A
YOLOv8 algorithm improvement method based on unmanned aerial vehicle aerial image small target detection model
CN120976712A