Electrical drawing identification method, system, equipment and medium
By using multi-scale rasterization, grouped attention, and graph neural networks to process electrical drawings, the problems of multi-scale, noise, and sample imbalance in electrical drawing recognition are solved, achieving efficient and accurate component recognition and bill of materials generation.
Patent Information
- Application Number
- CN202511667737.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-14
- Publication Date
- 2026-02-27
AI Technical Summary
Existing technologies for electrical drawing recognition suffer from problems such as multi-scale components, complex lines and table noise, imbalanced category samples, and high-resolution attention computation overhead, resulting in low recognition efficiency and insufficient accuracy.
By employing multi-scale rasterization processing, grouped attention calculation, class-balanced loss function, and graph neural network, combined with vector analysis, data augmentation, and semantic gating fusion, a graph structure representation of the detection results is constructed to achieve efficient identification of components and generation of material lists.
It significantly improves the robustness and accuracy of electrical drawing recognition, reduces computational complexity, adapts to the recognition requirements of high-resolution drawings, alleviates the problem of sample imbalance, and enables accurate grouping of components and generation of bill of materials.
Smart Images

Figure CN121582958A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of energy storage equipment technology for power systems, specifically to a method, system, equipment, and medium for electrical drawing recognition. Background Technology
[0002] In the field of electrical engineering, electrical drawings are crucial for equipment design, installation, maintenance, and acceptance. However, the identification and analysis of equipment materials in electrical drawings currently relies heavily on manual labor, resulting in inefficiency and a high risk of errors. While some image recognition technologies have been attempted for electrical drawing recognition, these methods have several shortcomings. For example, the extraction accuracy is insufficient, and interference from components within the drawings leads to poor subsequent recognition results. In terms of data augmentation, the methods are relatively simplistic and cannot effectively address the diversity and complexity of components in electrical drawings. Furthermore, the computational efficiency of target recognition algorithms is low, making it difficult to meet the needs of large-scale electrical drawing recognition. Traditional OCR and CV methods perform recognition work independently, lacking semantic recognition capabilities and failing to accurately identify the relationships between data points, thus hindering the accurate and efficient extraction and summarization of all materials within the drawings. Summary of the Invention
[0003] In view of the above-mentioned problems, the present invention provides an electrical drawing recognition method, system, device and medium.
[0004] Therefore, the technical problem solved by this invention is to address the difficulties in the prior art in simultaneously dealing with multi-scale devices in drawings, complex lines and table noise, class sample imbalance, and high-resolution attention computation overhead.
[0005] To solve the above-mentioned technical problems, the present invention provides the following technical solution: an electrical drawing recognition method, comprising, The electrical drawing file is subjected to vector parsing to obtain a set of vector entities. The vector entities contain geometric information, layer attributes and text content. The set of vector entities is rasterized to generate a multi-scale raster map. The raster map includes line channels, symbol channels, text rendering channels and table line channels. Before rasterization, the vector lines are subjected to deformation processing, and after rasterization, the raster image is subjected to noise processing. Multi-scale visual features are extracted using a convolutional neural network backbone. After being aggregated through a feature pyramid network, group attention calculation is performed. The features are divided into multiple groups according to channels and attention calculation is performed separately for each group. Semantic gating coefficients are calculated based on text embedding and detection confidence. The attention output is then residually fused with the original features using the semantic gating coefficients. Based on the fused features, target detection is performed to obtain the bounding boxes, categories, and confidence scores of components. The detection network is trained using a class-balanced loss function that combines the weights of the effective number of samples and the normalized frequency. A graph structure is constructed to represent the detection results. Nodes contain visual features, location information, text embeddings, and category confidence. Edge weights are calculated by similarity and spatial distance. The node representations are updated through graph neural network message passing. Based on the updated node representations, component grouping and field matching are performed to generate a bill of materials.
[0006] As a preferred embodiment of the electrical drawing recognition method of the present invention, the step of performing vector parsing on the electrical drawing file to obtain a vector entity set includes reading the layer information and entity information of the electrical drawing file and extracting the attribute information of the vector entities; Different types of vector entities are rasterized to generate corresponding classification channels; Rendering is performed during the rasterization process to preserve line connectivity; The text content in the electrical drawing file is extracted and mapped into a text embedding representation.
[0007] As a preferred embodiment of the electrical drawing recognition method of the present invention, the step of applying deformation processing to vector lines before rasterization and applying noise processing to the raster image after rasterization includes perturbing the geometric properties of the vector lines before rasterization to generate a set of deformed vector entities. After rasterizing the deformed vector entity set, noise is superimposed on the pixel values of the raster image; The table structure in the raster image is transformed.
[0008] As a preferred embodiment of the electrical drawing recognition method of the present invention, the step of performing group attention calculation includes dividing the features into multiple feature groups according to the channel dimension, and flattening the features of each feature group into a sequence form; Calculate intra-group attention for each feature group, and add positional encoding to the intra-group attention calculation to preserve spatial location information; The attention outputs of each feature group are fused using a channel fusion mechanism; Cross-scale attention computation is performed between feature layers of different scales. Local attention computation is used for high-resolution feature layers, and global attention computation is used for low-resolution feature layers.
[0009] The beneficial effects of this preferred technical solution are as follows: It reduces the computational complexity of attention through a grouped attention mechanism, lowers the computational overhead of traditional full attention, significantly reduces memory usage, and accelerates the training and inference processes. By introducing positional encoding within groups to preserve spatial location information and employing differentiated attention strategies at different scale feature layers, it retains long-range interaction capabilities while achieving efficient multi-scale information transmission, making it particularly suitable for processing high-resolution electrical drawing recognition tasks.
[0010] As a preferred embodiment of the electrical drawing recognition method of the present invention, the step of training the detection network using a class-balanced loss function that combines effective sample number weight and normalized frequency includes: counting the number of samples in each category, calculating the effective sample number weight based on the sample number and a preset attenuation coefficient, wherein the effective sample number weight is negatively correlated with the sample number. Log-normalization is performed on the sample frequencies of each category to obtain the normalized frequencies; The category adaptive parameter is calculated based on the normalized frequency and the basic parameters, and the category adaptive parameter is negatively correlated with the normalized frequency; The effective sample number weight is used as the loss weight coefficient, and the category adaptive parameter is used as the hard sample modulation index to calculate the classification loss.
[0011] The beneficial effects of this preferred technical solution are that it effectively alleviates the problem of imbalanced component category samples in electrical drawing recognition by combining the effective sample number weight and the normalized frequency. The effective sample number weight decreases as the number of samples increases, avoiding excessive influence of high-frequency categories on model training; the category adaptive parameter dynamically adjusts the penalty intensity of difficult samples according to the normalized frequency, giving stronger attention to low-frequency rare categories, thereby improving the recall rate and overall detection stability of categories with few samples.
[0012] As a preferred embodiment of the electrical drawing recognition method of the present invention, the construction of the graph structure to represent the detection result includes using the detection result as a node of the graph structure, and each node contains the visual features, position information, text embedding and category confidence of the corresponding component; Calculate the visual similarity and text similarity between nodes; Calculate the spatial distance between nodes based on their location information; The edge weights between nodes in the graph structure are calculated based on the visual similarity, the text similarity, and the spatial distance. The graph structure is sparsified while preserving the local neighborhood connections of each node.
[0013] As a preferred embodiment of the electrical drawing recognition method of the present invention, the step of updating the node representation through graph neural network message passing includes performing multi-level message passing on each node of the graph structure and its neighboring nodes. In each layer of message passing, the features of the neighboring nodes are weighted and aggregated based on the edge weights, and combined with the node's own features to update the node representation. Calculate the correlation degree between nodes based on the updated node representation, and group nodes with a correlation degree higher than a preset threshold into the same group to achieve component grouping. By combining the text embedding information in the updated node representation with the spatial positional relationship of the nodes, the nodes are matched with the table fields; The class confidence of a node is adjusted based on the consistency of its neighbors.
[0014] This invention provides an electrical drawing recognition system.
[0015] To solve the above-mentioned technical problems, the present invention provides the following technical solution: an electrical drawing recognition system, comprising: a data preprocessing module, used to perform vector parsing on electrical drawing files to obtain a set of vector entities, and to rasterize the set of vector entities to generate a multi-scale raster image; The data augmentation module is used to apply deformation processing to the vector lines before rasterization and to apply noise processing to the raster image after rasterization. The feature extraction module is used to extract multi-scale visual features using a convolutional neural network backbone and then aggregate them through a feature pyramid network. The attention enhancement module is used to perform group attention calculation on the converged features, calculate semantic gating coefficients based on text embedding and detection confidence, and use the semantic gating coefficients to perform residual fusion between the attention output and the original features; The target detection module is used to detect component targets based on the fused features. The detection network is trained using a class-balanced loss function that combines the weights of the effective sample number and the normalized frequency. The relation modeling module is used to construct a graph structure to represent the detection results, update the node representation through graph neural network message passing, and perform component grouping and field matching based on the updated node representation; The output module is used to generate a bill of materials.
[0016] The present invention provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the electrical drawing recognition method described above.
[0017] The present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the electrical drawing recognition method described above.
[0018] The beneficial effects of this invention are as follows: The introduction of multi-directional Sobel and structured table synthesis in data augmentation significantly improves robustness to line symbols and table boundaries, especially in low-contrast / scan noise scenarios; the use of grouped adaptive attention based on FlashAttention retains the long-range interaction capabilities of Transformer while significantly reducing memory overhead and accelerating training / inference, making it suitable for high-resolution electrical diagram applications; CB-Focal alleviates class imbalance and improves recall and overall stability for classes with fewer samples by using "effective sample number" weights and class adaptive γ; the introduction of semantic graphs and GNNs enables modeling of relationships between components, making table field mapping and material summarization more accurate. Attached Figure Description
[0019] 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.
[0020] Figure 1 This is a flowchart illustrating an electrical drawing recognition method according to an embodiment of the present invention.
[0021] Figure 2 This is an analytical schematic diagram of an electrical drawing recognition method provided in one embodiment of the present invention. Detailed Implementation
[0022] To make the present invention more apparent and understandable, the 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, 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.
[0023] Example 1, referring to Figure 1 This is one embodiment of the present invention, which provides an electrical drawing recognition method, including: Step 1: Perform vector parsing on the electrical drawing file to obtain a set of vector entities. The vector entities contain geometric information, layer attributes, and text content. Rasterize the set of vector entities to generate a multi-scale raster image. The raster image includes line channels, symbol channels, text rendering channels, and table line channels. Step 2: Apply deformation processing to the vector lines before rasterization, and apply noise processing to the raster image after rasterization; Step 3: Multi-scale visual features are extracted using a convolutional neural network backbone. After being aggregated through a feature pyramid network, group attention calculation is performed. The features are divided into multiple groups according to channels and attention calculation is performed separately. Semantic gating coefficients are calculated based on text embedding and detection confidence. The attention output is then residually fused with the original features using the semantic gating coefficients. Step 4: Based on the fused features, target detection is performed to obtain the bounding boxes, categories, and confidence scores of components. The detection network is trained using a class-balanced loss function that combines the weights of the effective number of samples and the normalized frequency. Step 5: Construct a graph structure to represent the detection results. Nodes contain visual features, location information, text embeddings, and category confidence. Edge weights are calculated by similarity and spatial distance. The node representation is updated through graph neural network message passing. Based on the updated node representation, components are grouped and fields are matched to generate a bill of materials.
[0024] In practical applications of electrical engineering, electrical drawings often contain hundreds or even thousands of different types of components, which exhibit multi-scale and diverse characteristics. For example, small components such as wires and terminals may occupy only a fraction of the drawing, while large equipment such as distribution cabinets and control boxes may occupy a tenth of the entire drawing. Simultaneously, electrical drawings contain numerous complex lines, dense tables, and text annotations of varying font sizes, all intertwining to create complex visual noise. Furthermore, the quality of drawings obtained in actual projects varies greatly; scanned drawings often suffer from broken lines, low contrast, and paper aging. The frequency of different types of components appearing in drawings also differs significantly. Common circuit breakers and contactors have ample samples, but rare components such as special sensors and dedicated switches are scarce. This sample imbalance makes it difficult for traditional identification methods to accurately detect the few sample categories. More importantly, material compilation requires not only identifying individual components but also understanding the relationships between them, such as which parts belong to the same equipment and which component corresponds to the technical parameters in the table. This semantic relationship information is crucial for generating an accurate and traceable bill of materials.
[0025] To address the aforementioned issues, the electrical drawing recognition method provided in this embodiment achieves end-to-end material recognition through five steps. First, step 1 converts the electrical drawing into a multi-resolution feature representation containing four channels: lines, symbols, text, and tables, through vector analysis and multi-scale rasterization. This preserves the accurate geometric information of the vector drawing while providing rasterized data suitable for neural network input in subsequent processing, solving the feature extraction problem for multi-scale components. Step 2 applies targeted data augmentation before and after rasterization, effectively simulating issues such as broken lines, noise, and table complexity in actual drawings, improving the model's robustness. Step 3 employs a grouped attention mechanism and semantic gating fusion strategy, reducing computational complexity while maintaining the ability to capture long-range dependencies, adapting to the processing requirements of high-resolution drawings. Step 4 applies differentiated weights to component categories with different frequencies through a class-balanced loss function, effectively alleviating the sample imbalance problem and improving the recognition accuracy of rare components. Step 5 uses graph neural networks to model the semantic and spatial relationships between components, enabling functions such as equipment grouping, table field matching, and confidence correction. Ultimately, it generates an accurate and traceable bill of materials, thus completely solving the core technical problems faced by intelligent electrical drawing recognition, such as multi-scale recognition, complex noise, sample imbalance, computational efficiency, and semantic association.
[0026] Example 2, refer to Figures 1-2 As one embodiment of the present invention, an electrical drawing recognition method is provided based on the previous embodiment, including: Step 1: Perform vector parsing on the electrical drawing file to obtain a set of vector entities. The vector entities contain geometric information, layer attributes, and text content. Rasterize the set of vector entities to generate a multi-scale raster image. The raster image includes line channels, symbol channels, text rendering channels, and table line channels, including the following steps A1-A4: A1: Read the layer information and entity information of the electrical drawing file, and extract the attribute information of the vector entity; A2: Rasterize different types of vector entities to generate corresponding classification channels; A3: Rendering is performed during the rasterization process to preserve line connectivity; A4: Extract the text content from the electrical drawing file and map it into a text embedding representation.
[0027] In this embodiment, step A1 involves extracting the attribute information of the vector entities by: using a vector parsing library to read electrical drawing files in DWG or DXF format, traversing all entity objects in the file, and calling the attribute interface for each entity to obtain geometric information, layer name, line width, text content, font size, and block references. Specifically, for line entities, the start coordinates, end coordinates, and line width are extracted; for text entities, the text string, insertion point coordinates, and font size are extracted; for symbol block entities, the block name, insertion point coordinates, rotation angle, and scaling ratio are extracted; and for table entities, cell boundary coordinates and line attributes are extracted. The extracted attribute information is stored as a structured vector entity collection, where each vector entity contains complete geometric and semantic attributes.
[0028] In an optional implementation, in step A1, extracting the attribute information of the vector entity can be achieved by: when the electrical drawing file is a scanned image rather than a vector format, using optical character recognition (OCR) technology to extract the text content. Specifically, the scanned image is first preprocessed, including grayscale conversion, binarization, and noise removal; then, an OCR engine is used to identify text regions in the image, extracting text strings and text box coordinates; for graphic elements, edge detection and contour extraction algorithms are used to identify the geometric shape and position information of lines and symbols; and the confidence score of each recognition result is recorded. The identified text content and geometric information are then organized into structured data similar to vector entities.
[0029] In another optional implementation, in step A1, extracting the attribute information of the vector entities can also be achieved by: for electrical drawing files with missing or damaged vector information, using a hybrid approach combining vector analysis and image recognition. First, attempt to read complete vector entities from the file using a vector analysis library and extract their attribute information; for entities that fail to be analyzed or have incomplete attributes, render the area as an image and then use computer vision methods for supplementary recognition, such as identifying standard electrical symbols through template matching and extracting missing text information through text detection and recognition techniques. The vector analysis results and image recognition results are then fused, prioritizing the high-precision results of vector analysis and supplementing the missing parts with image recognition results, ultimately forming a complete set of vector entities.
[0030] Step 2: Applying deformation processing to the vector lines before rasterization and applying noise processing to the raster image after rasterization includes the following steps B1-B3: B1: Perturb the geometric properties of the vector lines before rasterization to generate a set of deformed vector entities; B2: After rasterizing the deformed vector entity set, noise is superimposed on the pixel values of the raster image; B3: Transform the table structure in the raster image.
[0031] In this embodiment, step 2 involves applying deformation processing by: randomly perturbing the geometric properties of vector lines before rasterization, including randomly perturbing the line width by ±1 to 3 pixels, inserting breakpoints of 2 to 10 pixels in length at random positions within the line segment, and applying an affine transformation with a rotation angle within ±5 degrees to the vector entity. After rasterization, Gaussian noise, salt-and-pepper noise, brightness contrast drift, and paper aging texture are superimposed on the pixel values of the raster image, where the standard deviation of Gaussian noise is set to 5 to 15, and the density of salt-and-pepper noise is set to 0.01 to 0.05. For table structures, adjacent cells are randomly selected for merging or a single cell is split into multiple sub-cells, the intensity of table lines is randomly changed to fluctuate within the range of 50% to 150%, and a background pattern is randomly inserted into the table area. Through the above-mentioned phased and multi-type data augmentation, problems such as broken lines, scanning noise, and table complexity in electrical drawings during actual use are effectively simulated.
[0032] In an optional implementation, step 2, applying deformation processing can be achieved by employing a simplified enhancement strategy based on affine transformation. Before rasterization, a uniform geometric transformation is applied to the entire set of vector entities on the drawing, including translation, rotation, scaling, and shearing. The transformation parameters are randomly selected within a preset range, for example, the translation distance does not exceed 5% of the drawing size, the rotation angle is within ±10 degrees, and the scaling ratio is between 0.9 and 1.1. After rasterization, a uniform image enhancement operation is applied to the generated raster image, including adding Gaussian blur to simulate scan defocus, adjusting the gamma value to simulate exposure changes, and adding random rectangular occlusions to simulate drawing damage. This method has high computational efficiency and is suitable for scenarios where the enhancement effect requirements are not high but a large number of drawings need to be processed quickly.
[0033] In another alternative implementation, step 2, applying deformation processing can also involve adaptively selecting enhancement strategies based on component categories and drawing quality. First, the electrical drawings are quality-assessed to identify the main problem types, such as line breakage, contrast levels, and table complexity. Targeted enhancements are then applied to different problems: for high-quality drawings, mild random perturbations are applied to increase data diversity; for drawings with existing line breakage issues, breakpoint insertion operations are reduced or skipped, and other types of perturbations are enhanced instead; for low-contrast drawings, brightness and contrast adjustments and texture overlays are emphasized; for simple tables, the intensity of table structure transformations is increased. Simultaneously, based on the sample requirements of rare component categories, stronger enhancements are applied to drawing areas containing these components, achieving synergistic optimization of data enhancement and sample balancing.
[0034] Step 3: Multi-scale visual features are extracted using a convolutional neural network backbone. After aggregation through a feature pyramid network, group attention calculation is performed. The features are divided into multiple groups by channel and attention calculation is performed separately for each group. Semantic gating coefficients are calculated based on text embedding and detection confidence. The attention output is then residually fused with the original features using the semantic gating coefficients. This includes the following steps C1-C4: C1: Divide the features into multiple feature groups according to the channel dimension, and flatten the features of each feature group into a sequence form; C2: Calculate the intra-group attention for each feature group, and add positional encoding to the intra-group attention calculation to preserve spatial positional information; C3: The attention outputs of each feature group are fused through a channel fusion mechanism; C4: Perform cross-scale attention computation between feature layers of different scales, using local attention computation for high-resolution feature layers and global attention computation for low-resolution feature layers.
[0035] In this embodiment, step C2 involves adding positional encoding by simultaneously adding relative positional encoding within each feature group when calculating attention using FlashSoftmax based on FlashAttention. Specifically, after flattening the H×W spatial positions of the feature map into a sequence, the row and column coordinates of each position in the original feature map are recorded. The row and column offsets between any two positions in the sequence are calculated, and these relative offsets are used as positional encodings input into the attention calculation. This ensures that the attention score not only reflects the similarity of feature content but also considers the spatial proximity, thus preserving the spatial layout information of components in the drawing during global attention calculation.
[0036] In an optional implementation, in step C2, adding positional encoding can be achieved by employing an absolute positional encoding scheme. Before flattening the features into a sequence, a positional encoding vector is generated for each spatial location in the feature map. This vector is obtained through an embedding layer mapping based on the row and column indices of that location in the feature map. The positional encoding vector is then directly superimposed onto the feature vector at the corresponding location, completing the injection of positional information. In subsequent attention calculations, the feature vectors already contain positional information, thus the attention mechanism can implicitly perceive the spatial relationships between different locations.
[0037] In another alternative implementation, in step C2, positional encoding can be added by introducing it only in cross-scale attention computation. For intra-group attention computation within the same scale, since the features already have strong local continuity, positional encoding can be omitted to reduce computational overhead. However, when performing attention interactions between feature layers at different scales, the spatial correspondence between high-resolution and low-resolution layers is complex. In this case, relative positional encoding is introduced to explicitly identify the spatial mapping relationship between feature points at two scales, ensuring the accuracy of cross-scale information fusion.
[0038] Step 4: Based on the fused features, target detection is performed to obtain the bounding boxes, categories, and confidence scores of components. The detection network is trained using a class-balanced loss function that combines the weights of the effective sample number and the normalized frequency. This includes the following steps D1-D4: D1: Count the number of samples in each category, and calculate the effective sample weight based on the sample number and the preset attenuation coefficient. The effective sample weight is negatively correlated with the sample number. D2: Log-normalize the sample frequencies of each category to obtain the normalized frequencies; D3: Calculate the category adaptive parameter based on the normalized frequency and the basic parameters, wherein the category adaptive parameter is negatively correlated with the normalized frequency; D4: Use the effective sample number weight as the loss weight coefficient and the category adaptive parameter as the hard sample modulation index to calculate the classification loss.
[0039] Furthermore, the class-balanced loss function is calculated as follows: First, the number of samples in each class is counted. Based on the sample number and a preset attenuation coefficient, the effective sample number weight is calculated. This weight is calculated by subtracting the attenuation coefficient from the total sample number (1 - 1) as the numerator and adding the attenuation coefficient to the power of 1 as the denominator, achieving the effect that the more samples there are, the smaller the weight becomes. Then, the logarithm of the sum of the sample numbers for each class is taken, and divided by the logarithm of the sum of the total sample numbers to obtain the normalized frequency. Next, the class adaptive parameter is calculated based on the normalized frequency and the basic parameters. This parameter is obtained by multiplying the basic parameters by the product of the adjustment coefficient and the normalized frequency. Finally, when calculating the classification loss, the effective sample number weight is used as the loss weight coefficient, and the class adaptive parameter is used as the modulation index for hard samples, applying a weighted penalty to the prediction confidence. This loss function reduces the loss contribution of high-frequency classes such as circuit breakers and contactors by using the effective sample number weight, and applies a stronger hard sample penalty to rare classes such as special sensors by using the class adaptive parameter, thereby alleviating the class imbalance problem.
[0040] Step 5: Construct a graph structure to represent the detection results. Nodes contain visual features, location information, text embeddings, and category confidence. Edge weights are calculated based on similarity and spatial distance. The node representation is updated through graph neural network message passing. Based on the updated node representation, component grouping and field matching are performed to generate a bill of materials, including the following steps E1-E9: E1: The detection results are used as nodes in a graph structure, and each node contains the visual features, location information, text embedding, and category confidence of the corresponding component; E2: Calculate the visual similarity and textual similarity between nodes; E3: Calculate the spatial distance between nodes based on their location information; E4: Calculate the edge weights between nodes in the graph structure based on the visual similarity, the text similarity, and the spatial distance; E5: Sparsify the graph structure while preserving the local neighborhood connections of each node.
[0041] E6: Perform multi-level message passing on each node of the graph structure and its neighboring nodes. In each level of message passing, the features of the neighboring nodes are weighted and aggregated based on the edge weights, and then combined with the node's own features to update the node representation. E7: Calculate the correlation between nodes based on the updated node representation, and group nodes with a correlation higher than a preset threshold into the same group to achieve component grouping; E8: Combine the text embedding information in the updated node representation with the spatial position relationship of the nodes to match the nodes with the table fields; E9: Adjust the class confidence of a node based on the consistency of its neighbors.
[0042] In this embodiment, step 5, updating the node representation through graph neural network message passing involves performing 2 to 3 layers of message passing iterations. In each iteration, the node collects feature information from its neighboring nodes and updates its own representation. Specifically, for each node in the graph structure, its set of neighboring nodes is first determined based on pre-calculated edge weights. Then, the features of all neighboring nodes are weighted and summed to obtain the neighbor aggregated features. Simultaneously, the node's own features are extracted. The neighbor aggregated features and the node's own features are linearly transformed using different transformation weight matrices and then added together. Finally, an activation function is applied to obtain the updated representation of the node in the current layer. After multiple layers of message passing, the representation of each node integrates the visual features, textual semantics, and spatial location information of components within its multi-hop neighborhood, providing a node representation with rich context for subsequent component grouping, table field matching, and confidence correction.
[0043] In an optional implementation, in step 5, updating the node representation via graph neural network message passing can be achieved by employing an attention-weighted message aggregation method. In each layer of message passing, instead of using fixed edge weights, the importance weights of neighboring nodes to the current node are dynamically calculated based on the node's features. Specifically, the features of the current node and the features of each neighboring node are input into the attention calculation module to obtain the attention score of the current node for each neighbor. The attention scores of all neighbors are normalized to obtain attention weights, and then the attention weights are used to perform weighted aggregation of the neighbor features. This approach enables the model to adaptively select and fuse neighbor information that is more relevant to the current component, improving its ability to model the differences in the strength of relationships between different components in complex electrical drawings.
[0044] In another optional implementation, in step 5, updating the node representation through graph neural network message passing can also be achieved by employing a categorized message passing strategy. Different message passing weights and aggregation methods are designed based on the category of the component corresponding to the node. Specifically, for line-type component nodes, the focus is on aggregating geometric connection information from spatially adjacent nodes; for symbol-type component nodes, the focus is on aggregating semantic association information from nodes with high text similarity; and for table cell nodes, the focus is on aggregating structured information from nodes with aligned rows and columns. In each layer of message passing, the corresponding aggregation weight matrix and transformation method are selected according to the node category, making the relationship modeling of different types of components more accurate and improving the accuracy of equipment grouping and field matching in bill of materials generation.
[0045] During the data input stage, DWG / DXF files or scanned images are processed first. These files contain various entities, such as lines, text, mixed text, and symbol blocks. ezdxf is then used to read layer and entity information, constructing a vector entity set. Each of them The data includes attributes such as geometric information, layer name, line width, text content, font size, and block references. A multi-scale raster image is then generated, and each scale is rasterized. During rasterization, anti-aliasing rendering is used to preserve line connectivity and width information. For text content, text attributes are preferentially parsed directly as reference text; if only scanned images are available, PaddleOCR is used for recognition, and the recognition confidence is recorded. Finally, each semantic mask / channel is output, including line channels, symbol channels, text rendering channels, and table line channels. To improve training efficiency, a slicing strategy is adopted, generating training samples by sliding or randomly slicing large-scale drawings (sizes of 512, 1024, or 2048) and preserving the global position information of the sliced drawings for subsequent aggregation.
[0046] To improve robustness to broken lines, low contrast, diverse tables, and few-sample symbols, further data augmentation was performed on the generated data samples. Before rasterization, random width perturbations, breakpoint insertion, and slight affine deformations were applied to the vector lines of tables and electrical symbols. After rasterization, Gaussian noise, salt-and-pepper noise, brightness / contrast shift, and paper aging textures were added. For tabular data, further random merging and cell splitting were performed, line intensity was changed, and background images were inserted into the tables to improve the model's ability to resolve tables.
[0047] The network as a whole adopts the ConvNeXt backbone network to extract multi-scale visual features. After being converged by FPN, the proposed GAF (Grouped Adaptive Flash Attention) module is inserted at the neck to enhance global context awareness across space. At the input end, the DWG / vector parsing module rasterizes lines, symbols, and text into multi-resolution image channels (line channel, symbol channel, text rendering channel, etc.). At the same time, for text, such as... Figure 2 The TA23 algorithm prioritizes parsing or performing OCR on the scanned image to obtain text strings, which are then further mapped to text embeddings. Symbols, if available, can be mapped to symbol embeddings. These text and symbol embeddings are either projected vectors and incorporated into visual features through pixel-wise / box-wise concatenation or cross-channel fusion to provide semantic priors during attention calculation and detection head classification. A key improvement of GAF is that it first flattens the input feature map (H×W) into a sequence and divides it into g groups according to channels C (C being the number of channels in the convolution output, 96) (g being a manually set hyperparameter, set to 4). Within each group, FlashSoftmax based on FlashAttention is used, and intra-group relative position encoding is added to preserve spatial location information. Inter-group fusion is achieved through a lightweight channel mechanism. Simultaneously, a semantic gating coefficient α, calculated from the text embeddings and detection confidence using a small MLP, is introduced. α is generated by a small 2-layer multilayer perceptron. This is used to adaptively adjust the fusion of the attention output with the original features according to the residual form Y=α⊙O+(1−α)⊙X, where , respectively, are the input feature maps of the GAF module and the feature maps computed by FlashAttention; ⊙ represents the Hadamard product. A sparse Cross-ScaleAttention strategy is employed across scales (local attention for high-resolution layers and relative global attention for low-resolution layers) to achieve efficient multi-scale information transfer. Compared to the high overhead of traditional full attention O(n·m·d), GAF reduces the complexity to approximately O(n·d·(1+1 / g)).
[0048] The classification loss uses the CB-Focal method of this invention, which weights the number of effective samples. Where β is the effective sample number smoothing coefficient, taken as 0.9999, and n+c is the actual number of bounding boxes. with normalized frequency Combined, define category adaptation ,in The reference modulation coefficient is set to 1.5. The rarity amplification factor is set to 1.0, and the final loss is: Where p is the class probability of the bounding box output by the sigmoid function. This is the probability offset term; if the bounding box is a positive sample, , To prevent log(0), this loss is jointly trained with bounding box regression (e.g., CIoU) in the classification branch of the detection head, thereby downgrading the weights of high-frequency classes and imposing a stronger hard sample penalty on rare classes; for classes with very few samples, oversampling or intra-batch guaranteed occurrence strategies can be used to complement the weight effect of CB-Focal.
[0049] Graph Neural Networks (GNNs) are used to model the semantic and spatial relationships of the detection results. The input includes a set of detection results. Each of them Includes visual features Location information (including center coordinates and bounding box size), OCR text embedding And the category confidence score s and the coordinates of the text. First, construct a graph structure, where nodes represent detection results and edge weights... It is calculated jointly by visual / textual similarity and spatial distance, and the formula is as follows: The graph is then normalized and fed into the GNN model. To control the sparsity of the graph, local neighborhood truncation is used, meaning only the k nearest neighbors of each node are connected. Next, the node representation is updated through L layers (L=2−3) of GNN message passing, with the update formula for each layer being... in, Let i be the set of all neighbors in the graph that are connected to i by an edge. A linear transformation matrix that is characteristic of itself. The linear transformation matrix of the "neighbor" messages ultimately yields the semantic representation of each node. The GNN's functions include grouping detected nodes (such as the same device, the same table row, or the same material group), table field filling (combining text embeddings and spatial column / row projections for field matching), and confidence correction (enhancing the judgment of few-sample classes through neighbor consistency). In implementation, text embeddings can use pre-trained sentence transformers or character-level CNNs (if the text is short). For table parsing, additionally constructing the table topology (using cell boundaries as nodes or constraints) helps improve the accuracy of field matching.
[0050] During training, 500 samples are randomly selected every 50 rounds for model validation. The model with the best validation performance is saved, i.e., the model with the minimum overall loss. The batch size is set to 10, and the initial learning rate is set to 0.0001. The training continues until the learning rate reaches 0.000001 and stops decreasing, or until the maximum number of iterations is reached. The resulting trained model is then used as the component detection model.
[0051] Example 3 is an embodiment of the present invention, which provides an electrical drawing recognition system, including: The data preprocessing module is used to perform vector parsing on electrical drawing files to obtain a set of vector entities, and to rasterize the set of vector entities to generate a multi-scale raster map. The data augmentation module is used to apply deformation processing to the vector lines before rasterization and to apply noise processing to the raster image after rasterization. The feature extraction module is used to extract multi-scale visual features using a convolutional neural network backbone and then aggregate them through a feature pyramid network. The attention enhancement module is used to perform group attention calculation on the converged features, calculate semantic gating coefficients based on text embedding and detection confidence, and use the semantic gating coefficients to perform residual fusion between the attention output and the original features; The target detection module is used to detect component targets based on the fused features. The detection network is trained using a class-balanced loss function that combines the weights of the effective sample number and the normalized frequency. The relation modeling module is used to construct a graph structure to represent the detection results, update the node representation through graph neural network message passing, and perform component grouping and field matching based on the updated node representation; The output module is used to generate a bill of materials.
[0052] This embodiment also provides an electronic device applicable to an electrical drawing recognition method, 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 an electrical drawing recognition method as proposed in the above embodiment.
[0053] This embodiment also provides a storage medium storing a computer program that, when executed by a processor, implements an electrical drawing recognition method as described in the above embodiments.
[0054] The storage medium proposed in this embodiment belongs to the same inventive concept as the electrical drawing recognition method 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.
[0055] 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.
[0056] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended 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 recognizing electrical drawings, characterized in that: include, The electrical drawing file is subjected to vector parsing to obtain a set of vector entities. The vector entities contain geometric information, layer attributes and text content. The set of vector entities is rasterized to generate a multi-scale raster map. The raster map includes line channels, symbol channels, text rendering channels and table line channels. Before rasterization, the vector lines are subjected to deformation processing, and after rasterization, the raster image is subjected to noise processing. Multi-scale visual features are extracted using a convolutional neural network backbone. After being aggregated through a feature pyramid network, group attention calculation is performed. The features are divided into multiple groups according to channels and attention calculation is performed separately for each group. Semantic gating coefficients are calculated based on text embedding and detection confidence. The attention output is then residually fused with the original features using the semantic gating coefficients. Based on the fused features, target detection is performed to obtain the bounding boxes, categories, and confidence scores of components. The detection network is trained using a class-balanced loss function that combines the weights of the effective number of samples and the normalized frequency. A graph structure is constructed to represent the detection results. Nodes contain visual features, location information, text embeddings, and category confidence. Edge weights are calculated by similarity and spatial distance. The node representations are updated through graph neural network message passing. Based on the updated node representations, component grouping and field matching are performed to generate a bill of materials.
2. The electrical drawing recognition method as described in claim 1, characterized in that: The step of performing vector parsing on electrical drawing files to obtain a set of vector entities includes reading the layer information and entity information of the electrical drawing files and extracting the attribute information of the vector entities; Different types of vector entities are rasterized to generate corresponding classification channels; Rendering is performed during the rasterization process to preserve line connectivity; The text content in the electrical drawing file is extracted and mapped into a text embedding representation.
3. The electrical drawing recognition method as described in claim 2, characterized in that: The step of applying deformation processing to vector lines before rasterization and applying noise processing to the raster image after rasterization includes perturbing the geometric properties of the vector lines before rasterization to generate a set of deformed vector entities. After rasterizing the deformed vector entity set, noise is superimposed on the pixel values of the raster image; The table structure in the raster image is transformed.
4. The electrical drawing recognition method as described in claim 3, characterized in that: The group attention calculation includes dividing the features into multiple feature groups according to the channel dimension, and flattening the features of each feature group into a sequence form. Calculate intra-group attention for each feature group, and add positional encoding to the intra-group attention calculation to preserve spatial location information; The attention outputs of each feature group are fused using a channel fusion mechanism; Cross-scale attention computation is performed between feature layers of different scales. Local attention computation is used for high-resolution feature layers, and global attention computation is used for low-resolution feature layers.
5. The electrical drawing recognition method as described in claim 4, characterized in that: The method of training the detection network using a class-balanced loss function that combines effective sample number weights and normalized frequency includes: counting the number of samples in each category; calculating the effective sample number weights based on the sample number and a preset decay coefficient; and the effective sample number weights are negatively correlated with the sample number. Log-normalization is performed on the sample frequencies of each category to obtain the normalized frequencies; The category adaptive parameter is calculated based on the normalized frequency and the basic parameters, and the category adaptive parameter is negatively correlated with the normalized frequency; The effective sample number weight is used as the loss weight coefficient, and the category adaptive parameter is used as the hard sample modulation index to calculate the classification loss.
6. The electrical drawing recognition method as described in claim 5, characterized in that: The constructed graph structure representing the detection results includes using the detection results as nodes in the graph structure, with each node containing the visual features, location information, text embedding, and category confidence of the corresponding component; Calculate the visual similarity and text similarity between nodes; Calculate the spatial distance between nodes based on their location information; The edge weights between nodes in the graph structure are calculated based on the visual similarity, the text similarity, and the spatial distance. The graph structure is sparsified while preserving the local neighborhood connections of each node.
7. The electrical drawing recognition method as described in claim 6, characterized in that: The method of updating node representation through graph neural network message passing includes performing multi-level message passing on each node of the graph structure and its neighboring nodes. In each level of message passing, the features of the neighboring nodes are weighted and aggregated based on edge weights, and then combined with the node's own features to update the node representation. Calculate the correlation degree between nodes based on the updated node representation, and group nodes with a correlation degree higher than a preset threshold into the same group to achieve component grouping. By combining the text embedding information in the updated node representation with the spatial positional relationship of the nodes, the nodes are matched with the table fields; The class confidence of a node is adjusted based on the consistency of its neighbors.
8. An electrical drawing recognition system, employing an electrical drawing recognition method as described in any one of claims 1 to 7, characterized in that, include: The data preprocessing module is used to perform vector parsing on electrical drawing files to obtain a set of vector entities, and to rasterize the set of vector entities to generate a multi-scale raster map. The data augmentation module is used to apply deformation processing to the vector lines before rasterization and to apply noise processing to the raster image after rasterization. The feature extraction module is used to extract multi-scale visual features using a convolutional neural network backbone and then aggregate them through a feature pyramid network. The attention enhancement module is used to perform group attention calculation on the converged features, calculate semantic gating coefficients based on text embedding and detection confidence, and use the semantic gating coefficients to perform residual fusion between the attention output and the original features; The target detection module is used to detect component targets based on the fused features. The detection network is trained using a class-balanced loss function that combines the weights of the effective sample number and the normalized frequency. The relation modeling module is used to construct a graph structure to represent the detection results, update the node representation through graph neural network message passing, and perform component grouping and field matching based on the updated node representation; The output module is used to generate a bill of materials.
9. 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 drawing recognition method according to any one of claims 1 to 7.
10. 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 drawing recognition method according to any one of claims 1 to 7.