Data set construction method and device, model training method and device and anomaly detection method and device

By using image segmentation model and geometric transformation operations to generate negative sample images, the problem of difficulty in obtaining negative sample images in the prior art is solved, and the construction efficiency of the anomaly detection data set and the detection performance of the model are improved.

CN120147773APending Publication Date: 2025-06-13GD MIDEA AIR CONDITIONING EQUIP CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510089149.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-20
Publication Date
2025-06-13

AI Technical Summary

Technical Problem

In the prior art, abnormality detection methods for electronic components and circuit boards rely on manual visual inspection or simple image processing, are inefficient, have insufficient accuracy, and are costly to acquire negative sample images and are difficult to cover all possible defect types.

Method used

By acquiring positive sample images, a mask image is obtained using the image segmentation model, and a geometric transformation operation is performed to generate negative sample images, and an abnormality detection data set is constructed. This method does not require additional annotation or preprocessing, and directly generates negative sample images using positive sample images.

Benefits of technology

Improve the efficiency of data set construction, and automatically generate negative samples to avoid the tedious steps of manual annotation or finding actual defect samples, improving the detection performance and accuracy of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120147773A_ABST
    Figure CN120147773A_ABST
Patent Text Reader

Abstract

The invention provides a data set construction, model training and anomaly detection method and device, and belongs to the technical field of artificial intelligence, and the method comprises the steps: inputting a positive sample image into an image segmentation model, and obtaining a mask image outputted by the image segmentation model, and performing geometric transformation operation on the mask image to obtain a newly added mask image, and replacing any mask image in the sample image to generate a negative image sample. According to the method, the mask image is obtained by using the image segmentation model, the mask image is subjected to geometric transformation to generate the negative sample image, the anomaly detection data set is finally constructed, the negative sample image is generated by directly using the positive sample image, additional labeling or preprocessing is not needed, the data set construction efficiency is improved, and the detection accuracy is improved. The process of automatically generating the negative samples avoids the tedious step of manually marking or searching actual defect samples in a traditional method, the efficiency is further improved, the representativeness and practicability of the data set are enhanced, and improvement of the detection performance and accuracy of the model is facilitated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and particularly relates to a method and device for dataset construction, model training, and anomaly detection. Background Art

[0002] In the field of electronic manufacturing, the quality inspection of electronic components and circuit boards is of crucial importance. Accurately identifying whether a component or circuit board is qualified has a direct impact on ensuring product quality and production efficiency. However, constructing an effective anomaly detection dataset is one of the key challenges for achieving high-precision detection. Positive sample images (images of qualified electronic components or circuit boards) are relatively easy to obtain, but the generation of negative sample images (images containing defects) is more difficult and requires diversification to cover various possible defect situations.

[0003] Currently, some detection methods mainly rely on manual visual inspection or simple image processing techniques, which have problems such as low efficiency, insufficient accuracy, and difficulty in dealing with complex defects. When constructing a dataset, a large number of negative sample images are usually required, but the acquisition cost of these images is high and it is difficult to cover all possible defect types. In addition, existing dataset construction methods often lack systematicness and diversity, resulting in insufficient generalization ability of the trained models.

[0004] In the prior art, the method for generating negative sample images is relatively single, usually relying on defect samples collected in actual production, which is not only time-consuming and laborious, but also difficult to cover all possible defect types. In addition, the negative sample images generated by existing methods lack diversity, resulting in a significant decline in the detection performance of the trained models when facing new and unseen defects. Summary of the Invention

[0005] The present invention provides a method and device for dataset construction, model training, and anomaly detection, so as to solve the defect of difficult collection of negative sample images in the current method of constructing a dataset by online acquisition.

[0006] The present invention provides a method for dataset construction, including the following steps: Obtain a positive sample image set, where the positive sample images in the positive sample image set are obtained by photographing qualified electronic components or qualified circuit boards; Input the positive sample images into an image segmentation model to obtain a mask image output by the image segmentation model, where the mask image is a local image of the area where each electronic component body is located in the positive sample image; Perform a geometric transformation operation on any one of the mask images to obtain a new mask image, and use the new mask image to replace the any one of the mask images in the positive sample image to generate a negative image sample; Repeat the step of performing geometric transformation on any mask image to obtain a new mask image and then generating a negative image sample until the negative sample image set is constructed completely; Construct an anomaly detection data set by using the positive sample image set and the negative sample image set.

[0007] According to a data set construction method provided by the present invention, the obtaining of a new mask image after performing geometric transformation on any mask image includes: Determine an operation mode for performing geometric transformation on any mask image according to the component attributes of the electronic components related to any mask image; Wherein, the component attributes include at least one of shape attribute, size attribute, function attribute and layout attribute; the geometric transformation operation includes one or a combination of rotation operation, translation operation and scaling operation.

[0008] According to a data set construction method provided by the present invention, the image segmentation model is obtained by training an initial segmentation model with a general data set and then performing fine-tuning training with historical positive sample images and historical negative sample images with mask image labels; before training the initial segmentation model with the general data set, it further includes normalizing the image samples in the general data set according to the image input requirements of the initial segmentation model.

[0009] According to a data set construction method provided by the present invention, the generation method of the negative image sample further includes: Adjust the color of any positive sample image or any negative image sample to generate a new negative image sample; The color adjustment includes changing at least one of brightness, contrast, color temperature and saturation.

[0010] The present invention also provides a model training method, including the following steps: Construct an anomaly detection data set based on any one of the above data set construction methods; Train a feature extractor with the anomaly detection data set to obtain an image recognition model for determining whether a target to be measured is abnormal based on the recognition result of an input image; The target to be measured is an electronic component or a circuit board, and the input image is obtained by photographing the electronic component or the circuit board.

[0011] According to the model training method provided by the present invention, the feature extractor is constructed based on a siamese network model, and the siamese network model is composed of two sub-network models with shared weights; The training of the feature extractor with the anomaly detection data set includes: Based on the positive image samples and negative image samples in the anomaly detection dataset, generate multiple groups of positive sample pairs and multiple groups of negative sample pairs, and set labels for each of the positive sample pairs and each of the negative sample pairs; Input any one of the positive sample pairs or any one of the negative sample pairs into the feature extractor to obtain two feature vectors output by the sub-network model, so as to determine the feature distance between the two feature vectors; Based on the loss value of the feature distance, adjust the network parameters of the feature extractor; Iteratively execute the steps of inputting any one of the positive sample pairs or any one of the negative sample pairs into the feature extractor to adjusting the network parameters of the feature extractor until the model convergence condition is reached; The positive sample pair is composed of two randomly selected positive image samples, and the negative sample pair is composed of one randomly selected negative image sample and one positive image sample.

[0012] According to the model training method provided by the present invention, the model convergence condition is that the feature distance of the positive sample pair is greater than a first preset threshold and the feature distance of the negative sample pair is greater than a second preset threshold.

[0013] The present invention also provides an anomaly detection method, including the following steps: Collect an image of the target to be measured as an input image and input it into the image recognition model to obtain a feature vector to be measured output by the image recognition model, and the image recognition model is obtained based on any one of the above model training methods; Match the feature vector to be measured with the feature vector templates in the pre-constructed feature vector library to determine whether the target to be measured is abnormal according to the matching result; The target to be measured is an electronic component or a circuit board, and the feature vector templates are generated by using the image recognition model to extract features from different positive sample images and negative sample images. Each feature vector template corresponding to the negative sample image is labeled with a defect type label, and each feature vector template corresponding to the positive sample image is labeled with a normal label.

[0014] According to the anomaly detection method provided by the present invention, the matching the feature vector to be measured with the feature vector templates in the pre-constructed feature vector library to determine whether the target to be measured is abnormal includes: Obtain the feature distance between the feature vector to be measured and each feature vector template in the feature vector library; If the maximum feature distance among all the feature distances is less than the preset distance threshold, determine whether the target to be measured is abnormal according to the label of the feature vector template corresponding to the maximum feature distance.

[0015] According to the anomaly detection method provided by the present invention, if the maximum feature distance among all the feature distances is greater than or equal to the preset distance threshold, the to-be-detected feature vector is added to the feature vector library as a new feature vector template, and a label is assigned to the new feature vector template.

[0016] The present invention also provides a dataset construction device, mainly including: A sample collection unit for obtaining a set of positive sample images, where the positive sample images in the set of positive sample images are obtained by photographing qualified electronic components or qualified circuit boards; An image segmentation unit for inputting the positive sample image into an image segmentation model to obtain a mask image output by the image segmentation model, where the mask image is a local image of the region where each electronic component body is located in the positive sample image; An image processing unit for performing a geometric transformation operation on any mask image to obtain a new mask image, so as to replace the any mask image in the positive sample image with the new mask image to generate a negative image sample; An iteration control unit for controlling the repeated execution of the step of performing a geometric transformation operation on any mask image to obtain a new mask image until the negative sample image set is constructed; to construct an anomaly detection dataset by using the set of positive sample images and the set of negative sample images.

[0017] The present invention also provides a model training device, mainly including: A sample calling unit for obtaining an anomaly detection dataset constructed based on any one of the above dataset construction methods; A training control unit for training a feature extractor by using the anomaly detection dataset to obtain an image recognition model for determining whether a to-be-detected target is abnormal based on the recognition result of an input image; The to-be-detected target is an electronic component or a circuit board, and the input image is obtained by photographing the electronic component or the circuit board.

[0018] The present invention also provides an anomaly detection device, mainly including: An image acquisition unit for collecting an image of a to-be-detected target as an input image and inputting it into an image recognition model to obtain a to-be-detected feature vector output by the image recognition model, where the image recognition model is obtained based on any one of the above model training methods; A detection decision unit for matching the to-be-detected feature vector with a feature vector template in a pre-constructed feature vector library to determine whether the to-be-detected target is abnormal according to the matching result; The target to be measured is an electronic component or a circuit board. The feature vector template is generated by extracting features from different positive sample images and negative sample images using the image recognition model. Each feature vector template corresponding to a negative sample image is labeled with a defect type label, and each feature vector template corresponding to a positive sample image is labeled with a normal label.

[0019] The dataset construction, model training, anomaly detection methods and devices provided by the present invention use an image segmentation model to obtain a mask image, perform geometric transformation on the mask image to generate negative sample images, and finally construct an anomaly detection dataset. Negative sample images are directly generated using positive sample images without additional annotation or preprocessing, improving the efficiency of dataset construction. The process of automatically generating negative samples avoids the cumbersome steps of manual annotation or finding actual defect samples in traditional methods, further improving the efficiency, enhancing the representativeness and practicality of the dataset, and contributing to improving the detection performance and accuracy of the model. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or related technologies, the following will briefly introduce the drawings required for use in the description of the embodiments or related technologies. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0021] Figure 1 is a flowchart of the dataset construction method provided by the present invention.

[0022] Figure 2 is a flowchart of the model training method provided by the present invention.

[0023] Figure 3 is a flowchart of the anomaly detection method provided by the present invention.

[0024] Figure 4 is a schematic structural diagram of the dataset construction device provided by the present invention.

[0025] Figure 5 is a schematic structural diagram of the model training device provided by the present invention.

[0026] Figure 6 is a schematic structural diagram of the anomaly detection device provided by the present invention.

[0027] Figure 7 is a schematic structural diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0028] To make the objectives, technical solutions and advantages of the present invention clearer, the technical solutions in the present invention will be clearly and completely described below with reference to the accompanying drawings in the present invention. Apparently, the described embodiments are some but not all of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present invention without any creative work fall within the scope of protection of the present invention.

[0029] It should be noted that in the description of the present invention, the terms "comprise", "include" or any other variation thereof are intended to cover non-exclusive inclusion, such that a process, method, article or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the phrase "comprising a..." does not exclude the presence of additional identical elements in the process, method, article or device comprising the element. The orientation or positional relationship indicated by terms such as "upper", "lower", etc. is based on the orientation or positional relationship shown in the drawings, and is only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operate in a specific orientation, and thus should not be construed as a limitation on the present invention. Unless otherwise clearly specified and limited, the terms "mount", "connect" and "couple" should be understood in a broad sense. For example, it may be a fixed connection, a detachable connection or an integral connection; it may be a mechanical connection or an electrical connection; it may be a direct connection or an indirect connection through an intermediate medium, and it may be the internal communication of two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0030] The terms "first", "second", etc. in the present invention are used to distinguish similar objects and are not used to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present invention can be implemented in an order other than those illustrated or described herein, and the objects distinguished by "first", "second", etc. are generally of the same type and do not limit the number of objects. For example, the first object may be one or more.

[0031] In the vision-based plug-in detection of printed circuit boards (PCBs) by automatic optical inspection (AOI), it mainly involves the polarity recognition of electronic components such as capacitors, diodes, and sockets, as well as the detection of installation compliance (such as whether there is a dry joint, abnormal connection of solder joints, etc.) and other related defects. Due to the influence of various factors such as the non-uniform production of different electronic component manufacturers and PCB manufacturers, lighting, and a large number of detection items, there are significant problems with the detection accuracy and detection stability of traditional image recognition methods.

[0032] To solve this problem, currently, traditional supervised artificial intelligence models are also used to identify relevant abnormalities, and generally, the recognition stability has been significantly improved compared to traditional manual inspection. However, when using this method for fault detection, there are restrictions in the difficult collection of negative sample images, and the detection ability for unknown types of defects is not strong.

[0033] The following combines Figures 1-6 to describe the dataset construction, model training, anomaly detection methods and their devices provided by the present invention, which can solve the related problems existing in the prior art to a certain extent.

[0034] Figure 1 is a schematic flowchart of the dataset construction method provided by the present invention, as Figure 1 shown, including but not limited to the following steps: Step 101, obtain a positive sample image set.

[0035] Among them, the positive sample images in the positive sample image set are obtained by photographing qualified electronic components or qualified circuit boards.

[0036] Specifically, the present invention first collects a set of images of qualified electronic components or circuit boards, and these images are used as positive sample images to construct a positive sample image set. These positive sample images can be obtained by photographing with a high-resolution camera under standard lighting conditions to ensure that the images are clear, noise-free, and can accurately reflect the normal state of electronic components or circuit boards.

[0037] For example, 1000 qualified PCB board images and 500 qualified electronic component images can be randomly selected from the production line to form a positive sample image set.

[0038] Step 102, input the positive sample images into an image segmentation model to obtain the mask images output by the image segmentation model.

[0039] Among them, the mask images are local images of the regions where the main bodies of the electronic components are located in the positive sample images.

[0040] Input each collected positive sample image into the pre-trained image segmentation model. The image segmentation model can be a deep learning-based convolutional neural network (such as U-Net, Mask R-CNN, etc.), which has been pre-trained on a general image segmentation dataset and fine-tuned with a small number of labeled electronic component or circuit board images to adapt to a specific electronic manufacturing scenario.

[0041] After receiving any positive sample image, the image segmentation model identifies and outputs a mask image, that is, a local image of the region where each electronic component body is located in the positive sample image.

[0042] The mask image is a binary image, where the pixel value of the region where the electronic component body is located can be 1 (or 255), and the pixel value of the background region is set to 0. For example, for a PCB board image containing multiple resistors and capacitors, the image segmentation model can accurately identify the contours of each resistor and each capacitor, and correspondingly crop the corresponding mask image in the positive sample image.

[0043] Step 103, perform a geometric transformation operation on any mask image to obtain a new mask image, and use the new mask image to replace the any mask image in the positive sample image to generate a negative image sample.

[0044] Select any mask image from all the obtained mask images and perform a geometric transformation operation on it to generate a new mask image. The geometric transformation operations include but are not limited to operations such as rotation, translation, and scaling. The specific operation method can be determined according to the component attributes (such as shape, size, function, and layout) of the electronic components related to the mask image. For example, for a long strip-shaped resistor, it can be rotated by 90°, 180°, or 270°; for a circular capacitor, it can be translated in any direction, and the translation distance is 1 / 4 to 1 / 2 of its diameter.

[0045] Through these geometric transformation operations, a new mask image is generated, and the new mask image is used to replace the corresponding mask image in the original positive sample image, thereby generating negative image samples. These negative image samples simulate various position, direction, and size errors that electronic components may occur in actual production, increasing the diversity of the dataset. In this way, multiple different negative image samples can be generated for any mask image.

[0046] Step 104, repeat the steps from performing a geometric transformation operation on any mask image to obtaining a new mask image to generating the negative image sample until the negative sample image set is constructed.

[0047] Repeat the geometric transformation operation and the negative sample generation process in step 103 until the negative sample image set is constructed. According to the actual required scale of the negative sample image set, negative samples equal to or more than the number of positive sample images can be generated. For example, 1000 negative sample images are generated to jointly form a data set with 1000 positive sample images. Or, negative sample images are generated according to a preset ratio, such as 1000 negative sample images corresponding to 10,000 positive sample images.

[0048] Step 105, construct an anomaly detection data set by using the positive sample image set and the negative sample image set.

[0049] Finally, combine the positive sample image set obtained in step 101 and the negative sample image set generated in step 104 to construct a complete anomaly detection data set.

[0050] This anomaly detection data set contains positive and negative sample images and can be used to train and evaluate an anomaly detection model. The data set constructed in this way not only covers the normal states of electronic components or circuit boards, but also includes various possible abnormal states, providing rich and diverse data support for model training and helping to improve the generalization ability and detection accuracy of the model.

[0051] Taking the construction of an anomaly detection data set for PCB board detection as an example, the above steps are described in detail as follows: Step 1, collect 1000 qualified PCB board images from the PCB production line to construct a positive sample image set.

[0052] Step 2, use the pre-trained U-Net model to segment each PCB board image to generate a mask image of the area where the main body of each electronic component is located.

[0053] Step 3, perform a geometric transformation on any mask image to generate a negative sample image. For example, select a mask image of a long-strip resistor, perform a 90° rotation operation on it to generate a new mask image, and replace the corresponding mask image in the original image to generate a negative sample image. It is also possible to translate it 10 pixels along its length direction to generate another new mask image, and replace the corresponding mask image in the original image to generate another negative sample image.

[0054] Step 4, repeat the above steps, perform relevant geometric transformations on different mask images to generate 1000 negative sample images.

[0055] Step 5, combine 1000 positive sample images and 1000 negative sample images to construct a complete anomaly detection data set.

[0056] The dataset construction method provided by the present invention uses an image segmentation model to obtain a mask image, performs geometric transformation on the mask image to generate a negative sample image, and finally constructs an anomaly detection dataset. It directly generates negative sample images from positive sample images without additional annotation or preprocessing, improving the efficiency of dataset construction. The process of automatically generating negative samples avoids the cumbersome steps of manual annotation or finding actual defective samples in traditional methods, further improving the efficiency, enhancing the representativeness and practicality of the dataset, and helping to improve the detection performance and accuracy of the model.

[0057] As an alternative embodiment, the above-mentioned geometric transformation operation on any mask image to obtain a new mask image specifically includes: Determine the operation method for performing the geometric transformation operation on the any mask image according to the component attributes of the electronic components related to the any mask image.

[0058] Different electronic components or different PCB boards may have different component attributes in actual applications. For example, there may be significant differences in the placement method on the PCB, the selection of models during design, and the role played in the entire circuit. The main purpose of performing geometric transformation operations on any mask image in the present invention is to generate negative sample images, thereby constructing a rich and diverse anomaly detection dataset. A rich and diverse dataset enables the trained model to better learn the feature differences between the normal and abnormal states of electronic components. The model can contact more negative sample images during the training process, enabling it to more accurately identify and classify various abnormal situations, thereby improving the generalization ability and detection accuracy of the model.

[0059] The new mask image generated through geometric transformation operations can simulate various changes in the position, orientation, and size that electronic components or PCB boards may encounter in actual production. This makes the generated negative sample images more diverse, covering more abnormal situations, thereby improving the representativeness and practicality of the anomaly detection dataset. By generating a diverse set of negative sample images and training the model, it can more accurately identify true abnormal situations in actual detection and reduce false positives. For example, it can not only distinguish a truly defective electronic component but also distinguish an electronic component with a normal structure but a different orientation, thereby improving the reliability of detection.

[0060] Specifically, the component attributes include at least one of shape attribute, size attribute, function attribute, and layout attribute; the geometric transformation operation includes one or a combination of rotation operation, translation operation, and scaling operation.

[0061] Among them, the shape attributes can be simply divided into regular shapes and irregular shapes (such as symmetric shapes and asymmetric shapes), and can also be further subdivided into circles, rectangles, sectors, trapezoids, etc. The present invention does not make specific limitations on this.

[0062] Taking the division into regular shapes and irregular shapes as an example, for components with regular shapes, such as circular capacitors and square resistors, rotation operations can be performed. The rotation angles can be set to common values such as 0°, 90°, 180°, 270°, etc. to simulate the placement of components in different directions.

[0063] For components with irregular shapes, such as special-shaped chips and inductors with special shapes, translation operations can be performed. The translation distance can be set to 1 / 4 to 1 / 2 of the length of the electronic component to simulate the placement of the electronic component in different positions, etc.

[0064] The size and shape can be simply divided into larger electronic components and smaller electronic components, and the corresponding thresholds can be set according to the actual detection scenario for division.

[0065] For larger components, such as large integrated circuit chips, scaling operations can be performed. The scaling ratio can be set to 0.8 to 1.2 to simulate the possible size deviations of components during the production process. For smaller components, such as chip resistors and chip capacitors, small-angle rotation or small-range translation operations can be performed. For example, the rotation angle can be set to -10° to 10°, and the translation distance can be set to 1 to 2 pixels to simulate the possible small position and direction changes of electronic components during the production process.

[0066] The function attributes can be simply divided into key function components, such as filter capacitors and core processors, and non-key function components, such as indicator lights and auxiliary capacitors. Slight translation or small-angle rotation operations can be performed on key function components. The translation distance can be set to 1 / 10 to 1 / 20 of the width of the component, and the rotation angle can be set to -5° to 5° to simulate the possible small displacements or rotations of electronic components during actual use. For non-key function components, larger-angle rotation or larger-range translation operations can be performed. The rotation angle can be set to -45° to 45°, and the translation distance can be set to 1 / 3 to 1 / 2 of the length of the component to generate more diverse negative sample data.

[0067] Layout attributes can be simply divided into edge components and internal components. For electronic components located at the edge of the PCB board, a translation operation towards the inside of the circuit board can be performed. The translation distance can be set to 1 / 2 to 2 / 3 of the distance between the component and the edge of the circuit board to simulate the possible position offset of the electronic component during the production process. For electronic components located inside the PCB board, a rotation operation can be performed. The rotation angle can be set to -30° to 30° to simulate the possible direction change of the electronic component during the production process.

[0068] Further, the step of generating a negative image sample by replacing any one of the mask images in the positive sample image with the newly added mask image can specifically be achieved by fusing a blank canvas with the original positive sample image, and then replacing the pixel values in the mask image area of the blank canvas with those in the corresponding area of the original positive sample image to generate the final negative sample image.

[0069] The dataset construction method provided by the present invention can flexibly select different geometric transformation operations according to the different component attributes of different electronic components, and can generate more diverse negative sample images. The model can encounter a wider range of abnormal situations during the training process. This enables the model to not only identify common defect types but also accurately identify some rare or unseen defect types, thereby improving the generalization ability of the model. By considering that in a production environment, the position, direction, and size of electronic components may change due to various factors (such as equipment accuracy, operation errors, etc.), diverse negative sample images can enable the model to better adapt to these changes and enhance the robustness of the model.

[0070] At the same time, selecting appropriate geometric transformation operations according to the different component attributes of electronic components can ensure that the generated negative sample images are closer to the actual production situation, avoiding blindly generating a large number of unrealistic negative sample images, improving the practicality and authenticity of the negative sample images, and affecting the training efficiency of the model.

[0071] As an optional embodiment, the image segmentation model is obtained by training an initial segmentation model using a general dataset and then performing fine-tuning training using historical positive sample images and historical negative sample images with mask image labels.

[0072] It should be noted that the mentioned image segmentation model is a key tool for constructing an anomaly detection dataset. Its training process is divided into two stages: first, training the initial segmentation model using a general dataset, and then fine-tuning the model using historical positive sample images and historical negative sample images with mask image labels. This phased training method aims to fully utilize the wide applicability of the general dataset and ensure that the model can accurately adapt to specific electronic component or circuit board image segmentation tasks.

[0073] The general dataset should contain rich and diverse images, covering different scenes, objects, and textures, so that the model can learn a wide range of feature representations. For example, open-source datasets such as ImageNet can be selected. The images in these datasets have a high degree of diversity and complexity and are suitable for pre-training segmentation models.

[0074] The initial segmentation model can be based on classical architectures in deep learning, such as U-Net, Mask R-CNN, or DeepLab, etc. Taking U-Net as an example, its network structure mainly consists of an encoder and a decoder. The encoder is used to extract high-level features of the image, and the decoder gradually restores the spatial resolution of the image, and finally outputs a segmentation mask with the same size as the input image.

[0075] Perform normalization processing on the images in the general dataset, including operations such as resizing the images and normalizing the pixel values, to adapt to the model input. For example, adjust all images to a unified size, such as 256×256 pixels, and normalize the pixel values to the range [0,1].

[0076] Input the preprocessed general dataset images into the initial segmentation model, calculate the predicted mask through forward propagation, and then use the loss function to calculate the loss value between the predicted mask and the ground truth mask. Subsequently, update the model parameters through backpropagation to continuously optimize the model performance. During the training process, multiple training epochs can be set, and the intermediate states of the model can be saved regularly for subsequent analysis and fine-tuning.

[0077] The historical positive sample images and historical negative sample images are from previous electronic component or PCB board detection projects. These images have obtained accurate mask image labels through manual annotation or previous detection processes. The positive sample images represent normal electronic components or circuit boards, while the negative sample images contain various types of defects or abnormalities.

[0078] Similar to the training stage of the general dataset, perform normalization processing on the historical sample images, including operations such as resizing the images and normalizing the pixel values, to keep them consistent with the preprocessing method of the general dataset and ensure that the model can smoothly receive and process these images.

[0079] Input the preprocessed historical sample images into the initial segmentation model, calculate the predicted mask through forward propagation, and then use the loss function to calculate the loss value between the predicted mask and the ground truth mask. Subsequently, update the model parameters through backpropagation to fine-tune the model and obtain the final image segmentation model.

[0080] As an alternative embodiment, the generation method of the negative image samples may further include: Adjust the color of any positive sample image or any negative image sample to generate a new negative image sample; The color adjustment includes changing at least one of brightness, contrast, color temperature, and saturation.

[0081] In order to further enrich the diversity of the negative sample image set, in addition to geometric transformation operations, the present invention can also perform color adjustment on any positive sample image or the generated negative sample image. The color adjustment includes changing at least one of brightness, contrast, color temperature, and saturation, and these adjustments can simulate the color changes of images under different lighting conditions, shooting devices, or post-processing.

[0082] These color adjustment operations can simulate the visual effects of images under various abnormal or extreme conditions, thereby creating image features significantly different from normal samples. These adjusted images are visually and statistically different from normal samples and can effectively serve as negative samples to help the model learn to distinguish normal from abnormal situations.

[0083] Taking the brightness adjustment of the sample image as an example, the intensity value of each pixel of a positive sample image can be subtracted by the average intensity value, then multiplied by 1.8, and then added with the average intensity value to generate an image with too high contrast; the intensity value of each pixel of another positive sample image can be subtracted by the average intensity value, then multiplied by 0.5, and then added with the average intensity value to generate an image with too low contrast. These adjusted images as negative sample images can enhance the robustness of the model to contrast changes.

[0084] The diversity of the negative sample image set can also be further enhanced by performing color adjustment on the local areas of any positive sample image or any negative image sample.

[0085] Figure 2 is a schematic flowchart of the model training method provided by the present invention, as Figure 2 shown, mainly the following steps: Step 201, construct an anomaly detection data set based on the data set construction method provided in any of the above embodiments.

[0086] Step 202, use the anomaly detection data set to train a feature extractor to obtain an image recognition model for determining whether the target to be measured is abnormal based on the recognition result of the input image.

[0087] Wherein, the target to be measured is an electronic component or a circuit board, and the input image is obtained by photographing the electronic component or the circuit board.

[0088] The method of how to generate the anomaly detection data set in step 201 has been explained in detail in the above embodiments and will not be elaborated here.

[0089] Select a suitable initial network model. For example, a conventional Convolutional Neural Network (CNN) model can be used as the architecture feature extractor.

[0090] Preprocess the images in the anomaly detection dataset, including operations such as resizing the images and normalizing the pixel values, to adapt to the input requirements of the feature extractor. For example, resize all images to a unified size, such as 256×256 pixels, and normalize the pixel values to the range [0,1].

[0091] Divide the preprocessed dataset into a training set and a validation set, usually in a ratio of 80% for the training set and 20% for the validation set. Input the image samples in the training set into the feature extractor, and the anomaly probability of each output image sample will be obtained. Update the network parameters of the feature extractor through the backpropagation algorithm according to the loss value to optimize the model performance. After each epoch, use the validation set to evaluate the model performance, calculate the loss and accuracy on the validation set, and ensure that the trained model performs well on the validation set. Finally, the validation set can be used to evaluate the model performance, calculate the accuracy, recall rate, and F1 score of the model on the validation set, and ensure that the model has high precision and strong robustness. Optimize the model performance by adjusting hyperparameters (such as the learning rate, batch size, etc.) until the model reaches satisfactory performance on the validation set, and obtain the trained image recognition model.

[0092] As an alternative embodiment, the feature extractor is constructed based on a siamese network model, and the siamese network model consists of two sub-network models with shared weights; The training of the feature extractor using the anomaly detection dataset includes: Based on the positive image samples and negative image samples in the anomaly detection dataset, generate multiple groups of positive sample pairs and multiple groups of negative sample pairs, and set labels for each positive sample pair and each negative sample pair; Input any one of the positive sample pairs or any one of the negative sample pairs into the feature extractor to obtain two feature vectors output by the sub-network model, and determine the feature distance between the two feature vectors; Adjust the network parameters of the feature extractor based on the loss value of the feature distance; Iteratively execute the steps from inputting any one of the positive sample pairs or any one of the negative sample pairs into the feature extractor to adjusting the network parameters of the feature extractor until the model convergence condition is reached; The positive sample pair is composed of two randomly selected positive image samples, and the negative sample pair is composed of one randomly selected negative image sample and one positive image sample.

[0093] The present invention provides a method for training a feature extractor constructed based on a Siamese network model. The Siamese network consists of two sub-networks with shared weights. By inputting positive sample pairs and negative sample pairs, the distance between feature vectors is calculated, and the network parameters are adjusted based on the loss value of the distance until the model converges. This method is particularly suitable for tasks that require distinguishing similar samples (such as normal and abnormal electronic component or PCB board images).

[0094] Randomly select two images from the positive sample set to form a positive sample pair. Since both of these images are from normal samples, their labels are set to 0, indicating the same class. Randomly select one image from the negative sample set and then randomly select one image from the positive sample set to form a negative sample pair. The label of this pair of images is set to 1, indicating different classes.

[0095] Taking the training process of any positive sample pair or negative sample as an example, input the positive sample pair into the Siamese network model. Each sub-network processes one image respectively and outputs a feature vector. Calculate the Euclidean distance or other suitable distance metric between the two feature vectors.

[0096] Taking the calculation of the Euclidean distance as an example, its formula is: ; where, and are the i th elements of the two feature vectors respectively, and n is the dimension of the feature vector.

[0097] Furthermore, use a contrastive loss function to calculate the loss value. This contrastive loss function encourages the feature distances of samples of the same class to be small and the feature distances of samples of different classes to be large.

[0098] Optionally, the formula of the above contrastive loss function is: ; where, y is the label (0 or 1) of the sample pair, and m is a preset threshold used to control the minimum distance of samples of different classes.

[0099] Furthermore, according to the calculated loss value, update the network parameters through the backpropagation algorithm. Use an optimizer such as Adam for parameter update to minimize the loss function.

[0100] Repeat the above training steps, continuously input new sample pairs, calculate the loss and adjust the parameters. Monitor the loss value during the training process and the performance metrics on the validation set, such as accuracy. When the loss value no longer decreases significantly, or the performance metrics on the validation set reach stability and meet the preset performance requirements, it is considered that the model has converged. At this time, stop the training and obtain the trained image recognition model.

[0101] Specifically, the model convergence condition is that the feature distance of the positive sample pair is greater than the first preset threshold and the feature distance of the negative sample pair is greater than the second preset threshold.

[0102] The model training method provided by the present invention uses a siamese network model to construct a feature extractor, calculates the feature vector distances of positive and negative sample pairs, and optimizes using a contrastive loss function, effectively improving the model's ability to distinguish normal and abnormal samples. The feature distance of the positive sample pair is encouraged to become smaller, while the feature distance of the negative sample pair is encouraged to become larger, enabling the model to better separate different categories of samples in the feature space. This not only improves the model's discrimination ability and generalization ability, but also reduces misjudgment and missed judgment, improves training efficiency and stability, and has good adaptability and practical application effects.

[0103] Figure 3 is a schematic flowchart of the anomaly detection method provided by the present invention, as Figure 3 shown, mainly including but not limited to the following steps: Step 301, collect an image of the target to be measured as an input image and input it into the image recognition model to obtain the feature vector to be measured output by the image recognition model. The image recognition model is obtained based on the model training method described in any one of the above.

[0104] A high-resolution camera can be used to collect images of the electronic component or PCB board to be measured. Ensure that the image is clear and noise-free, and can accurately reflect the appearance characteristics of the target to be measured.

[0105] The collected image can be preprocessed, including resizing the image to a unified size (such as 224x224 pixels) and normalizing the pixel values to the range [0,1] to adapt to the input requirements of the image recognition model.

[0106] Input the preprocessed image into the trained image recognition model to obtain the feature vector to be measured output by it. This feature vector to be measured is a point in a high-dimensional space and represents the feature representation of the image.

[0107] Step 302, match the feature vector to be measured with the feature vector templates in the pre-constructed feature vector library to determine whether the target to be measured is abnormal according to the matching result. Specifically, it includes: Obtain the feature distance between the feature vector to be measured and each feature vector template in the feature vector library; If the maximum feature distance among all the feature distances is less than the preset distance threshold, determine whether the target to be measured is abnormal according to the label of the feature vector template corresponding to the maximum feature distance.

[0108] Pre-construct a feature vector library, which contains feature vector templates generated by extracting features from different positive sample images and negative sample images through an image recognition model. Each feature vector template is labeled with a corresponding tag. The template corresponding to the normal sample image is labeled with a normal tag, and the template corresponding to the negative sample image is labeled with a defect type tag.

[0109] Further, calculate the distance between the feature vector to be measured and each feature vector template in the feature vector library. For example, the Euclidean distance, cosine similarity, etc. can be calculated.

[0110] If the distance between the feature vector to be measured and the feature vector template corresponding to a negative sample image in the feature vector library is less than a preset threshold, and the template is labeled with a defect type tag, then it is determined that the target to be measured is abnormal, and the corresponding defect type is output.

[0111] If the distance between the feature vector to be measured and the feature vector template corresponding to a positive sample image in the feature vector library is less than a preset threshold, and the template is labeled with a normal tag, then it is determined that the target to be measured is normal.

[0112] Further, if the maximum feature distance among all the feature distances is greater than or equal to the preset distance threshold, then the feature vector to be measured is added to the feature vector library as a new feature vector template, and a tag is labeled for the new feature vector template.

[0113] Specifically, if the distances between the feature vector to be measured and all the templates in the feature vector library are greater than the preset threshold, it is considered that the state of the target to be measured is uncertain and may be a new defect type. At this time, it can be further manually inspected or its feature vector can be added to the feature vector library and labeled as a new defect type.

[0114] The anomaly detection method provided by the present invention uses the method of feature vector comparison for anomaly detection, which can greatly reduce the dependence on the number of negative sample images, effectively improve the detection ability for diverse environments and unknown defects, can improve the detection efficiency, and is applicable to large-scale production environments.

[0115] Figure 4 It is a schematic structural diagram of the dataset construction device provided by the present invention, as Figure 4 shown, mainly including but not limited to: A sample collection unit 41, which is used to obtain a positive sample image set, and the positive sample images in the positive sample image set are obtained by photographing qualified electronic components or qualified circuit boards.

[0116] An image segmentation unit 42, which is used to input the positive sample image into an image segmentation model to obtain a mask image output by the image segmentation model. The mask image is a local image of the region where the main body of each electronic component is located in the positive sample image.

[0117] An image processing unit 43 is configured to perform a geometric transformation operation on any mask image to obtain a new mask image, and use the new mask image to replace the any mask image in the positive sample image to generate a negative image sample.

[0118] An iterative control unit 44 is configured to control the repeated execution of the steps from performing a geometric transformation operation on any mask image to obtaining a new mask image to generating the negative image sample until the negative sample image set is constructed; and use the positive sample image set and the negative sample image set to construct an anomaly detection data set.

[0119] It should be noted that when the data set construction device provided by the present invention is specifically running, it can execute the data set construction method provided in any of the above embodiments, which will not be elaborated here one by one.

[0120] Figure 5 is a schematic structural diagram of a model training device provided by the present invention, as Figure 5 shown, mainly including but not limited to: A sample calling unit 51 is configured to obtain an anomaly detection data set constructed based on the data set construction method provided in any of the above embodiments.

[0121] A training control unit 52 is configured to train a feature extractor using the anomaly detection data set to obtain an image recognition model for determining whether a target to be detected is abnormal based on the recognition result of an input image.

[0122] The target to be detected is an electronic component or a circuit board, and the input image is obtained by photographing the electronic component or the circuit board.

[0123] It should be noted that when the model training device provided by the present invention is specifically running, it can execute the model training method provided in any of the above embodiments, which will not be elaborated here one by one.

[0124] Figure 6 is a schematic structural diagram of an anomaly detection device provided by the present invention, as Figure 6 shown, mainly including but not limited to: An image acquisition unit 61 is configured to acquire an image of a target to be detected as an input image and input it into the image recognition model, and obtain a feature vector to be detected output by the image recognition model, where the image recognition model is obtained based on the model training method provided in any of the above embodiments.

[0125] A detection decision unit 62 is configured to match the feature vector to be detected with a feature vector template in a pre-constructed feature vector library to determine whether the target to be detected is abnormal according to the matching result.

[0126] Wherein, the target to be measured is an electronic component or a circuit board, and the feature vector template is generated by extracting features from different positive sample images and negative sample images using the image recognition model. Each feature vector template corresponding to a negative sample image is labeled with a defect type label, and each feature vector template corresponding to a positive sample image is labeled with a normal label.

[0127] It should be noted that when the anomaly detection device provided by the present invention is specifically operating, it can execute the anomaly detection method provided in any of the above embodiments, which will not be elaborated here one by one.

[0128] Figure 7 is a schematic structural diagram of an electronic device provided by the present invention, as Figure 7 shown, the electronic device may include: a processor 710, a communication interface 720, a memory 730, and a communication bus 740. Among them, the processor 710, the communication interface 720, and the memory 730 complete mutual communication through the communication bus 740. The processor 710 can call the logical instructions in the memory 730 to execute a data set construction method, which includes: obtaining a positive sample image set, where the positive sample images in the positive sample image set are obtained by photographing qualified electronic components or qualified circuit boards; inputting the positive sample images into an image segmentation model to obtain a mask image output by the image segmentation model, where the mask image is a local image of the area where each electronic component body is located in the positive sample image; performing a geometric transformation operation on any mask image to obtain a new mask image, so as to use the new mask image to replace the any mask image in the positive sample image to generate a negative image sample; repeating the step of performing a geometric transformation operation on any mask image to obtain a new mask image until the negative sample image set is constructed; using the positive sample image set and the negative sample image set to construct an anomaly detection data set.

[0129] Alternatively, the processor 710 can call the logical instructions in the memory 730 to execute a model training method, which includes: constructing an anomaly detection data set based on the data set construction method; training a feature extractor using the anomaly detection data set to obtain an image recognition model for determining whether the target to be measured is abnormal based on the recognition result of the input image; the target to be measured is an electronic component or a circuit board, and the input image is obtained by photographing the electronic component or the circuit board.

[0130] Alternatively, the processor 710 may call the logical instructions in the memory 730 to execute an anomaly detection method, which includes: collecting an image of a target to be tested as an input image and inputting it into an image recognition model, obtaining a feature vector to be tested output by the image recognition model, where the image recognition model is obtained based on the above model training method; matching the feature vector to be tested with the feature vector templates in a pre-constructed feature vector library to determine whether the target to be tested is abnormal according to the matching result; the target to be tested is an electronic component or a circuit board, and the feature vector templates are generated after feature extraction of different positive sample images and negative sample images by the image recognition model, and each feature vector template corresponding to the negative sample image is labeled with a defect type label, and each feature vector template corresponding to the positive sample image is labeled with a normal label.

[0131] In addition, when the logical instructions in the above-mentioned memory 730 are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), magnetic disks, or optical discs that can store program codes.

[0132] On the other hand, the present invention also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the dataset construction method provided in each of the above embodiments. The method includes: obtaining a set of positive sample images, where the positive sample images in the set of positive sample images are obtained by photographing qualified electronic components or qualified circuit boards; inputting the positive sample images into an image segmentation model to obtain a mask image output by the image segmentation model, where the mask image is a local image of the region where each electronic component body is located in the positive sample image; performing a geometric transformation operation on any mask image to obtain a new mask image, so as to use the new mask image to replace the any mask image in the positive sample image to generate a negative image sample; repeating the step of performing a geometric transformation operation on any mask image to obtain a new mask image until the set of negative sample images is constructed; using the set of positive sample images and the set of negative sample images to construct an anomaly detection dataset.

[0133] Alternatively, the computer can execute the model training method provided in each of the above embodiments. The method includes: constructing an anomaly detection dataset based on the dataset construction method; training a feature extractor using the anomaly detection dataset to obtain an image recognition model for determining whether a target to be measured is abnormal based on the recognition result of an input image; the target to be measured is an electronic component or a circuit board, and the input image is obtained by photographing the electronic component or the circuit board.

[0134] Alternatively, the computer can execute the anomaly detection method provided in each of the above embodiments. The method includes: collecting an image of a target to be measured as an input image and inputting it into the image recognition model to obtain a feature vector of the target to be measured output by the image recognition model, where the image recognition model is obtained based on the above model training method; matching the feature vector of the target to be measured with a feature vector template in a pre-constructed feature vector library to determine whether the target to be measured is abnormal according to the matching result; the target to be measured is an electronic component or a circuit board, and the feature vector template is generated by extracting features from different positive sample images and negative sample images using the image recognition model. Each feature vector template corresponding to a negative sample image is labeled with a defect type label, and each feature vector template corresponding to a positive sample image is labeled with a normal label.

[0135] In another aspect, the present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it implements the dataset construction method provided in the above embodiments. The method includes: obtaining a set of positive sample images, where the positive sample images in the set of positive sample images are obtained by photographing qualified electronic components or qualified circuit boards; inputting the positive sample images into an image segmentation model to obtain a mask image output by the image segmentation model, where the mask image is a local image of the region where each electronic component body is located in the positive sample image; performing a geometric transformation operation on any one of the mask images to obtain a new mask image, so as to use the new mask image to replace the any one of the mask images in the positive sample image to generate a negative image sample; repeating the step of performing a geometric transformation operation on any one of the mask images to obtain a new mask image until the set of negative sample images is constructed; using the set of positive sample images and the set of negative sample images to construct an anomaly detection dataset.

[0136] Or execute a model training method, which includes: constructing an anomaly detection dataset based on the dataset construction method; using the anomaly detection dataset to train a feature extractor to obtain an image recognition model for determining whether a target to be measured is abnormal based on the recognition result of an input image; the target to be measured is an electronic component or a circuit board, and the input image is obtained by photographing the electronic component or the circuit board.

[0137] Or execute an anomaly detection method, which includes: collecting an image of a target to be measured as an input image and inputting it into the image recognition model to obtain a feature vector to be measured output by the image recognition model, where the image recognition model is obtained based on the above model training method; matching the feature vector to be measured with a feature vector template in a pre-constructed feature vector library to determine whether the target to be measured is abnormal according to the matching result; the target to be measured is an electronic component or a circuit board, and the feature vector template is generated by extracting features from different positive sample images and negative sample images using the image recognition model. Each feature vector template corresponding to a negative sample image is labeled with a defect type label, and each feature vector template corresponding to a positive sample image is labeled with a normal label.

[0138] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art can understand and implement it without creative labor.

[0139] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the essence of the above technical solution, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0140] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for constructing a data set, characterized in that: include: Acquire a positive sample image set, wherein the positive sample images in the positive sample image set are obtained by photographing qualified electronic components or qualified circuit boards; Inputting the positive sample image into an image segmentation model, obtaining a mask image output by the image segmentation model, wherein the mask image is a local image of the area where each electronic component body in the positive sample image is located; Performing a geometric transformation operation on any mask image to obtain a newly added mask image, so as to replace any mask image in the positive sample image with the newly added mask image to generate a negative image sample; Repeat the step of performing a geometric transformation operation on any mask image to obtain a newly added mask image to generate a negative image sample until a negative sample image set is constructed; An anomaly detection dataset is constructed using the positive sample image set and the negative sample image set.

2. The method for constructing a data set according to claim 1, characterized in that: The step of performing a geometric transformation operation on any mask image to obtain a newly added mask image includes: Determining, according to the component attributes of the electronic components related to any of the mask images, an operation mode of performing a geometric transformation operation on any of the mask images; The component attributes include at least one of shape attributes, size attributes, function attributes and layout attributes; the geometric transformation operation includes one or a combination of rotation operation, translation operation and scaling operation.

3. The method for constructing a data set according to claim 1, characterized in that: The image segmentation model is obtained by training an initial segmentation model using a general data set and then fine-tuning the model using historical positive sample images and historical negative sample images with mask image labels. Before using the general data set to train the initial segmentation model, the method also includes normalizing the image samples in the general data set according to the image input requirements of the initial segmentation model.

4. The method for constructing a data set according to claim 1, characterized in that: The method for generating the negative image sample further includes: Performing color adjustment on any positive sample image or any negative image sample to generate a new negative image sample; The color adjustment includes changing at least one of brightness, contrast, color temperature and saturation.

5. A model training method, characterized in that: include: Constructing an anomaly detection dataset based on the dataset construction method according to any one of claims 1 to 4; The feature extractor is trained using the anomaly detection data set to obtain an image recognition model that determines whether the target to be detected is abnormal based on the recognition result of the input image; The target to be measured is an electronic component or a circuit board, and the input image is obtained by photographing the electronic component or the circuit board.

6. The model training method according to claim 5, characterized in that: The feature extractor is constructed based on a twin network model, which consists of two sub-network models that share weights; The using the anomaly detection data set to train the feature extractor comprises: Based on the positive image samples and the negative image samples in the anomaly detection dataset, generate multiple groups of positive sample pairs and multiple groups of negative sample pairs, and set a label for each of the positive sample pairs and each of the negative sample pairs; Inputting any of the positive sample pairs or any of the negative sample pairs into the feature extractor to obtain two feature vectors output by the sub-network model to determine a feature distance between the two feature vectors; Adjusting the network parameters of the feature extractor based on the loss value of the feature distance; Iteratively executing the steps of inputting any one of the positive sample pairs or any one of the negative sample pairs into the feature extractor to adjusting the network parameters of the feature extractor until a model convergence condition is reached; The positive sample pair is composed of two randomly selected positive image samples, and the negative sample pair is composed of one randomly selected negative image sample and one positive image sample.

7. The model training method according to claim 6, characterized in that: The model convergence condition is that the feature distance of the positive sample pair is greater than a first preset threshold and the feature distance of the negative sample pair is greater than a second preset threshold.

8. An anomaly detection method, characterized in that: include: Capturing an image of the target to be measured as an input image and inputting it into an image recognition model, obtaining a feature vector to be measured output by the image recognition model, wherein the image recognition model is obtained based on the model training method according to any one of claims 5 to 7; Matching the feature vector to be tested with a feature vector template in a pre-built feature vector library to determine whether the target to be tested is abnormal according to the matching result; The target to be tested is an electronic component or a circuit board. The feature vector template is generated after feature extraction of different positive sample images and negative sample images using the image recognition model. The feature vector template corresponding to each negative sample image is annotated with a defect type label, and the feature vector template corresponding to each positive sample image is annotated with a normal label.

9. The abnormality detection method according to claim 8, characterized in that: The step of matching the feature vector to be tested with a feature vector template in a pre-built feature vector library to determine whether the target to be tested is abnormal according to the matching result includes: Acquire a feature distance between the feature vector to be tested and each feature vector template in the feature vector library; If the maximum characteristic distance among all the characteristic distances is less than the preset distance threshold, it is determined whether the target to be detected is abnormal according to the label of the characteristic vector template corresponding to the maximum characteristic distance.

10. The abnormality detection method according to claim 9, characterized in that: If the maximum feature distance among all the feature distances is greater than or equal to the preset distance threshold, the feature vector to be tested is added to the feature vector library as a new feature vector template, and a label is added to the new feature vector template.

11. A data set construction device, characterized in that: include: A sample collection unit, used to obtain a positive sample image set, wherein the positive sample images in the positive sample image set are obtained by photographing qualified electronic components or qualified circuit boards; An image segmentation unit, used for inputting the positive sample image into an image segmentation model, and obtaining a mask image output by the image segmentation model, wherein the mask image is a local image of the area where each electronic component body in the positive sample image is located; An image processing unit, configured to obtain a newly added mask image after performing a geometric transformation operation on any mask image, so as to replace any mask image in the positive sample image with the newly added mask image to generate a negative image sample; An iterative control unit is used to control the repeated execution of the step of performing a geometric transformation operation on any mask image to obtain a newly added mask image to the step of generating a negative image sample until a negative sample image set is constructed; so as to use the positive sample image set and the negative sample image set to construct an anomaly detection data set.

12. A model training device, characterized in that: include: A sample calling unit, used to obtain an anomaly detection data set constructed based on the data set construction method according to any one of claims 1 to 4; A training control unit, used to train a feature extractor using the anomaly detection data set to obtain an image recognition model that determines whether the target to be detected is abnormal based on a recognition result of an input image; The target to be measured is an electronic component or a circuit board, and the input image is obtained by photographing the electronic component or the circuit board.

13. An abnormality detection device, characterized in that: include: An image acquisition unit, used for acquiring an image of a target to be measured as an input image to be input into an image recognition model, and obtaining a feature vector to be measured output by the image recognition model, wherein the image recognition model is obtained based on the model training method according to any one of claims 5 to 7; A detection decision unit, used for matching the feature vector to be tested with a feature vector template in a pre-built feature vector library, so as to determine whether the target to be tested is abnormal according to the matching result; The target to be tested is an electronic component or a circuit board. The feature vector template is generated after feature extraction of different positive sample images and negative sample images using the image recognition model. The feature vector template corresponding to each negative sample image is annotated with a defect type label, and the feature vector template corresponding to each positive sample image is annotated with a normal label.