A cable defect image recognition method and system

CN122948822APending Publication Date: 2026-10-20HENAN JUYUAN ELECTRIC CABLE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611152181.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-31
Publication Date
2026-10-20

AI Technical Summary

Technical Problem

然而,缺陷种类繁多、形态尺度各异,且数据集中存在长尾分布现象,罕见缺陷的样本稀少;工业现场背景复杂,光照条件变化剧烈,存在环境噪声干扰

Benefits of technology

[0006]本发明通过利用卷积神经网络提取中间层特征图并进行网格划分与量化,结合空间位置编码构建结构化前缀键,能够将图像局部特征转化为易于检索的低维表示。根据填充率和键分布熵调整前缀缓存存入新键的阈值,实现了对缓存规模的精细化控制。设置差异化的特征重校准机制,在缓存命中时利用推理引导向量作为通道注意力权重强化特征,在未命中时则基于全局语义特征计算加权距离并融合邻近键生成临时引导向量进行特征补偿。该方法能够增强电缆缺陷的关键通道特征响应,在不增加繁重计算开销的前提下,提升了电缆缺陷图像识别的准确率与推理速度。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure FT_1
    Figure FT_1
  • Figure FT_2
    Figure FT_2
  • Figure FT_3
    Figure FT_3
Patent Text Reader

Abstract

This invention belongs to the field of image processing, specifically a method and system for cable defect image recognition. The recognition method includes: extracting a specified intermediate layer output feature map of the cable defect image using a convolutional neural network; dividing the feature map into a grid, quantizing the grid feature vectors to obtain a quantization index, and fusing spatial location encoding to construct a structured prefix key; storing the prefix key, category contribution vector, and inference guidance vector in a prefix cache, and adaptively adjusting the threshold for adding a new key based on the cache fill rate and key distribution entropy; when a prefix key is hit, adapting the matched inference guidance vector to the channel dimension and using it as the channel attention weight to correct the feature map; when a prefix key is not hit, calculating the weighted coefficient based on global semantic features, calculating the weighted distance between the current key and the cached key, fusing neighboring keys to generate a temporary guidance vector, and completing feature recalibration; and using the recalibrated feature response to output the cable defect recognition result through subsequent modules of the network.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of image recognition, and in particular relates to a method and system for recognizing cable defects in images. Background Technology

[0002] Under natural environmental conditions and long-term industrial service, cable surfaces are prone to various structural defects, including insulation damage, sheath cracking, aging deformation, and localized corrosion. If these defects are not detected in time, they can lead to short circuits, power outages, and even fires. Deep learning-based cable defect image detection technology has improved inspection efficiency. However, defects are diverse in type and scale, exhibit a long-tail distribution in datasets, and rare defect samples are scarce. Industrial environments are complex, with drastic changes in lighting conditions and environmental noise interference. These factors make traditional deep learning models susceptible to background noise when extracting cable defect features, resulting in insufficient feature representation and generalization capabilities for real defect areas. Existing convolutional neural networks, once trained, cannot adjust feature extraction preferences based on the local spatial distribution and global semantics of different input images. Although existing research attempts to enhance sensitivity to key regions using conventional attention mechanisms, these methods cannot remember or utilize historical prior experience accumulated during past recognition processes. When faced with rare defects or samples with ambiguous shapes, the model lacks external experience guidance, leading to missed and false detections. With the continuous accumulation of inspection data, how to store valuable feature patterns and achieve rapid retrieval and recalibration of feature responses during new sample inference has become a current technical bottleneck. Therefore, the field of cable defect image recognition urgently needs a new method that can break through the limitations of traditional static inference from an overall architecture perspective. By reusing historical inference experience and guiding the feature extraction process, it can solve the problems of background interference and the difficulty of identifying sparse samples, thereby improving the accuracy of recognition. Summary of the Invention

[0003] To improve the accuracy and inference speed of cable defect image recognition, this invention provides a cable defect image recognition method and system.

[0004] In a first aspect, the present invention provides the following technical solution: a method for cable defect image recognition, comprising: A convolutional neural network is used to extract the output feature map of the cable defect image to be identified at a specified intermediate layer; the output feature map is divided into grids, and the feature vectors within the grids are quantized to generate quantization indexes; the spatial location encoding is combined with the quantization indexes to generate structured prefix keys corresponding to each grid, forming a prefix key set; each structured prefix key in the prefix key set is traversed and queried in a pre-built prefix cache, the prefix cache storing the prefix key and its corresponding category contribution vector and inference guidance vector, and the threshold for storing new keys in the prefix cache is adaptively adjusted according to the fill rate and key distribution entropy; The algorithm iterates through each structured prefix key in the prefix key set. When the current structured prefix key is matched, the corresponding inference guidance vector is obtained. When the current structured prefix key is not matched, a weighting coefficient is determined based on the global semantic features of the output feature map. The weighted distance between the current structured prefix key and the cached keys in the prefix cache is calculated, and neighboring keys are fused to generate a temporary guidance vector. After completing the iteration, all the obtained inference guidance vectors and temporary guidance vectors are averaged and aggregated to generate a global guidance vector. The global guidance vector is then adapted to the channel dimension and applied as a channel attention weight to the output feature map of the specified intermediate layer to generate a recalibrated feature response. The recognition result is obtained by using the recalibrated feature response through the remaining part of the convolutional neural network.

[0005] Secondly, the present invention provides the following technical solution: a cable defect image recognition system, comprising the following modules: The query module is used to extract the output feature map of the cable defect image to be identified in a specified intermediate layer using a convolutional neural network; divide the output feature map into grids, quantize the feature vectors within the grids to generate a quantization index; combine the spatial location encoding with the quantization index to generate a structured prefix key corresponding to each grid, forming a prefix key set; traverse and query each structured prefix key in the prefix key set in a pre-built prefix cache, wherein the prefix cache stores the prefix key and its corresponding category contribution vector and inference guidance vector, and the threshold for storing new keys in the prefix cache is adaptively adjusted according to the fill rate and key distribution entropy; The generation module is used to traverse and query each structured prefix key in the prefix key set. When the current structured prefix key is matched, the corresponding inference guidance vector is obtained. When the current structured prefix key is not matched, the weighting coefficient is determined based on the global semantic features of the output feature map, the weighted distance between the current structured prefix key and the cached keys in the prefix cache is calculated, and the neighboring keys are fused to generate a temporary guidance vector. After completing the traversal, all the obtained inference guidance vectors and temporary guidance vectors are averaged and aggregated to generate a global guidance vector. The global guidance vector is adapted to the channel dimension and applied as the channel attention weight to the output feature map of the specified intermediate layer to generate a recalibrated feature response. The recognition module is used to calculate the recognition result using the recalibrated feature response through the remaining part of the convolutional neural network.

[0006] This invention utilizes a convolutional neural network to extract intermediate layer feature maps, perform grid partitioning and quantization, and construct structured prefix keys by combining spatial location encoding. This transforms local image features into easily retrieved low-dimensional representations. The threshold for storing new keys in the prefix cache is adjusted based on the fill rate and key distribution entropy, achieving fine-grained control over the cache size. A differentiated feature recalibration mechanism is implemented: when the cache hits, the inference guide vector is used as a channel attention weight to strengthen features; when the cache misses, a weighted distance is calculated based on global semantic features, and neighboring keys are fused to generate a temporary guide vector for feature compensation. This method enhances the key channel feature response of cable defects, improving the accuracy and inference speed of cable defect image recognition without increasing computational overhead. Attached Figure Description

[0007] Figure 1 A flowchart of a cable defect image recognition method; Figure 2 A schematic diagram of the ResNet-50 network structure and the specified intermediate layer feature extraction locations; Figure 3 This diagram illustrates the grid division and quantization index generation for the output feature map. Detailed Implementation

[0008] In this application, the terms "exemplarily" or "for example" are used to indicate that something is being described as an example, illustration, or illustration. Any embodiment or design described as "exemplarily" or "for example" in this application should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of terms such as "exemplarily" or "for example" is intended to present the relevant concepts in a specific manner.

[0009] In this application, a method for cable defect image recognition is provided, such as... Figure 1 As shown, the method includes: S1. A convolutional neural network is used to extract the output feature map of the cable defect image to be identified at a specified intermediate layer. The output feature map is divided into grids, and the feature vectors within the grids are quantized to generate a quantization index. Spatial location encoding is combined with the quantization index to generate structured prefix keys corresponding to each grid, forming a prefix key set. Each structured prefix key in the prefix key set is traversed and queried in a pre-built prefix cache. The prefix cache stores the prefix key and its corresponding category contribution vector and inference guidance vector. The threshold for storing new keys in the prefix cache is adaptively adjusted based on the fill rate and key distribution entropy.

[0010] The cable defect image to be identified is adjusted to a resolution of 512×512 and then input into the network. After forward propagation to the layer 3 module, an output feature map with a spatial size of 32×32 and 1024 channels is obtained. The layer arrangement of this ResNet-50 network and the feature extraction points of the specified intermediate layers are as follows: Figure 2 As shown.

[0011] The output feature map is divided into a non-overlapping grid of size 2×2 with a stride of 2. The mean value of the feature pixels within each grid in the spatial dimension is calculated to obtain the grid feature vector. A product quantization algorithm is used, and the grid feature vector is mapped to a discrete quantization center index using the faiss.IndexPQ algorithm library.

[0012] Two-dimensional relative coordinates are generated for each grid cell. These coordinates are then converted into spatial position encoding vectors using a sine-cosine position encoding algorithm. The spatial position encoding vectors are then concatenated with the quantization index along the feature dimension to generate a multi-dimensional vector-based structured prefix key. This results in the set of prefix keys for the current output feature map at all grid cell positions.

[0013] A lookup is performed in the instantiated character-based hash table prefix cache. This prefix cache stores the structured prefix keys of historical training samples, the class contribution vector calculated via backpropagation, and an inference guidance vector containing deep feature priors. The inference guidance vector is randomly initialized using a Gaussian distribution during model training, and in subsequent iterations, the feature stream of the current batch of hit samples is reduced in dimensionality via linear mapping and then updated using an exponential moving average (EMA) mechanism. Its fixed dimension is set to 64 dimensions, corresponding to the output feature map. Before each attempt to store a new key, the current number of cache entries is obtained and divided by the maximum capacity to calculate the fill rate. Simultaneously, Shannon entropy is calculated based on the access frequency of each key as the key distribution entropy. The current storage threshold is determined by multiplying the preset basic control constant, the cache idle rate (i.e., 1 minus the fill rate), and the key distribution entropy, and then adding the bias term. If the cosine similarity between the new key and all cache keys is lower than the current storage threshold, a hash mapping storage operation is performed. When storing a new key, determine whether the number of entries in the current prefix cache is less than K: if it is less than K, directly generate the inference guidance vector corresponding to the new key by randomly initializing it with a Gaussian distribution, and initialize the corresponding category contribution vector to a vector of all zeros; if it is greater than or equal to K, read the K nearest neighbor cache keys with the smallest weighted distance, calculate their mean to generate and write the category contribution vector and inference guidance vector corresponding to the new key.

[0014] In some implementations, the extraction of the output feature map of the cable defect image to be identified in a specified intermediate layer using a convolutional neural network includes: Acquire a three-channel RGB image of the cable defect to be identified with a resolution of 512 pixels × 512 pixels; Subtract the preset dataset mean matrix from the pixel value of each pixel in the image of the cable defect to be identified, and then divide by the preset standard deviation matrix to complete the standard normalization of the image pixels. The standardized image is used as tensor data and input into the convolutional neural network constructed using the ResNet-50 architecture for forward inference computation. The inference process is truncated, and the extraction position is located at the last bottleneck layer structure of the Layer 3 block of the ResNet-50 architecture. The output matrix sequence with a tensor size of 32×32×1024 is used as the output feature map of the specified intermediate layer.

[0015] In the preprocessing and importing stage of defect image data, the original cable surface inspection image is identified and processed into a cable defect image matrix with a width of 512 pixels, a height of 512 pixels, and containing three color channels of red, green and blue through a bilinear interpolation cropping algorithm. The initial pixel values ​​are distributed in the integer range of 0 to 255.

[0016] During numerical normalization, a mean matrix for three channels, derived from a large dataset of cable defects, is pre-configured in the program memory. The mean matrix is ​​preferably set to 123.675, 116.28, and 103.53, and the standard deviation matrix is ​​preferably set to 58.395, 57.12, and 57.375. The original value of each pixel in the image corresponding to a channel is subtracted from the aforementioned mean and divided by the corresponding standard deviation. This transforms the overall pixel distribution of the image to a standard space with a mean of 0 and a variance of 1, completing the normalization mapping of the data format.

[0017] The preprocessed tensor data is fed into a convolutional neural network model built with the ResNet-50 architecture to perform hierarchical feature extraction forward inference. The input of the convolutional neural network model is tensor data in three-channel RGB format with a resolution of 512 pixels × 512 pixels. Its structure includes a first layer of 7 × 7 large convolutional layer, a max pooling layer, Layer1 with 3 bottleneck layers, Layer2 with 4 bottleneck layers, Layer3 with 6 bottleneck layers, and Layer4 with 3 bottleneck layers. The output after truncated inference is an output feature map matrix with a size of 32 × 32 × 1024.

[0018] After the tensor data passes through the network's first 7×7 large convolutional layer, max pooling layer, and Layer 1 and Layer 2 containing multiple residual blocks, the network continues computation in Layer 3 (conv4_x stage) with 1024 channels. The forward propagation data stream is truncated, and the extraction cutoff point is specified at the output node of the last bottleneck layer in Layer 3, which contains 6 cascaded residual modules.

[0019] After the cumulative downsampling effect in the early stage of the network structure, a total spatial downsampling rate of 16 times is achieved. At this node, a feature data stream with a size of 32 in height, 32 in width, and 1024 channels is obtained, and it is defined as the output feature map matrix of the specified intermediate layer for use in the calculation process.

[0020] In some implementations, dividing the output feature map into a grid and quantizing the feature vectors within the grid to generate a quantization index includes: Divide the one-dimensional feature vector within the grid into four fixed-length sub-vectors along the channel dimension; Load the quantized codebook containing 256 cluster centers, which was pre-generated using the K-means clustering algorithm; Through formula Get the integer index of the corresponding cluster center As a quantization value, where j is an integer from 0 to 255, For any of the aforementioned sub-vectors, Let j be the j-th cluster center in the quantization codebook. for and Euclidean distance; The quantization values ​​corresponding to the four sub-vectors are concatenated in sequence to generate a four-dimensional discrete quantization index vector.

[0021] The 1024-dimensional one-dimensional feature vector of a single grid extracted by Layer 3 of the ResNet-50 network is divided into 4 independent continuous data segments along its 1024-dimensional channel dimension, generating 4 sub-vectors of length 256. For example, the first sub-vector is the 0th to 255th dimension, and so on.

[0022] Load the independent quantized codebook matrix that was previously trained on the cable defect image training set using the K-means clustering algorithm. The four sub-vectors share this quantized codebook matrix, which has a size of 256 rows × 256 columns, representing a total of 256 cluster centers with a length of 256 dimensions.

[0023] During the quantization matching phase, the Euclidean distance between each 256-dimensional sub-vector and the 256 cluster centers in the codebook matrix is ​​calculated. For example, when processing the first sub-vector, the squared Euclidean distance between it and each center point is calculated one by one. If its distance to the cluster center with index number 42 is the smallest, with a distance value of 0.35, then the quantization value of the sub-vector is determined to be the integer 42.

[0024] After completing independent matching of all four sub-vectors, the four discrete integers obtained, ranging from 0 to 255 (e.g., 42, 156, 7, 219 respectively), are concatenated according to the original channel segmentation order to generate a 1×4 four-dimensional discrete quantization index vector: 42, 156, 7, 219. This operation reduces the dimensionality of high-dimensional continuous floating-point features into fixed-length integer codes, improving the addressing and matching speed of subsequent prefix cache lookup processes. The complete steps for generating the feature map grid segmentation rules, channel splitting logic, and quantization index are as follows: Figure 3 As shown.

[0025] In some implementations, the category contribution vector is calculated as follows: Record the total number N of samples N in which the pre-trained model generates a specific prefix key in the historical training samples; Through formula The category contribution vector V of the specific prefix key is calculated, where i takes values ​​from 1 to N. During the i-th training forward propagation to generate the specific prefix key, the prediction confidence vector is formed by the output probability values ​​of the pre-trained model's Softmax classification layer for each defect category. Cross-entropy loss function about The partial derivatives, This is an element-wise multiplication operation.

[0026] During the historical record phase of iterative optimization of cable defect images by the pre-trained model, a counter and accumulator are set for each specific prefix key that triggers activation. When the target task includes 10 specific cable defect categories such as insulation damage and sheath scratches, the total number of samples N hit by that specific prefix key in multiple batches of forward propagation is recorded. For example, N is preferably set to 500 times.

[0027] For the i-th hit in these 500 hit events, such as the 42nd forward propagation, obtain the 10-dimensional prediction confidence vector output by the softmax layer at the end of the classification network. For example, the probability of the insulation damage category is 0.85, while the probabilities of other categories range from 0.01 to 0.05.

[0028] At the same time, extract the cross-entropy loss calculated by the network at the classification node. This confidence vector The 10-dimensional partial derivative vector is used to obtain the absolute value of the gradient magnitude by taking the absolute value of each element. For example, the gradient magnitude for the insulation failure class is 0.15. The confidence vector is then used... The element-wise multiplication with the gradient magnitude vector indicates the sensitivity of the prefix key to class classification in this feature extraction.

[0029] After multiplying N samples, a summation operation is performed, and the result is normalized by dividing by the total number of hits N, which is 500, generating a 10-dimensional real-valued category contribution vector V. The values ​​of each dimension in this vector represent the importance of this structured prefix key in distinguishing 10 different cable defects.

[0030] In some implementations, the threshold for storing new keys in the prefix cache is adaptively adjusted based on the fill rate and key distribution entropy, including: Read the number of prefix keys already stored in the prefix cache and divide it by the maximum storage capacity of the prefix cache to obtain the current fill rate R, which is between 0 and 1. Statistical analysis of the percentage of prefix keys corresponding to each defect category in the current prefix cache. Through formula The bond distribution entropy E is calculated, where It is a preset minimum positive number; Obtain the system's preset, positive-zero basic control constant C and positive-zero linear penalty bias term b, and then use the formula... The similarity threshold for determining whether a new prefix key should be stored is derived. .

[0031] Update the storage threshold. Monitor the database usage status of prefix key-value pairs. Assuming the current maximum physical storage capacity of the prefix cache is set to 100,000 records, and the current actual number of stored keys is 75,000, the current fill rate variable R is calculated to be 0.75 after division.

[0032] Based on the category contribution information of existing key-value associations in the prefix cache, the frequency proportion of the stored keys corresponding to 10 types of cable defects, such as insulation, sheath, and shielding, is statistically analyzed. For example, insulating keys account for 0.40%, and sheathing keys account for 0.25%. When calculating the information distribution balance, a preset minimum positive number with an optimal value of 1e-8 is used. To reduce meaningless values ​​from logarithmic operations, the proportions of each category should be calculated separately. Add 1e-8, calculate the base-2 logarithm, and then multiply by the original proportion. Sum all 10 categories and take the negative sign to calculate the current key distribution entropy E, assuming it is currently 2.15. The category label corresponding to the dimension with the largest value in the category contribution vector is then identified as the unique category to which the prefix key belongs.

[0033] The optimal hyperparameters, determined by a grid search algorithm, are preset, with the basic control constant C preferably set to 0.4 and the linear penalty bias term b preferably set to 0.05. The obtained parameters are then substituted into the threshold formula to calculate the similarity threshold. The value is 0.269. In one embodiment, to prevent the similarity threshold from being greater than or equal to 1, the upper limit of the similarity threshold is set to 0.99, that is, the maximum value is 0.99.

[0034] Under this constraint, when the cosine similarity between a new prefix key to be stored and all cached prefix keys is less than 0.269, a memory address is allocated to it and the storage operation is performed, thereby controlling the storage of feature information based on storage redundancy and category diversity.

[0035] S2, iterate through and query each structured prefix key in the prefix key set. When the current structured prefix key is matched, obtain the corresponding inference guidance vector. When the current structured prefix key is not matched, determine the weighting coefficient based on the global semantic features of the output feature map, calculate the weighted distance between the current structured prefix key and the cached key in the prefix cache, and fuse neighboring keys to generate a temporary guidance vector. After completing the traversal, average and aggregate all the obtained inference guidance vectors and temporary guidance vectors to generate a global guidance vector. After channel dimension adaptation, the global guidance vector is applied as a channel attention weight to the output feature map of the specified intermediate layer to generate a recalibrated feature response.

[0036] The algorithm iterates through each structured prefix key in the current prefix key set. When a hash lookup algorithm finds a cache entry matching the current structured prefix key in the prefix cache, it is considered a hit, and the associated inference guidance vector is extracted. If no matching entry is found, it is considered a miss. The output feature map is then processed with `torch.nn.AdaptiveAvgPool2d` to obtain a global semantic feature vector, which is input into a single hidden layer fully connected network to calculate the adaptive weighting coefficients for each channel dimension. The Euclidean distance between the current structured prefix key and all cache keys in the prefix cache after applying the adaptive weighting coefficients is calculated; this is the weighted distance. The K nearest neighbor cache keys with the smallest weighted distance are selected, and the reciprocals of these K weighted distance values ​​are converted into normalized weights. The inference guidance vectors corresponding to these neighbor keys are then weighted and summed according to the normalized weights to generate a temporary guidance vector.

[0037] After traversing the current prefix key set and obtaining the inference guidance vectors or temporary guidance vectors corresponding to all grids, the arithmetic mean of all guidance vectors is calculated along the grid number dimension to generate a unique global guidance vector. The global guidance vector is then subjected to channel number upscaling and transformation using a torch.nn.Sequential multilayer perceptron model containing torch.nn.Linear layers and a torch.nn.Sigmoid activation function, ensuring its channel number matches that of the output feature map. It is then mapped to continuous values ​​between 0 and 1, completing channel dimension adaptation and serving as global channel attention weights. These channel attention weights are then multiplied along the channel dimension with the original output feature map to generate the recalibrated feature response.

[0038] In some implementations, applying the global guiding vector, after channel dimension adaptation, as channel attention weights to the output feature map of the specified intermediate layer includes: Obtain the global guidance vector generated by aggregation, and convert it into an adaptation vector v with the same number of channels as the output feature map of the specified intermediate layer through linear mapping; Through formula The adaptation vector v is activated and mapped to generate a channel scaling weight array w, where D is 1+e -v ; Obtain the three-dimensional output feature map F of the forward propagation output of the specified intermediate layer; Through formula Update the original feature map data to generate a recalibrated 3D output feature map. ,in To update the height and width sliced ​​2D matrix of the output feature map in the c-th channel of the previous 3D model, This is the sliced ​​two-dimensional matrix after the corresponding channel is updated. Let w be the scalar element of the channel scaling weight array w in the corresponding channel c. This represents the multiplication operation between a scalar and a matrix.

[0039] After completing the retrieval of all local grid prefix keys and the generation of temporary miss vectors, and calculating the arithmetic mean, a one-dimensional global inference guide vector with a preferred dimension of 64 is obtained and input into a single fully connected layer without bias terms for dimension upscaling. The weight matrix of this fully connected layer is preferably 64 rows × 1024 columns. After dot product operation, the original 64-dimensional guide vector is transformed into an adaptation vector v with a length of 1024 dimensions, the length of which is aligned with the total number of channels in the specified intermediate layer.

[0040] Perform a Sigmoid activation operation on each component of the 1024-dimensional adaptation vector, i.e., the formula... For example, when the original value of the first dimension of the adaptation vector is 1.5, the output value is 0.817, which is combined to obtain a one-dimensional channel scaling weight array w containing 1024 scalar values.

[0041] Based on this, the three-dimensional tensor output from the current batch of forward inference of the specified intermediate layer is received. The output feature map F has spatial dimensions of 32 pixels high, 32 pixels wide, and 1024 channels deep. For any channel with channel index c, ranging from 0 to 1023, its original 32×32-dimensional slice matrix is ​​extracted. Multiply all 1024 pixel values ​​in the two-dimensional matrix by the scalar value at the c-th position in the channel scaling weight array w. As calculated above, it is 0.817.

[0042] By performing this scalar-matrix multiplication update layer by layer on all 1024 channels, a recalibrated feature map of the same size (32×32×1024) is output. This allows for the adjustment of channel characteristics using prior cache information.

[0043] In some implementations, determining the weighting coefficients based on the global semantic features of the output feature map and calculating the weighted distance between the current structured prefix key and the cached keys in the prefix cache includes: A global average pooling operation is performed on the output feature map to extract a one-dimensional global semantic feature vector; The global semantic feature vector is input into a two-layer fully connected neural network structure. The softmax normalization layer at the end calculates two positive real numbers that sum to 1, which are then assigned as spatial weight coefficients. With index weight coefficient ; For each cache key in the prefix cache, the formula is used. Calculate the weighted distance scalar D between the currently missed structured prefix key and the cached key, where Encode the Manhattan distance between the two spatial locations. The Euclidean distance between the cluster centers corresponding to the quantization indices of the two is given.

[0044] When the prefix cache misses, the output feature map of size 32×32×1024 is retrieved from the specified intermediate layer, and a global average pooling operation is applied to its height and width spatial dimensions. That is, the arithmetic mean of 1024 pixels in each channel is calculated to reduce its dimension to a one-dimensional global semantic feature vector of length 1024, which represents the macroscopic structural information of the current defect image.

[0045] The feature vector is fed into a two-layer fully connected neural network structure. The input of the two-layer fully connected neural network structure is the one-dimensional global semantic feature vector. The two-layer fully connected neural network structure includes a first fully connected layer with 256 hidden nodes and using the ReLU activation function, and a second fully connected layer with two nodes. The final output is a real value containing the two nodes, which is then subjected to exponential normalization by a Softmax layer, and the output is assigned as spatial weight coefficients. With index weight coefficient Two positive real numbers. For example, the normalized output results are 0.65 and 0.35, and 0.65 is assigned to the spatial weight coefficient accordingly. Assign 0.35 to the index weight coefficient. .

[0046] When initiating neighbor key retrieval, the existing cached keys in the prefix cache are traversed, and a two-level distance calculation is performed between the currently unmatched structured prefix key and a candidate cached key. The multi-dimensional spatial location encoding vectors of both parties are extracted, and the sum of the absolute differences between the two vectors across all corresponding dimensions is calculated to obtain the Manhattan distance at the spatial encoding level. The value here is 0.4.

[0047] Read the four-dimensional discrete quantization indices of both parties, look up the corresponding 256-dimensional sub-vectors of the four independent indices in the table, and concatenate them according to the original channel segmentation order to restore the complete 1024-dimensional cluster center vector. Calculate the Euclidean distance between the two. Let's assume the calculated result is 5.20.

[0048] The two are weighted and calculated using the formula D=0.65×0.4+0.35×5.20, resulting in a weighted distance scalar D of 2.08. The distance scalar is then sorted in ascending order based on this calculated distance scalar to locate the nearest candidate cache key, thus completing the distance measurement.

[0049] S3, the recognition result is obtained by using the recalibrated feature response through the remaining part of the convolutional neural network.

[0050] The recalibrated feature responses are used as input and fed into subsequent network layers of the ResNet50 model. Deep residual features are extracted using the layer 4 module, and a global average pooling layer is applied to compress the spatial dimension of the feature map to 1×1. After being flattened into a one-dimensional feature vector, it is input to the classifier module's `torch.nn.Linear` fully connected layer, mapping to obtain the logistic regression values ​​for each cable defect category. The `torch.nn.functional.softmax` activation function is applied to calculate the predicted probability distribution for each category, and the category label corresponding to the maximum probability is selected as the cable defect image recognition result.

[0051] 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 the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for recognizing cable defects in images, characterized in that, include: A convolutional neural network is used to extract the output feature map of the cable defect image to be identified at a specified intermediate layer; The output feature map is divided into grids, and the feature vectors within the grids are quantized to generate quantization indexes. Spatial location encoding is combined with the quantization indexes to generate structured prefix keys corresponding to each grid, forming a prefix key set. The structured prefix keys in the prefix key set are traversed and queried in the pre-built prefix cache. The prefix cache stores the prefix keys and their corresponding category contribution vectors and inference guidance vectors. The threshold for storing new keys in the prefix cache is adaptively adjusted according to the fill rate and key distribution entropy. Iterate through each structured prefix key in the prefix key set. When the current structured prefix key is matched, obtain the corresponding inference guidance vector. When the current structured prefix key is not matched, a weighting coefficient is determined based on the global semantic features of the output feature map, the weighted distance between the current structured prefix key and the cached key in the prefix cache is calculated, and neighboring keys are fused to generate a temporary guiding vector. After traversal is completed, all the obtained inference guiding vectors and temporary guiding vectors are averaged and aggregated to generate a global guiding vector. The global guiding vector is adapted to the channel dimension and applied as a channel attention weight to the output feature map of the specified intermediate layer to generate a recalibrated feature response. The recognition result is obtained by using the recalibrated feature response through the remaining part of the convolutional neural network.

2. The method according to claim 1, characterized in that, The step of dividing the output feature map into a grid and quantizing the feature vectors within the grid to generate a quantization index includes: Divide the one-dimensional feature vector within the grid into four fixed-length sub-vectors along the channel dimension; Load the quantized codebook containing 256 cluster centers, which was pre-generated using the K-means clustering algorithm; Through formula Get the integer index of the corresponding cluster center As a quantization value, where j is an integer from 0 to 255, For any of the aforementioned sub-vectors, Let j be the j-th cluster center in the quantization codebook. for and Euclidean distance; The quantization values ​​corresponding to the four sub-vectors are concatenated in sequence to generate a four-dimensional discrete quantization index vector.

3. The method according to claim 1, characterized in that, The specific method for calculating the category contribution vector is as follows: Record the total number N of samples N in which the pre-trained model generates a specific prefix key in the historical training samples; Through formula The category contribution vector V of the specific prefix key is calculated, where i takes values ​​from 1 to N. During the i-th training forward propagation to generate the specific prefix key, the prediction confidence vector is formed by the output probability values ​​of the pre-trained model's Softmax classification layer for each defect category. Cross-entropy loss function about The partial derivatives, This is an element-wise multiplication operation.

4. The method according to claim 1, characterized in that, The threshold for storing new keys in the prefix cache is adaptively adjusted based on the fill rate and key distribution entropy, including: Read the number of prefix keys already stored in the prefix cache and divide it by the maximum storage capacity of the prefix cache to obtain the current fill rate R, which is between 0 and 1. Statistical analysis of the percentage of prefix keys corresponding to each defect category in the current prefix cache. The bond distribution entropy E is calculated. Obtain the system's preset, positive-zero basic control constant C and positive-zero linear penalty bias term b, and then use the formula... The similarity threshold for determining whether a new prefix key should be stored is derived. .

5. The method according to claim 1, characterized in that, The step of applying the global guidance vector, after channel dimension adaptation, as channel attention weights to the output feature map of the specified intermediate layer includes: Obtain the global guidance vector generated by aggregation, and convert it into an adaptation vector v with the same number of channels as the output feature map of the specified intermediate layer through linear mapping; Through formula The adaptation vector v is activated and mapped to generate a channel scaling weight array w, where D is 1+e -v ; Obtain the three-dimensional output feature map F of the forward propagation output of the specified intermediate layer; Through formula Update the original feature map data to generate a recalibrated 3D output feature map. ,in To update the height and width sliced ​​2D matrix of the output feature map in the c-th channel of the previous 3D model, This is the sliced ​​two-dimensional matrix after the corresponding channel is updated. Let w be the scalar element of the channel scaling weight array w in the corresponding channel c. This represents the multiplication operation between a scalar and a matrix.

6. The method according to claim 1, characterized in that, The step of determining weighting coefficients based on the global semantic features of the output feature map and calculating the weighted distance between the current structured prefix key and the cached keys in the prefix cache includes: A global average pooling operation is performed on the output feature map to extract a one-dimensional global semantic feature vector; The global semantic feature vector is input into a two-layer fully connected neural network structure. The softmax normalization layer at the end calculates two positive real numbers that sum to 1, which are then assigned as spatial weight coefficients. With index weight coefficient ; For each cache key in the prefix cache, the formula is used. Calculate the weighted distance scalar D between the currently missed structured prefix key and the cached key, where Encode the Manhattan distance between the two spatial locations. The Euclidean distance between the cluster centers corresponding to the quantization indices of the two is given.

7. The method according to claim 1, characterized in that, The step of extracting the output feature map of the cable defect image to be identified in a specified intermediate layer using a convolutional neural network includes: Acquire a three-channel RGB image of the cable defect to be identified with a resolution of 512 pixels × 512 pixels; Subtract the preset dataset mean matrix from the pixel value of each pixel in the image of the cable defect to be identified, and then divide by the preset standard deviation matrix to complete the standard normalization of the image pixels. The standardized image is used as tensor data and input into the convolutional neural network constructed using the ResNet-50 architecture for forward inference computation. The inference process is truncated, and the extraction position is located at the last bottleneck layer structure of the Layer 3 block of the ResNet-50 architecture. The output matrix sequence with a tensor size of 32×32×1024 is used as the output feature map of the specified intermediate layer.

8. A cable defect image recognition system, characterized in that, include: The query module is used to extract the output feature map of the cable defect image to be identified in a specified intermediate layer using a convolutional neural network; The output feature map is divided into grids, and the feature vectors within the grids are quantized to generate quantization indexes. Spatial location encoding is combined with the quantization indexes to generate structured prefix keys corresponding to each grid, forming a prefix key set. The structured prefix keys in the prefix key set are traversed and queried in the pre-built prefix cache. The prefix cache stores the prefix keys and their corresponding category contribution vectors and inference guidance vectors. The threshold for storing new keys in the prefix cache is adaptively adjusted according to the fill rate and key distribution entropy. The generation module is used to traverse and query each structured prefix key in the prefix key set. When the current structured prefix key is matched, the corresponding inference guidance vector is obtained. When the current structured prefix key is not matched, a weighting coefficient is determined based on the global semantic features of the output feature map, the weighted distance between the current structured prefix key and the cached key in the prefix cache is calculated, and neighboring keys are fused to generate a temporary guiding vector. After traversal is completed, all the obtained inference guiding vectors and temporary guiding vectors are averaged and aggregated to generate a global guiding vector. The global guiding vector is adapted to the channel dimension and applied as a channel attention weight to the output feature map of the specified intermediate layer to generate a recalibrated feature response. The recognition module is used to calculate the recognition result using the recalibrated feature response through the remaining part of the convolutional neural network.

9. A computer-readable storage medium storing a computer program thereon, characterized in that, The computer program, when executed by a processor, implements the method as described in any one of claims 1-7.

10. An electronic device comprising a readable storage medium and a processor, wherein a computer program is stored on the readable storage medium, characterized in that, The computer program, when executed by a processor, implements the method as described in any one of claims 1-7.