A photovoltaic module unsupervised defect detection method based on contrastive learning
By constructing an unsupervised defect detection model based on contrastive learning, and utilizing contrastive learning networks and multivariate Gaussian mixture distributions, the problems of complex feature extraction and imbalanced samples in photovoltaic module detection are solved, enabling rapid and accurate detection of minute defects and improving the robustness and adaptability of the detection.
Patent Information
- Application Number
- CN202211434097.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-16
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2042-11-16
AI Technical Summary
Traditional machine vision inspection technology suffers from problems such as complex feature extraction and classifier design, poor adaptability, and low robustness in photovoltaic module defect detection. Furthermore, deep learning algorithms have very few abnormal samples in photovoltaic module datasets, resulting in insufficient detection accuracy and real-time performance, especially poor ability to detect minute defects.
An unsupervised defect detection method based on contrastive learning is adopted. A model is constructed that includes two encoder networks and a symmetric cross-attention network for object pointing. A defect discrimination model is constructed by multivariate Gaussian mixture distribution and trained using normal photovoltaic images to enhance feature learning and detect minute defects.
It enables the detection of tiny and diverse defects in photovoltaic modules, solves the problem of sample imbalance, and has the advantages of being fast, accurate, and highly adaptable to the environment, enabling effective detection even with a small number of defect images.
Smart Images

Figure CN115861190B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of industrial product production detection, more particularly, it relates to a photovoltaic module unsupervised defect detection method based on contrast learning. BACKGROUND
[0002] Due to the gradual depletion of traditional energy, new energy represented by solar photovoltaic power generation has developed rapidly in recent years. In the production and processing process of photovoltaic cell modules, in addition to the defects of the material itself, the multiple processing of the cell sheet on the automatic production line also increases the damage rate of the cell sheet, causing defects such as hidden cracks, fragments, virtual welding, and broken grids in the module. These defects directly affect the conversion efficiency and service life of the product. With the continuous improvement of industrial automation level, traditional manual detection has the disadvantages of low precision, poor real-time performance, and high cost, which is not suitable for the current automated production environment.
[0003] Machine vision is a widely used automated detection technology. Traditional machine vision detection technology requires manual feature extraction and classifier design, which requires professionals in the relevant field to participate and adapt to the algorithm. However, in actual industrial production process, there are many types of industrial parts with different specifications, and the types of defects vary greatly depending on the industrial product. Traditional machine vision detection technology has the problems of complex feature extraction and classifier design, poor adaptability, and low robustness, which makes it difficult to meet the accuracy and real-time requirements of industrial production in industrial detection.
[0004] In recent years, deep learning technology has been widely applied in the field of image due to its strong feature learning ability. Since deep learning model does not require manual feature extraction, it combines feature extraction and classifier in traditional machine vision, and directly learns the mapping relationship from input to output. This can avoid tedious and complex image preprocessing and manual feature extraction operations, and can also adapt to different scenarios and different types of defects, thereby improving the accuracy, robustness, and real-time performance of industrial detection.
[0005] However, in the photovoltaic module dataset, the number of abnormal samples is extremely small, which causes a serious imbalance between positive and negative samples. In actual production process, not only the types of photovoltaic module abnormalities are diverse, but also the manifestations of abnormalities are various, and the area of abnormalities is small. For photovoltaic hidden crack defects, the defect manifestation is not obvious, and existing deep learning algorithms often require balanced samples and can only detect larger objects, and have poor detection ability for small abnormalities.
[0006] Contrastive learning has been widely used in deep learning tasks due to its strong feature representation capability. It does not need labeled supervision signals, but trains in a self-supervised manner on a large amount of unlabeled data, so as to obtain the feature expression of the data. However, at present, contrastive learning is mainly applied to unsupervised pre-training, and has not been involved in the field of image anomaly detection. SUMMARY
[0007] The purpose of the present application is to overcome the deficiencies in the prior art, and provide a photovoltaic module unsupervised defect detection method based on contrastive learning, comprising:
[0008] Step 1, constructing a contrastive learning network model: using normal samples to train the contrastive learning network model; the contrastive learning network model comprises two encoder networks and an object-oriented symmetric cross-attention network;
[0009] Step 2, constructing a defect discrimination model: based on the encoder network of step 1, obtaining the feature distribution of normal samples, and using a multivariate Gaussian mixture distribution to construct a defect discrimination model for normal sample features;
[0010] Step 3, inputting the image to be tested into the encoder network of step 1 to obtain the feature, and obtaining the detection result of the image based on the defect discrimination model of step 2.
[0011] As preferred, step 1 comprises:
[0012] Step 1.1, collecting photovoltaic module images under actual working conditions;
[0013] Step 1.2, constructing a data set, comprising:
[0014] Step 1.2.1, gray-scale the photovoltaic module image, correct the image angle, and change the size to a fixed size;
[0015] Step 1.2.2, dividing the gray-scale image into a normal image set and an abnormal image set, and constructing a training set and a test set, the training set only contains normal images, and the test set contains normal images and abnormal images;
[0016] Step 1.3, constructing two encoder networks: constructing a first encoder network and a second encoder network, the input of the encoder network is a fixed-size gray-scale image; the two encoders have the same structure but different parameters, and the outputs of the two encoders are denoted as f and q respectively;
[0017] Step 1.4, constructing an object-oriented symmetric cross-attention network;
[0018] Step 1.5, training the contrastive learning network model.
[0019] As preferred, in step 1.3, the encoder network comprises 4 residual blocks, each of which is composed of two convolutional layers with 3x3 convolutional kernels, and the activation function is Relu; and a convolutional layer with 3x3 convolutional kernel is used for transformation after the last residual block.
[0020] As preferred, step 1.4 comprises:
[0021] Step 1.4.1, correlation coefficient calculation: the input of the symmetric cross-attention network of the object pointing is the output of the two encoder networks, and the dimensions of the input are reshaped to retain the spatial position information; the correlation coefficient of q to f is calculated by using cosine similarity:
[0022]
[0023] In the above formula, f i and q j represent vectors in the spatial dimensions of f and q, represent the transpose vector of f i , ||*||2 represents the two-norm of the vector, and the correlation coefficient R represents the similarity of the features in the subject space of the two pictures;
[0024] Step 1.4.2, attention weight calculation: the correlation coefficient R is subjected to row-wise average pooling to obtain a vector p:
[0025] p = avgPool(R)
[0026] In the above formula, avgPool represents the average pooling operation, and p represents the average correlation of q to f at each spatial point, which is mapped and reshaped by a trainable attention layer to obtain the attention weight map A of q to f;
[0027] Step 1.4.3, symmetric attention weight calculation: the correlation coefficient of f to q can be obtained by the symmetric operation of step 1.4.1:
[0028]
[0029] The attention weight map A' of f to q can be obtained by step 1.4.2;
[0030] Step 1.4.4, enhanced feature calculation: the attention weight map is multiplied with the features f and q output by the encoder to obtain the enhanced features, which are calculated as follows:
[0031]
[0032]
[0033] In the above formula, represents the dot product operation, f′ represents the enhanced feature of f, and q′ represents the enhanced feature of q.
[0034] Preferably, step 1.5 includes:
[0035] Step 1.5.1: Initialize the weights of the contrastive learning network model to random, small values using a Gaussian function, and set the values of the hyperparameters in the model; the hyperparameters include the number of iterations, the size of the sample set used in each training round, the learning rate, and the learning rate decay value;
[0036] Step 1.5.2: Randomly sample the training set. In each iteration, two different normal photovoltaic images are randomly sampled from the training set.
[0037] Step 1.5.3: Apply random data augmentation to the two normal photovoltaic images to obtain two enhanced photovoltaic images. The data augmentation operations include cropping, color transformation, and resizing.
[0038] Step 1.5.4: Input the two enhanced photovoltaic images into the contrastive learning network model to obtain the enhancement features f′ and q′ of the two enhanced photovoltaic images respectively;
[0039] Step 1.5.5: Construct the loss function for training the contrastive learning network model based on the enhanced features f′ and q′;
[0040] Step 1.5.6: Based on the loss function of the contrastive learning network model, Adam is used as the optimizer, and gradient descent is used to update the first encoder network and the object-pointing symmetric cross-attention network.
[0041] Step 1.5.7: For the second encoder network, the momentum gradient update method is used to update the parameters based on the parameters of the first encoder network. The update formula is as follows:
[0042] θ2=mθ2+(1-m)θ1
[0043] In the above formula, θ1 represents the parameters of the first encoder, θ2 represents the parameters of the second encoder, and m is the momentum update parameter, which is set to a value in the range of 0.9 to 0.999 according to the actual situation.
[0044] Step 1.5.8: Determine if the iteration count has been reached: if yes, proceed to step 1.5.9; if not, return to step 1.5.2.
[0045] Step 1.5.9: Store the parameters and trained weights in the contrastive learning network model.
[0046] Preferably, step 1.5.5 includes:
[0047] Step 1.5.5.1: For each identical spatial location of enhanced features f′ and q′, the feature f... i ′ and q′ i The formula for calculating cosine similarity is:
[0048]
[0049] Step 1.5.5.2: The loss function for training the contrastive learning network model is the negative of the sum of the cosine similarities at all spatial locations on the feature map.
[0050] L=∑ i -D(f i ′,q′ i ).
[0051] Preferably, step 2 includes:
[0052] Step 2.1: Read the first encoder network from the trained contrastive learning network model;
[0053] Step 2.2: Fit a multivariate Gaussian mixture model to each spatial location of the normal photovoltaic image features;
[0054] Step 2.3: Based on the aforementioned multivariate Gaussian mixture model M ij The outlier score s for each spatial location in the feature is calculated using Mahalanobis distance. ij The calculation formula is as follows:
[0055]
[0056] Step 2.4: Calculate the anomaly detection threshold, including:
[0057] Step 2.4.1: Input all images in the training set into the encoder network to obtain their features f;
[0058] Step 2.4.2: Based on the aforementioned multivariate Gaussian mixture model M ij Calculate the anomaly score s for each spatial location in feature f. ij Step 2.4.3: Take the largest anomaly score in the training set as the anomaly detection threshold π.
[0059] Step 2.5: Construct a defect detection module, including:
[0060] Step 2.5.1: Input the image to be detected x into the encoder network to obtain its features f;
[0061] Step 2.5.2: Based on the aforementioned multivariate Gaussian mixture model M ij Calculate the anomaly score s for each spatial location in feature f. ij ;
[0062] Step 2.5.3: Take the maximum anomaly score in each spatial location as the anomaly score s of the image to be detected x;
[0063] Step 2.5.4: Specify the anomaly detection threshold as the threshold π obtained in step 2.5.4;
[0064] Step 2.5.5: Determine whether the abnormal score is greater than the specified threshold π. If so, determine that the image to be detected x is an abnormal image; otherwise, determine that the image to be detected x is a normal image.
[0065] Preferably, step 2.2 includes:
[0066] Step 2.2.1: Perform random data augmentation on the normal photovoltaic images in the training set to obtain a total of N augmented images, each represented as x. k ;
[0067] Step 2.2.2: The enhanced image x... k Input the encoder network to obtain its features f k ;
[0068] Step 2.2.3: For each spatial location (i, j) of the normal image, N features f k Fit a multivariate Gaussian mixture model M ij Its mean μ ij The calculation formula is:
[0069]
[0070] Its variance σ ij The calculation formula is:
[0071]
[0072] Preferably, step 3 includes:
[0073] Step 3.1: Read the defect identification module;
[0074] Step 3.2: Input the image to be detected;
[0075] Step 3.3: Preprocess the image to be detected, including:
[0076] Step 3.3.1: Crop the image to be detected, remove the background area, and obtain the main body of the image to be detected;
[0077] Step 3.3.2: Perform image correction and grayscale processing on the detected image, and then scale it.
[0078] Step 3.4: Input the preprocessed image into the defect discrimination module, and the defect discrimination module returns the discrimination result.
[0079] The beneficial effects of this invention are as follows: This invention proposes an unsupervised defect detection method for photovoltaic modules based on contrastive learning. This method can effectively detect small and diverse defects in photovoltaic modules, requiring only normal photovoltaic images for training, and can solve the problem of imbalanced samples. A contrastive learning network model is constructed, including two encoder networks and an object-pointing symmetric cross-attention network, using momentum to update the encoder parameters. A multivariate Gaussian mixture model is fitted to each spatial location of the features in the normal photovoltaic image. The defect detection module determines whether there is a defect in the image to be detected. This method can achieve fast and accurate detection of unknown defects even with a small number of defective images, and has the advantages of environmental adaptability and strong robustness. Attached Figure Description
[0080] Figure 1 A schematic diagram of a comparative learning network model;
[0081] Figure 2 A flowchart illustrating the training process of a comparative learning network model;
[0082] Figure 3 This is a schematic diagram of the encoder network structure;
[0083] Figure 4 A schematic diagram of a cross-attention network structure for object pointing;
[0084] Figure 5 A schematic diagram illustrating the construction of a defect discrimination model;
[0085] Figure 6 This is a schematic diagram illustrating the experimental results where the image to be detected is a normal image.
[0086] Figure 7 This is a schematic diagram of the experimental results when the image to be detected is an abnormal image. Detailed Implementation
[0087] The present invention will be further described below with reference to embodiments. The description of the embodiments below is only for the purpose of helping to understand the present invention. It should be noted that those skilled in the art can make several modifications to the present invention without departing from the principle of the present invention, and these improvements and modifications also fall within the protection scope of the claims of the present invention.
[0088] As one example, such as Figure 1As shown, this invention proposes an unsupervised defect detection method for photovoltaic modules based on contrastive learning. Addressing the challenges of high difficulty in defect identification, diverse defect forms, complex detection environments, and extreme imbalance between positive and negative samples in photovoltaic modules, it provides an unsupervised anomaly detection model capable of detecting minute and unknown anomalies. The unsupervised anomaly detection model comprises a contrastive learning network model and a defect discrimination model. The contrastive learning network model includes two encoder networks and an object-pointing symmetric cross-attention network; the encoder networks employ a residual network model. (The text repeats itself here.) Figure 5 As shown, the defect discrimination model is based on an encoder network to obtain the feature distribution of normal samples. A multivariate Gaussian mixture distribution is used to construct a defect discrimination model for the features of normal samples. Defect detection is achieved by judging whether the abnormal score reaches a set threshold. In practical applications, the image to be tested is input into the defect discrimination module, which then returns the discrimination result.
[0089] Specifically, the steps of the unsupervised defect detection method for photovoltaic modules based on contrastive learning include:
[0090] Step 1: Construct a contrastive learning network model: Train the contrastive learning network model using normal samples; the contrastive learning network model consists of two encoder networks and a symmetric cross-attention network for object pointing;
[0091] Step 2: Construct a defect discrimination model: Based on the encoder network in Step 1, obtain the feature distribution of normal samples, and construct a defect discrimination model for the features of normal samples using a multivariate Gaussian mixture distribution;
[0092] Step 3: Input the image to be tested into the encoder network in Step 1 to obtain features, and obtain the detection result of the image based on the defect discrimination model in Step 2.
[0093] like Figure 2 As shown, step 1 includes:
[0094] Step 1.1: Collect images of photovoltaic modules under actual operating conditions;
[0095] Step 1.2: Construct the dataset, including:
[0096] Step 1.2.1: Convert the photovoltaic module image to grayscale, correct the image angle, and change its size to a fixed size; for example, the fixed size is 64×64.
[0097] Step 1.2.2: Divide the grayscale image into a normal image set and an abnormal image set, and construct a training set and a test set. The training set contains only normal images, and the test set contains both normal images and abnormal images.
[0098] Step 1.3: Construct two encoder networks: Construct a first encoder network and a second encoder network. The input of the encoder network is a grayscale image of a fixed size, for example, a 64×64 grayscale image. The two encoders have the same structure but different parameters. Let the outputs of the two encoders be f and q, respectively.
[0099] Step 1.4: Construct a symmetrical cross-attention network for object pointing;
[0100] Step 1.5: Train the contrastive learning network model.
[0101] like Figure 3 As shown, in step 1.3, the encoder network contains 4 residual blocks, each residual block consists of two convolutional layers with 3×3 convolutional kernels and the activation function is ReLU; after the last residual block, a convolutional layer with 3×3 convolutional kernels is used for transformation.
[0102] like Figure 4 As shown, step 1.4 includes:
[0103] Step 1.4.1, Correlation Coefficient Calculation: The input to the object-pointing symmetric cross-attention network is the output of two encoder networks. The dimensions of the input are reshaped to preserve spatial location information; for example, the dimensions of the input are reshaped to 512×16 and 512×16 respectively. The cosine similarity is used to calculate the correlation coefficient of q with respect to f.
[0104]
[0105] In the above formula, and Represents vectors in the space dimensions f and q. Represent f i The transpose of the vector, ||*||2 represents the L2 norm of the vector, and the correlation coefficient R represents the feature similarity in the subject space of the two images;
[0106] Step 1.4.2, Attention Weight Calculation: Calculate the correlation coefficient. The vector p is obtained by average pooling by row:
[0107] p = avgPool(R)
[0108] In the above formula, avgPool represents the average pooling operation, p represents the average correlation of q with each spatial point of f, and a trainable attention layer is used to map and reshape p to obtain the final attention weight map A of q with respect to f.
[0109] Step 1.4.3, Symmetric Attention Weight Calculation: The correlation coefficient of f with respect to q can be obtained through the symmetric operation in Step 1.4.1:
[0110]
[0111] The attention weight map A′ of f with respect to q can be obtained through step 1.4.2;
[0112] Step 1.4.4, Enhanced Feature Calculation: Attention weight maps A and A′ represent the attention between the main subject in two images. Multiplying the attention weight maps by the encoder output features f and q makes the features more emphasize the main subject in the image, thus making defect detection more accurate. The enhanced feature calculation is as follows:
[0113]
[0114]
[0115] In the above formula, Let f' represent the dot product operation, and q' represent the enhanced features of f and q', respectively. A residual mechanism is used to preserve information from the original features, and an attention map A is added to emphasize the influence of the subject in the image. The resulting enhanced features f' and q' focus more on the subject in the image compared to the original features, thus reducing interference from irrelevant backgrounds for defect detection.
[0116] Step 1.5 includes:
[0117] Step 1.5.1: Initialize the weights of the contrastive learning network model to random, small values using a Gaussian function, and set the values of the hyperparameters in the model; the hyperparameters include the number of iterations, the size of the sample set used in each training round, the learning rate, and the learning rate decay value;
[0118] Step 1.5.2: Randomly sample the training set. In each iteration, two different normal photovoltaic images are randomly sampled from the training set.
[0119] Step 1.5.3: Apply random data augmentation to the two normal photovoltaic images to obtain two enhanced photovoltaic images. The data augmentation operations include cropping, color transformation, and resizing.
[0120] Step 1.5.4: Input the two enhanced photovoltaic images into the contrastive learning network model to obtain the enhancement features f′ and q′ of the two enhanced photovoltaic images respectively;
[0121] Step 1.5.5: Construct the loss function for training the contrastive learning network model based on the enhanced features f′ and q′;
[0122] Step 1.5.6: Based on the loss function of the contrastive learning network model, Adam is used as the optimizer, and gradient descent is used to update the first encoder network and the object-pointing symmetric cross-attention network.
[0123] Step 1.5.7: For the second encoder network, the momentum gradient update method is used to update the parameters based on the parameters of the first encoder network. The update formula is as follows:
[0124] θ2=mθ2+(1-m)θ1
[0125] In the above formula, θ1 represents the parameters of the first encoder, θ2 represents the parameters of the second encoder, and m is the momentum update parameter, which is set to a value in the range of 0.9 to 0.999 according to the actual situation.
[0126] Step 1.5.8: Determine if the iteration count has been reached: if yes, proceed to step 1.5.9; if not, return to step 1.5.2.
[0127] Step 1.5.9: Store the parameters and trained weights in the contrastive learning network model.
[0128] Step 1.5.5 includes:
[0129] Step 1.5.5.1: For each identical spatial location of enhanced features f′ and q′, the feature f... i ′ and q′ i The formula for calculating cosine similarity is:
[0130]
[0131] Step 1.5.5.2: To ensure that features at the same spatial location are as similar as possible, the loss function for training the contrastive learning network model is the negative of the sum of the cosine similarities at all spatial locations on the feature map:
[0132] L=∑ i -D(f i ′,q′ i ).
[0133] Step 2 includes:
[0134] Step 2.1: Read the first encoder network from the trained contrastive learning network model;
[0135] Step 2.2: Fit a multivariate Gaussian mixture model to each spatial location of the normal photovoltaic image features;
[0136] Step 2.3: Based on the multivariate Gaussian mixture model M ij The outlier score s for each spatial location in the feature is calculated using Mahalanobis distance. ijThe calculation formula is as follows:
[0137]
[0138] Step 2.4: Calculate the anomaly detection threshold, including:
[0139] Step 2.4.1: Input all images in the training set into the encoder network to obtain their features f;
[0140] Step 2.4.2: Based on the multivariate Gaussian mixture model M ij Calculate the anomaly score s for each spatial location in feature f. ij ;
[0141] Step 2.4.3: Take the largest anomaly score in the training set as the anomaly detection threshold π;
[0142] Step 2.5: Construct a defect detection module, including:
[0143] Step 2.5.1: Input the image to be detected x into the encoder network to obtain its features f;
[0144] Step 2.5.2: Based on the multivariate Gaussian mixture model M ij Calculate the anomaly score s for each spatial location in feature f. ij ;
[0145] Step 2.5.3: Take the maximum anomaly score in each spatial location as the anomaly score s of the image to be detected x;
[0146] Step 2.5.4: Specify the anomaly detection threshold as the threshold π obtained in step 2.5.4;
[0147] Step 2.5.5: Determine whether the abnormal score is greater than the specified threshold π. If so, determine that the image to be detected x is an abnormal image; otherwise, determine that the image to be detected x is a normal image.
[0148] Step 2.2 includes:
[0149] Step 2.2.1: Perform random data augmentation on the normal photovoltaic images in the training set to obtain a total of N augmented images, each represented as x. k ;
[0150] Step 2.2.2: The enhanced image x... k Input the encoder network to obtain its features f k ;
[0151] Step 2.2.3: For each spatial location (i, j) of the normal image, N features f k Fit a multivariate Gaussian mixture model M ijIts mean μ ij The calculation formula is:
[0152]
[0153] Its variance σ ij The calculation formula is:
[0154]
[0155] Step 3 includes:
[0156] Step 3.1: Read the defect identification module;
[0157] Step 3.2: Input the image to be detected;
[0158] Step 3.3: Preprocess the image to be detected, including:
[0159] Step 3.3.1: Crop the image to be detected, remove the background area, and obtain the main body of the image to be detected;
[0160] Step 3.3.2: Perform image correction and grayscale processing on the detected image, and scale it, for example, to a size of 64×64.
[0161] Step 3.4: Input the preprocessed image into the defect discrimination module, and the defect discrimination module returns the discrimination result.
[0162] The detection results of this invention are as follows Figure 6 and Figure 7 As shown, the first row contains the image to be detected, and the second row contains the anomaly score values for the detected image. The results show a significant difference in anomaly scores between normal and abnormal images, demonstrating the effective identification of anomalies.
Claims
1. An unsupervised defect detection method for photovoltaic modules based on contrastive learning, characterized in that, include: Step 1: Construct a contrastive learning network model: Train the contrastive learning network model using normal samples; The contrastive learning network model comprises two encoder networks and an object-pointing symmetrical cross-attention network; the two encoder networks include a first encoder network and a second encoder network, the input of which is a fixed-size grayscale image; the two encoder networks have the same structure but different parameters, and their outputs are denoted as f and q, respectively; and the two encoder networks are trained using normal photovoltaic images; Step 2: Construct a defect discrimination model: Based on the first encoder network in Step 1, obtain the feature distribution of normal samples, and construct a defect discrimination model for the features of normal samples using a multivariate Gaussian mixture distribution; Step 2 includes: Step 2.1: Read the first encoder network from the trained contrastive learning network model; Step 2.2: Fit a multivariate Gaussian mixture model to each spatial location of the normal photovoltaic image features; Step 2.3: Based on the aforementioned multivariate Gaussian mixture model M ij The outlier score s for each spatial location in the feature is calculated using Mahalanobis distance. ij The calculation formula is as follows: in, For each spatial location (i,j) in a normal image, μ ij σ is the mean. ij The corresponding variance; Step 2.4: Calculate the anomaly detection threshold, including: Step 2.4.1: Input all images in the training set into the first encoder network to obtain their features f; Step 2.4.2: Based on the aforementioned multivariate Gaussian mixture model M ij Calculate the anomaly score s for each spatial location in feature f. ij ; Step 2.4.3: Take the largest anomaly score in the training set as the anomaly detection threshold π; Step 2.5: Construct a defect detection module, including: Step 2.5.1: Input the image to be detected x into the first encoder network to obtain its features f; Step 2.5.2: Based on the aforementioned multivariate Gaussian mixture model M ij Calculate the anomaly score s for each spatial location in feature f. ij ; Step 2.5.3: Take the maximum anomaly score in each spatial location as the anomaly score s of the image to be detected x; Step 2.5.4: Specify the anomaly detection threshold as the threshold π obtained in step 2.4; Step 2.5.5: Determine whether the abnormal score is greater than the specified threshold π. If yes, determine that the image to be detected x is an abnormal image; otherwise, determine that the image to be detected x is a normal image. Step 3: Input the image to be tested into the first encoder network in Step 1 to obtain features, and obtain the detection result of the image based on the defect discrimination model described in Step 2.
2. The unsupervised defect detection method for photovoltaic modules based on contrastive learning according to claim 1, characterized in that, Step 1 includes: Step 1.1: Collect images of photovoltaic modules under actual operating conditions; Step 1.2: Construct the dataset, including: Step 1.2.1: Convert the photovoltaic module image to grayscale, correct the image angle, and change the size to a fixed dimension; Step 1.2.2: Divide the grayscale image into a normal image set and an abnormal image set, and construct a training set and a test set. The training set contains only normal images, and the test set contains both normal images and abnormal images. Step 1.3: Construct two encoder networks: Construct a first encoder network and a second encoder network. The input to both encoder networks is a grayscale image of a fixed size. The two encoders have the same structure but different parameters. Let the outputs of the two encoders be f and q, respectively. Step 1.4: Construct a symmetrical cross-attention network for object pointing; Step 1.5: Train the contrastive learning network model.
3. The unsupervised defect detection method for photovoltaic modules based on contrastive learning according to claim 2, characterized in that, In step 1.3, both the first encoder network and the second encoder network contain 4 residual blocks. Each residual block consists of two convolutional layers with 3×3 kernels and the activation function is ReLU. After the last residual block, a convolutional layer with 3×3 kernels is used for transformation.
4. The unsupervised defect detection method for photovoltaic modules based on contrastive learning according to claim 3, characterized in that, Step 1.4 includes: Step 1.4.1, Correlation Coefficient Calculation: The input to the symmetric cross-attention network pointing to the object is the output of two encoder networks. The dimensions of the input are reshaped to preserve spatial location information. The cosine similarity is used to calculate the correlation coefficient of q with respect to f. In the above formula, f i and q j Represents vectors in the space dimensions f and q, where f i T Represent f i The transpose of the vector, ||*||2 represents the L2 norm of the vector, and the correlation coefficient R represents the feature similarity in the subject space of the two images. Step 1.4.2, Attention Weight Calculation: The correlation coefficient R is subjected to row-wise average pooling to obtain the vector p: p = avgPool(R) In the above formula, avgPool represents the average pooling operation, p represents the average correlation of q with each spatial point of f, and a trainable attention layer is used to map and reshape p to obtain the final attention weight map A of q with respect to f. Step 1.4.3, Symmetric Attention Weight Calculation: The correlation coefficient of f with respect to q can be obtained through the symmetric operation in Step 1.4.1: The attention weight map A′ of f with respect to q can be obtained through step 1.4.2; Step 1.4.4, Enhanced Feature Calculation: Multiply the attention weight map with the features f and q output by the encoder. The enhanced feature calculation is as follows: In the above formula, f represents the dot product operation. ′ q represents the enhanced features of f. ′ This represents the enhanced features of q.
5. The unsupervised defect detection method for photovoltaic modules based on contrastive learning according to claim 4, characterized in that, Step 1.5 includes: Step 1.5.1: Initialize the weights of the contrastive learning network model to random, small values using a Gaussian function, and set the values of the hyperparameters in the model; the hyperparameters include the number of iterations, the size of the sample set used in each training round, the learning rate, and the learning rate decay value; Step 1.5.2: Randomly sample the training set. In each iteration, two different normal photovoltaic images are randomly sampled from the training set. Step 1.5.3: Apply random data augmentation to the two normal photovoltaic images to obtain two enhanced photovoltaic images. The data augmentation operations include cropping, color transformation, and resizing. Step 1.5.4: Input the two enhanced photovoltaic images into the contrastive learning network model to obtain the enhancement features f′ and q of the two enhanced photovoltaic images respectively. ′ ; Step 1.5.5: Based on enhanced features f′ and q ′ Construct the loss function for training the contrastive learning network model; Step 1.5.6: Based on the loss function of the contrastive learning network model, Adam is used as the optimizer, and gradient descent is used to update the first encoder network and the object-pointing symmetric cross-attention network. Step 1.5.7: For the second encoder network, the momentum gradient update method is used to update the parameters based on the parameters of the first encoder network. The update formula is as follows: θ2=mθ2+(1-m)θ1 In the above formula, θ1 represents the parameters of the first encoder, θ2 represents the parameters of the second encoder, and m is the momentum update parameter, which is set to a value in the range of 0.9 to 0.999 according to the actual situation. Step 1.5.8: Determine if the iteration count has been reached: if yes, proceed to step 1.5.9; if not, return to step 1.5.
2. Step 1.5.9: Store the parameters and trained weights in the contrastive learning network model.
6. The unsupervised defect detection method for photovoltaic modules based on contrastive learning according to claim 5, characterized in that, Step 1.5.5 includes: Step 1.5.5.1: Enhance features f′ and q ′ Features f at each identical spatial location i ′ and q i ′ The formula for calculating cosine similarity is: Step 1.5.5.2: The loss function for training the contrastive learning network model is the negative of the sum of the cosine similarities at all spatial locations on the feature map. L=∑ i -D(f i ′,q i ′ )。 7. The unsupervised defect detection method for photovoltaic modules based on contrastive learning according to claim 6, characterized in that, Step 2.2 includes: Step 2.2.1: Perform random data augmentation on the normal photovoltaic images in the training set to obtain a total of N augmented images, each image represented as x. k ; Step 2.2.2: The enhanced image x... k Input the first encoder network to obtain its features f k ; Step 2.2.3: For each spatial location (i,j) of the normal image, N features f k Fit a multivariate Gaussian mixture model M ij Its mean μ ij The calculation formula is: Its variance σ ij The calculation formula is:
8. The unsupervised defect detection method for photovoltaic modules based on contrastive learning according to claim 6, characterized in that, Step 3 includes: Step 3.1: Read the defect identification module; Step 3.2: Input the image to be detected; Step 3.3: Preprocess the image to be detected, including: Step 3.3.1: Crop the image to be detected, remove the background area, and obtain the main body of the image to be detected; Step 3.3.2: Perform image correction and grayscale processing on the detected image, and then scale it. Step 3.4: Input the preprocessed image into the defect discrimination module, and the defect discrimination module returns the discrimination result.
Citation Information
Patent Citations
Radar target identification method based on Transform and time convolution network
CN115079116A
Method and device for generative adversarial network training
US20190130221A1