A method for detecting edge collapse of a magnetic material

CN122434875APending Publication Date: 2026-07-21HUAIYIN INSTITUTE OF TECHNOLOGY
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HUAIYIN INSTITUTE OF TECHNOLOGY
Filing Date
2026-04-28
Publication Date
2026-07-21

AI Technical Summary

Technical Problem

Existing magnetic material chipping detection technologies suffer from problems such as insensitivity to minor chipping defects, low detection efficiency, large subjective human error, and low detection accuracy and consistency. Furthermore, existing Anomalib models fail to effectively utilize mid-level and deep features, making it difficult to balance local sensitivity with global structural consistency.

Method used

By improving the Anomalib model and introducing Coordinate Attention and Axial Attention modules, a heterogeneous dual-branch processing architecture is constructed to extract mid-level and deep-level features respectively. Through cross-branch alignment constraints and dynamic fusion, the joint representation capability of local details and global structure is enhanced. Special modeling is performed for the corners and edges of magnetic materials to achieve efficient detection of minor edge chipping defects.

Benefits of technology

It significantly improves the sensitivity and positioning accuracy of magnetic material edge breakage detection, reduces the false alarm rate, and improves detection efficiency and accuracy. It meets the feature extraction requirements of high-incidence areas such as corners and edges, and realizes efficient and accurate automatic detection of magnetic material edge breakage.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122434875A_ABST
    Figure CN122434875A_ABST
Patent Text Reader

Abstract

A kind of magnetic material edge collapse detection method, comprising the following steps: first, the background of magnetic material image is cut and standardized splicing, and the corner and edge regular atlas are obtained.Two improved Anomalib models with the same structure are used to detect the corner and edge defects respectively.The improved Anomalib model is based on Anomalib improvement, and the improvement steps include: using ResNet18 as the backbone, embedding coordinate attention at Layer2 to enhance local positioning, and embedding axial attention at Layer3 to strengthen the global;Constructing a double-branch architecture, the middle and deep features are input into PaDiM and FastFlow subnetworks respectively to realize parallel modeling, and through alignment constraint collaborative optimization, finally dynamic fusion output.During detection, the test sample is input into the corresponding model after the same preprocessing, and whether the magnetic material exists edge collapse is judged according to the corner and edge defect judgment results.This method improves the accuracy and pertinence of detection through model structure optimization.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of magnetic material edge chipping detection technology, and specifically to a method for detecting magnetic material edge chipping. Background Technology

[0002] In the field of magnetic material inspection, traditional techniques for detecting chipping defects mainly rely on manual visual inspection. However, these methods suffer from drawbacks such as insensitivity to minor chipping and edge wear, low inspection efficiency, and significant subjective errors, resulting in low accuracy and consistency. Alternatively, simple image processing methods can be used to identify chipping defects at the edges of magnetic materials. However, traditional image processing methods require manually setting feature extraction rules, which can only extract shallow surface features. They have low sensitivity to minor chipping, are difficult to adapt to the complex textures and edge morphology variations of magnetic material surfaces, and have high false positive and false negative rates for chipping defects compared to normal chamfers, scratches, and other non-defect edges, leading to insufficient robustness.

[0003] With the development of deep learning technology, anomaly detection models based on the Anomalib framework have been initially applied to the detection of chipped edges in magnetic materials. However, existing Anomalib models mostly use a single backbone network for feature extraction, lacking the ability to represent features specific to subtle and irregular defects such as chipped edges in magnetic materials. Specifically, traditional models do not fully utilize the local details such as edges and textures contained in the mid-level features, nor do they effectively model the long-distance spatial dependencies in the deep features, making it difficult to simultaneously consider local sensitivity and global structural consistency.

[0004] Furthermore, existing methods typically do not perform structural adaptation and regional differentiation modeling for the geometric distribution characteristics of chipping defects at the corners and edges of magnetic materials. A single model architecture is difficult to balance between global structure and local details, which limits detection accuracy and generalization ability. Summary of the Invention

[0005] To address the shortcomings of existing technologies in defect sample dependence, local detail capture capability, and structural adaptability, this technical solution provides a method for detecting edge chipping in magnetic materials. By employing prior knowledge of image geometry, improving the backbone network structure, and implementing heterogeneous decoupling, cross-branch alignment constraints, and dynamic fusion, targeted feature modeling is performed for high-incidence areas of edge chipping in magnetic materials. The introduction of spatial coordinate perception and axial attention mechanisms enhances the backbone network's ability to jointly represent local details and global structure. Furthermore, a heterogeneous dual-branch processing architecture is constructed to achieve decoupling modeling, alignment constraints, and dynamic fusion of mid-level local features and deep-level global features. This effectively improves the detection sensitivity and localization accuracy for minute edge chipping defects, meeting the needs for targeted feature extraction and analysis of high-incidence areas such as corners and edges in magnetic material edge chipping detection. It effectively improves the detection sensitivity for minute edge chipping defects and effectively solves the technical problems.

[0006] This invention is achieved through the following technical solution:

[0007] A method for detecting edge chipping in magnetic materials, comprising the following steps:

[0008] S1: Cropping and standardizing the background of the magnetic material image to obtain a regular atlas of corners and edges;

[0009] S2: Improve the Anomalib model, including the following steps:

[0010] S2.1: ResNet18 is used as the backbone network, and the Coordinate Attention module and the Axial Attention module are integrated into the network;

[0011] S2.2: Construct a heterogeneous dual-branch processing architecture: Extract the mid-level and deep features of the ResNet18 backbone network, and input the mid-level and deep features into the PaDiM sub-network and FastFlow sub-network in the anomalib model respectively to achieve parallel modeling and collaborative optimization through alignment constraints;

[0012] S2.3: The improved Anomalib anomaly detection model is trained using corner and edge regularization atlases respectively to obtain optimized corner defect detection models and edge defect detection models;

[0013] S3: Process the magnetic material to be tested to obtain the corner splicing image and the edge splicing image to be tested. Input the corner splicing image to be tested into the corner defect detection model for detection, and input the edge splicing image to be tested into the edge defect detection model for detection.

[0014] S4: The corner defect detection model and the edge defect detection model detect and process their input images respectively, and then achieve dynamic fusion through the learning fusion unit. Based on the dual-branch adaptive allocation of fusion weights, the comprehensive abnormal probability distribution and defect location are obtained, and the corresponding defect detection results are obtained respectively.

[0015] S5: Output the detection results.

[0016] Furthermore, the specific operation method of step S1 includes the following steps:

[0017] S1.1: Obtain the original image data of the magnetic material, perform background cropping preprocessing on the original image to remove irrelevant background areas, and obtain the magnetic material image with the background cropped.

[0018] S1.2: Based on the cropped image obtained in step S1.1, using the coordinates of its four corner points, and taking each corner point coordinate as the center, crop out a square region with a preset fixed side length from the cropped image to obtain four corner sub-images;

[0019] S1.3: Based on the four corner sub-images obtained in step S1.2, arrange them according to their spatial orientation corresponding to the original magnetic material, and stitch them together to form a total square image. This composite image includes the four corner regions of the magnetic material and part of the background, serving as the corner images.

[0020] S1.4: Based on the cropped image obtained in step S1.1, the remaining area after cropping the four corners is cropped into four images of the same width, and then rotated to the horizontal direction to obtain the edge sub-images;

[0021] S1.5: Based on the edge sub-images obtained in step S1.4, stretch them to a uniformly specified length so that all edge sub-images have the same size. Then, arrange and stitch the transformed images from top to bottom in the direction of outer edge at the bottom and inner edge at the top to obtain a total rectangular image, which serves as the edge image.

[0022] Furthermore, the background cropping preprocessing described in step S1.1 includes the following steps: binarizing the original image using an adaptive thresholding algorithm to enhance object edge features; the adaptive thresholding algorithm uses Gaussian weighted local thresholding calculation; detecting the outermost contour of the magnetic material using a Suzuki85-based contour tracking algorithm; approximating the contour using a Douglas-Pockmark polygon simplification algorithm to obtain key corner points; determining the minimum bounding box of the magnetic material using an extreme point calculation algorithm, and expanding a white border of a specified width on the basis of the minimum bounding box to complete image cropping; the specified width is 100 pixels, used to retain part of the background area outside the edge of the magnetic material.

[0023] Furthermore, in step S1.2, the cropping is performed with each corner point as the center, and square regions with preset fixed side lengths are cropped from the cropped image to obtain four corner sub-images; the fixed side length is set to 140 pixels.

[0024] Furthermore, the four corner sub-images mentioned in step S1.3 are obtained by horizontally and vertically stitching the top and bottom horizontal images of the original magnetic material, and then by horizontally stitching the bottom and bottom right images together to form the bottom horizontal image. Finally, the top and bottom horizontal images are vertically stitched together to obtain the corner images. The spatial orientation of each corner sub-image in the corner image satisfies the following: in a clockwise direction, they are top left, top right, bottom left, and bottom right, and the outside is the background.

[0025] Furthermore, the specific process of cropping the edge sub-images in step S1.4 is as follows: First, calculate the coordinate range of the edge region after removing the four corners, where the edge length is determined by "edge length = corresponding edge length of the original image - 2 × edge length of the corner square", and the edge width is set to a preset value of 120 pixels, thereby defining the effective detection length of each edge region; second, based on the edge region range determined above, calculate the center line and its vertical direction of each edge region through vector operations, thereby determining the orientation angle and affine transformation reference of the edge region, and rotate each edge region to the horizontal direction with the help of affine transformation; crop the edge sub-images, and after cropping, each edge sub-image contains the complete outline of the corresponding edge of the magnetic material and part of the background.

[0026] Furthermore, the stretching of the edge sub-image in step S1.5 is achieved by stretching the length to a uniform 500 pixels through bilinear interpolation; the stitching is performed by automatically correcting the direction using a regional brightness mean comparison algorithm to ensure that the white background is at the bottom during stitching.

[0027] Furthermore, the specific operation of step S2.1 is as follows: Structural improvements are made to address the feature distribution characteristics of the non-collapsed magnetic material samples. In Layer 2, the second 3×3 convolutional layer of the first residual block is replaced with a CoordinateAttention (CA) module (spatial coordinate attention module). Since the output of Layer 2 is a high-resolution mid-level feature, primarily representing the local details of the edges and textures of the non-collapsed magnetic material, encoding spatial coordinate information through the CA module significantly enhances the directional sensitivity and positioning accuracy of local features. In Layer 3, the second 3×3 convolutional layer of the first residual block is replaced with an Axial Attention (AA) module (axial attention module). Since the output of Layer 3 is a low-resolution deep feature, primarily representing the overall structural morphology of the magnetic material, modeling long-distance spatial dependencies through the axial attention mechanism strengthens the ability to express and model the global structural features of normal samples. Both attention modules are embedded without changing the feature map dimension, ensuring the compatibility and training stability of the overall network structure.

[0028] Furthermore, the implementation process of the Coordinate Attention spatial coordinate attention module in step S2.1 includes: performing global average pooling on the feature map output by the ResNet18 backbone network to obtain channel feature descriptors in the horizontal and vertical directions respectively; performing dimensional transformation and activation on the feature descriptors through a fully connected layer to generate attention weights in the horizontal and vertical directions; and multiplying the attention weights with the original feature map to obtain the feature map after enhancing the edge collapse feature; the activation adopts the Sigmoid function.

[0029] Furthermore, the implementation process of the Axial Attention module described in step S2.1 includes: decomposing the input feature map into two axes along the height and width directions respectively; calculating the attention weight for each axis independently through a one-dimensional attention mechanism; normalizing the attention weights through the Softmax function; and multiplying the normalized attention weights of the two axes with the original feature map to obtain the output feature map that fuses the axial information.

[0030] Furthermore, the mid-level features from layer 2 and the deep features from layer 3 are extracted, and these features are bound to two functional branches in the heterogeneous dual-branch architecture according to their hierarchical levels. The mid-level features, after being normalized by a whitening adaptation layer matched with axial attention, are input into the PaDiM sub-network of the anomalib model to model the local subtle features of normal samples. The deep features, after being unified in dimension by a lightweight learnable adaptation layer coordinated with coordinate attention, are input into the FastFlow sub-network of the anomalib model to model the global structure of normal samples. A cross-branch structure is introduced during the dual-branch modeling process, and alignment constraints are used to ensure that the two branches... The model collaborates with FastFlow to learn the global feature normalized flow distribution and constrains the Gaussian distribution of PaDiM to maintain consistency in its global structure. Simultaneously, it leverages PaDiM's local feature responses to normal samples, using feature-level distillation loss as a constraint, to guide FastFlow to improve its perception and sensitivity to detailed textures. Finally, it achieves dynamic fusion through a lightweight learnable fusion unit based on feature uncertainty. The fusion weights are adaptively allocated based on the confidence and uncertainty output of the two branches in the forward propagation, enabling the model to autonomously learn the optimal local-global feature fusion strategy during training with normal samples.

[0031] Furthermore, the specific operational steps for constructing the heterogeneous dual-branch processing architecture described in step S2.2 include:

[0032] S2.21: Feature Extraction and Adaptation: Extracting mid-layer features from layer 2 output and deep features output by layer 3 The mid-layer features are regularized using a whitening adapter layer as follows:

[0033] ;

[0034] in, , These are the mean vector and covariance matrix of the layer features in the normal samples of the training set, respectively. The whitening matrix, after normalization It satisfies an isotropic Gaussian distribution;

[0035] The deep features are then processed through a lightweight, learnable adaptation layer that works in conjunction with coordinate attention to unify the dimensions, resulting in:

[0036] ;

[0037] in, It is a deep adaptation feature after unifying dimensions; For 1×1 convolution, Layer normalization is used to map feature dimensions to the unified dimensions required by FastFlow. ;

[0038] S2.22: Normalize the middle layer features Input the PaDiM subnetwork in the anomalib model to model the subtle local features of normal samples;

[0039] To achieve fine modeling of local textures, a multivariate Gaussian distribution is fitted at each spatial location (each (i, j) coordinate point on the feature map):

[0040] ;

[0041] ;

[0042] ;

[0043] in, It is the height of the mid-layer feature map. It is the width of the mid-layer feature map. Let N be the feature vector of the nth training sample at position (i,j) in the mid-layer feature map space, where N is the number of training samples. This represents the transpose operation of a vector. The regularization coefficient is . It is the identity matrix. It is a regularization term;

[0044] Pixel-level anomaly scores were obtained using Mahalanobis distance during testing.

[0045] ;

[0046] Image-level score: ;

[0047] The PaDiM branch is located in the mid-level feature map space. The pixel-level anomaly score indicates that the larger the value, the greater the deviation from the normal distribution at that location, and the more likely it is to be a defect area. The mid-level features of the current test sample In spatial location The eigenvector at that location; Covariance matrix The inverse matrix is ​​used to calculate the standardized Mahalanobis distance;

[0048] S2.23: Adapted deep features Input the FastFlow subnetwork in the anomalib model to model the global structure of normal samples;

[0049] To achieve distributed modeling of the global structure, this subnetwork employs a series of invertible transformations. This maps deep features to a latent variable space that follows a standard normal distribution. :

[0050] ;

[0051] in, It is a standard Gaussian distribution;

[0052] The core training objective of the FastFlow model is to map normal features to a standard normal distribution through an invertible transformation by maximizing the log-likelihood. Here, to enable the model to learn the global distribution pattern of normal samples, the invertible transformation parameters are optimized by maximizing the log-likelihood during the training phase.

[0053] ;

[0054] in, It is the training loss function of the FastFlow subnetwork. Minimizing this loss is equivalent to maximizing the log-likelihood of normal samples. It is the expectation operator. This is the characteristic distribution of normal samples; It refers to "all deep features sampled from a normal sample distribution". , calculate the average value within the parentheses; It is a standard normal distribution The probability density function; Latent variables obtained after reversible transformation of deep features; It is the logarithm of the absolute value of the Jacobian determinant, used for transformation and correction of probability density.

[0055] Abnormal scores during testing are defined as negative log-likelihood.

[0056] ;

[0057] in, This is the image-level anomaly score output by the FastFlow branch; this formula is directly related to the log-likelihood loss in the aforementioned training phase: the training phase maximizes the log-likelihood of normal samples, enabling the invertible transformation. Normal features are mapped to the center of a standard normal distribution; during testing, the features of abnormal samples, after mapping, will deviate from the standard normal distribution, leading to... Significantly reduced, its negative logarithm The higher the score, the greater the deviation of the global structure of the sample from the normal pattern, and the more likely there are defects.

[0058] S2.24: Utilize the global feature normalization flow distribution learned from FastFlow to constrain the Gaussian distribution of PaDiM, ensuring its consistency across the global structure, and construct the distribution alignment loss:

[0059] ;

[0060] in, It is a cross-branch distribution alignment loss function used to constrain the global structural consistency of the two features of PaDiM and FastFlow; This is the global feature aggregation vector of the PaDiM branch. This is the global latent variable aggregation vector for the FastFlow branch. It is a learnable linear mapping matrix;

[0061] Meanwhile, leveraging the local feature responses extracted from normal samples using PaDiM, and constrained by feature-level distillation loss, FastFlow is guided to improve its perception and sensitivity to detailed textures.

[0062] ;

[0063] in, It is a feature-level distillation loss function used to guide FastFlow to learn the local detail texture perception capability of the PaDiM branch; This is a pixel-level anomaly score map output by PaDiM. This is a pixel-level negative log-likelihood plot output by FastFlow. This is an upsampling operation used to... Resolution aligned to ;

[0064] S2.25: Dynamic Fusion Based on Feature Uncertainty: Through Lightweight Learnable Fusion Units To achieve dynamic fusion, fusion weights are adaptively assigned based on the confidence and uncertainty responses output by the two branches during forward propagation:

[0065] ;

[0066] in, These are the outlier score fusion weights for the PaDiM branch and the FastFlow branch, respectively, which are normalized using the Softmax function to satisfy... ; , These are the uncertainty measures of the PaDiM branch and the FastFlow branch outputs, respectively. These are the learnable parameters of the fusion unit; It is a lightweight, learnable fusion unit used to dynamically generate fusion weights based on input features; It is a normalization function;

[0067] Final anomaly score:

[0068] ;

[0069] It is the final anomaly score output by the model, which is a weighted fusion result of the anomaly scores of the PaDiM branch and the FastFlow branch; It is the image-level anomaly score output by the PaDiM branch; It is the image-level anomaly score output by the FastFlow branch;

[0070] This formula achieves adaptive fusion of local detail anomalies and global structural anomalies by dynamically allocating weights: when the PaDiM branch has a higher confidence in local textures, As the size increases, the model focuses more on detecting detailed defects; when the FastFlow branch has higher confidence in the global structure... By increasing the size of the model, it focuses more on detecting overall structural defects, thereby autonomously learning the optimal local-global feature fusion strategy during training using only normal samples.

[0071] Furthermore, step 2.3 is specifically implemented as follows: The corner image set and the edge image set are independently trained using the improved Anomalib anomaly detection model framework to optimize the weight parameters within the model. After training, the optimized corner defect detection model weights and edge defect detection model weights are obtained, and these weights are loaded into the corresponding model frameworks to obtain usable corner defect detection models and edge defect detection models. This scheme, through precise pre-cropping, corner and edge separation modeling, and standardized input, avoids confusion between corner and edge features, effectively improving the defect detection rate, reducing false alarms, and accelerating model convergence and inference speed, while also reducing dependence on massive training data.

[0072] Furthermore, the unsupervised training process includes: using defect-free images from the corner image set and the edge image set as training samples, inputting them into the improved Anomalib model, and jointly optimizing the learnable parameters in the FastFlow branch, adaptation layer and fusion unit by minimizing the negative log-likelihood loss, cross-branch distribution alignment loss, feature distillation loss and normal sample fusion score regularization term of the FastFlow sub-network, so that the model learns the normal feature distribution of defect-free corners, edges and corresponding background regions.

[0073] Furthermore, the detection processing described in step S4 is performed as follows: mid-layer and deep features are extracted by improving the ResNet18 backbone network, and local anomaly features and global structural anomaly features are output by the PaDiM sub-network and FastFlow sub-network, respectively.

[0074] Furthermore, in the comprehensive abnormal probability distribution data described in step S4, pixels with an abnormal probability greater than the preset threshold of 0.55 are recorded as abnormal pixels. Abnormal regions with an area of ​​not less than 40 pixels are filtered out through connected component analysis. If such abnormal regions exist, they are determined to be defects. If the corner defect detection result or the edge defect detection result shows that there is a defect, it is determined that the magnetic material to be tested has a chipping problem.

[0075] Beneficial effects

[0076] The magnetic material edge chipping detection method proposed in this invention has the following advantages compared with the prior art:

[0077] (1) In the image preprocessing stage, this invention achieves precise positioning and cropping based on the actual contour of the magnetic material, ensuring that each cropping is within the effective area of ​​the magnetic material, thus avoiding the loss of key information from the source. Through precise pre-cropping, the corners and edges of the magnetic material are separated and fed into independent models for modeling and training, achieving "dedicated models for dedicated purposes," effectively avoiding confusion between corner and edge features; at the same time, the fixed and standardized cropping results keep the model input consistent, and compared with random cropping, the model converges faster, the training effect is more stable, and training can be completed without relying on massive amounts of data, significantly reducing data collection costs. Thanks to precise pre-cropping, corner and edge separation modeling, and standardized input, the defect detection rate can be effectively improved, false alarms can be reduced, and the model inference speed is faster, resulting in better overall detection performance and efficiency.

[0078] (2) By cutting out the corners and edges of the magnetic material and performing standardization processes such as rotation and stretching, the present invention accurately locates the learning target of the model on the edge part that needs to be solved. At the same time, it effectively separates the two local structures with significant differences, namely the corners and edges, laying a high-quality data foundation for subsequent unsupervised learning; and significantly improves the accuracy and robustness of magnetic material edge breakage detection.

[0079] (3) In the improved Anomalib model, this invention introduces a CoordinateAttention module in Layer 2 of the backbone network to enhance the sensitivity of mid-layer features to the direction of edge texture and the localization accuracy. In Layer 3, an AxialAttention module is introduced to strengthen the ability of deep features to model the long-distance dependence of global structure. Both attention modules are embedded without changing the dimension of the feature map, realizing joint feature enhancement from local details to global structure. On this basis, a heterogeneous dual-branch processing architecture is constructed. The mid-layer features of Layer 2 are input into the PaDiM sub-network to capture local subtle anomalies, and the deep features of Layer 3 are input into the FastFlow sub-network to model the global structure distribution. The efficient collaboration between local features and global features is achieved through cross-branch distribution alignment and mutual constraint. Finally, the fusion weights are dynamically allocated by a learnable fusion unit based on feature uncertainty, so that the model can learn the optimal fusion strategy autonomously during the training process using only normal samples, thus achieving accurate capture of edge collapse.

[0080] (4) This invention adopts a training strategy of independent modeling of different parts, allowing the corner model and the edge model to focus on learning the normal patterns of their specific regions, which greatly reduces false alarms caused by differences in regional features and makes the detection results interpretable, enabling direct location of defect types. In summary, this invention constructs a highly customized detection scheme from data preprocessing and feature extraction to model inference, achieving efficient, accurate, and reliable automatic detection of magnetic material edge breakage. Attached Figure Description

[0081] Figure 1 This is a schematic diagram of the overall process of the present invention.

[0082] Figure 2 This is a corner splicing diagram of the present invention.

[0083] Figure 3 This is a diagram showing the edge splicing in this invention.

[0084] Figure 4 This is a diagram of the backbone network structure of the improved Anomalib model in this invention.

[0085] Figure 5 This is a diagram of the dual-branch network structure of the improved Anomalib model in this invention. Detailed Implementation

[0086] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments. The described embodiments are merely some embodiments of the present invention, and not all embodiments. Various modifications and improvements made to the technical solutions of the present invention by those skilled in the art without departing from the design concept of the present invention should fall within the protection scope of the present invention.

[0087] Example 1:

[0088] like Figure 1 As shown, a method for detecting edge chipping in magnetic materials includes the following steps:

[0089] S1: Cropping and standardizing the background of the magnetic material image to obtain a regular atlas of corners and edges.

[0090] S1.1: Perform background cropping preprocessing on the original image to remove irrelevant background areas. This includes the following sub-steps:

[0091] First, the original image is binarized using an adaptive thresholding algorithm to enhance object edges. This adaptive thresholding algorithm employs Gaussian weighted local thresholding, and the calculation formula is as follows:

[0092] ;

[0093] in, For pixels Local threshold, It is the Gaussian weighted average of the pixels in the neighborhood of this point. This is a constant offset. The neighborhood size is set to 15. 15 pixels, The value is 5.

[0094] Secondly, a contour tracking algorithm based on Suzuki85 is used to detect the outermost contour of the rectangular magnetic material in the binary image. This algorithm can effectively extract the boundaries of connected components in the image, obtaining the complete contour point set of the magnetic material.

[0095] Then, the Douglas-Peucker polygon simplification algorithm is applied to approximate the contour to obtain key corner points. This algorithm retains the main shape features of the contour recursively, and the simplification threshold is set to 5 pixels, meaning that the maximum distance between the simplified contour and the original contour does not exceed 5 pixels.

[0096] Next, the minimum bounding box of the rectangular magnetic material is determined using an extreme point calculation algorithm. Specifically, for the simplified set of corner points, the minimum and maximum values ​​of the x and y coordinates are calculated to obtain the coordinates of the top-left corner of the minimum bounding box. and the coordinates of the bottom right corner .

[0097] Finally, the image is cropped by extending a white border of a specified width based on the minimum bounding box. The specified width is 100 pixels, used to preserve part of the background area outside the rectangular magnetic material's edge, which is crucial for subsequent corner and edge feature extraction. The cropped image size is... Pixel.

[0098] S1.2: Corner and edge sub-image cropping;

[0099] Based on the cropped image obtained in step S1.1, and the coordinates of the key corner points. These four corner points are the key corner points obtained in step S1.1 after simplification using the Douglas-Puk algorithm, and are marked sequentially in a clockwise direction as follows: Using the coordinates of each corner point as the center, square regions with preset fixed side lengths are cropped from the cropped image to obtain four corner sub-images. ,in The preset fixed side length is 140 pixels, meaning that the size of each corner sub-image is 140×140 pixels, including the corner point and its surrounding area, ensuring that corner defects can be completely included in the cropping area.

[0100] S1.3: Corner image stitching;

[0101] Based on the four corner sub-images obtained in step S1.2, they are arranged according to their spatial orientation corresponding to the original magnetic material and spliced ​​together to form a total square image. This composite image includes the four corner regions of the magnetic material and part of the background, serving as corner images.

[0102] Figure 2 This is an example of a corner stitched image obtained after processing a rectangular magnetic material sample using steps S1.2 and S1.3. Figure 2 As shown, the original rectangular magnetic materials are arranged and stitched clockwise according to their spatial orientation (top left, top right, bottom right, bottom left). The top left and top right horizontal stitchings are then combined to obtain the top horizontal stitching image, and the bottom right and bottom left horizontal stitchings are combined to form the bottom horizontal stitching image. Finally, the top and bottom horizontal stitching images are vertically stitched together to obtain the corner images. This composite image includes the four corner regions of the magnetic material and part of the background, with a size of 280×280 pixels, and serves as the corner images for subsequent model training.

[0103] S1.4: Based on the cropped image obtained in step S1.1, after cropping the four corners, the remaining rectangular area is segmented by edges.

[0104] First, determine the four sides of the rectangular magnetic material. Taking the top side as an example, its two endpoints are the top left corner and the bottom right corner. and the top right corner Use vector operations to calculate the centerline and perpendicular direction of the edge.

[0105] Secondly, taking the edge as the center, extend a specified width inwards and outwards along the vertical direction. The specified width is 60 pixels, that is, extend 60 pixels inwards from the edge towards the magnetic material and 60 pixels outwards, forming a rectangular area with a width of 120 pixels and a length equal to the edge length. The edge length is determined by "edge length = corresponding edge length of the original image - 2 × corner square edge length". Each edge sub-image contains the complete outline of the corresponding edge of the magnetic material and part of the background.

[0106] Then, the edge region is rotated to the horizontal direction through an affine transformation to ensure consistency in subsequent processing. Specifically, the direction vector of the centerline of the edge region is first determined through vector operations, and the angle between this direction vector and the horizontal direction (positive X-axis direction) is calculated. Based on the included angle Construct the rotation matrix, the formula for which is:

[0107] ;

[0108] in, Let be a rotation matrix. The angle between the centerline and the horizontal direction. Let the rotation matrix be the center of rotation of the edge region (such as the midpoint of the center line); perform an affine transformation based on this rotation matrix to rotate the edge region to the horizontal direction.

[0109] Repeat the above process to obtain the edge sub-images of the four sides respectively.

[0110] S1.5: Edge image stitching;

[0111] Since the widths of the various edge sub-images are the same but their lengths differ, they are stretched to a specified length to make all edge sub-images the same size. The specified length is 500 pixels, and bilinear interpolation is used for stretching to maintain image quality.

[0112] The four stretched edge sub-images are automatically corrected for orientation using a regional brightness mean comparison algorithm, and then stitched together in order from top to bottom with the outer edge at the bottom and the inner edge at the top, ensuring that the white background is at the bottom during stitching; after stitching, a total rectangular image is obtained, which serves as the edge image.

[0113] Figure 3 This is an example of an edge-stitched image obtained after processing the same magnetic material sample using steps S1.4 and S1.5. For example... Figure 3As shown, the sorting order is top (outer side facing up), right (outer side rotated to the right and then outer side facing up), bottom (outer side rotated to the bottom and then outer side facing up), and left (outer side rotated to the left and then outer side facing up). The final stitched edge image size is 500×480 pixels.

[0114] S2: Construct the Anomalib anomaly detection model. The specific steps are as follows:

[0115] S2.1: Improvements to the backbone network;

[0116] An anomaly detection model is improved based on the Anomalib framework, using ResNet18 as the backbone network. To enhance the extraction capability of edge collapse features, in Layer 2 of the ResNet18 backbone network, the second 3×3 convolutional layer of the first residual block is replaced with a Coordinate Attention (CA) module (spatial coordinate attention module), and in Layer 3, the second 3×3 convolutional layer of the first residual block is replaced with an Axial Attention (AA) module (axial attention module). The structure is as follows: Figure 4 As shown.

[0117] The implementation process of the Coordinate Attention module embedded in the second-layer residual block includes: processing the feature map output by the second layer of the ResNet18 backbone network. Global average pooling is performed to obtain channel feature descriptors in the horizontal and vertical inverse directions, respectively. and The calculation formula is:

[0118] ;

[0119] ;

[0120] in, Vertical channel feature descriptor In the The feature value of the row position, Horizontal channel feature descriptor In the Feature values ​​of column positions For the number of channels, For height, Width; The expression represents the first in the height direction. OK, Indicates the first in the width direction List; Indicates the feature map at the height position Width position Eigenvalues ​​at; Indicates the feature map at the height position Width position The eigenvalue at that location.

[0121] The feature descriptors are dimensionality transformed and activated through a fully connected layer to generate attention weights in the horizontal and vertical directions. Specifically, and After concatenation, the data undergoes 1×1 convolution for dimensionality reduction, batch normalization, and non-linear activation. Then, it is subjected to 1×1 convolution for dimensionality increase to restore the original number of channels. Finally, attention weights are generated using the Sigmoid function. and :

[0122] ;

[0123] ;

[0124] in, This represents the Sigmoid activation function. They are respectively for and Intermediate features obtained after splicing, dimensionality reduction, batch normalization, and nonlinear activation; This represents a 1×1 convolution operation.

[0125] Multiplying the attention weights by the original feature map yields the enhanced feature map with improved edge collapse features:

[0126] ;

[0127] It is a feature map enhanced with coordinate attention.

[0128] The implementation process of the Axial Attention module embedded in the third layer residual block includes: the feature map output by the third layer of the ResNet18 backbone network. By performing self-attention calculations along the height and width axes respectively, global structural information is captured, and deep features are output. .

[0129] Input feature map The attention path is decomposed into independent attention paths along both the height and width directions. For the height-axis attention path, the query, key, and value matrix is ​​defined as follows:

[0130] ;

[0131] in This is a learnable projection matrix specific to the height axis, used to map input features to a query, key, and value space. The superscript (h) indicates that this projection matrix is ​​used in the height axis attention path.

[0132] The height axis attention output features are:

[0133] ;

[0134] It is the product of the query matrix and the transpose key matrix, used to calculate the attention weights in the height direction; The scaling factor is used to scale the attention weights to prevent gradient vanishing due to excessively large softmax input caused by excessively high dimensionality. It is a normalized exponential function used to convert the attention weights in the height direction into a probability distribution;

[0135] For the width-axis attention path, define the query, key, and value matrix under the width-axis path:

[0136] ;

[0137] in A learnable projection matrix specific to the width axis, superscript Characterized by its applicability to width-axis attention paths;

[0138] The width axis attention output is:

[0139] ;

[0140] The outputs of the two axial attentions are fused:

[0141] ;

[0142] It is the final deep feature map after fusion.

[0143] S2.2: Configure heterogeneous decoupling of two branches, cross-branch alignment constraints, and dynamic fusion architecture; the overall architecture is as follows: Figure 5 As shown; specifically including:

[0144] S2.21: Feature Extraction and Adaptation:

[0145] Extracting the mid-layer features of the second layer embedded with coordinate attention from the improved ResNet18 backbone network The third layer of deep features with embedded axial attention ;

[0146] The mid-layer features are regularized by the whitening adapter layer as follows:

[0147] ;

[0148] in, , These are the mean vector and covariance matrix of the layer features in the normal samples of the training set, respectively. The whitening matrix, after normalization It satisfies an isotropic Gaussian distribution;

[0149] The deep features are then processed through a lightweight, learnable adaptation layer in conjunction with coordinate attention to unify the dimensions, resulting in:

[0150] ;

[0151] in, It is a deep adaptation feature after unifying dimensions; For 1×1 convolution, Layer normalization is used to map feature dimensions to the unified dimensions required by FastFlow. .

[0152] S2.22: PaDiM branch: Local subtle feature modeling;

[0153] The regularized middle layer features The PaDiM subnetwork is input, and to achieve fine modeling of local textures, a multivariate Gaussian distribution is fitted separately for each spatial location (i,j) on the feature map:

[0154] ;

[0155] ;

[0156] ;

[0157] in, It is the height of the mid-layer feature map. It is the width of the mid-layer feature map. Let be the feature vector of the nth training sample at position (i,j) in the mid-layer feature map space; N is the number of training samples; This represents the transpose operation of a vector; The regularization coefficient is used. It is the identity matrix. It is a regularization term;

[0158] Pixel-level anomaly scores were obtained using Mahalanobis distance during testing.

[0159] ;

[0160] Image-level score ;

[0161] The PaDiM branch is located in the mid-level feature map space. The pixel-level anomaly score indicates that the larger the value, the greater the deviation from the normal distribution at that location, and the more likely it is to be a defect area. The mid-level features of the current test sample In spatial location The eigenvector at that location; Covariance matrix The inverse matrix is ​​used to calculate the standardized Mahalanobis distance;

[0162] S2.23: FastFlow branch: Global structure modeling;

[0163] Adapted deep features Input to the FastFlow subnetwork, through a series of reversible transformations This maps deep features to a latent variable space that follows a standard normal distribution. :

[0164] ;

[0165] in It is a standard Gaussian distribution.

[0166] To enable the model to learn the global distribution pattern of normal samples, the invertible transformation parameters are optimized by maximizing the log-likelihood during the training phase.

[0167] ;

[0168] in, It is the training loss function of the FastFlow subnetwork. Minimizing this loss is equivalent to maximizing the log-likelihood of normal samples. It is the expectation operator. This is the characteristic distribution of normal samples; It refers to "all deep features sampled from a normal sample distribution". , calculate the average value within the parentheses; It is a standard normal distribution The probability density function; Latent variables obtained after reversible transformation of deep features; It is the logarithm of the absolute value of the Jacobian determinant, used for transformation and correction of probability density.

[0169] Abnormal scores during testing are defined as negative log-likelihood.

[0170] ;

[0171] in, This is the image-level anomaly score output by the FastFlow branch; this formula is directly related to the log-likelihood loss in the aforementioned training phase: the training phase maximizes the log-likelihood of normal samples, enabling the invertible transformation. Normal features are mapped to the center of a standard normal distribution; during testing, the features of abnormal samples, after mapping, will deviate from the standard normal distribution, leading to... Significantly reduced, its negative logarithm The higher the score, the greater the deviation of the global structure of the sample from the normal pattern, and the more likely there are defects.

[0172] S2.24: Cross-branch distribution alignment mutual constraint ff;

[0173] Using the global feature normalization flow distribution learned from FastFlow, we constrain the Gaussian distribution of PaDiM to maintain consistency in its global structure, and construct the distribution alignment loss:

[0174] ;

[0175] in, It is a cross-branch distribution alignment loss function used to constrain the global structural consistency of the two features of PaDiM and FastFlow; This is the global feature aggregation vector of the PaDiM branch. This is the global latent variable aggregation vector for the FastFlow branch. It is a learnable linear mapping matrix;

[0176] Meanwhile, leveraging the local feature responses extracted from normal samples using PaDiM, and constrained by feature-level distillation loss, FastFlow is guided to improve its perception and sensitivity to detailed textures.

[0177] ;

[0178] in, It is a feature-level distillation loss function used to guide FastFlow to learn the local detail texture perception capability of the PaDiM branch; This is a pixel-level anomaly score map output by PaDiM. This is a pixel-level negative log-likelihood plot output by FastFlow. This is an upsampling operation used to... Resolution aligned to ;

[0179] S2.25: Dynamic fusion based on feature uncertainty;

[0180] Through lightweight learnable fusion units To achieve dynamic fusion, fusion weights are adaptively assigned based on the confidence and uncertainty responses output by the two branches during forward propagation:

[0181] ;

[0182] in, These are the outlier score fusion weights for the PaDiM branch and the FastFlow branch, respectively, which are normalized using the Softmax function to satisfy... ; , These are the uncertainty measures of the PaDiM branch and the FastFlow branch outputs, respectively. These are the learnable parameters of the fusion unit; It is a lightweight, learnable fusion unit used to dynamically generate fusion weights based on input features; It is a normalization function;

[0183] Final anomaly score:

[0184] ;

[0185] It is the final anomaly score output by the model, which is a weighted fusion result of the anomaly scores of the PaDiM branch and the FastFlow branch; It is the image-level anomaly score output by the PaDiM branch; It is the image-level anomaly score output by the FastFlow branch;

[0186] This formula achieves adaptive fusion of local detail anomalies and global structural anomalies by dynamically allocating weights: when the PaDiM branch has a higher confidence in local textures, As the size increases, the model focuses more on detecting detailed defects; when the FastFlow branch has higher confidence in the global structure... By increasing the size of the model, it focuses more on detecting overall structural defects, thereby autonomously learning the optimal local-global feature fusion strategy during training using only normal samples.

[0187] S2.3: Model training;

[0188] The corner image set and the edge image set obtained in step 3 are respectively put into the improved Anomalib anomaly detection model in steps 4 to 5 for independent unsupervised training to obtain the corner defect detection model and the edge defect detection model.

[0189] The unsupervised training process includes: using defect-free images from the corner image set and the edge image set as training samples, and inputting them into the improved corner anomaly detection model and the edge defect detection model for independent training, respectively. For each model, the training samples are input into the improved ResNet18 backbone network to extract the Layer 2 mid-layer features embedded with Coordinate Attention and the Layer 3 deep features embedded with Axial Attention; the Layer 2 features are normalized by a whitening adaptation layer and then input into the PaDiM sub-network to learn the Gaussian distribution of local subtle features of normal samples; the Layer 3 features are normalized by a lightweight learnable adaptation layer and then input into the FastFlow sub-network to learn the normalized flow distribution of the global structure of normal samples. During the dual-branch joint training process, the learnable parameters in the FastFlow branch, adaptation layer and fusion unit are jointly optimized by minimizing the negative log-likelihood loss of the FastFlow sub-network, the cross-branch distribution alignment mutual constraint loss between PaDiM and FastFlow, the feature-level distillation loss of PaDiM on FastFlow, and the normal sample fusion score regularization term output by the fusion unit based on feature uncertainty. This enables the model to autonomously learn the normal feature distribution of defect-free corners, edges and corresponding background regions, as well as the optimal local-global feature fusion strategy during the training process using only normal samples.

[0190] The training parameters were set as follows: batch size of 16, initial learning rate of 0.001, Adam optimizer used, and 200 training epochs. After each training epoch, the model performance was evaluated using a validation set, and the optimal model parameters were saved.

[0191] S3: Process the magnetic material to be tested and input it into the model for testing;

[0192] The same background cropping, component segmentation, and stitching processes as in step S1 are performed on the rectangular magnetic material to be detected, resulting in the stitched image of the corner and the stitched image of the edge to be detected. Specifically, the following steps are performed sequentially:

[0193] Background cropping preprocessing: Remove irrelevant background;

[0194] Corner point recognition and corner sub-image cropping, edge sub-image acquisition and processing;

[0195] Corner images are stitched together to obtain the corner image to be detected, and edge images are stitched together to obtain the edge image to be detected.

[0196] The corner stitched image to be detected is input into the corner defect detection model, and the edge stitched image to be detected is input into the edge defect detection model to obtain the corresponding defect detection results.

[0197] S4: The model performs detection on the input image. The specific detection process is as follows: The model performs forward inference on the input image, extracts mid- and deep features through the improved ResNet18 backbone network, outputs local anomaly features through the PaDiM sub-network, and outputs global structural anomaly features through the FastFlow sub-network. Then, dynamic fusion is achieved through the trained lightweight learnable fusion unit based on feature uncertainty. The fusion weights are adaptively allocated according to the confidence and uncertainty response output by the two branches in the forward propagation, so as to obtain the comprehensive anomaly probability distribution and defect location, and output a pixel-level anomaly score map.

[0198] The determination of magnetic material edge chipping defects is carried out based on the output results of the improved Anomalib anomaly detection model. First, the pixel-level anomaly score map output by the model is obtained. The score map is binarized using the optimal judgment threshold of 0.55 determined by an adaptive method. Pixels with scores greater than the threshold are marked as abnormal pixels, and the rest are marked as normal pixels, thus obtaining a binarized anomaly mask.

[0199] Subsequently, connected component analysis was performed on the anomaly mask to identify all continuous anomalous pixel regions. A minimum defect area threshold of 40 pixels was set, and isolated anomalous points with areas smaller than this threshold were filtered out. If at least one valid anomalous connected component still exists after filtering, it is determined that there is a chipping defect in the corresponding magnetic material region. If no defect is detected, it is determined that there is no defect.

[0200] S5: Output the detection results and make a judgment on them;

[0201] A comprehensive judgment is made based on the obtained corner defect detection results and edge defect detection results:

[0202] If there are defects at the corners or edges, the rectangular magnetic material to be tested is determined to have edge chipping issues.

[0203] If there are no defects at the corners and edges, the rectangular magnetic material to be tested is determined to have no edge chipping issues.

[0204] The above embodiments are only for illustrating the technical concept and features of the present invention, and are intended to enable those skilled in the art to understand the content of the present invention and implement it accordingly. They should not be construed as limiting the scope of protection of the present invention. All equivalent transformations or modifications made in accordance with the spirit and essence of the present invention should be covered within the scope of protection of the present invention.

Claims

1. A method for detecting edge chipping in magnetic materials, characterized in that: Including the following steps: S1: Cropping and standardizing the background of the magnetic material image to obtain a regular atlas of corners and edges; S2: Improve the Anomalib model, including the following steps: S2.1: ResNet18 is used as the backbone network, and the Coordinate Attention module and the Axial Attention module are integrated into the network; S2.2: Construct a heterogeneous dual-branch processing architecture: Extract the mid-level and deep features of the ResNet18 backbone network, and input the mid-level and deep features into the PaDiM sub-network and FastFlow sub-network in the anomalib model respectively to achieve parallel modeling and collaborative optimization through alignment constraints; S2.3: The improved Anomalib anomaly detection model is trained using corner and edge regularization atlases respectively to obtain optimized corner defect detection models and edge defect detection models; S3: Process the magnetic material to be tested to obtain the corner splicing image and the edge splicing image to be tested. Input the corner splicing image to be tested into the corner defect detection model for detection, and input the edge splicing image to be tested into the edge defect detection model for detection. S4: The corner defect detection model and the edge defect detection model detect and process their input images respectively, and then achieve dynamic fusion through the learning fusion unit. Based on the dual-branch adaptive allocation of fusion weights, the comprehensive abnormal probability distribution and defect location are obtained, and the corresponding defect detection results are obtained respectively. S5: Output the detection results.

2. The method for detecting chipped edges of magnetic materials according to claim 1, characterized in that: The specific operation method of step S1 includes the following steps: S1.1: Obtain the original image data of the magnetic material, perform background cropping preprocessing on the original image to remove irrelevant background areas, and obtain the magnetic material image with the background cropped. S1.2: Based on the cropped image obtained in step S1.1, using the coordinates of its four corner points, and taking each corner point coordinate as the center, crop out a square region with a preset fixed side length from the cropped image to obtain four corner sub-images; S1.3: Based on the four corner sub-images obtained in step S1.2, arrange them according to their spatial orientation corresponding to the original magnetic material, and stitch them together to form a total square image. This composite image includes the four corner regions of the magnetic material and part of the background, serving as the corner images. S1.4: Based on the cropped image obtained in step S1.1, the remaining area after cropping the four corners is cropped into four images of the same width, and then rotated to the horizontal direction to obtain the edge sub-images; S1.5: Based on the edge sub-images obtained in step S1.4, stretch them to a uniformly specified length so that all edge sub-images have the same size. Then, arrange and stitch the transformed images from top to bottom in the direction of outer edge at the bottom and inner edge at the top to obtain a total rectangular image, which serves as the edge image.

3. The method for detecting chipped edges of magnetic materials according to claim 2, characterized in that: In step S1.2, the cropping is performed with each corner point as the center, and square regions with preset fixed side lengths are cropped from the cropped image to obtain four corner sub-images.

4. The method for detecting chipped edges of magnetic materials according to claim 2, characterized in that: The four corner sub-images mentioned in step S1.3 are obtained by horizontally and vertically stitching the top horizontal stitching image with the top left and top right of the original magnetic material, and the bottom horizontal stitching image with the bottom right and bottom left horizontal stitching image. Then, the top horizontal image and the bottom horizontal image are vertically stitched together to obtain the corner image.

5. The method for detecting chipped edges of magnetic materials according to claim 2, characterized in that: The specific process of cropping the edge sub-images in step S1.4 is as follows: First, calculate the coordinate range of the edge region after removing the four corners, where the edge length is determined by "edge length = corresponding edge length of the original image - 2 × edge length of the corner square", thereby defining the effective detection length of each edge region; second, based on the edge region range determined above, calculate the center line and its vertical direction of each edge region through vector operations, thereby determining the orientation angle and affine transformation reference of the edge region, and rotate each edge region to the horizontal direction with the help of affine transformation; crop the edge sub-images, and after cropping, each edge sub-image contains the complete outline of the corresponding edge of the magnetic material and part of the background.

6. The method for detecting chipped edges of magnetic materials according to claim 2, characterized in that: The stretching of the edge sub-image in step S1.5 is achieved by stretching the length to a uniform pixel size through bilinear interpolation; the stitching is performed by automatically correcting the direction using a regional brightness mean comparison algorithm to ensure that the white background is at the bottom during stitching.

7. The method for detecting chipped edges of magnetic materials according to claim 1, characterized in that: The specific operation of step S2.1 is as follows: In Layer 2, the second 3×3 convolutional layer of the first residual block is replaced with the CoordinateAttention spatial coordinate attention module; in Layer 3, the second 3×3 convolutional layer of the first residual block is replaced with the Axial Attention axial attention module; both attention modules are embedded without changing the dimension of the feature map. The implementation process of the Coordinate Attention spatial coordinate attention module includes: performing global average pooling on the feature map output by the ResNet18 backbone network to obtain channel feature descriptors in the horizontal and vertical directions respectively; performing dimension transformation and activation on the feature descriptors through a fully connected layer to generate attention weights in the horizontal and vertical directions; and multiplying the attention weights with the original feature map to obtain the feature map after enhancing the edge collapse feature. The implementation process of the Axial Attention module includes: decomposing the input feature map into two axes along the height and width directions respectively; calculating the attention weight for each axis independently through a one-dimensional attention mechanism; normalizing the attention weights through the Softmax function; and multiplying the normalized attention weights of the two axes with the original feature map to obtain the output feature map that fuses the axial information.

8. The method for detecting chipped edges of magnetic materials according to claim 7, characterized in that: The specific operation method of step S2.2 is as follows: extract the mid-level features output by layer2 and the deep features output by layer3, and bind the mid-level features and deep features to the two functional branches in the heterogeneous dual-branch architecture according to their levels. The mid-layer features are normalized by a whitening adapter layer that matches the axial attention and then input into the PaDiM sub-network in the anomalib model to model the local subtle features of normal samples. Deep features are fed into the FastFlow subnetwork of the anomalib model after being unified in dimension by a lightweight learnable adaptation layer that works in conjunction with coordinate attention, to model the global structure of normal samples. A cross-branch structure is introduced during the bi-branch modeling process, and alignment constraints are used to ensure collaboration between the two branches. The normalized flow distribution of global features learned by FastFlow is used to constrain the Gaussian distribution of PaDiM, maintaining consistency in the global structure. Simultaneously, the local feature responses extracted by PaDiM from normal samples are used, constrained by feature-level distillation loss, to guide FastFlow in improving its perception and sensitivity to detailed textures. Finally, dynamic fusion is achieved through a lightweight learnable fusion unit based on feature uncertainty. The fusion weights are adaptively allocated based on the confidence and uncertainty output by the bi-branch in the forward propagation, allowing the model to autonomously learn the optimal local-global feature fusion strategy during training with normal samples.

9. The method for detecting chipped edges of magnetic materials according to claim 1, characterized in that: The specific operation method of step 2.3 is as follows: independently unsupervised training is performed on the corner image set and the edge image set using the improved Anomalib anomaly detection model framework to train and optimize the weight parameters inside the model. After training, the optimized corner defect detection model weights and edge defect detection model weights are obtained. The weights are then loaded into the corresponding model frameworks to obtain usable corner defect detection models and edge defect detection models. The unsupervised training process includes: taking defect-free images from the corner image set and the edge image set as training samples, inputting them into the improved Anomalib model, and jointly optimizing the learnable parameters in the FastFlow branch, adaptation layer and fusion unit by minimizing the negative log-likelihood loss, cross-branch distribution alignment loss, feature distillation loss and normal sample fusion score regularization term of the FastFlow sub-network, so that the model learns the normal feature distribution of defect-free corners, edges and corresponding background regions.

10. The method for detecting chipped edges of magnetic materials according to claim 1, characterized in that: The detection processing described in step S4 is as follows: mid-layer and deep features are extracted by improving the ResNet18 backbone network, and local anomaly features and global structural anomaly features are output by the PaDiM sub-network and FastFlow sub-network, respectively.