A method and system for cable defect generation and detection based on component awareness
By employing component-aware segmentation and defect sample generation methods, the problems of sample scarcity and low accuracy in cable defect detection are solved, achieving efficient and accurate cable defect detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- NANJING LINGSHU INTELLIGENT TECHNOLOGY CO LTD
- Filing Date
- 2026-03-24
- Publication Date
- 2026-06-12
Smart Images

Figure CN122200142A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent power cable inspection technology, specifically to a method and system for generating and detecting cable defects based on component perception. Background Technology
[0002] Currently, cables, as the core carriers of power transmission and communication signal transmission, are widely used in power systems, rail transportation, industrial production, and civil infrastructure. Their structural integrity and operational status directly determine the stability and safety of the transmission system. During long-term service, cables are susceptible to environmental corrosion, mechanical stress, aging fatigue, and other factors, resulting in various defects such as insulation damage, exposed cores, cracked joints, surface scratches, missing markings, and sheath cracks. Timely and accurate defect detection of cables is an important prerequisite for ensuring their continuous and reliable operation.
[0003] Traditional cable defect detection relies primarily on manual visual inspection, which is inefficient, labor-intensive, and susceptible to factors such as lighting, viewing angle, and operator experience, resulting in high rates of missed and false detections. This makes it difficult to meet the high-efficiency inspection requirements for long-distance, large-scale cables. While existing machine vision-based automatic cable defect detection technologies improve efficiency to some extent by using image acquisition and visual recognition algorithms for defect identification, these technologies heavily depend on a large number of high-quality, precisely labeled defect samples. However, in real-world engineering scenarios, cable defect samples are scarce, on-site acquisition is costly, and manual pixel-level labeling of defects is labor-intensive, time-consuming, and lacks precision. Insufficient sample quantity and quality directly limit the training effect and generalization ability of defect detection models.
[0004] Meanwhile, existing defect sample generation methods mostly adopt random defect generation logic, and the generated defect locations and shapes do not match the actual cable defect characteristics, resulting in poor sample authenticity and engineering applicability. Furthermore, existing defect detection models do not rely on the refined segmentation results of cable components to carry out targeted detection, and the learning of defect characteristics of different functional components is insufficient, resulting in low model detection accuracy and robustness, and failing to achieve accurate, efficient and intelligent detection of cable defects. Summary of the Invention
[0005] To address the challenges of scarce, difficult to collect, and costly annotation samples in existing industrial scenarios, which hinders the convergence and generalization of directly trained detection models, this invention proposes a component-aware cable defect generation and detection method, comprising:
[0006] Obtain defect-free images of the cable;
[0007] The defect-free cable image is segmented using component perception to obtain the functional components of the cable in the defect-free cable image, the physical boundaries of each functional component, and the physical and functional logical association information between each functional component;
[0008] Based on the information of each functional component, physical boundary, and physical and functional logical association, a cable defect sample with mask annotation is generated.
[0009] Based on the cable defect samples with mask annotations, a cable defect detection dataset is constructed, and a defect detection model is trained based on the cable defect detection dataset.
[0010] Acquire an image of the cable to be inspected, perform defect detection on the image of the cable to be inspected using the defect detection model, and output the defect detection result.
[0011] Optionally, the step of performing component-aware segmentation on the defect-free cable image to obtain the functional components of the cable in the defect-free cable image, the physical boundaries of each functional component, and the physical and functional logical association information between each functional component includes:
[0012] Multi-scale visual features of the defect-free cable image are extracted using a visual backbone network.
[0013] Cross-modal attention calculation is performed on the multi-scale visual features, the randomly initialized learnable embedding vectors of the preset cable functional component categories, and the text embeddings of the pre-trained language model for each preset cable functional component category to obtain the attention maps of each functional component at different scales.
[0014] Upsampling and thresholding are performed on the attention maps at different scales to obtain the instance segmentation results and physical boundary coordinates of each functional component;
[0015] Based on the instance segmentation results, determine the functional components of the cable in the defect-free cable image and the type of each functional component;
[0016] Based on the physical boundary coordinates, determine the physical boundaries and spatial distribution of each functional component;
[0017] Based on the type and spatial distribution of each functional component, the physical and functional logical association information between each functional component is obtained.
[0018] Optionally, the functional components include one or more of the following: cable insulation layer, wire conductor, cable connector, cable marking and sealing sheath;
[0019] The physical and functional logical association information includes one or more of the following: physical connection relationships between functional components, structural constraint information of the functional components themselves, information on the areas where defects are allowed to occur on the corresponding functional components, and information on the compliance defect types corresponding to different functional components.
[0020] Optionally, generating a masked cable defect sample based on the functional components, physical boundaries, and physical-functional logical association information includes:
[0021] The target functional component is determined from the various functional components of the cable. Based on the type of the target functional component and combined with the physical and functional logical association information between the various functional components, the compliance defect type and defect morphology parameters of the target functional component are matched.
[0022] Based on the physical boundaries corresponding to the target functional components, the defect compliance generation area is locked within the physical boundary range;
[0023] Within the defect compliance generation area, based on the compliance defect type and defect morphology parameters, a cable defect image and pixel-level mask annotation information corresponding to the cable defect image are generated.
[0024] The cable defect image is integrated with the mask annotation information to obtain a cable defect sample with mask annotation;
[0025] The types of compliance defects include one or more of the following: insulation layer damage, exposed wire core, cracked joint, surface scratches, missing markings, and aging cracks in the sheath;
[0026] The mask annotation information includes one or more of the following: the functional component type where the defect is located, the defect type label, the pixel-level coordinates of the defect outline, and the defect region mask matrix.
[0027] Optionally, generating a cable defect image within the defect compliance generation area, based on the compliance defect type and defect morphology parameters, includes:
[0028] Based on the aforementioned compliance defect types and defect morphology parameters, a natural language defect prompt is constructed;
[0029] The natural language defect prompt is encoded into an anomaly embedding vector through a pre-trained language model, and the anomaly embedding vector is fused with the learnable embedding vector of the preset cable functional component category to obtain the defect condition embedding vector.
[0030] Based on the attention map of the target functional component, a low-density sampling strategy is used to select highly activated pixel regions, and these highly activated pixel regions are used as defect generation constraint regions.
[0031] Based on the attention maps of the target functional components at different scales, the attention mask is obtained;
[0032] Based on the attention mask, the defect morphology parameters, the defect conditional embedding vector, and the defect generation constraint region, a defect region is generated within the defect compliance generation region using a preset latent diffusion model;
[0033] The defective area is fused with the defect-free image of the cable to obtain a cable defect image;
[0034] The potential diffusion model is an image generation model based on conditional input, used to generate defect regions that conform to component constraints according to input conditions.
[0035] Optionally, the step of constructing a cable defect detection dataset based on the masked cable defect samples, and training a defect detection model based on the cable defect detection dataset, includes:
[0036] The cable defect samples with masked annotations are integrated with the cable defect-free images to construct a cable defect detection dataset, which is then divided into a training set, a validation set, and a test set according to a preset ratio.
[0037] Based on the training set and validation set, the preset defect segmentation and detection network is trained in a supervised manner, and the model parameters are iteratively optimized until the model converges, thus obtaining the converged defect segmentation model.
[0038] The performance of the converged defect segmentation model is tested using the test set. Once the preset accuracy requirements are met, the trained cable defect detection model is obtained.
[0039] The defect segmentation and detection network is the SegFormer segmentation network.
[0040] Optionally, the step of performing supervised training on the preset defect segmentation and detection network based on the training set and validation set, iteratively optimizing the model parameters until the model converges, and obtaining the converged defect segmentation model, includes:
[0041] Based on the training and validation sets, the SegFormer segmentation network is iteratively optimized using a joint loss function consisting of cross-entropy loss and Dice loss. After each training round, the model loss value is calculated, and the model parameters are updated by backpropagation based on the loss value.
[0042] Simultaneously, the model training effect is verified in real time through the validation set, and the validation set loss and model detection accuracy are calculated. When the validation set loss tends to stabilize after a preset number of rounds and the model detection accuracy reaches a preset threshold, the parameter iteration is stopped, the model is determined to have converged, and the converged defect segmentation model is obtained.
[0043] Optionally, the defect detection results include: defect location information, defect type, pixel-level mask of defect outline, and information about the functional component to which the defect belongs.
[0044] Based on the same inventive concept, the present invention also provides a component-aware cable defect generation and detection system, comprising:
[0045] The image acquisition module is used to acquire defect-free images of the cable.
[0046] The component perception module is used to perform component perception segmentation on the defect-free image of the cable to obtain the functional components of the cable in the defect-free image, the physical boundaries of each functional component, and the physical and functional logical association information between each functional component.
[0047] The defect generation module is used to generate cable defect samples with mask annotations based on the functional components, physical boundaries, and physical and functional logical association information.
[0048] The model training module is used to construct a cable defect detection dataset based on the cable defect samples with mask annotations, and to train a defect detection model based on the cable defect detection dataset.
[0049] The defect detection module is used to acquire the cable image to be inspected, perform defect detection on the cable image using the defect detection model, and output the defect detection results.
[0050] Optionally, the component awareness module includes:
[0051] The feature extraction submodule is used to extract multi-scale visual features of the defect-free image of the cable through a visual backbone network;
[0052] The cross-modal computation submodule is used to perform cross-modal attention computation on the multi-scale visual features, the randomly initialized learnable embedding vectors of the preset cable functional component categories, and the text embeddings of the pre-trained language model for each preset cable functional component category, to obtain the attention maps of each functional component at different scales.
[0053] The graph processing submodule is used to upsample and threshold the attention maps at different scales to obtain the instance segmentation results and physical boundary coordinates of each functional component.
[0054] The type segmentation submodule is used to determine the functional components of the cable in the defect-free cable image and the type of each functional component based on the instance segmentation result.
[0055] The boundary calculation submodule is used to determine the physical boundaries and spatial distribution of each functional component based on the physical boundary coordinates.
[0056] The logical association submodule is used to obtain the physical and functional logical association information between the functional components based on the type and spatial distribution of each functional component.
[0057] Optionally, the functional components include one or more of the following: cable insulation layer, wire conductor, cable connector, cable marking and sealing sheath;
[0058] The physical and functional logical association information includes one or more of the following: physical connection relationships between functional components, structural constraint information of the functional components themselves, information on the areas where defects are allowed to occur on the corresponding functional components, and information on the compliance defect types corresponding to different functional components.
[0059] Optionally, the defect generation module includes:
[0060] The parameter matching submodule is used to determine the target functional component from the various functional components of the cable, and match the compliance defect type and defect morphology parameters of the target functional component according to the type of the target functional component and the physical and functional logical association information between the various functional components.
[0061] The region generation submodule is used to lock the defect compliance generation region within the physical boundary based on the physical boundary corresponding to the target functional component.
[0062] The feature generation submodule is used to generate a cable defect image and pixel-level mask annotation information corresponding to the cable defect image within the defect compliance generation area, based on the compliance defect type and defect morphology parameters.
[0063] The information integration submodule is used to integrate the cable defect image with the mask annotation information to obtain a cable defect sample with mask annotation;
[0064] The types of compliance defects include one or more of the following: insulation layer damage, exposed wire core, cracked joint, surface scratches, missing markings, and aging cracks in the sheath;
[0065] The mask annotation information includes one or more of the following: the functional component type where the defect is located, the defect type label, the pixel-level coordinates of the defect outline, and the defect region mask matrix.
[0066] Optionally, the feature generation submodule includes:
[0067] The prompt construction unit is used to construct a natural language prompt based on the compliance defect type and defect morphology parameters;
[0068] The vector fusion unit is used to encode the natural language defect prompt into an anomaly embedding vector through a pre-trained language model, and fuse the anomaly embedding vector with the learnable embedding vector of a preset cable functional component category to obtain a defect condition embedding vector.
[0069] The constraint generation unit is used to select highly activated pixel regions based on the attention map of the target functional component using a low-density sampling strategy, and to use the highly activated pixel regions as the defect generation constraint regions.
[0070] The mask generation unit is used to obtain the attention mask based on the attention maps of the target functional components at different scales;
[0071] The defect diffusion unit is used to generate a defect region within the defect compliance generation region based on the attention mask, the defect morphology parameters, the defect conditional embedding vector, and the defect generation constraint region, using a preset potential diffusion model.
[0072] A defect fusion unit is used to fuse the defective area with the defect-free image of the cable to obtain a cable defect image;
[0073] The potential diffusion model is an image generation model based on conditional input, used to generate defect regions that conform to component constraints according to input conditions.
[0074] Optionally, the model training module includes:
[0075] The defect integration submodule is used to integrate the cable defect samples with masked annotations with the cable defect-free images to construct a cable defect detection dataset, and divide it into a training set, a validation set and a test set according to a preset ratio.
[0076] The iterative optimization submodule is used to perform supervised training on the preset defect segmentation and detection network based on the training set and validation set, iteratively optimize the model parameters until the model converges, and obtain the converged defect segmentation model.
[0077] The performance testing submodule is used to perform performance testing on the converged defect segmentation model using the test set. After meeting the preset accuracy requirements, the trained cable defect detection model is obtained.
[0078] The defect segmentation and detection network is the SegFormer segmentation network.
[0079] Optionally, the iterative optimization submodule includes:
[0080] The loss calculation unit is used to perform iterative parameter optimization on the SegFormer segmentation network based on the training set and validation set, using a joint loss function composed of cross-entropy loss and Dice loss. After each round of training, the model loss value is calculated, and the model parameters are updated by backpropagation based on the loss value.
[0081] The accuracy verification unit is used to verify the model training effect in real time through the verification set, calculate the verification set loss and the model detection accuracy. When the verification set loss tends to stabilize after a preset number of rounds and the model detection accuracy reaches a preset threshold, the parameter iteration is stopped, the model is determined to have converged, and the converged defect segmentation model is obtained.
[0082] Optionally, the defect detection results include: defect location information, defect type, pixel-level mask of defect outline, and information about the functional component to which the defect belongs.
[0083] In another aspect, the present invention also provides an electronic device, comprising: at least one processor and a memory; the memory and the processor are connected via a bus;
[0084] The memory is used to store one or more programs;
[0085] When the one or more programs are executed by the at least one processor, a component-aware cable defect generation and detection method as described above is implemented.
[0086] In another aspect, the present invention also provides a computer device readable storage medium having an executable program stored thereon, wherein when the executable program is executed, it implements the component-aware cable defect generation and detection method described above.
[0087] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0088] This invention provides a component-aware cable defect generation and detection method and system, comprising: acquiring a defect-free cable image; performing component-aware segmentation on the defect-free cable image to obtain the functional components of the cable in the defect-free image, the physical boundaries of each functional component, and the physical and functional logical association information between each functional component; generating masked cable defect samples based on the functional components, physical boundaries, and physical and functional logical association information; constructing a cable defect detection dataset based on the masked cable defect samples, and training a defect detection model based on the cable defect detection dataset; acquiring a cable image to be detected, performing defect detection on the cable image to be detected using the defect detection model, and outputting the defect detection result; this invention, by performing component awareness on the image, can accurately locate the functional components of the cable and define the relationships between the components, which is beneficial for realizing the understanding of cable structure and components. The method achieves refined representation of correlations; it generates masked cable defect samples based on the information of each functional component, physical boundary, and physical-functional logical correlation, ensuring that the generated defect samples match the actual component structure and functional logic of the cable. It also enables pixel-level annotation of defect areas, improving the realism and annotation accuracy of the defect samples. By constructing a dataset and training a defect detection model using masked cable defect samples, the model can fully learn the defect features of different functional components of the cable, effectively improving the recognition accuracy and generalization ability of the defect detection model. Therefore, the method of this invention, through the coordinated use of component-aware segmentation and component-constraint-based defect sample generation, can achieve precision, standardization, and automation throughout the entire cable defect detection process, comprehensively improving the sample quality, detection accuracy, and execution efficiency of cable defect detection. This forms a highly efficient defect detection system adapted to the structural characteristics of cables, possessing strong technical practicality and detection reliability. Attached Figure Description
[0089] Figure 1 A flowchart illustrating a component-aware cable defect generation and detection method provided by the present invention;
[0090] Figure 2 A schematic diagram of a cable image acquired in a component-aware cable defect generation and detection method provided by the present invention;
[0091] Figure 3 The overall framework diagram of a component-aware cable defect generation and detection method provided by the present invention;
[0092] Figure 4 The first cable image to be detected in the component-aware cable defect generation and detection method provided by the present invention;
[0093] Figure 5The defect detection image of the first cable image in the component-aware cable defect generation and detection method provided by the present invention;
[0094] Figure 6 The second cable image to be detected is provided in the component-aware cable defect generation and detection method of the present invention.
[0095] Figure 7 The defect detection image of the second cable image is provided in the component-aware cable defect generation and detection method of the present invention.
[0096] Figure 8 A schematic diagram of the structural composition of a component-aware cable defect generation and detection system provided by the present invention;
[0097] Figure 9 This is a schematic diagram of the structure of an electronic device provided by the present invention. Detailed Implementation
[0098] This invention proposes a method, system, device, and medium for generating and detecting cable defects based on component perception. The specific embodiments of this invention will be further described in detail below with reference to the accompanying drawings.
[0099] Example 1:
[0100] This invention provides a method for generating and detecting cable defects based on component awareness, as illustrated in the flowchart below. Figure 1 As shown, it includes:
[0101] Step 1: Obtain a defect-free image of the cable;
[0102] Step 2: Perform component-aware segmentation on the defect-free cable image to obtain the functional components of the cable, the physical boundaries of each functional component, and the physical and functional logical association information between each functional component in the defect-free cable image.
[0103] Step 3: Based on the information of each functional component, physical boundary, and physical and functional logical association, generate cable defect samples with mask annotations;
[0104] Step 4: Based on the cable defect samples with mask annotations, construct a cable defect detection dataset, and train a defect detection model based on the cable defect detection dataset;
[0105] Step 5: Obtain the cable image to be inspected, use the defect detection model to perform defect detection on the cable image to be inspected, and output the defect detection results.
[0106] In one implementation, the defect-free cable image in step 1 above is obtained by acquiring multi-view, high-resolution normal cable images (e.g., using an industrial camera and a ring light), and then performing noise reduction, enhancement, perspective correction, and normalization processing on them.
[0107] Specifically, the aforementioned normal cable images can include high-resolution color cable images of various cable models acquired from different angles (such as 0°, 45°, 90°) and against different backgrounds (for example, images can be obtained using...). (to be represented), as shown in the diagram. Figure 2 As shown, the acquired cable images First, bilateral filtering is performed for noise reduction, which is done at the pixel level. The output at this point can be represented as:
[0108] ;
[0109] In the formula,
[0110] ;
[0111] in, Represents pixels The grayscale value output after bilateral filtering; Represented in pixels The sum of normalized weights within the central neighborhood; Represented in pixels The neighborhood centered on; Indicates the weights controlling spatial distance; This represents the weight used to control grayscale differences; Represented in pixels The neighborhood centered Any pixel within The original grayscale value; Represents pixels grayscale value;
[0112] In each preset Within a small window, the bilateral filtering result is enhanced using CLAHE. The resulting cumulative distribution function after clipping can be:
[0113] ;
[0114] In the formula,
[0115] ;
[0116] in, Indicates the target grayscale value The cumulative distribution function after clipping; This represents the total number of valid pixels in the vertical dimension that participate in the histogram statistics within the window. This represents the total number of valid pixels in the horizontal dimension within the window that participate in the histogram statistics; Represents grayscale level Corresponding grayscale value The original histogram count at time; Indicates the clipping threshold; Indicates the total number of gray levels; This represents the rounding function;
[0117] The enhanced image is geometrically corrected for perspective distortion using a homography matrix (e.g., represented by 𝐻), satisfying the following relationship:
[0118] ;
[0119] In the formula,
[0120] ;
[0121] ;
[0122] in, This represents the x-coordinate of the image pixels after perspective distortion correction; This represents the vertical coordinate of the image pixels after perspective distortion correction; The x-coordinate of the original image pixels before correction (where perspective distortion exists); Represents the ordinate of the original image pixels before correction (where perspective distortion exists); This represents the matrix element in the first row and first column. This represents the matrix element in the first row and second column. This represents the matrix element in the 1st row and 3rd column; the rest are similar.
[0123] After geometric correction, the image is scaled proportionally to 512×512. The scaling factor can be:
[0124] ;
[0125] and,
[0126] ;
[0127] ;
[0128] Then, zero-padding is applied to any insufficient areas, and finally, zero-mean unit variance normalization is performed on all pixels for each channel. The expression can be as follows:
[0129] ;
[0130] in, Indicates the proportional scaling factor; This represents the function that takes the maximum value. Indicates the width of the original geometrically corrected image; Indicates the height of the original geometrically corrected image; Indicates the scaling factor. The actual width of the scaled image; Indicates the scaling factor. The actual height of the scaled image; This represents the sample mean of each channel of the image; This represents the standard deviation of each channel of the image; Represents the normalized coordinates The pixel values at that location are used as standardized data for model input; This indicates the coordinates after geometric correction, proportional scaling, and zero-filling. Pixel value at;
[0131] In the above implementation, by adding a preprocessing step for the acquired data and using bilateral filtering to denoise the image, the edge and texture details of each functional component of the cable can be completely preserved while removing noise, avoiding excessive edge blurring. By introducing CLAHE enhancement, the local contrast of the image can be improved, and the detailed features of the cable surface and component area can be enhanced, making subtle texture and structural differences clearer. Perspective distortion correction using homography matrix can eliminate geometric distortion caused by multi-view shooting, ensuring that the geometric shape and positional relationship of the cable and its functional components are accurate and consistent. Furthermore, zero-mean unit variance normalization is performed on the image to eliminate pixel distribution differences caused by different acquisition environments and lighting conditions, standardize data distribution, and thus help improve the training stability and convergence speed of the subsequent component perception segmentation and defect detection model.
[0132] In one implementation, step 2 above, which involves performing component-aware segmentation on the defect-free cable image to obtain the functional components of the cable in the defect-free image, the physical boundaries of each functional component, and the physical and functional logical association information between each functional component, may include:
[0133] Multi-scale visual features of the defect-free cable image are extracted using a visual backbone network.
[0134] Cross-modal attention calculation is performed on the multi-scale visual features, the randomly initialized learnable embedding vectors of the preset cable functional component categories, and the text embeddings of the pre-trained language model for each preset cable functional component category to obtain the attention maps of each functional component at different scales.
[0135] Upsampling and thresholding are performed on the attention maps at different scales to obtain the instance segmentation results and physical boundary coordinates of each functional component;
[0136] Based on the instance segmentation results, determine the functional components of the cable in the defect-free cable image and the type of each functional component;
[0137] Based on the physical boundary coordinates, determine the physical boundaries and spatial distribution of each functional component;
[0138] Based on the type and spatial distribution of each functional component, the physical and functional logical association information between each functional component is obtained.
[0139] For example, the functional components may include one or more of the following: cable insulation, wire conductor, cable connector, cable marking, and sealing sheath;
[0140] The physical and functional logical association information may include one or more of the following: physical connection relationships between functional components, structural constraint information of the functional components themselves, information on the areas where defects are allowed to occur on the corresponding functional components, and information on the types of compliance defects corresponding to different functional components;
[0141] In this implementation, the visual backbone network can be a hybrid visual feature extraction network combining a ResNet50 network and a Transformer. Through the visual backbone network, feature maps are output at low, middle, and high levels, forming multi-scale visual features. For ease of discussion, this can be simplified to low-level feature maps and high-level feature maps, as shown in the following expressions:
[0142] ;
[0143] ;
[0144] in, Represents the low-level feature map; Represents high-level feature maps; Indicates the height of the low-level feature map; Indicates the width of the low-level feature map; Indicates the channel dimension of the feature map; Indicates the height of the high-level feature map; Indicates the width of the high-level feature map; Represents the real number field, indicating that all elements of the feature map are real numbers;
[0145] In the initial stage of model training, to enable the network to recognize and distinguish different functional components (such as exposed conductors, insulation layers, connectors, and markings in cables), a set of learnable vector representations (embeddings) needs to be pre-assigned to each component. Specifically, the model pre-trains learnable embedding vectors with channel dimension d for each component category. The vector is initially given by a mean of 0 and a variance of . (e.g., normal distribution) The vectors are randomly distributed and continuously updated during training with gradient descent, eventually aligning them with the feature space of the corresponding components in the image. The role of component embedding is to: after the network extracts the features F of a local image region, it calculates... By measuring the similarity between components, the network can determine which functional component the region leans towards. This mechanism is similar to using category labels in image semantic segmentation, but in this invention, only vectors are used instead of one-hot encoding to represent categories, allowing the model to flexibly capture subtle differences between components. Furthermore, this invention can also encode the corresponding text description into text embeddings through a pre-trained language model to participate in cross-modal attention calculations, thereby enabling the model to learn component features jointly in both visual and semantic dimensions.
[0146] For example, the cross-modal attention calculation formula mentioned above can be as follows:
[0147] ;
[0148] in, Representation Component exist The cross-modal attention weight matrix (i.e., attention mask) of the layer; represents the normalized exponential function, used to map the raw score of attention calculation to the interval [0, 1], and the sum of the weights at all positions is 1; express The set of feature vectors at all locations in the layer feature map; Representation Component The transpose matrix of the learnable embedding vector; Representation Component The transpose matrix of the text description embedding vector; Indicates the channel dimension of the feature map; express The corresponding feature layer; express The corresponding feature layer; this example achieves cross-modal fusion by combining visual embeddings and text embeddings. After completing the weight normalization, finally Output component category and attention association weights of feature layer. Reshape the weight vector corresponding to a single component category in the weight matrix according to the spatial size of the low-level or high-level feature map to obtain a two-dimensional attention map that corresponds one-to-one with the spatial location of the image. This attention map can intuitively show the strength of the association between different regions in the image and the target component. The region with the higher the weight value, the more significant the response in the attention map.
[0149] In the above implementation, by employing a hybrid visual backbone network combining ResNet50 and Transformer, low-level fine-grained texture features and high-level global semantic features of defect-free cable images can be extracted simultaneously, forming multi-scale visual features to balance component detail representation and overall structural understanding. By introducing learnable embedding vectors corresponding to component categories and text embeddings to conduct cross-modal attention computation, it is possible to accurately match each functional component of the cable from both visual features and text semantic dimensions. Compared to traditional one-hot encoding, this method can capture subtle differences between different components more flexibly and delicately, thereby outputting attention weight matrices and attention maps at different scales that accurately represent the correlation strength between image regions and components. Upsampling and thresholding based on the multi-scale attention map can accurately obtain the instance segmentation results and physical boundary coordinates of each functional component, which is beneficial for accurately locating and extracting the boundaries of components such as cable insulation, conductor cores, and connectors. Combining component type and spatial distribution further yields physical and functional logical association information such as physical connections between components, structural constraints, allowable defect areas, and compliant defect types, which can avoid discrepancies between the location and type of defect generation and the actual characteristics of the cable components, while effectively improving the accuracy and reliability of component segmentation.
[0150] In one implementation, step 3 above, which involves generating masked cable defect samples based on the functional components, physical boundaries, and physical-functional logical association information, may include:
[0151] The target functional component is determined from the various functional components of the cable. Based on the type of the target functional component and combined with the physical and functional logical association information between the various functional components, the compliance defect type and defect morphology parameters of the target functional component are matched.
[0152] Based on the physical boundaries corresponding to the target functional components, the defect compliance generation area is locked within the physical boundary range;
[0153] Within the defect compliance generation area, based on the compliance defect type and defect morphology parameters, a cable defect image and pixel-level mask annotation information corresponding to the cable defect image are generated.
[0154] The cable defect image is integrated with the mask annotation information to obtain a cable defect sample with mask annotation;
[0155] The types of compliance defects may include one or more of the following: insulation layer damage, exposed wire core, cracked joint, surface scratches, missing markings, and aging cracks in the sheath;
[0156] The mask annotation information may include one or more of the following: the functional component type where the defect is located, the defect type label, the pixel-level coordinates of the defect outline, and the defect region mask matrix.
[0157] In this implementation, the process of generating a cable defect image within the defect compliance generation area, based on the compliance defect type and defect morphology parameters, may include:
[0158] Based on the aforementioned compliance defect types and defect morphology parameters, a natural language defect prompt is constructed;
[0159] The natural language defect prompt is encoded into an anomaly embedding vector through a pre-trained language model, and the anomaly embedding vector is fused with the learnable embedding vector of the preset cable functional component category to obtain the defect condition embedding vector.
[0160] Based on the attention map of the target functional component, a low-density sampling strategy is used to select highly activated pixel regions, and these highly activated pixel regions are used as defect generation constraint regions.
[0161] Based on the attention maps of the target functional components at different scales, the attention mask is obtained;
[0162] Based on the attention mask, the defect morphology parameters, the defect conditional embedding vector, and the defect generation constraint region, a defect region is generated within the defect compliance generation region using a preset latent diffusion model;
[0163] The defective area is fused with the defect-free image of the cable to obtain a cable defect image;
[0164] The potential diffusion model can be a conditional input-based image generation model, used to generate defect regions that meet component constraints based on input conditions;
[0165] In the above implementation, two main strategies, "Prompt Modifications" (PM) and "Low-density Sampling" (LS), are used to introduce semantic damage information into the target component region and generate diverse synthetic defect images that conform to physical and functional constraints. Specifically, the prompt modification process can be as follows:
[0166] According to components Generate a natural language prompt describing the abnormal state of the functional component (i.e., the aforementioned natural language defect prompt, for example, it can be implemented using...). (This is indicated by phrases such as "insulation layer cracked, copper conductor partially exposed" or "connection loose, cracked"), and then the defect notification text is embedded and fused. Encode into a change vector using a pre-trained language model. With the original text embedded (e.g., it can be used) (For representation) Linear weighted fusion is performed according to the following expression:
[0167] , ;
[0168] in, Representation Component The fused text prompt embedding vector, Corresponding cable functional component category; Represents the weighting coefficients for linear weighted fusion; Representation Component The original text embedding vector; Representation Component The defective text embedding vector; by performing linear weighted fusion through this expression, the strength of the damage can be controlled, and the fused prompt can be embedded... Attention mask of corresponding components These are together used as conditional inputs to the latent diffusion model (LDM). The model is then performed in the latent space. The reverse denoising iteration generates a local image reconstruction that conforms to the semantics of the prompt, enabling destructive modification of the component region.
[0169] Specifically, the implementation process of the aforementioned low-density sampling strategy can be as follows:
[0170] Based on attention mask The value of is used to select the top p% (e.g., 5%) of the most activated pixel locations as the high-activation pixel region, as shown in the following expression:
[0171] ;
[0172] in, Represents the set of highly active pixel locations; Represents the pixel coordinates of the feature map. The vertical axis (row index) is used. The x-axis (column index); Representation Component Attention mask in coordinates Activation value at; only at The region injects more random noise or enhances cue signals into the potential space, while keeping the original features of the remaining pixels unchanged. This allows for the concentrated generation of local defects while avoiding overall image distortion. Each sampling can be randomly selected. By combining different subsets with different prompts, various forms of defects can be generated for the same component. Finally, iterative interaction with multiple components is performed. For complex defect scenarios, prompts combined with low-density sampling strategies can be applied sequentially to multiple components on the same image. For example, cracks can be generated for the insulation layer first, followed by loosening for the joint. Alternatively, different components can be randomly selected in each iteration to simulate complex defects such as multiple cracks or peeling. Each completed loop produces a new synthetic defect image. By setting a preset number of loops, a defect set containing various logical and visual differences can be constructed. Through this hybrid strategy of prompt modification combined with low-density sampling, this invention not only achieves precise control and location of functional component-level anomalies but also generates diverse synthetic defect images while ensuring overall image quality.
[0173] The above implementation can also consider retrieving the nearest normal sample, calculating the attention residual, and performing morphological processing and cross-scale aggregation to generate the final cable defect sample. Specifically, this can be done by synthesizing a defect image set (e.g., using...). After the representation is generated, the local attention perturbation is transformed into an interpretable full-image defect segmentation mask through the sub-processes of Reference-to-Neighbor Association (RNA), Residual Mapping, and Cross-Scale Difference Aggregation (CSDA), including:
[0174] Pre-build a normal cable feature library (e.g., you can use...) (to be represented), where This represents the global feature vector obtained after preprocessing the first normal image. Indicates the first The global feature vector obtained after preprocessing the normal image; the global feature vector extracted by 𝐼 (e.g., the last layer of the Transformer) for each synthesized defect image. Calculate its global eigenvectors And through nearest neighbor search algorithms (such as the ANN index built by FAISS) in The most similar normal sample was retrieved from the middle. ; and on and Attention maps of each component that have been generated and Alignment is performed, and the residuals are calculated using the following expression:
[0175] ;
[0176] in, Representation Component exist Coordinates in the layer feature map Attention residual value at the location; Represents the maximum value function; Representation Component exist Attention weights / masks in layer feature maps; Indicates the first Zhang Synthetic Defect Image In coordinates Feature / attention value at the location; Indicates the first Zhang Reference Normal Image In coordinates Feature / attention value at the location; Indicates the low-level feature layer; This represents the high-level feature layer; only the positive values are retained to eliminate interference from existing high-response regions in normal samples. The residual maps at each scale are then automatically thresholded using Otsu to obtain a binarized mask. Morphological opening / closing operations (e.g., erosion followed by dilation) are used to remove noise and small connected components, and small holes are filled to ensure the continuity of the mask region. Finally, the low-resolution and high-resolution component-level binary masks are upsampled to a uniform size of 512×512, including: Injected into the corresponding skip connection layers, and into the backbone feature map. The fusion process can be achieved by adding channels one by one or by cascading and then reducing the dimensionality through 1×1 convolution. The expression can be as follows:
[0177] , ;
[0178] in, Indicates the fused Layer feature map; This represents a 1×1 convolution operation; Indicates before fusion Original backbone feature map of the layer; Indicates the mask weight coefficients; This represents the binary mask of component c in layer s after upsampling; An attention mask representing the low-level feature map; An attention mask representing a high-level feature map;
[0179] Therefore, the above implementation introduces a prompt modification strategy, encoding natural language defect prompts into anomaly embedding vectors and linearly weighting them with the original component text embeddings (e.g., precisely controlling the degree of defect damage through an α coefficient). This, combined with a latent diffusion model, generates semantically consistent local defect regions, achieving precise semantic control of component-level anomalies. A low-density sampling strategy selects high-activation pixel regions of the attention mask as defect generation constraint regions, injecting noise or enhanced prompt signals only in these regions. This concentrates the generation of local defects while avoiding overall image distortion. Furthermore, by randomly selecting subsets of high-activation regions and applying strategies sequentially / randomly across multiple components, diverse single and composite defects can be generated. The image is trapped; combining reference neighbor association, residual mapping and cross-scale difference aggregation sub-process, the most similar normal sample is retrieved and the attention residual is calculated (only positive values are retained to eliminate interference from normal regions). After Otsu automatic thresholding and morphological processing, a coherent component-level binary mask is obtained. After cross-scale aggregation, it is fused with the backbone feature map to generate an interpretable full-image defect segmentation mask. The final generated cable defect samples with mask annotation have semantic consistency, physical compliance and morphological diversity. Moreover, the mask annotation contains accurate pixel-level defect information, which can effectively solve the problems of scarce real cable defect samples, high annotation cost and single defect morphology, and improve the generalization ability and detection accuracy of the detection model.
[0180] In one implementation, step 4 above involves constructing a cable defect detection dataset based on the masked cable defect samples, and training a defect detection model using the cable defect detection dataset, including:
[0181] The cable defect samples with masked annotations are integrated with the cable defect-free images to construct a cable defect detection dataset, which is then divided into a training set, a validation set, and a test set according to a preset ratio.
[0182] Based on the training set and validation set, the preset defect segmentation and detection network is trained in a supervised manner, and the model parameters are iteratively optimized until the model converges, thus obtaining the converged defect segmentation model.
[0183] The performance of the converged defect segmentation model is tested using the test set. Once the preset accuracy requirements are met, the trained cable defect detection model is obtained.
[0184] The defect segmentation and detection network is the SegFormer segmentation network. After sampling to the original resolution on the SegFormer segmentation network, the final defect segmentation mask is output, which can accurately cover defect areas such as breaks, cracks and peeling in the cable image.
[0185] In this implementation, the process of performing supervised training on a pre-defined defect segmentation and detection network based on the training and validation sets, iteratively optimizing the model parameters until the model converges, and obtaining the converged defect segmentation model may include:
[0186] Based on the training and validation sets, the SegFormer segmentation network is iteratively optimized using a joint loss function consisting of cross-entropy loss and Dice loss. After each training round, the model loss value is calculated, and the model parameters are updated by backpropagation based on the loss value.
[0187] Simultaneously, the model training effect is verified in real time through the validation set, and the validation set loss and model detection accuracy are calculated. When the validation set loss tends to stabilize after a preset number of consecutive rounds and the model detection accuracy reaches a preset threshold, the parameter iteration is stopped, the model is determined to have converged, and the converged defect segmentation model is obtained.
[0188] In the above implementation, samples are constructed to fully cover both normal and defective samples. The normal sample portion can include samples randomly selected from the original cable images, representing various models, shooting angles, and lighting conditions, to ensure the model can adapt to the changing environment of the production site. The synthetic defect sample portion can include calling the cable defect detection dataset and using the refined segmentation mask generated in step 3 as pixel-level supervision labels. All normal and synthetic defective samples are divided into training, validation, and test sets according to a ratio of 70%, 15%, and 15%, respectively. A small number of real defect images are additionally retained in the validation and test sets and manually or semi-automatically labeled to objectively evaluate the model's generalization ability in real-world scenarios. To improve the robustness of the defect detection model to geometric and lighting changes and noise interference, online data augmentation strategies can be introduced during the training phase. These can include geometric transformations such as ±10° small-angle random rotation, ±5% translation, scaling within the range of 0.9–1.1, and horizontal flipping; ±20% brightness and contrast perturbation; and adding Gaussian noise or implementing gamma transformation in local areas to simulate various interference factors in complex production environments. Based on this data, SegFormer-B1 can be selected as the encoder backbone and a lightweight MLP decoder to construct a segmentation network. The input size is a 512×512 color image, and the output is a multi-channel probability map of the corresponding component and defect categories. The network training adopts joint cross-entropy loss and Dice loss, where the expression of the cross-entropy term can be as follows:
[0189] ;
[0190] in, Represents cross-entropy loss; This represents the total number of pixels used in the loss calculation; Indicates the first The real label of each pixel; The model predicts the first The probability value of each pixel being a defect;
[0191] The expression for Dice loss can be as follows:
[0192] ;
[0193] in, Indicates Dice loss; Indicates the smoothing term;
[0194] Preferably, both loss weights are set to 1, and the AdamW optimizer is considered (the initial learning rate can be set as follows). Weight decay The system employs a combination of cosine annealing or poly scheduling, with a batch size of 16 and a training duration of 100 epochs. Every 5 epochs, IoU and F1 scores are monitored on the validation set to stop early and avoid overfitting. After training, the optimal model is exported in ONNX format (supporting dynamic input), and 8-bit quantization and decoder channel pruning can be performed before deployment to reduce file size. During deployment, production line cameras acquire images in real-time and preprocess them on edge devices. Real-time inference can then be completed on the ONNXRuntime GPU at a speed of <50 ms / frame. If any pixel in the output probability map exceeds a set threshold (0.5), an alarm or rejection device is triggered, and a screenshot of the defective area and the corresponding ROI are uploaded to the MES / OPC UA platform for quality traceability and online learning, thereby achieving full-process automation and continuous optimization of cable defect detection.
[0195] For example, the defect detection results in step 5 above may include: defect location information, defect type, pixel-level mask of defect outline, and information about the functional component to which the defect belongs.
[0196] This method integrates computer vision feature extraction, cross-modal attention alignment, and deep generative models. Through multi-component decoupling, logical anomaly synthesis, residual mapping, and cross-scale information aggregation, it achieves self-supervised generation of high-fidelity defect samples and their interpretable and accurate segmentation detection.
[0197] In summary, this invention addresses the problems of scarce real-world defect samples, difficult collection, high annotation costs, and poor convergence and generalization of directly trained detection models in existing industrial scenarios. It proposes a component-aware cable defect generation and detection method, the overall framework of which is shown in the diagram below. Figure 3As shown, through data acquisition and preprocessing, defect-free cable images with clear edges, accurate geometric shapes, uniform dimensions, and standardized pixel distribution are obtained. Based on this, component-aware learning is introduced, and cross-modal attention computation is performed to complete the decoupling and modeling of cable components. Logical anomaly generation is introduced during the process. By combining prompts for modification with a low-density sampling strategy, high-activation attention regions are locked as defect generation constraint areas. A latent diffusion model is used to generate semantically consistent and physically compliant diverse cable defect images and corresponding preliminary pixel-level mask annotations within the compliant component areas. The annotated anomaly masks are then integrated, and through Otsu automatic thresholding and morphological opening / closing operations, a coherent component-level binary mask is obtained. After cross-scale aggregation, it is fused with the backbone feature map to generate a high-precision, interpretable full-image defect segmentation mask, completing the final annotation and optimization of defect samples. Finally, the detection model training and deployment stage begins. A training dataset is constructed based on the generated high-quality defect samples with mask annotations. Joint cross-entropy and Dice loss are used to train the defect detection model, completing the model deployment to achieve automated and accurate identification of cable defects.
[0198] Example 2:
[0199] The segmentation performance of the component-aware cable defect generation and detection method proposed in this invention is verified through a specific embodiment, as detailed below:
[0200] (1) Dataset selection:
[0201] Total sample size: 1200 images (900 normal images, 300 composite images, and real defects);
[0202] Resolution: 512×512;
[0203] Defect types: insulation tear, exposed conductor, loose connector, surface scratches, etc.
[0204] (2) Ablation test
[0205] To verify the necessity and effectiveness of the core modules of this invention, three sets of comparative ablation experiments were designed based on the above dataset. Pixel-IoU (pixel intersection-to-union ratio) and Dice-Score (Dice coefficient) were used as the core evaluation indicators for defect segmentation performance. By sequentially removing the two core modules of component-aware segmentation and logical anomaly generation, the improvement effect of each module on segmentation accuracy was compared and analyzed.
[0206] Table 1 presents the results of the ablation experiments to demonstrate the effectiveness of each proposed module;
[0207] Table 1 Ablation Experiment Results
[0208] Experimental setup Pixel-IoU Dice-Score Includes component-aware segmentation and logic exception generation 0.872 0.916 Component-aware partitioning 0.830 0.880 Component-aware segmentation and no logical exception generation 0.780 0.825
[0209] In the ablation experiments described above, component-aware learning was first removed. At this point, the model lost effective decoupling of the functional components in the image, resulting in a significant decrease in the quality of its attention mask. This led to a drop in Pixel-IoU from 0.872 to 0.830 and the Dice score from 0.916 to 0.880, fully demonstrating the importance of component-level alignment for accurate segmentation. Subsequently, after further removing logical anomaly generation, the training set lacked diverse defect samples synthesized through self-supervised methods, further weakening the model's generalization ability to anomaly patterns. Pixel-IoU and Dice scores dropped to 0.780 and 0.825, respectively, thus verifying the crucial role of logical anomaly generation in enriching training samples and improving edge detection. These results indicate that both component-aware learning and logical anomaly generation are indispensable for achieving high-precision, interpretable cable defect segmentation and detection capabilities.
[0210] (3) Qualitative analysis
[0211] Based on the quantitative verification of the ablation experiment, further qualitative analysis was conducted through visualization to intuitively verify the actual segmentation effect of the method of the present invention. Figure 4 Taking the first cable image as an example, the output segmentation result is as follows: Figure 5 As shown, with Figure 6 Taking the second cable image as an example, the output segmentation result is as follows: Figure 7 As shown, it can be seen that the defect detection model of the present invention has clear boundaries and complete regions in the segmentation results, and can accurately delineate the true outline of the target defect or structure.
[0212] As illustrated by the above embodiments, the component-aware cable defect generation and detection method proposed in this invention can effectively decouple the various functional components of the cable through component-aware segmentation, which is beneficial to improving the quality of attention masks. Combined with logic anomaly generation, it can synthesize diverse defect samples, enrich training data, and enhance the model's generalization ability to anomaly patterns, ultimately enabling the model to achieve a high level of segmentation performance. At the same time, from the qualitative results, the segmentation results generated by the method of this invention have clear boundaries and complete regions, which can accurately delineate the true contour of the defect. It exhibits strong robustness in edge detail processing, extraction of minute cracks, and target recognition in complex backgrounds. It can effectively solve the practical problems in traditional cable defect segmentation, such as insufficient component decoupling, scarce samples leading to low segmentation accuracy, weak generalization ability, and inaccurate edge capture. It can meet the actual engineering needs of cable defect detection, has high segmentation accuracy and practical application promotion value, and can efficiently support the accurate identification and subsequent maintenance of cable defects.
[0213] Example 3:
[0214] Based on the same inventive concept, this invention also provides a cable defect generation and detection system based on component perception, as shown in the schematic diagram below. Figure 8 As shown, it includes:
[0215] The image acquisition module is used to acquire defect-free images of the cable.
[0216] The component perception module is used to perform component perception segmentation on the defect-free image of the cable to obtain the functional components of the cable, the physical boundaries of each functional component, and the physical and functional logical association information between each functional component in the defect-free image of the cable.
[0217] The defect generation module is used to generate cable defect samples with mask annotations based on the functional components, physical boundaries, and physical and functional logical association information.
[0218] The model training module is used to construct a cable defect detection dataset based on the cable defect samples with mask annotations, and to train a defect detection model based on the cable defect detection dataset.
[0219] The defect detection module is used to acquire the cable image to be inspected, perform defect detection on the cable image using the defect detection model, and output the defect detection result.
[0220] In one implementation, the component awareness module may include:
[0221] The feature extraction submodule is used to extract multi-scale visual features of the defect-free image of the cable through a visual backbone network;
[0222] The cross-modal computation submodule is used to perform cross-modal attention computation on the multi-scale visual features, the randomly initialized learnable embedding vectors of the preset cable functional component categories, and the text embeddings of the pre-trained language model for each preset cable functional component category, to obtain the attention maps of each functional component at different scales.
[0223] The graph processing submodule is used to upsample and threshold the attention maps at different scales to obtain the instance segmentation results and physical boundary coordinates of each functional component.
[0224] The type segmentation submodule is used to determine the functional components of the cable in the defect-free cable image and the type of each functional component based on the instance segmentation result.
[0225] The boundary calculation submodule is used to determine the physical boundaries and spatial distribution of each functional component based on the physical boundary coordinates.
[0226] The logical association submodule is used to obtain the physical and functional logical association information between the functional components based on the type and spatial distribution of each functional component.
[0227] For example, the functional components may include one or more of the following: cable insulation, wire conductor, cable connector, cable marking, and sealing sheath;
[0228] The physical and functional logical association information includes one or more of the following: physical connection relationships between functional components, structural constraint information of the functional components themselves, information on the areas where defects are allowed to occur on the corresponding functional components, and information on the compliance defect types corresponding to different functional components.
[0229] In one implementation, the defect generation module may include:
[0230] The parameter matching submodule is used to determine the target functional component from the various functional components of the cable, and match the compliance defect type and defect morphology parameters of the target functional component according to the type of the target functional component and the physical and functional logical association information between the various functional components.
[0231] The region generation submodule is used to lock the defect compliance generation region within the physical boundary based on the physical boundary corresponding to the target functional component.
[0232] The feature generation submodule is used to generate a cable defect image and pixel-level mask annotation information corresponding to the cable defect image within the defect compliance generation area, based on the compliance defect type and defect morphology parameters.
[0233] The information integration submodule is used to integrate the cable defect image with the mask annotation information to obtain a cable defect sample with mask annotation;
[0234] The types of compliance defects include one or more of the following: insulation layer damage, exposed wire core, cracked joint, surface scratches, missing markings, and aging cracks in the sheath;
[0235] The mask annotation information includes one or more of the following: the functional component type where the defect is located, the defect type label, the pixel-level coordinates of the defect outline, and the defect region mask matrix.
[0236] In this implementation, the feature generation submodule may include:
[0237] The prompt construction unit is used to construct a natural language prompt based on the compliance defect type and defect morphology parameters;
[0238] The vector fusion unit is used to encode the natural language defect prompt into an anomaly embedding vector through a pre-trained language model, and fuse the anomaly embedding vector with the learnable embedding vector of a preset cable functional component category to obtain a defect condition embedding vector.
[0239] The constraint generation unit is used to select highly activated pixel regions based on the attention map of the target functional component using a low-density sampling strategy, and to use the highly activated pixel regions as defect generation constraint regions.
[0240] The mask generation unit is used to obtain the attention mask based on the attention maps of the target functional components at different scales;
[0241] The defect diffusion unit is used to generate a defect region within the defect compliance generation region based on the attention mask, the defect morphology parameters, the defect conditional embedding vector, and the defect generation constraint region, using a preset potential diffusion model.
[0242] A defect fusion unit is used to fuse the defective area with the defect-free image of the cable to obtain a cable defect image;
[0243] The potential diffusion model is an image generation model based on conditional input, used to generate defect regions that conform to component constraints according to input conditions.
[0244] In one implementation, the model training module may include:
[0245] The defect integration submodule is used to integrate the cable defect samples with masked annotations with the cable defect-free images to construct a cable defect detection dataset, and divide it into a training set, a validation set and a test set according to a preset ratio.
[0246] The iterative optimization submodule is used to perform supervised training on the preset defect segmentation and detection network based on the training set and validation set, iteratively optimize the model parameters until the model converges, and obtain the converged defect segmentation model.
[0247] The performance testing submodule is used to perform performance testing on the converged defect segmentation model using the test set. After meeting the preset accuracy requirements, the trained cable defect detection model is obtained.
[0248] The defect segmentation and detection network is the SegFormer segmentation network.
[0249] In this implementation, the iterative optimization submodule may include:
[0250] The loss calculation unit is used to perform iterative parameter optimization on the SegFormer segmentation network based on the training set and validation set, using a joint loss function composed of cross-entropy loss and Dice loss. After each round of training, the model loss value is calculated, and the model parameters are updated by backpropagation based on the loss value.
[0251] The accuracy verification unit is used to verify the model training effect in real time through the verification set, calculate the verification set loss and the model detection accuracy. When the verification set loss tends to stabilize after a preset number of rounds and the model detection accuracy reaches a preset threshold, the parameter iteration is stopped, the model is determined to have converged, and the converged defect segmentation model is obtained.
[0252] For example, the defect detection result may include: defect location information, defect type, pixel-level mask of defect outline, and information about the functional component to which the defect belongs.
[0253] Example 4:
[0254] like Figure 9 As shown, the present invention also provides an electronic device, which may be a computer device, a microcontroller device, a smart mobile device, etc. The electronic device in this embodiment may include a processor, a memory, a transceiver component, etc. The memory, processor, and transceiver component are connected via a bus; the memory can be used to store executable programs, and an exemplary executable program may include instructions; the processor is used to execute the instructions stored in the memory. The memory can also be used to store data, which can be accessed and / or modified when instructions are executed.
[0255] The processor may be a Central Processing Unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. It is the computing and control core of the terminal, and it is suitable for implementing one or more instructions. Specifically, it is suitable for loading and executing one or more instructions in the storage medium to implement the corresponding method flow or corresponding function, so as to implement the steps of the component-aware cable defect generation and detection method in the above embodiments.
[0256] Example 5:
[0257] Based on the same inventive concept, this invention also provides a readable storage medium, specifically an electronic device readable storage medium (Memory). This readable storage medium is a memory device within an electronic device used to store programs and data. It is understood that the storage medium here can include both built-in storage media within the electronic device and extended storage media supported by the electronic device. The storage medium provides storage space, which stores the terminal's operating system. Furthermore, this storage space also stores one or more instructions suitable for loading and execution by a processor. These instructions can be one or more executable programs (including program code). It should be noted that the storage medium here can be high-speed RAM or non-volatile memory, such as at least one disk storage device. Loading and executing one or more instructions stored in the storage medium by the processor can implement the steps of the component-aware cable defect generation and detection method described in the above embodiments.
[0258] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0259] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0260] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1The function specified in one or more boxes.
[0261] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0262] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit its scope of protection. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that after reading the present invention, they can still make various changes, modifications or equivalent substitutions to the specific implementation methods of the application, but these changes, modifications or equivalent substitutions are all within the scope of protection of the claims pending approval.
Claims
1. A method for generating and detecting cable defects based on component awareness, characterized in that, include: Obtain defect-free images of the cable; The defect-free cable image is segmented using component perception to obtain the functional components of the cable in the defect-free cable image, the physical boundaries of each functional component, and the physical and functional logical association information between each functional component; Based on the information of each functional component, physical boundary, and physical and functional logical association, a cable defect sample with mask annotation is generated. Based on the cable defect samples with mask annotations, a cable defect detection dataset is constructed, and a defect detection model is trained based on the cable defect detection dataset. Acquire an image of the cable to be inspected, perform defect detection on the image of the cable to be inspected using the defect detection model, and output the defect detection result.
2. The method as described in claim 1, characterized in that, The step of performing component-aware segmentation on the defect-free cable image to obtain the functional components of the cable in the defect-free cable image, the physical boundaries of each functional component, and the physical and functional logical association information between each functional component includes: Multi-scale visual features of the defect-free cable image are extracted using a visual backbone network. Cross-modal attention calculation is performed on the multi-scale visual features, the randomly initialized learnable embedding vectors of the preset cable functional component categories, and the text embeddings of the pre-trained language model for each preset cable functional component category to obtain the attention maps of each functional component at different scales. Upsampling and thresholding are performed on the attention maps at different scales to obtain the instance segmentation results and physical boundary coordinates of each functional component; Based on the instance segmentation results, determine the functional components of the cable in the defect-free cable image and the type of each functional component; Based on the physical boundary coordinates, determine the physical boundaries and spatial distribution of each functional component; Based on the type and spatial distribution of each functional component, the physical and functional logical association information between each functional component is obtained.
3. The method as described in claim 1 or 2, characterized in that, The functional components include one or more of the following: cable insulation layer, wire conductor, cable connector, cable marking and sealing sheath; The physical and functional logical association information includes one or more of the following: physical connection relationships between functional components, structural constraint information of the functional components themselves, information on the areas where defects are allowed to occur on the corresponding functional components, and information on the compliance defect types corresponding to different functional components.
4. The method as described in claim 1, characterized in that, The process of generating a masked cable defect sample based on the functional components, physical boundaries, and physical-functional logical association information includes: The target functional component is determined from the various functional components of the cable. Based on the type of the target functional component and combined with the physical and functional logical association information between the various functional components, the compliance defect type and defect morphology parameters of the target functional component are matched. Based on the physical boundaries corresponding to the target functional components, the defect compliance generation area is locked within the physical boundary range; Within the defect compliance generation area, based on the compliance defect type and defect morphology parameters, a cable defect image and pixel-level mask annotation information corresponding to the cable defect image are generated. The cable defect image is integrated with the mask annotation information to obtain a cable defect sample with mask annotation; The types of compliance defects include one or more of the following: insulation layer damage, exposed wire core, cracked joint, surface scratches, missing markings, and aging cracks in the sheath; The mask annotation information includes one or more of the following: the functional component type where the defect is located, the defect type label, the pixel-level coordinates of the defect outline, and the defect region mask matrix.
5. The method as described in claim 2 or 4, characterized in that, Within the defect compliance generation area, a cable defect image is generated based on the compliance defect type and defect morphology parameters, including: Based on the aforementioned compliance defect types and defect morphology parameters, a natural language defect prompt is constructed; The natural language defect prompt is encoded into an anomaly embedding vector through a pre-trained language model, and the anomaly embedding vector is fused with the learnable embedding vector of the preset cable functional component category to obtain the defect condition embedding vector. Based on the attention map of the target functional component, a low-density sampling strategy is used to select highly activated pixel regions, and these highly activated pixel regions are used as defect generation constraint regions. Based on the attention maps of the target functional components at different scales, the attention mask is obtained; Based on the attention mask, the defect morphology parameters, the defect conditional embedding vector, and the defect generation constraint region, a defect region is generated within the defect compliance generation region using a preset latent diffusion model; The defective area is fused with the defect-free image of the cable to obtain a cable defect image; The potential diffusion model is an image generation model based on conditional input, used to generate defect regions that conform to component constraints according to input conditions.
6. The method as described in claim 1, characterized in that, The process of constructing a cable defect detection dataset based on the masked cable defect samples and training a defect detection model based on the cable defect detection dataset includes: The cable defect samples with masked annotations are integrated with the cable defect-free images to construct a cable defect detection dataset, which is then divided into a training set, a validation set, and a test set according to a preset ratio. Based on the training set and validation set, the preset defect segmentation and detection network is trained in a supervised manner, and the model parameters are iteratively optimized until the model converges, thus obtaining the converged defect segmentation model. The performance of the converged defect segmentation model is tested using the test set. Once the preset accuracy requirements are met, the trained cable defect detection model is obtained. The defect segmentation and detection network is the SegFormer segmentation network.
7. The method as described in claim 6, characterized in that, The process of performing supervised training on a pre-defined defect segmentation and detection network based on the training and validation sets, iteratively optimizing model parameters until the model converges, and obtaining a converged defect segmentation model includes: Based on the training and validation sets, the SegFormer segmentation network is iteratively optimized using a joint loss function consisting of cross-entropy loss and Dice loss. After each training round, the model loss value is calculated, and the model parameters are updated by backpropagation based on the loss value. Simultaneously, the model training effect is verified in real time through the validation set, and the validation set loss and model detection accuracy are calculated. When the validation set loss tends to stabilize after a preset number of consecutive rounds and the model detection accuracy reaches a preset threshold, the parameter iteration is stopped, the model is determined to have converged, and the converged defect segmentation model is obtained.
8. The method as described in claim 1, characterized in that, The defect detection results include: defect location information, defect type, pixel-level mask of defect outline, and information about the functional component to which the defect belongs.
9. A component-aware cable defect generation and detection system, characterized in that, include: The image acquisition module is used to acquire defect-free images of the cable. The component perception module is used to perform component perception segmentation on the defect-free image of the cable to obtain the functional components of the cable in the defect-free image, the physical boundaries of each functional component, and the physical and functional logical association information between each functional component. The defect generation module is used to generate cable defect samples with mask annotations based on the functional components, physical boundaries, and physical and functional logical association information. The model training module is used to construct a cable defect detection dataset based on the cable defect samples with mask annotations, and to train a defect detection model based on the cable defect detection dataset. The defect detection module is used to acquire the cable image to be inspected, perform defect detection on the cable image using the defect detection model, and output the defect detection result.
10. The system as described in claim 9, characterized in that, The component awareness module includes: The feature extraction submodule is used to extract multi-scale visual features of the defect-free image of the cable through a visual backbone network; The cross-modal computation submodule is used to perform cross-modal attention computation on the multi-scale visual features, the randomly initialized learnable embedding vectors of the preset cable functional component categories, and the text embeddings of the pre-trained language model for each preset cable functional component category, to obtain the attention maps of each functional component at different scales. The graph processing submodule is used to upsample and threshold the attention maps at different scales to obtain the instance segmentation results and physical boundary coordinates of each functional component. The type segmentation submodule is used to determine the functional components of the cable in the defect-free cable image and the type of each functional component based on the instance segmentation result. The boundary calculation submodule is used to determine the physical boundaries and spatial distribution of each functional component based on the physical boundary coordinates. The logical association submodule is used to obtain the physical and functional logical association information between the functional components based on the type and spatial distribution of each functional component.