Circuit board image registration method, electronic device, and storage medium

By combining a flow-matching diffusion model and a cyclic consistency constraint-based image registration method with semi-supervised training and symmetric priors for printed circuit boards, the problems of high accuracy, high efficiency, and low annotation dependence in printed circuit board inspection are solved, achieving sub-pixel-level registration and fast inference.

CN122176024APending Publication Date: 2026-06-09SHANGHAI STEP ELECTRIC
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SHANGHAI STEP ELECTRIC
Filing Date
2026-05-13
Publication Date
2026-06-09

Smart Images

  • Figure CN122176024A_ABST
    Figure CN122176024A_ABST
Patent Text Reader

Abstract

This application relates to a circuit board image registration method, electronic device, and storage medium. The circuit board image registration method includes: preprocessing a standard template image of the circuit board and a real-world image to be inspected, and stitching them along the channel dimension to form a conditional input; inputting the conditional input into a registration model, which generates a preliminary deformation field based on a flow-matching diffusion model; obtaining a forward deformation field and a backward deformation field based on the preliminary deformation field; applying inverse consistency constraints to the forward and backward deformation fields to output a final deformation field that conforms to symmetry constraints; and spatially aligning the real-world image to be inspected with the standard template image based on the final deformation field to output the registered image. This invention, by constructing an end-to-end registration framework based on a flow-matching diffusion model and innovatively introducing cyclic consistency symmetry constraints, achieves an organic unity of high precision, high efficiency, strong symmetry, and low annotation dependence in printed circuit board image registration tasks.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer vision and image processing technology, specifically to a circuit board image registration method, electronic device, and storage medium. Background Technology

[0002] Image registration is a fundamental task in computer vision, aiming to establish spatial correspondences between two or more images. It has crucial applications in industrial quality control, such as automated optical inspection (AOI) of printed circuit board assemblies. In such precision manufacturing scenarios, it is necessary to align the image to be inspected, containing the actual component layout, with a standard design template image with high precision (typically sub-pixel level) for defect detection and quality verification. Symmetric image registration, by simultaneously estimating bidirectional spatial transformations and forcing them to satisfy inverse consistency, has become an important paradigm for eliminating the inherent biases of traditional unidirectional registration and obtaining more reliable geometric alignment.

[0003] Existing symmetrical image registration techniques can be mainly divided into two categories, but both have significant limitations and are difficult to fully meet the high requirements of industrial inspection.

[0004] The first category is based on traditional optimization methods, such as using variational computation or numerical optimization to iteratively solve the bidirectional transformation. While these methods can achieve high accuracy, their iterative solution process leads to high computational costs and slow speed, making it difficult to meet the high-throughput real-time detection requirements of production lines.

[0005] The second category is based on deep learning methods. In recent years, Generative Adversarial Networks (GANs) and Convolutional Neural Networks (CNNs) have been used for registration tasks, accelerating forward inference. However, GAN frameworks suffer from training instability and pattern collapse, making it difficult to capture the complex spatial deformation distribution between PCB components and pads; while purely supervised regression frameworks heavily rely on large amounts of data with precise alignment labels for training, which is extremely costly to obtain in industrial scenarios.

[0006] Therefore, there is an urgent need for a high-precision and high-efficiency image registration method suitable for visual inspection of printed circuit boards. Summary of the Invention

[0007] To overcome the above-mentioned defects, this application is proposed, which provides a robust registration scheme that can achieve high accuracy, addressing the complex local elastic deformation of PCB images caused by factors such as mechanical stress and thermal effects, as well as interference from noise and illumination changes during the imaging process.

[0008] According to a first aspect of the present invention, a circuit board image registration method is provided, comprising: The standard template image of the circuit board and the actual image to be inspected are preprocessed and stitched along the channel dimension to form the conditional input; The conditions are input into the registration model, which generates a preliminary deformation field based on the flow matching diffusion model. The forward deformation field and the backward deformation field are obtained according to the preliminary deformation field and the parameter sharing and input exchange mechanism. The forward deformation field and the backward deformation field are subjected to inverse consistency constraints by cyclic consistency constraints to output a final deformation field that conforms to symmetry constraints. Based on the final deformation field, the actual image to be inspected is spatially aligned with the standard template image, and the registered image is output.

[0009] Traditional registration methods are either high in accuracy but slow, or fast but low in accuracy or unstable in training (GAN / CNN). In contrast, the flow matching diffusion model models registration as the optimal transmission path of a probabilistic flow. It inherits the high-quality modeling capability of diffusion models for complex non-rigid deformations, and during inference, it only requires a single-step sampling to directly reach the target state from the initial state. Cyclic consistency constraints force the forward and backward deformation fields to satisfy inverse consistency, fundamentally solving the inherent symmetry loss problem of unidirectional registration. The semi-supervised training strategy utilizes both labeled and unlabeled data for collaborative optimization, significantly reducing reliance on expensive manual annotation. The synergistic effect of these techniques enables this method to simultaneously achieve sub-pixel-level high-precision registration, fast inference per pair in approximately 15 milliseconds, strict symmetry consistency maintenance, and high data efficiency requiring only a small amount of labeled data for training. This meets the comprehensive requirements of industrial automated optical inspection for high precision, high efficiency, strong symmetry, and low annotation dependence.

[0010] In the above technical solution, the registration model generates a preliminary deformation field based on the flow matching diffusion model, including: Using the aforementioned input conditions and diffusion time step t as conditions, a probabilistic flow vector field is obtained through flow matching diffusion model regression. After encoding and decoding, a dense displacement field is output. The dense displacement field is then added to the identity grid to obtain the preliminary deformation field.

[0011] Standard diffusion models require dozens or even hundreds of iterations of denoising to generate results, severely limiting inference speed. In contrast, the flow matching paradigm directly regresses the probability flow vector field from the initial distribution to the target distribution. Once the network learns this vector field, it can directly reach the aligned deformation from the identity deformation in a single step during inference, without any iterative sampling. Furthermore, the regression target directly addresses the deformation field rather than intermediate representations, avoiding the accumulation and propagation of errors. This design allows our method to inherit the high-quality modeling capabilities of diffusion models for complex deformations while improving inference speed by two orders of magnitude compared to traditional diffusion models, achieving a balance between sub-pixel accuracy and real-time inference.

[0012] In any of the above technical solutions, the registration model is trained based on the flow matching diffusion model, which includes: using a semi-supervised training strategy to train the flow matching diffusion model with the final deformation field as the optimization target, to obtain the trained registration model; during the training of the registration model, the flow matching diffusion model is optimized using a total loss composed of supervised loss and unsupervised loss weights, and the training process gradually adjusts the loss weights through a progressive weight adjustment mechanism to obtain the trained registration model.

[0013] In the early stages of training, the unsupervised loss weight is set to zero, allowing the model to establish correct deformation priors and basic alignment capabilities through supervised signals. As training progresses, the unsupervised loss weight is gradually increased to its maximum value, enabling the model to learn the true distribution and refined features of deformation from massive amounts of unlabeled data based on correct priors. This progressive training ensures that the model first establishes correct basic representations before generalizing through self-supervised signals, achieving registration accuracy comparable to fully supervised training with only about 5% of labeled data. This significantly reduces reliance on expensive manual annotation and greatly improves the model's generalization ability for cross-production deployment.

[0014] In any of the above technical solutions, the flow matching diffusion model adopts an encoder-decoder architecture, including a feature encoder, a time step embedding fusion module, and a deformable flow decoder; The feature encoder is a multi-level downsampling U-Net structure, which introduces a self-attention mechanism in the deep feature map at a preset resolution; The time-step embedding fusion module encodes the diffusion time steps to generate embedding vectors, and injects the embedding vectors into each layer of the encoder-decoder architecture through adaptive instance normalization. The deformable stream decoder employs transposed convolutional upsampling and performs skip connections to fuse it with the corresponding layer features of the encoder in the encoder-decoder architecture.

[0015] Printed circuit board images contain numerous repetitive texture structures such as regular pad arrays and horizontal lines. Ordinary convolutional kernels have limited receptive fields, making it difficult to capture the long-range dependencies between these periodic components. Introducing a self-attention mechanism into deep feature maps allows each location to interact with all locations globally, thus accurately modeling the spatial correspondence of repetitive textures. Diffusion time steps are injected into each layer of the encoder and decoder through adaptive instance normalization. This is because different time steps correspond to different stages of the deformation process, and the network needs to dynamically adjust the mean and variance of features according to the current time step to adapt to different degrees of deformation. Skip connections directly pass the spatial detail features of the encoder's high-resolution layers to the decoder, effectively compensating for the edge and texture information lost during downsampling, ensuring that the output deformation field remains sharp at component boundaries and pad edges. The combined effect of this design is: the self-attention mechanism significantly improves the registration accuracy for periodic repetitive structures; adaptive instance normalization enhances the network's temporal modeling ability for the deformation process; and skip connections ensure the local fineness of the output deformation field. Together, these three mechanisms achieve high-precision prediction of dense deformation fields.

[0016] In any of the above technical solutions, the deformation stream decoder outputs deformation fields at multiple resolutions and adopts a coarse-to-fine strategy for registration: the decoder outputs deformation fields at low resolution, medium resolution and full resolution respectively. During training, the loss is calculated for the deformation fields at each scale. During inference, the low-resolution deformation field is first applied for coarse registration, and then the medium-resolution and high-resolution deformation fields are applied sequentially for fine-tuning based on the coarse registration.

[0017] In any of the above technical solutions, the parameter sharing and input exchange mechanism is as follows: using the same flow matching diffusion model, the conditional input and the conditional input after exchanging the input order are processed respectively to obtain the forward deformation field and the backward deformation field.

[0018] If two independent networks are used to predict the forward and backward deformation fields separately, not only does the number of parameters double, but the predictions of the two networks naturally do not satisfy the inverse consistency relation. Parameter sharing forces the same network to learn a symmetric representation—outputting the forward deformation field when given a fixed image and a moving image as inputs, and outputting the backward deformation field after swapping the input order. The network must learn an inherent exchange symmetry, that is, the output deformation fields after swapping the input order should be inverse transformations of each other. This design lays a solid foundation for subsequent cycle consistency constraints at the model structure level, while avoiding parameter redundancy and prediction inconsistency problems caused by independent predictions, reducing the number of model parameters, and improving training and inference efficiency.

[0019] In any of the above technical solutions, the cyclic consistency constraint is achieved through cyclic consistency loss. Using the cyclic consistency loss, the composite transformation formed by the superposition of the forward deformation field and the backward deformation field is constrained to approach the identity transformation.

[0020] Traditional unidirectional registration independently predicts the forward and backward deformation fields, which often do not satisfy a strict inverse consistency relation. Cyclic consistency loss directly calculates the difference between the composite transformed image and the original image, penalizing the degree to which the composite transformation deviates from the identity transformation at the pixel level. This loss function is fully differentiable; through backpropagation, the gradient simultaneously adjusts the forward and backward deformation fields, forcing them to adapt to each other and satisfy the inverse consistency relation. This constraint is particularly important for printed circuit boards with mirror-symmetric layouts, as registration results that violate symmetry can lead to a large number of false positives in subsequent defect detection. The cyclic consistency constraint enforces strict inverse consistency at the pixel level, ensuring that the registration results conform to physical design rules and significantly improving the reliability of subsequent defect detection.

[0021] In any of the above technical solutions, the semi-supervised training strategy includes: A total loss function containing both supervised and unsupervised loss is constructed, with the final deformation field as the optimization objective, and the network parameters of the flow matching diffusion model are iteratively optimized. The supervised loss is applied to image pairs labeled with the true deformation field, while the unsupervised loss is applied to unlabeled image pairs.

[0022] Supervised learning alone requires a large amount of precisely labeled deformation field data, which is extremely costly to obtain in industrial scenarios. Unsupervised learning alone, while not relying on labels, has limited accuracy based solely on self-supervised signals such as photometric consistency and lacks guidance from real deformation. Semi-supervised strategies organically combine these two approaches: supervised loss provides accurate deformation priors, acting as an anchor and guide throughout the training process; unsupervised loss utilizes massive amounts of unlabeled images to mine common patterns in deformation distribution and self-supervised signals. Both share the same network parameters, and the unsupervised loss also acts as a regularization mechanism, effectively preventing overfitting on labeled data. During iterative optimization, the model benefits from both the high-precision guidance of labeled data and the wide distribution of unlabeled data, achieving synergistic utilization of both labeled and unlabeled data. This significantly improves data utilization efficiency and model generalization ability in industrial scenarios where labeled data is scarce.

[0023] In any of the above technical solutions, the supervised loss includes flow matching loss, supervised cyclic consistency loss, and smoothness regularization loss, and the unsupervised loss includes photometric consistency loss, stability consistency loss, and unsupervised cyclic consistency loss.

[0024] The various loss functions are clearly defined and synergistically optimized: the flow matching loss directly supervises the regression of the deformation field, serving as the core guarantee for the overall registration accuracy; the cycle consistency loss ensures the symmetry of the forward and backward deformation fields; the smoothness regularization loss penalizes abrupt gradients in the deformation field, as abrupt changes in the deformation field correspond to physically unrealistic wrinkling deformations, and the smoothness constraint ensures that the output deformation field conforms to the physical laws of elastic deformation. In the unsupervised aspect, the photometric consistency loss utilizes the natural prior that the aligned image intensities should be similar, providing a self-supervised signal without annotation; the stability consistency loss applies random brightness and contrast adjustments and small translations to the input data, requiring the network to maintain consistency in the flow vectors predicted for the original and enhanced images, forcing the network to learn the essential characteristics of deformation rather than overfitting to input noise; and the unsupervised cycle consistency loss provides a symmetric self-supervised signal for unlabeled data. This synergistic optimization of multiple losses achieves joint optimization of registration accuracy, deformation smoothness, symmetry consistency, and robustness against interference, with the stability consistency loss particularly enhancing the model's resistance to changes in production line lighting and slight camera jitter.

[0025] In any of the above technical solutions, the training process gradually adjusts the loss weight through a progressive weight adjustment mechanism, including increasing the supervised loss weight in the early stage of training and gradually increasing the unsupervised loss weight to 1.0 as the training iteration progresses. During the inference phase, a fixed diffusion time step t=0.5 is used to perform a single forward propagation to obtain the final deformation field, and the image spatial alignment is completed through a spatial transformation network.

[0026] In the initial training phase, model parameters are randomized. Adding unsupervised loss or self-supervised signals like photometric consistency at this stage could lead the model to an incorrect optimal solution, such as mapping all pixels to the same location to minimize photometric error. The progressive weight adjustment mechanism sets the unsupervised loss weight to zero in the early training phase, allowing the model to establish correct deformation priors and basic alignment capabilities through supervised signals. Then, the unsupervised loss weight is gradually increased, enabling the model to learn a refined deformation distribution from unlabeled data based on correct priors. During the inference phase, since the flow matching model has already learned the direct mapping from the initial distribution to the target distribution, there is no need to simulate the inverse diffusion process. Fixing the diffusion time step is equivalent to directly sampling the final state in one step. This design ensures that unsupervised signals do not mislead the model in the early training phase, and no iterative sampling is required during the inference phase. The inference speed is two orders of magnitude faster than the standard diffusion model, which requires dozens of sampling steps, fully meeting the real-time requirements of industrial online detection.

[0027] In any of the above technical solutions, when generating the initial deformation field, the inherent symmetry prior of the circuit board is explicitly introduced; The symmetric priors include axisymmetric priors and centrally symmetric priors; The symmetric prior is encoded to obtain prior features, which are then fused with the conditional input in the channel dimension. The fused features are then input into the flow matching diffusion model.

[0028] Printed circuit board (PCB) designs inherently possess strong prior knowledge—most PCBs exhibit axial symmetry about their central axis or centrosymmetry about their center point. Purely data-driven methods fail to utilize this prior knowledge; when there are insufficient symmetrical samples in the training data or the deformation is complex, the model may produce inconsistent predictions in symmetrical regions, such as two symmetrical pads being predicted as having different displacements. This method extracts the symmetry axis position from the PCB design file and constructs a symmetry mask as an additional channel, stitched together with the image input. This symmetry mask identifies whether the symmetrical position of each pixel about the symmetry axis is within the effective area of ​​the image. Based on this, the network can infer that if a pixel at a certain position moves by a certain vector, the pixel at its symmetrical position should move accordingly. This hard-coded prior knowledge effectively compensates for the shortcomings of purely data-driven methods, acting as a regularization constraint on the network's predictions. Combining PCB design priors with data-driven learning further improves registration accuracy on symmetrically laid-out PCBs, making the registration results more consistent with physical design rules, making it particularly suitable for detecting high-density symmetrically laid-out PCBs such as memory modules and graphics cards.

[0029] In any of the above technical solutions, when forming the conditional input, the effective area masks corresponding to the standard template image and the actual image to be inspected are also stitched and fused with the preprocessed standard template image and the actual image to be inspected in the channel dimension to form the conditional input. After that, the flow matching diffusion model is input. The effective area mask is used to identify the effective area where the circuit board lines, pads and components are located, so that the flow matching diffusion model performs registration operation on the effective area.

[0030] Printed circuit board (PCB) images contain a large number of background pixels. These areas do not contain any feature information required for registration. If the entire image is input into the network indiscriminately, the model may be interfered with by background noise and misidentify background texture as the basis for registration. An effective region mask accurately identifies the true positions of PCB traces, pads, and components. When input into the network as an additional channel, the network can assign higher weights to effective regions when calculating loss and updating parameters, and may even completely ignore background regions. This design guides the model to focus limited computational resources and expressive power on the structures that truly need alignment, effectively avoiding the interference of background noise in the registration process. Furthermore, by reducing the invalid regions that need to be processed, inference time is further shortened while maintaining registration accuracy, making it particularly suitable for PCB images with complex backgrounds or sparse traces.

[0031] According to another aspect of the present invention, a computer-readable storage medium is also provided, on which a computer program is stored. When executed by a processor, the computer program implements the circuit board image registration method described in any of the above-described technical solutions. The registration method described in this invention is essentially a series of executable computational steps and algorithmic flows. These steps are solidified into computer program code and stored in various media. Users can completely reproduce the registration method of this invention on any compatible computing device by reading the medium and executing the program, without needing to understand complex algorithmic details or retrain the model. This solidifies the technical solution of this invention into a reproducible, distributable, and deployable product form, facilitating industrial replication and large-scale deployment in industrial scenarios.

[0032] According to another aspect of the present invention, an electronic device is also provided, including a processor and a memory, wherein a computer program is stored in the memory, and when the processor executes the computer program, it implements the circuit board image registration method described in any of the above technical solutions.

[0033] This invention constructs an end-to-end registration framework based on a flow matching diffusion model and innovatively introduces cyclic consistency symmetry constraints and semi-supervised training strategies, achieving an organic unity of high precision, high efficiency, strong symmetry, and low annotation dependence in printed circuit board image registration tasks. Attached Figure Description

[0034] The disclosure of this application will become more readily understood with reference to the accompanying drawings. It will be readily understood by those skilled in the art that these drawings are for illustrative purposes only and are not intended to limit the scope of protection of this application. Wherein: Figure 1 This is a flowchart of a circuit board image registration method according to an embodiment of this application; Figure 2 This is a schematic diagram of the circuit board image registration principle according to an embodiment of this application. Detailed Implementation

[0035] Some embodiments of this application are described below with reference to the accompanying drawings. Those skilled in the art should understand that these embodiments are merely illustrative of the technical principles of this application and are not intended to limit the scope of protection of this application.

[0036] In the description of this application, "module" and "processor" can include hardware, software, or a combination of both. A module can include hardware circuitry, various suitable sensors, communication ports, memory, and may also include software components, such as program code, or a combination of software and hardware. A processor can be a central processing unit, microprocessor, image processor, digital signal processor, or any other suitable processor. The processor has data and / or signal processing capabilities. The processor can be implemented in software, in hardware, or a combination of both. Computer-readable storage media includes any suitable medium capable of storing program code, such as magnetic disks, hard disks, optical disks, flash memory, read-only memory, random access memory, etc. The term "A and / or B" means all possible combinations of A and B, such as only A, only B, or A and B. The terms "at least one A or B" or "at least one of A and B" have a similar meaning to "A and / or B" and can include only A, only B, or A and B. The singular terms "a" or "this" can also include plural forms.

[0037] Diffusion models, particularly the flow matching paradigm, have demonstrated advantages in training stability and sample quality as a new generation of generative models. Flow matching achieves efficient single-step inference by directly regressing probabilistic flow trajectories, while maintaining the high-quality generative capabilities of diffusion models. Although these advances have brought new possibilities for improving image registration performance, how to effectively apply flow matching diffusion models to industrial inspection scenarios and combine them with symmetry constraints to achieve high-precision, high-efficiency, and data-efficient registration remains a gap in the current technological landscape. Existing methods generally fail to effectively utilize the inherent and strong symmetry prior knowledge in PCB design drawings to strictly constrain the registration process, leading to physically unreasonable registration results that disrupt the overall symmetry structure when dealing with complex deformations, thus affecting the reliability of subsequent inspections.

[0038] like Figure 1 As shown, a circuit board image registration method according to an embodiment of the present invention includes the following steps: Step 102: Preprocess the standard template image of the circuit board and the actual image to be inspected, and stitch them together along the channel dimension to form the conditional input.

[0039] Step 104: Input the conditions into the registration model.

[0040] Step 106: The registration model generates a preliminary deformation field based on the flow matching diffusion model. The forward deformation field and the backward deformation field are obtained according to the preliminary deformation field and the parameter sharing and input exchange mechanism. The forward deformation field and the backward deformation field are subjected to inverse consistency constraints by cyclic consistency constraints to output the final deformation field that conforms to the symmetry constraints.

[0041] Step 108: Based on the final deformation field, spatially align the actual image to be inspected with the standard template image, and output the registered image.

[0042] Traditional registration methods are either high in accuracy but slow, or fast but low in accuracy or unstable in training (GAN / CNN). In contrast, the flow matching diffusion model models registration as the optimal transmission path of a probabilistic flow. It inherits the high-quality modeling capability of diffusion models for complex non-rigid deformations, and during inference, it only requires a single-step sampling to directly reach the target state from the initial state. Cyclic consistency constraints force the forward and backward deformation fields to satisfy inverse consistency, fundamentally solving the inherent symmetry loss problem of unidirectional registration. The semi-supervised training strategy utilizes both labeled and unlabeled data for collaborative optimization, significantly reducing reliance on expensive manual annotation. The synergistic effect of these techniques enables this method to simultaneously achieve sub-pixel-level high-precision registration, fast inference per pair in approximately 15 milliseconds, strict symmetry consistency maintenance, and high data efficiency requiring only a small amount of labeled data for training. This meets the comprehensive requirements of industrial automated optical inspection for high precision, high efficiency, strong symmetry, and low annotation dependence.

[0043] Those skilled in the art should understand that step 108 above can be pre-trained and does not necessarily have to be executed in this order.

[0044] Specifically, based on the conditional input, a preliminary deformation field is generated through a flow-matched diffusion model, including: using the conditional input and diffusion time step t as conditions, a probability flow vector field is obtained by regression through the flow-matched diffusion model, a dense displacement field is output after encoding and decoding, and the dense displacement field is added to the identity grid to obtain the preliminary deformation field.

[0045] Standard diffusion models require dozens or even hundreds of iterations of denoising to generate results, severely limiting inference speed. In contrast, the flow matching paradigm directly regresses the probability flow vector field from the initial distribution to the target distribution. Once the network learns this vector field, it can directly reach the aligned deformation from the identity deformation in a single step during inference, without any iterative sampling. Furthermore, the regression target directly addresses the deformation field rather than intermediate representations, avoiding the accumulation and propagation of errors. This design allows our method to inherit the high-quality modeling capabilities of diffusion models for complex deformations while improving inference speed by two orders of magnitude compared to traditional diffusion models, achieving a balance between sub-pixel accuracy and real-time inference.

[0046] When training the registration model, the flow matching diffusion model is optimized by using a total loss composed of supervised and unsupervised losses. During the training process, the loss weights are gradually adjusted through a progressive weight adjustment mechanism to obtain the trained registration model.

[0047] In the early stages of training, the unsupervised loss weight is set to zero, allowing the model to establish correct deformation priors and basic alignment capabilities through supervised signals. As training progresses, the unsupervised loss weight is gradually increased to its maximum value, enabling the model to learn the true distribution and refined features of deformation from massive amounts of unlabeled data based on correct priors. This progressive training ensures that the model first establishes correct basic representations before generalizing through self-supervised signals, achieving registration accuracy comparable to fully supervised training with only about 5% of labeled data. This significantly reduces reliance on expensive manual annotation and greatly improves the model's generalization ability for cross-production deployment.

[0048] The flow matching diffusion model adopts an encoder-decoder architecture, including a feature encoder, a temporal step embedding fusion module, and a deformable flow decoder. The feature encoder is a multi-level downsampling U-Net structure that introduces a self-attention mechanism in the deep feature map at a preset resolution. The temporal step embedding fusion module encodes the diffusion time steps to generate embedding vectors and injects the embedding vectors into each layer of the encoder-decoder architecture through adaptive instance normalization. The deformable flow decoder uses transposed convolution upsampling and performs skip connections to fuse with the corresponding layer features of the encoder in the encoder-decoder architecture.

[0049] Printed circuit board images contain numerous repetitive texture structures such as regular pad arrays and horizontal lines. Ordinary convolutional kernels have limited receptive fields, making it difficult to capture the long-range dependencies between these periodic components. Introducing a self-attention mechanism into deep feature maps allows each location to interact with all locations globally, thus accurately modeling the spatial correspondence of repetitive textures. Diffusion time steps are injected into each layer of the encoder and decoder through adaptive instance normalization. This is because different time steps correspond to different stages of the deformation process, and the network needs to dynamically adjust the mean and variance of features according to the current time step to adapt to different degrees of deformation. Skip connections directly pass the spatial detail features of the encoder's high-resolution layers to the decoder, effectively compensating for the edge and texture information lost during downsampling, ensuring that the output deformation field remains sharp at component boundaries and pad edges. The combined effect of this design is: the self-attention mechanism significantly improves the registration accuracy for periodic repetitive structures; adaptive instance normalization enhances the network's temporal modeling ability for the deformation process; and skip connections ensure the local fineness of the output deformation field. Together, these three mechanisms achieve high-precision prediction of dense deformation fields.

[0050] The parameter sharing and input exchange mechanism is as follows: using the same flow matching diffusion model, the conditional input and the conditional input after the input order is exchanged are processed respectively to obtain the forward deformation field and the backward deformation field.

[0051] If two independent networks are used to predict the forward and backward deformation fields separately, not only does the number of parameters double, but the predictions of the two networks naturally do not satisfy the inverse consistency relation. Parameter sharing forces the same network to learn a symmetric representation—outputting the forward deformation field when given a fixed image and a moving image as inputs, and outputting the backward deformation field after swapping the input order. The network must learn an inherent exchange symmetry, that is, the output deformation fields after swapping the input order should be inverse transformations of each other. This design lays a solid foundation for subsequent cycle consistency constraints at the model structure level, while avoiding parameter redundancy and prediction inconsistency problems caused by independent predictions, reducing the number of model parameters, and improving training and inference efficiency.

[0052] Among them, the cyclic consistency constraint is achieved through the cyclic consistency loss. By using the cyclic consistency loss, the composite transformation formed by the superposition of the forward deformation field and the backward deformation field is constrained to approach the identity transformation.

[0053] Traditional unidirectional registration independently predicts the forward and backward deformation fields, which often do not satisfy a strict inverse consistency relation. Cyclic consistency loss directly calculates the difference between the composite transformed image and the original image, penalizing the degree to which the composite transformation deviates from the identity transformation at the pixel level. This loss function is fully differentiable; through backpropagation, the gradient simultaneously adjusts the forward and backward deformation fields, forcing them to adapt to each other and satisfy the inverse consistency relation. This constraint is particularly important for printed circuit boards with mirror-symmetric layouts, as registration results that violate symmetry can lead to a large number of false positives in subsequent defect detection. The cyclic consistency constraint enforces strict inverse consistency at the pixel level, ensuring that the registration results conform to physical design rules and significantly improving the reliability of subsequent defect detection.

[0054] The semi-supervised training strategy specifically includes: constructing a total loss function that includes supervised loss and unsupervised loss, using the final deformation field as the optimization objective, and iteratively optimizing the network parameters of the flow matching diffusion model; wherein, the supervised loss is for image pairs labeled with the real deformation field, and the unsupervised loss is for unlabeled image pairs.

[0055] Supervised learning alone requires a large amount of precisely labeled deformation field data, which is extremely costly to obtain in industrial scenarios. Unsupervised learning alone, while not relying on labels, has limited accuracy based solely on self-supervised signals such as photometric consistency and lacks guidance from real deformation. Semi-supervised strategies organically combine these two approaches: supervised loss provides accurate deformation priors, acting as an anchor and guide throughout the training process; unsupervised loss utilizes massive amounts of unlabeled images to mine common patterns in deformation distribution and self-supervised signals. Both share the same network parameters, and the unsupervised loss also acts as a regularization mechanism, effectively preventing overfitting on labeled data. During iterative optimization, the model benefits from both the high-precision guidance of labeled data and the wide distribution of unlabeled data, achieving synergistic utilization of both labeled and unlabeled data. This significantly improves data utilization efficiency and model generalization ability in industrial scenarios where labeled data is scarce.

[0056] In addition, supervised losses include flow matching loss, supervised cycle consistency loss, and smoothness regularization loss, while unsupervised losses include photometric consistency loss, stability consistency loss, and unsupervised cycle consistency loss.

[0057] The various loss functions are clearly defined and synergistically optimized: the flow matching loss directly supervises the regression of the deformation field, serving as the core guarantee for the overall registration accuracy; the cycle consistency loss ensures the symmetry of the forward and backward deformation fields; the smoothness regularization loss penalizes abrupt gradients in the deformation field, as abrupt changes in the deformation field correspond to physically unrealistic wrinkling deformations, and the smoothness constraint ensures that the output deformation field conforms to the physical laws of elastic deformation. In the unsupervised aspect, the photometric consistency loss utilizes the natural prior that the aligned image intensities should be similar, providing a self-supervised signal without annotation; the stability consistency loss applies random brightness and contrast adjustments and small translations to the input data, requiring the network to maintain consistency in the flow vectors predicted for the original and enhanced images, forcing the network to learn the essential characteristics of deformation rather than overfitting to input noise; and the unsupervised cycle consistency loss provides a symmetric self-supervised signal for unlabeled data. This synergistic optimization of multiple losses achieves joint optimization of registration accuracy, deformation smoothness, symmetry consistency, and robustness against interference, with the stability consistency loss particularly enhancing the model's resistance to changes in production line lighting and slight camera jitter.

[0058] The training process uses a progressive weight adjustment mechanism to gradually adjust the loss weights. Specifically, this includes increasing the supervised loss weight in the early stages of training, gradually increasing the unsupervised loss weight to 1.0 as the training iterative progresses, and simultaneously gradually decreasing the supervised loss weight from 1.0 to 0.5. During the inference phase, the diffusion time step is fixed at t=0.5, a single forward propagation is performed to obtain the final deformation field, and image spatial alignment is completed through a spatial transformation network.

[0059] In the initial training phase, model parameters are randomized. Adding unsupervised loss or self-supervised signals like photometric consistency at this stage could lead the model to an incorrect optimal solution, such as mapping all pixels to the same location to minimize photometric error. To address this, the unsupervised loss weight is set to zero in the early training phase, allowing the model to establish correct deformation priors and basic alignment capabilities through supervised signals. Subsequently, the unsupervised loss weight is gradually increased, enabling the model to learn a refined deformation distribution from unlabeled data based on correct priors. During inference, since the flow matching model has already learned the direct mapping from the initial distribution to the target distribution, there's no need to simulate the inverse diffusion process. Fixing the diffusion time step is equivalent to directly sampling the final state in one step. This design ensures that unsupervised signals do not mislead the model in the early training phase, and no iterative sampling is required during inference. The inference speed is two orders of magnitude faster than the standard diffusion model, which requires dozens of sampling steps, fully meeting the real-time requirements of industrial online detection.

[0060] In addition, the inherent symmetry priors of the circuit board are explicitly introduced when generating the initial deformation field; Symmetric priors include axially symmetric priors and centrally symmetric priors; The symmetric prior is encoded to obtain prior features, which are then fused with the conditional input in the channel dimension. The fused feature input stream is then matched with the diffusion model.

[0061] Printed circuit board (PCB) design inherently possesses strong prior knowledge—most PCBs exhibit axial symmetry about their central axis or centrosymmetry about their center point. Purely data-driven methods fail to utilize this prior knowledge; when there are insufficient symmetrical samples in the training data or the deformation is complex, the model may produce inconsistent predictions in symmetrical regions, such as two symmetrical pads being predicted as having different displacements. This method extracts the symmetry axis position from the PCB design file and constructs a symmetry mask as an additional channel, stitched together with the image input. This symmetry mask identifies whether the symmetrical position of each pixel about the symmetry axis lies within the effective area of ​​the image. Based on this, the neural network model can infer that if a pixel at a certain position moves by a certain vector, the pixel at its symmetrical position should move accordingly. This hard-coded prior knowledge effectively compensates for the shortcomings of purely data-driven methods, acting as a regularization constraint on the neural network model's predictions. Combining PCB design priors with data-driven learning further improves registration accuracy on symmetrically laid-out PCBs, making the registration results more consistent with physical design rules, making it particularly suitable for inspection scenarios of high-density symmetrically laid-out PCBs such as memory modules and graphics cards.

[0062] Furthermore, when forming the conditional input, the effective area masks corresponding to the standard template image and the actual image to be inspected are also stitched and fused with the preprocessed standard template image and the actual image to be inspected in the channel dimension to form the conditional input. After that, the flow matching diffusion model is input. The effective area mask is used to identify the effective area where the circuit board lines, pads and components are located, so that the flow matching diffusion model can perform registration operation on the effective area.

[0063] Printed circuit board (PCB) images contain a large number of background pixels. These areas do not contain any feature information required for registration. If the entire image is indiscriminately input into a neural network model, the model may be interfered with by background noise and misjudge background texture as the basis for registration. An effective region mask accurately identifies the true positions of PCB traces, pads, and components. As an additional channel input into the network, the neural network model can assign higher weights to effective regions when calculating loss and updating parameters, and may even completely ignore background regions. This design guides the model to focus limited computational resources and expressive power on the structures that truly need alignment, effectively avoiding the interference of background noise in the registration process. Furthermore, by reducing the invalid regions that need to be processed, inference time is further shortened while maintaining registration accuracy, making it particularly suitable for PCB images with complex backgrounds or sparse traces.

[0064] In the embodiment using effective region masks, all loss functions calculated during training (including flow matching loss, cycle consistency loss, photometric consistency loss, etc.) are computed only within the regions identified by the effective region masks M_F and M_M. Specifically, for pixel-level losses, only pixels located within both M_F and the deformed field-mapped M_M regions participate in the loss calculation; pixel losses in the background region are set to zero. This design forces the model to focus all its attention on the effective structure of the circuit board, further improving the relevance and accuracy of registration.

[0065] refer to Figure 2 This invention provides a symmetry-constrained registration method for circuit board images based on a flow matching diffusion model. Its core lies in constructing an end-to-end deep learning framework. This framework learns the mapping from image pairs to a two-way deformation field through conditional flow matching technology and introduces cyclic consistency constraints to ensure the symmetry of the registration. Simultaneously, it utilizes a semi-supervised training strategy to reduce dependence on labeled data. It should be noted that... Figure 2 The formulas in this document are schematic diagrams, and their specific mathematical forms are defined in the main text of this manual.

[0066] For ease of description, the following symbols are first defined: Fixed image (standard template image): ; Moving image (actual image to be inspected): ; Forward deformation field: , indicating from arrive Spatial mapping; Backward deformation field: , indicating from arrive Spatial mapping; Identical deformation field: ,Right now ; Spatial Transformer Network (STN): Indicates based on the deformation field For images Perform bilinear resampling; Diffusion time step: ,correspond Figure 2 middle .

[0067] The symmetric constraint registration method for road panel images in this embodiment mainly includes the following steps: S1: Data Preparation and Input Obtain the standard template image of the PCB Place the image with the actual component to be detected. The two images are preprocessed: grayscale conversion, size normalization to 256×256 pixels, and intensity normalization to the [-1, 1] range. After preprocessing, they are concatenated along the channel dimension to form the conditional input of the network. .

[0068] In another embodiment, to further improve registration accuracy, the effective area masks (used to identify the effective areas where circuit board lines, pads, and components are located) corresponding to the standard template image and the actual image to be inspected are stitched and fused with the preprocessed image in the channel dimension to form a conditional input containing 4 channels. This enables the flow matching diffusion model to perform registration operations on the effective region, avoiding interference from the background region.

[0069] S2: Deformation field generation based on flow matching Construct a conditional flow matching diffusion model, using the aforementioned stitched image and diffusion time step. Given the condition, directly regress a probability flow vector field. This vector field defines the optimal transmission path from the initial distribution (identical deformation) to the target distribution (aligned deformation).

[0070] This conditional flow matching diffusion model employs a custom encoder-decoder architecture and includes the following key design features: (1) Feature encoder A U-Net architecture with 4 levels of downsampling is employed to extract multi-scale spatial features from stitched images. Each downsampling level contains two convolutional layers (3×3 kernels, stride 1) and one downsampling layer (convolution with stride 2, 3×3 kernels). Multi-head self-attention is introduced in the deep feature maps (1 / 8 and 1 / 16 resolution) to model long-range dependencies between repetitive texture components of the PCB.

[0071] The above four-level downsampling process can be formally represented as: in, Stitching images based on input conditions , These are the feature maps output from downsampling levels 1 to 4, with resolutions of [resolution values ​​to be filled in]. , , , The first and second level feature maps retain high spatial resolution and are mainly used to capture detailed features such as local edges and corners. The third and fourth level feature maps have a large receptive field and strong semantic abstraction ability. Based on this, a self-attention mechanism is introduced, which can establish long-range dependencies between global pixels with low computational overhead and effectively model the spatial correspondence of repetitive texture components in PCB images.

[0072] It should be noted that the collaborative design of downsampling and the self-attention mechanism has a clear logical connection. The encoder's four-level downsampling progressively compresses the spatial resolution of the input image, aiming to reduce the feature map size while expanding the receptive field. Specifically, let the input image resolution be... Then the resolution after the first level of downsampling is Level 2 is Level 3 is Level 4 is As the resolution decreases, the receptive field of the original image corresponding to each feature pixel expands exponentially, and each pixel in the level 3 and level 4 feature maps has aggregated a large range of spatial context information.

[0073] Building upon this, this invention introduces a multi-head self-attention mechanism in the 3rd-level (1 / 8 resolution) and 4th-level (1 / 16 resolution) feature maps. The rationale is that, firstly, the spatial size of low-resolution feature maps is small, and the computational complexity of self-attention is... The computational complexity is within an acceptable range and does not significantly increase training and inference overhead. On the other hand, each pixel in the deep feature map encodes rich semantic information, and self-attention can establish long-range dependencies between pixels globally, accurately capturing the spatial correspondence of periodically repeating textures (such as arrayed pads and parallel traces) in the PCB image. If self-attention is introduced into the full-resolution or shallow feature map, the computational complexity will increase quadratically, and shallow features lack semantic information, making it difficult for attention to converge to meaningful correspondences. Therefore, the "downsampling + deep self-attention" design of this invention is an integrated technical solution after comprehensive consideration.

[0074] Leveraging the powerful generative capabilities of the flow matching diffusion model, complex non-rigid deformations between PCB images can be accurately modeled, achieving sub-pixel-level alignment accuracy. Specifically, this invention combines U-Net's multi-level downsampling with a deep feature map self-attention mechanism—downsampling provides self-attention with a global perspective and acceptable computational complexity, while self-attention establishes accurate long-range correspondences for the downsampled semantic features—the synergistic effect of both significantly improves the registration accuracy for periodically repeating PCB structures, thus providing a more reliable registration basis for subsequent defect detection.

[0075] In another embodiment, the Transformer architecture can be used to replace the deep parts of U-Net, and the SwingTransformer module can be used to capture context information across windows, further improving the ability to model non-rigid deformations.

[0076] (2) Time step embedding and fusion continuous time steps After sinusoidal positional encoding and Gaussian frequency encoding, the data is mapped to an embedding vector via a multilayer perceptron (MLP). This embedding vector is then injected into each layer of the encoder and decoder using Adaptive Instance Normalization (AdaIN), dynamically modulating feature statistics so that the network can adjust its behavior according to the streaming time steps.

[0077] Specifically, the AdaIN operation is defined as follows: in, and Obtained by linear transformation of time-step embedding. and Feature maps The channel mean and standard deviation.

[0078] (3) Deformation Flow Decoder The decoder upsamples through transposed convolutions (4×4 kernel, stride 2) and fuses them with features from the corresponding layer of the encoder via skip connections. The decoder finally outputs a 2-channel dense displacement field. Adding this displacement field to a preset identity grid yields the preliminary deformation field: S3: Application of symmetry constraints and acquisition of two-way deformation field To achieve symmetric (inversely consistent) registration, this invention does not independently predict the forward and backward deformation fields, but instead achieves this through parameter sharing and input exchange mechanisms, and applies a cyclic consistency loss.

[0079] (1) Parameter sharing Using the same network To predict bidirectional deformation. The forward deformation field is obtained through... The backward deformation field is calculated by changing the input order. This design forces the network to learn a bidirectionally consistent deformation representation.

[0080] (2) Cyclic consistency constraint Define a cycle consistency loss function To ensure the forward deformation field With backward deformation field The composite transformation is approximately equivalent to the identity transformation. Specifically: in, This represents the composite operation of the deformation field. This loss constrains the network during training so that its predicted deformation fields satisfy inverse consistency at the pixel level.

[0081] In another embodiment, a symmetric KL divergence constraint can be used instead of the L1 loss to better handle the uncertain regions in the deformation field. Specifically, the deformation field is modeled as a Gaussian distribution, and the KL divergence between the forward and backward distributions is minimized.

[0082] S4: Semi-supervised training strategy To make full use of the large number of unlabeled PCB images that are readily available in industrial settings, this invention adopts a semi-supervised training strategy, and its total loss function is composed of a weighted average of supervised loss and unsupervised loss.

[0083] (1) Supervised loss (for labeled image pairs) When the input image has labels with real deformation fields When using flow matching loss This drives the network to predict vector fields that approximate the vector field. The optimal transmission path with the destination as the destination. Stream matching loss is defined as: , Simultaneously, it incorporates supervised cycle consistency loss. Smoothness regularization loss (Punishment for the drastic gradient of the deformation field): (2) Unsupervised loss (for unlabeled image pairs) Loss of photometric uniformity Assuming the aligned images should have similar intensities, minimize the L1 distance between the image warped by the deformation field and the target image: Stability Consistency Loss Apply random brightness / contrast adjustments and small translations (±2 pixels) to the unlabeled input, requiring the network to maintain stable flow vectors predicted for both the original and augmented images. in This indicates a data augmentation operation.

[0084] Unsupervised cycle consistency loss Similar to the cycle consistency loss in S3, but used for unlabeled data, it serves as a powerful self-supervised signal.

[0085] (3) Gradual weight adjustment mechanism In the initial training phase, the focus is on supervised loss to establish basic alignment capabilities; as training progresses, the weight of unsupervised loss is gradually increased. The total loss function is: in, Gradually increasing from 0 to 1.0, Correspondingly, it gradually decreased from 1.0 to 0.5.

[0086] In another embodiment, a Mean Teacher framework can be used for semi-supervised learning, where the parameters of the teacher model are the exponential moving average (EMA) of the student model parameters, and consistency loss is used to constrain the student model to make consistent predictions with the teacher model.

[0087] S5: Efficient single-step reasoning and image transformation.

[0088] After training, no iterative sampling is required during the inference phase. For the image pairs to be registered... The network only needs to propagate forward once. Specifically, take (Also acceptable) ),calculate The final forward deformation field is obtained directly. Similarly, by changing the input order, the backward deformation field can be obtained. Finally, the spatial transformer (STN) is used to transform the moving image based on the predicted deformation field. Resampling is performed to obtain the template Precisely aligned registered images .

[0089] In another preferred embodiment, the inherent symmetry prior of the circuit board is explicitly introduced when generating the initial deformation field. The symmetry prior is a geometric prior inherent in the circuit board, such as axially symmetrical layout features or rotationally symmetrical layout features about its center. Symmetry priors include axisymmetric priors (e.g., for a rectangular PCB, symmetry about the horizontal and vertical midlines) and centrosymmetric priors (e.g., symmetry about the center point for a circular or square PCB). This symmetry prior is then encoded to obtain a prior feature map. It is then fused with the conditional input in the channel dimension, and the fused feature input stream is matched with the diffusion model.

[0090] Specifically, for axisymmetric priors, a binary symmetric mask is constructed. The position of each pixel The value indicates whether the symmetrical position relative to the axis of symmetry is located within the effective area of ​​the image. This mask is stitched with image features to guide the network to focus on symmetrical structures. Experiments show that explicitly introducing symmetry priors can significantly improve registration accuracy, especially for high-density PCBs with repeating units and mirror-symmetric layouts.

[0091] This invention leverages the powerful generative capabilities of the flow-matching diffusion model to accurately model complex non-rigid deformations between PCB images, achieving sub-pixel-level alignment accuracy (experiments show that the average registration error can be controlled within 0.3 pixels on typical PCB datasets), thus providing a reliable foundation for subsequent defect detection. By constraining the deformation field at the probabilistic flow level through cyclic consistency loss, strict inverse consistency between forward and backward transformations is ensured, eliminating biases in unidirectional registration. The single-step inference mechanism based on flow matching improves inference speed by more than two orders of magnitude compared to traditional iterative optimization methods and standard diffusion models requiring multiple sampling steps (typically 50-100 steps). On an NVIDIA V100 GPU, processing a pair of 256×256 images takes only about 15 milliseconds, fully meeting the real-time requirements of industrial online inspection (typically requiring 30-50 frames per second). The semi-supervised training strategy can simultaneously utilize a small amount of valuable labeled data and a massive amount of unlabeled production line images. Experiments show that only about 5% of the labeled data is needed to achieve the same accuracy as fully supervised training, which significantly reduces the reliance on expensive manual annotation and improves the practicality and generalization ability of the method in data-scarce industrial scenarios.

[0092] This invention constructs an end-to-end registration framework based on a flow matching diffusion model and innovatively introduces cyclic consistency symmetry constraints and semi-supervised training strategies, achieving an organic unity of high precision, high efficiency, strong symmetry, and low annotation dependence in printed circuit board image registration tasks.

[0093] This embodiment provides a symmetric constraint registration method for circuit board images based on a flow matching diffusion model, including the following steps: Data Acquisition and Preprocessing. A batch of PCB image data, comprising 10,000 pairs, was acquired from the AOI equipment. 500 pairs were manually annotated by professionals using annotation tools (such as ITK-SNAP) to obtain dense deformation fields (sparse control point interpolation yielded dense deformation fields), and were thus labeled data. The remaining 9,500 pairs were treated as unlabeled data. All images were uniformly sized to 256×256 pixels, and after grayscale conversion, their intensity was normalized to the [-1, 1] range.

[0094] A flow-matching diffusion model is constructed using the U-Net architecture. The encoder contains four downsampling blocks, each containing two convolutional layers (3×3, 64 channels) and one convolutional downsampling layer with a stride of 2. A 4-head self-attention module is added after the 1 / 8 resolution layer (32×32 feature map) and the 1 / 16 resolution layer (16×16 feature map). The decoder contains four upsampling blocks, each containing one transposed convolutional layer (4×4, stride 2) and two convolutional layers (3×3). At time step t, a 128-dimensional vector is mapped using sinusoidal positional encoding, then passed through three MLP layers (128→256→512) to obtain the embedding vector, which is then injected into each convolutional layer of the encoder and decoder using AdaIN.

[0095] Training the model. The Adam optimizer was used with an initial learning rate of 1e-4 and weight decay of 1e-5. The batch size was set to 16 (4 pairs of labeled images and 12 pairs of unlabeled images). The total number of training epochs was 200. A progressive weight adjustment mechanism was used: for the first 50 epochs, λ... unsup =0, using only supervised loss; 50-100 rounds, λ unsup Linearly increases to 0.5; 100-150 rounds, λ unsup Increase to 0.8; 150-200 rounds, λ unsup =1.0. Supervised loss weight λ sup Accordingly, it decreases linearly from 1.0 in the first 50 rounds to 0.5 in the last 50 rounds.

[0096] Inference and Registration. Load the trained model parameters. For the image pair to be registered, set t=0.5 and perform one forward propagation to obtain the deformation field φ_F→M. Resample the moving image I_M using bilinear interpolation and output the registered image. On the test set, the average registration time is 12.5 ms / pair, and the average registration error (target registration error TRE) is 0.28 pixels.

[0097] This embodiment is basically the same as the above embodiment, except that the axisymmetric prior of the circuit board is explicitly introduced. Specifically: For each PCB template image, extract the symmetry axis position based on its design file (Gerber file). Assume the PCB is rectangular with a vertical centerline x = W / 2 and a horizontal centerline y = H / 2. Construct a symmetric mask M. sym ∈{0,1} H×W M sym (x,y)=1 indicates that the point (x,y) symmetrical about the vertical midline (2·(W / 2)-x,y) lies within the image, and the point (x,2·(H / 2)-y) symmetrical about the horizontal midline also lies within the image. This symmetrical mask is concatenated as an additional channel with the conditional input to form a 4-channel input [I F ;I M M sym ].

[0098] Experimental results show that by introducing a symmetric prior, the registration error on PCBs with symmetrical layouts (such as memory modules and graphics cards) is reduced from 0.28 pixels to 0.23 pixels, which greatly reduces the symmetry preservation error.

[0099] This embodiment illustrates an alternative implementation using Transformer instead of U-Net. This embodiment is essentially the same as the previous embodiments, differing only in the architecture of the flow matching diffusion model. Specifically, the Swing Transformer is used as the backbone network: The input image is divided into 4×4 patches, and the initial feature sequence is obtained through linear embedding.

[0100] Four Swing Transformer Block stages are stacked, each containing two consecutive Swing modules (one using window attention and one using shifted window attention), accompanied by a downsampling layer (patch merging) to reduce resolution.

[0101] The decoder employs a symmetrical Swing Transformer Block structure, upsampling through patch expanding and fusing with encoder features through skip connections.

[0102] The time step embedding is injected via AdaIN after the layer normalization of each Transformer Block.

[0103] The advantage of using the Transformer architecture is its ability to capture global context dependencies, resulting in better registration performance for flexible PCBs (FPCs) with large-scale non-rigid deformation. This embodiment is suitable for scenarios with extremely high accuracy requirements but relatively relaxed real-time requirements.

[0104] This embodiment illustrates a semi-supervised learning approach using Mean Teacher as an alternative implementation method. This embodiment is essentially the same as the previous embodiments, except that the semi-supervised training strategy employs the Mean Teacher framework. Maintain two models: student model θ and teacher model θ'.

[0105] The teacher model parameters are the exponential moving average of the student model parameters: θ' k =α·θ' {k-1} +(1-α)·θ k , where α is 0.999.

[0106] For labeled data, the student model is updated using supervised loss (flow matching loss + cycle consistency loss + smoothing loss).

[0107] For unlabeled data, apply two different data augmentations (e.g., random rotation ±5°, random scaling ±2%) to the same input, input them into the student model and the teacher model respectively, and calculate the consistency loss: .

[0108] The total loss is the weighted sum of supervised loss and consistency loss.

[0109] The Mean Teacher framework is generally more stable than progressive weight adjustment mechanisms, especially when there are differences in the distribution of unlabeled and labeled data. Experiments show that using the Mean Teacher framework, only 200 pairs of labeled data (2% labeling ratio) are needed to achieve accuracy similar to that of fully supervised learning.

[0110] This embodiment illustrates an alternative implementation for multi-scale deformation field prediction. This embodiment is essentially the same as the previous embodiments, except that the decoder outputs deformation fields at multiple resolutions, and a coarse-to-fine registration strategy is used: The decoder outputs deformation fields φ_1, φ_2, and φ_3 at 1 / 4, 1 / 2, and full resolution, respectively.

[0111] During training, the corresponding loss is calculated for the deformation field at each scale, and the total loss is the sum of the losses at each scale.

[0112] During inference, a coarse-scale deformation field φ_1 is first applied, and then fine-tuning is performed using fine deformation fields φ_2 and φ_3 based on the coarse registration.

[0113] Multi-scale strategies can better handle large overall offsets and fine local deformations, and are particularly suitable for situations where overall PCB offsets and local component warping coexist. On datasets containing significant overall offsets (>20 pixels), the registration error using a single-scale method is 0.52 pixels, while the multi-scale method can reduce it to 0.31 pixels.

[0114] According to embodiments of the present invention, a computer-readable storage medium is also provided, on which a computer program is stored. When executed by a processor, the computer program implements the circuit board image registration method described in any of the above technical solutions. The registration method described in this invention is essentially a series of executable computational steps and algorithmic flows. These steps are solidified into computer program code and stored in various media. Users can completely reproduce the registration method of this invention on any compatible computing device by reading the medium and executing the program, without needing to understand complex algorithmic details or retrain the model. This solidifies the technical solution of this invention into a reproducible, distributable, and deployable product form, facilitating industrial replication and large-scale deployment in industrial scenarios.

[0115] An embodiment of the present invention also provides an electronic device, including a processor and a memory, wherein a computer program is stored in the memory, and when the processor executes the computer program, it implements the circuit board image registration method described in any of the above technical solutions.

[0116] This invention constructs an end-to-end registration framework based on a flow matching diffusion model and innovatively introduces cyclic consistency symmetry constraints and semi-supervised training strategies, achieving an organic unity of high precision, high efficiency, strong symmetry, and low annotation dependence in printed circuit board image registration tasks.

[0117] It should be noted that although the steps in the above embodiments are described in a specific order, those skilled in the art will understand that in order to achieve the effect of this application, different steps do not necessarily have to be executed in such an order. They can be executed simultaneously (in parallel) or in other orders. These adjusted solutions are equivalent to the technical solutions described in this application and therefore will also fall within the protection scope of this application.

[0118] Those skilled in the art will understand that all or part of the processes in the method of the above-described embodiment can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable file, or some intermediate form. The computer-readable storage medium can include any entity or device capable of carrying the computer program code, a medium, a USB flash drive, a portable hard drive, a magnetic disk, an optical disk, a computer memory, a read-only memory, a random access memory, an electrical carrier signal, a telecommunication signal, and a software distribution medium, etc.

[0119] The technical solution of this application has been described above with reference to one embodiment shown in the accompanying drawings. However, it will be readily understood by those skilled in the art that the scope of protection of this application is obviously not limited to these specific embodiments. Without departing from the principles of this application, those skilled in the art can make equivalent changes or substitutions to the relevant technical features, and the technical solutions after these changes or substitutions will all fall within the scope of protection of this application.

Claims

1. A circuit board image registration method, characterized in that, include: The standard template image of the circuit board and the actual image to be inspected are preprocessed and stitched along the channel dimension to form the conditional input; The conditions are input into the registration model, which generates a preliminary deformation field based on the flow matching diffusion model. The forward deformation field and the backward deformation field are obtained according to the preliminary deformation field and the parameter sharing and input exchange mechanism. The forward deformation field and the backward deformation field are subjected to inverse consistency constraints by cyclic consistency constraints to output a final deformation field that conforms to symmetry constraints. Based on the final deformation field, the actual image to be inspected is spatially aligned with the standard template image, and the registered image is output.

2. The circuit board image registration method according to claim 1, characterized in that, The registration model generates a preliminary deformation field based on a flow-matching diffusion model, including: Using the aforementioned input conditions and diffusion time step t as conditions, a probabilistic flow vector field is obtained through flow matching diffusion model regression. After encoding and decoding, a dense displacement field is output. The dense displacement field is then added to the identity grid to obtain the preliminary deformation field.

3. The circuit board image registration method according to claim 1, characterized in that, The registration model is trained based on the flow matching diffusion model by: using a semi-supervised training strategy to train the flow matching diffusion model with the final deformation field as the optimization target, thereby obtaining the trained registration model; When training the registration model, the flow matching diffusion model is optimized by using a total loss composed of supervised and unsupervised losses. The training process uses a progressive weight adjustment mechanism to gradually adjust the loss weights to obtain the trained registration model.

4. The circuit board image registration method according to claim 1, characterized in that, The flow matching diffusion model adopts an encoder-decoder architecture, including a feature encoder, a time-step embedding fusion module, and a deformable flow decoder; The feature encoder is a multi-level downsampling U-Net structure, which introduces a self-attention mechanism in the deep feature map at a preset resolution; The time-step embedding fusion module encodes the diffusion time steps to generate embedding vectors, and injects the embedding vectors into each layer of the encoder-decoder architecture through adaptive instance normalization. The deformable stream decoder employs transposed convolutional upsampling and performs skip connections to fuse it with the corresponding layer features of the encoder in the encoder-decoder architecture.

5. The circuit board image registration method according to claim 4, characterized in that, The deep feature maps with the preset resolution include feature maps with a resolution of 1 / 8 of the original image resolution and feature maps with a resolution of 1 / 16 of the original image resolution. The self-attention mechanism is introduced only in the third-level output feature maps and the fourth-level output feature maps of the multi-level downsampling U-Net structure.

6. The circuit board image registration method according to claim 1, characterized in that, The parameter sharing and input exchange mechanism is as follows: using the same flow matching diffusion model, the conditional input and the conditional input after the input order is exchanged are processed respectively to obtain the forward deformation field and the backward deformation field.

7. The circuit board image registration method according to claim 1, characterized in that, The cyclic consistency constraint is achieved through cyclic consistency loss. Using the cyclic consistency loss, the composite transformation formed by the superposition of the forward deformation field and the backward deformation field is constrained to approach the identity transformation.

8. The circuit board image registration method according to claim 3, characterized in that, The semi-supervised training strategy includes: A total loss function containing both supervised and unsupervised loss is constructed, and the network parameters of the flow matching diffusion model are iteratively optimized with the final deformation field as the optimization objective. The supervised loss is applied to image pairs labeled with the true deformation field, while the unsupervised loss is applied to unlabeled image pairs.

9. The circuit board image registration method according to claim 8, characterized in that, The supervised loss includes flow matching loss, supervised cycle consistency loss, and smoothness regularization loss, while the unsupervised loss includes photometric consistency loss, stability consistency loss, and unsupervised cycle consistency loss.

10. The circuit board image registration method according to claim 8, characterized in that, The training process uses a progressive weight adjustment mechanism to gradually adjust the loss weights. This includes setting the weight of the unsupervised loss to zero and using only the supervised loss in the early stages of training, gradually increasing the weight of the unsupervised loss to 1.0 as the training iterates, and correspondingly decreasing the weight of the supervised loss from 1.0 to 0.

5. During the inference phase, a fixed diffusion time step t=0.5 is performed, a single forward propagation is executed to obtain the final deformation field, and image spatial alignment is completed through a spatial transformation network.

11. The circuit board image registration method according to any one of claims 1 to 10, characterized in that, When generating the initial deformation field, the inherent symmetry prior of the circuit board is explicitly introduced; The symmetric priors include axisymmetric priors and centrally symmetric priors; The symmetric prior is encoded to obtain prior features, which are then fused with the conditional input in the channel dimension. The fused features are then input into the flow matching diffusion model.

12. The circuit board image registration method according to any one of claims 1 to 10, characterized in that, When forming the conditional input, the effective area masks corresponding to the standard template image and the actual image to be inspected are also stitched and fused with the preprocessed standard template image and the actual image to be inspected in the channel dimension to form the conditional input. Then, the flow matching diffusion model is input. The effective area mask is used to identify the effective area where the circuit board lines, pads and components are located, so that the flow matching diffusion model performs registration operation on the effective area.

13. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the circuit board image registration method according to any one of claims 1-12.

14. An electronic device, characterized in that, It includes a processor and a memory, wherein the memory stores a computer program, and when the processor executes the computer program, it implements the circuit board image registration method according to any one of claims 1-12.