Photovoltaic panel defect generation method based on improved generative adversarial network
By improving the adaptive normalization and fine-grained channel attention module of the generative adversarial network, and combining it with a multidimensional loss function to optimize the generator and discriminator, the consistency and realism issues in the generation of photovoltaic panel defects were resolved, thereby improving the generation quality and stability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NANCHANG CAMPUS OF EAST CHINA UNIV OF TECH
- Filing Date
- 2026-03-17
- Publication Date
- 2026-05-22
AI Technical Summary
The existing BicycleGAN suffers from problems such as unstable generation quality, indistinct defect regions, unclear defect details, lack of explicit constraints, and insufficient ability to perceive cross-domain style differences in photovoltaic panel defect generation, resulting in poor consistency and low realism of generated images.
We replace the batch normalization layer with an adaptive normalization layer, embed an adaptive fine-grained channel attention module, use spatial partitioning convolution module and transposed convolution for feature processing, and construct a multidimensional loss function, including perceptual loss, style loss and total variation loss. We combine semantic label guidance and latent variable constraints to optimize the training process of the generator and discriminator.
It improves the quality, diversity, and realism of photovoltaic panel defect generation, enhances the ability to perceive cross-domain style differences, and ensures the salience and detail fidelity of defect areas, especially in the stability and accuracy of generation quality in small sample scenarios.
Smart Images

Figure CN121883481B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the photovoltaic industry, and in particular to a method for generating defects in photovoltaic panels based on an improved generative adversarial network. Background Technology
[0002] In the photovoltaic industry, with the rise of generative adversarial networks (GANs), more and more researchers are conducting in-depth research and exploration on this type of data augmentation method. The core of the BicycleGAN (Generative Adversarial Network) solution for photovoltaic panel defect generation addresses the pain points of scarce photovoltaic defect samples and class imbalance. Leveraging its bidirectional mapping and latent space constraints, it multimodal generation characteristics first collect and preprocess normal photovoltaic panel images and a small number of real defect samples to construct a training set without strict pairwise requirements. Then, it builds a model architecture adapted to photovoltaic images. The generator uses a U-Net structure to preserve defect details, the encoder maps images to the latent space, and the discriminator uses PatchGAN to distinguish between real and fake samples. During training, the network parameters are alternately updated with adversarial loss, latent space reconstruction loss, and image reconstruction loss as optimization objectives. Finally, by sampling different latent variables, it generates multiple types of defect samples, such as cracks, and combines metrics such as PSNR and SSIM to select high-fidelity samples, thereby improving the generalization ability of the subsequent defect detection model.
[0003] BicycleGAN addresses five core issues in the generation of defects in photovoltaic panels, and each issue has a corresponding targeted improvement solution.
[0004] First, the quality of the generated images is unstable, which manifests as conflicts in the optimization of multi-objective loss functions and imbalances in adversarial games, leading to drastic fluctuations in gradient backpropagation, slow network convergence or even divergence, and poor consistency of the generated images.
[0005] Secondly, the defect areas are not prominent. Because the network focuses more on learning the photovoltaic panel background with large information and simple features, it pays insufficient attention to the defect areas with small proportions and dense features, resulting in low contrast between defects and background and weak recognition.
[0006] Third, the defect details are not clear. The original max pooling downsampling is prone to losing key details such as defect edges. The fixed downsampling factor is difficult to adapt to defects of different sizes, and upsampling is prone to feature aliasing and edge blurring.
[0007] Fourth, the lack of explicit constraints on the quality of defect generation means that the overall loss calculation for the entire image cannot specifically optimize the quality of defect region generation, resulting in blurred defect features and difficulty in guaranteeing generation quality in small sample scenarios.
[0008] Fifth, it lacks the ability to perceive cross-domain style differences and the robustness of its patterns, making it difficult to adapt to cross-domain style differences such as uneven illumination of photovoltaic panel images and differences in background brightness, which affects the realism and stability of the generated images. Summary of the Invention
[0009] In view of the above, the main objective of this invention is to propose a photovoltaic panel defect generation method based on an improved generative adversarial network to solve the aforementioned technical problems.
[0010] This invention proposes a method for generating defects in photovoltaic panels based on an improved generative adversarial network, the method comprising the following steps:
[0011] Step 1: The encoding part of the generator is downsampled layer by layer using a spatial partitioning-based convolution module, the decoding part is upsampled layer by layer using transposed convolution, and the encoding part is connected to the output of the decoding part using a skip connection method.
[0012] An adaptive fine-grained channel attention module is embedded in the spatial partitioning convolution module and the output of the transposed convolution;
[0013] An adaptive normalization layer is set after the convolutional layer of the discriminator to dynamically adjust the normalization parameters according to the style of the input features in order to obtain the photovoltaic panel defect generation model.
[0014] Step 2: Use the defective photovoltaic panel image as the real target domain image, and the defect-free or other style photovoltaic panel image as the source domain image;
[0015] The real target domain image is input into the variational encoder to obtain the latent variable distribution; the latent variable distribution is reparameterized to obtain the first latent vector; the source domain image and the first latent vector are input into the generator to obtain the first target domain image.
[0016] The second latent vector is obtained by sampling through a standard normal distribution. The second latent vector and the source domain image are then input into the generator to obtain the second target domain image.
[0017] The source domain image is combined with the first target domain image and the second target domain image respectively, and then fed into the corresponding discriminator to determine the probability of authenticity, so as to obtain the identification result.
[0018] Step 3: Based on the identification results, construct the original loss function based on the BicycleGAN framework. Based on the first target domain image, the second target domain image, and the real target domain image, construct the perceptual loss, style loss, and total variation loss respectively.
[0019] The photovoltaic panel defect generation model is trained by weighted joint method for perceptual loss, style loss, total variation loss and original loss function. After training, the trained generator is retained and other components are discarded or disabled to obtain the trained photovoltaic panel defect generation model.
[0020] Step 4: Obtain the image of the photovoltaic panel to be tested and sample the second latent vector. Input the image of the photovoltaic panel to be tested and the second latent vector into the trained photovoltaic panel defect generation model to obtain a photovoltaic panel image with diverse defect features.
[0021] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0022] 1. This invention enhances the discriminator's ability to perceive cross-domain style differences and its robustness to patterns by replacing the batch normalization layer with an adaptive normalization layer in the discriminator, thereby improving the stability of adversarial training.
[0023] 2. This invention constructs an adaptive fine-grained channel attention module by embedding an adaptive fine-grained channel attention mechanism in the intermediate layer between the encoding and decoding parts of the generator. This allows the algorithm to retain core content and adapt to the style details of the target domain during cross-domain generation, thereby improving the quality, diversity, and realism of defective images.
[0024] 3. This invention improves defect contrast and is adapted in coordination with SPDConv and the adaptive fine-grained channel attention module by replacing max pooling downsampling with SPDConv in the generator to preserve key details, and replacing the original upsampling operation with transposed convolution in the decoding stage, thereby accurately restoring fine-grained defect details.
[0025] 4. This invention incorporates perceptual loss into the dual-branch (cVAE-GAN, cLR-GAN) training framework, and constructs a multi-dimensional loss function by combining style loss and total variation loss. It indirectly constrains the generated image by comparing the features of the generated image and the real image, and works with LR adversarial loss, KL divergence loss and pixel loss to achieve a dual improvement in generation quality and training stability under small sample conditions.
[0026] 5. The Adaptive Normalization Layer (Ada-DBIN) of this invention has plug-in characteristics, which can seamlessly replace the traditional normalization layer without major reconstruction of the network architecture, thus taking into account both practicality and scalability.
[0027] 6. This invention achieves controllable generation of defect regions and categories by combining semantic tag guidance with latent variable constraints. It can generate photovoltaic panel defect images of different types and forms in a targeted manner, covering the complex situation of multiple defects coexisting in real-world scenarios.
[0028] Additional aspects and advantages of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by means of embodiments of the invention. Attached Figure Description
[0029] Figure 1 This is a network structure diagram of the photovoltaic panel defect generation method based on an improved generative adversarial network proposed in this invention.
[0030] Figure 2 This is a network structure diagram of the generator of the present invention;
[0031] Figure 3 This is a network structure diagram of the discriminator of the present invention;
[0032] Figure 4 This is a network structure diagram of the normalization layer in the adaptive domain decoupling instance of the present invention;
[0033] Figure 5 This is a network structure diagram of the adaptive fine-grained channel attention module of the present invention;
[0034] Figure 6 This is a network structure diagram of the spatial partitioning downsampling convolution module of the present invention;
[0035] Figure 7 This is a network structure diagram of the transposed upsampling convolution module of the present invention;
[0036] Figure 8 This is a schematic diagram of the semantic label images used in the verification process.
[0037] Figure 9 A schematic diagram illustrating the images generated for each model during the verification process;
[0038] Figure 10 This is a schematic diagram of the ablation experiment images of the model. Detailed Implementation
[0039] Embodiments of the present invention are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.
[0040] These and other aspects of the embodiments of the present invention will become clear from the following description and accompanying drawings. In these descriptions and drawings, some specific embodiments of the present invention are specifically disclosed to illustrate some ways of implementing the principles of the embodiments of the present invention; however, it should be understood that the scope of the embodiments of the present invention is not limited thereto.
[0041] Please see Figure 1 This embodiment provides a method for generating defects in photovoltaic panels based on an improved generative adversarial network. The method includes the following steps:
[0042] Step 1: The encoding part of the generator is downsampled layer by layer using a spatial partitioning-based convolutional module (SPDConv), and the decoding part is upsampled layer by layer using a transposed convolution (TransConv). The encoding part is connected to the output of the decoding part using a skip connection method.
[0043] Furthermore, adaptive fine-grained channel attention modules (AFGCA) are embedded in the output parts of the spatially partitioned convolutional modules and the transposed convolutions to achieve feature enhancement; such as Figure 2 As shown, Figure 2 In this context, SPDConv represents a spatially partitioned convolutional module, TransConv represents a transposed convolution, and AFGCA represents an adaptive fine-grained channel attention module. This indicates a splicing operation.
[0044] An adaptive normalization layer is placed after the convolutional layer of the discriminator to dynamically adjust the normalization parameters according to the style of the input features, so as to obtain the photovoltaic panel defect generation model; for example Figure 3 As shown, the discriminator in this embodiment is a multi-scale discriminator, with several discriminator modules set in each scale. Each discriminator module contains a convolutional layer, an adaptive normalization layer, and a ReLU activation layer. Figure 3 In this context, Ada-DBIN represents an adaptive normalization layer, and Conv represents a convolution operation.
[0045] In a preferred embodiment of the present invention, the working process of the generator's encoding part downsampling layer by layer and the decoding part upsampling layer by layer is as follows:
[0046] The source domain image is concatenated with either the first or second latent vector along the channel dimension to obtain the input feature map.
[0047] The input feature map is used as the input to the spatial partitioning convolutional module. The input feature map is input into the first spatial partitioning convolutional module, which divides the space into multiple non-overlapping sub-regions.
[0048] Multiple sub-regions are stitched together along the channel dimension to obtain an intermediate feature map with an increased number of channels and a halved spatial size.
[0049] The intermediate feature map is convolved, the number of channels is adjusted, and then normalization and activation operations are performed sequentially to obtain the feature map output by the current spatial partition-based convolution module.
[0050] The feature map output by the current spatial partitioning-based convolutional module is input into the next spatial partitioning-based convolutional module. After passing through all spatial partitioning-based convolutional modules in sequence, the downsampling of the spatial partitioning-based convolutional modules is completed, and a multi-scale feature map is obtained.
[0051] The decoding part of the generator uses transposed convolution for upsampling. The process is as follows: through a single transposed convolution operation, the spatial size of the multi-scale feature map is simultaneously enlarged and the number of channels is adjusted.
[0052] In a preferred embodiment of the present invention, the adaptive normalization layer employs an adaptive domain decoupling instance normalization module. This module, designed for cross-domain generation tasks, is a feature style processing module whose core objective is to dynamically balance domain-independent and domain-dependent components in features, addressing the difficulty of traditional normalization in adapting to different style differences. It achieves fine-grained control over feature style through four core steps: instance normalization, style relevance quantification, adaptive weight calculation, and feature fusion. Figure 4 As shown, it can be used as a plug-in module to replace traditional normalization layers such as BatchNorm and Instance-Norm in generative adversarial networks. In scenarios such as photovoltaic panel defect image generation, it can effectively enhance the model's ability to perceive and adapt to cross-domain style differences.
[0053] The module first separates the basic features from the style residuals through instance normalization. It then obtains the preliminary feature maps extracted from the discriminator input layer, and calculates the mean of each channel for these preliminary feature maps. With variance Then calculate the fundamental features that are independent of the domain. Simultaneously, the style residual containing style information is extracted by subtracting it from the original input. This lays the foundation for subsequent style processing and achieves an initial decoupling of content and style.
[0054] ;
[0055] ;
[0056] ;
[0057] ;
[0058] in, This represents the mean. Represents variance. This represents the preliminary feature map. N represents the batch size; C represents the number of channels; H and W both represent spatial dimensions. The fundamental characteristic of domain independence, Indicates stylistic residuals, This indicates the batch size, number of channels, height, and width of the input feature map.
[0059] Then, to accurately quantify the inter-channel correlation of style features, the module introduces the calculation of the cosine similarity Gram matrix. First, the style residuals... Flattened The channel-space feature matrix is obtained, and the spatial dimension is L2 normalized to eliminate the scale effect. Then, the Gram matrix is obtained through matrix multiplication. Each element of the matrix represents the style correlation between the corresponding channels, providing a quantitative basis for subsequent weight calculation.
[0060] ;
[0061] ;
[0062] ;
[0063] in, Represents the channel-space feature matrix. This represents the flattening feature after normalization. This indicates the L2 normalization operation.
[0064] Next, domain-independent and domain-correlated style weights are further calculated based on the Gram matrix. First, the diagonal elements of the Gram matrix are removed to eliminate channel autocorrelation interference, resulting in the processed matrix. ;then the processed matrix The mean of each row is calculated, and the domain-independent weights are obtained using the Softmax function. This reflects the contribution of each channel to domain-independent content, enables differentiated evaluation of the style attributes of different channels, and provides clear numerical guidance for subsequent weighting.
[0065] ;
[0066] ;
[0067] in, Represents the Gram matrix, This indicates the transpose operation. This represents the processed matrix. This indicates the operation of removing the corner element. Indicates domain-independent weights, This represents the normalized exponential function.
[0068] Finally, this module designs an adaptive weighting mechanism. A lightweight importance predictor, consisting of adaptive average pooling, 1×1 convolution, and sigmoid activation, processes the initial feature map and outputs the importance score for each channel. The importance score of each channel is combined with the domain-independent weight. Element-wise multiplication is performed to obtain the final adaptive weights. Then, the final adaptive weights are broadcast. Extending to the feature map dimension, and style residuals Element-wise multiplication yields the weighted style residuals. Finally, the basic features Compared with weighted style residuals The components are added together to obtain the final output of the module, completing the feature fusion of "basic content + adaptive style".
[0069] This module boasts three core advantages: dynamic adaptability, style decoupling capability, and lightweight efficiency. Dynamic adaptability is reflected in the real-time adjustment of weights through a lightweight importance predictor, enabling it to adapt to style differences across various input features. Style decoupling capability, by explicitly separating domain-independent and domain-dependent components, allows the model to retain core content, such as the morphological features of photovoltaic panel defects, while flexibly adapting to the target domain style during cross-domain generation. Lightweight efficiency benefits from simplified matrix calculations and the SE attention mechanism, improving model performance without significantly increasing computational overhead, making it highly practical and scalable across various generative adversarial networks.
[0070] As a preferred embodiment of the present invention, the adaptive fine-grained channel attention module is an attention mechanism designed for the channel dimension of feature maps. Its core objective is to enhance the weights of key feature channels by finely modeling the dependencies between channels, while suppressing redundant information, thereby improving the model's ability to perceive important features. This module achieves fine-grained optimization of feature channels through designs such as fusing local and global channel interactions and dynamically adjusting the attention weight fusion ratio. It can be flexibly embedded into encoder and decoder modules of generative adversarial networks, effectively strengthening the expression of defect region features in photovoltaic panel defect image generation tasks. The principle and structure of the adaptive fine-grained channel attention mechanism are as follows: Figure 5 As shown in the figure, Conv1d represents one-dimensional convolution, and Conv2d represents 2D convolution.
[0071] The module first extracts channel-level global information through global feature compression. For the input feature map at the current scale... Adaptive average pooling is used to compress it to By aggregating spatial dimensional information, the features of each channel are condensed into a single value, providing a foundation for subsequent channel interaction calculations.
[0072] ;
[0073] in, Indicates adaptive average pooling. Represents the channel-level global feature vector;
[0074] To fully capture the dependencies between channels, the module is designed with a dual-channel interactive computing mechanism, including a first-channel interaction path and a second-channel interaction path.
[0075] First, the channel-level global feature vector is transposed and processed by one-dimensional convolution, then transposed back to the original dimension to obtain the channel-level global features; then the channel-level global feature vector is processed by 1X1 convolution to obtain the interaction information between channels.
[0076] The channel-level global feature vector is transposed and then processed by one-dimensional convolution, and then transposed back to the original dimension to obtain the local relationship in the channel dimension; the channel-level global feature vector is then processed by two-dimensional 1X1 convolution to obtain the global relationship in the channel dimension.
[0077] The global features along the channel dimension and the interaction information between channels are input into the first channel interaction path. The global interaction is calculated through matrix multiplication and activated by Sigmoid to obtain the first attention weight. The global features along the channel dimension and the interaction information between channels are input into the second channel interaction path. The reverse channel interaction is calculated by changing the order of matrix multiplication to obtain the second attention weight.
[0078] ;
[0079] ;
[0080] in, and These represent the global features at the channel level and the interaction information between channels, respectively. Indicates the first attention weight. This represents the Sigmoid activation function. Represents matrix multiplication. This represents the second attention weight.
[0081] To dynamically balance the contributions of the two channel interaction modes, the module introduces a Mix module for attention fusion. This module uses learnable parameters... Calculate the fusion coefficient Then, the first attention weight and the second attention weight are weighted and fused. This allows the model to adaptively adjust the proportion of the two attention modes according to the characteristics of the input features. In the defect area of the photovoltaic panel, the channel interaction weights related to the crack edge can be strengthened.
[0082] ;
[0083] ;
[0084] in, Represents the fusion coefficient. Indicates learnable parameters, This indicates the channel interaction weight.
[0085] The merged attention weights need further optimization to improve their granularity. The module will... After transposing, the weights are processed by one-dimensional convolution, then transposed back to the original dimension and activated by a sigmoid function to generate the final attention weights. Finally, the attention weight is multiplied element-wise with the feature map of the original input at the current scale to obtain the enhanced feature map, which strengthens the features of important channels (such as those containing defect details) and suppresses the features of redundant channels.
[0086] ;
[0087] in, Represents one-dimensional convolution. This indicates that the two dimensions of the input are swapped. This represents the final attention weight.
[0088] The core advantages of the adaptive fine-grained channel attention module are reflected in three aspects: First, it combines local channel dependency with global channel interaction to achieve fine-grained channel attention modeling; second, through the dynamic fusion mechanism of the Mix module, it improves the adaptability of attention to different feature distributions; and third, all operations maintain the consistency of input and output feature map shapes, allowing for seamless embedding into various convolutional neural network architectures with low computational overhead. In the photovoltaic panel defect generation task, this module can effectively guide the model to focus on the key features of the defect region, improving the clarity and saliency of defects in the generated image.
[0089] In this embodiment of the invention, the encoding part of the generator uses a spatial partitioning-based convolutional module for downsampling, i.e., it is implemented through a spatial partitioning downsampling convolutional module, which is a tensor processing unit that balances feature downsampling and detail preservation. Figure 6 As shown, the core function is to achieve efficient dimensionality transformation through spatial partitioning and convolutional fusion. Its workflow consists of two steps: First, the input tensor is spatially divided into four equal parts, and sub-regions are extracted according to the rules of even rows and even columns, odd rows and even columns, even rows and odd columns, and odd rows and odd columns. Then, the four partitions are concatenated along the channel dimension, making the number of channels four times the original and halving the spatial dimensions (height and width). Subsequently, a 3×3 convolutional layer is used to fuse the concatenated features, adjusting the number of channels to the specified output dimension, thus completing downsampling and feature integration.
[0090] The input and output dimensions of this module change clearly. Compared with traditional pooling or convolution, SPDConv retains more spatial details through multi-partition stitching, and at the same time achieves feature fusion with the help of convolutional layers, achieving a balance between sampling efficiency and detail preservation. It is suitable for scenarios that require compressing feature size without losing key local information, such as the encoder downsampling stage in the generation of photovoltaic panel defect images.
[0091] In this embodiment of the invention, the decoding part employs transposed convolution for upsampling, specifically through a transposed upsampling convolution module. This module is the core component in the Generator architecture responsible for upsampling during the decoding stage. It primarily uses transposed convolution to enlarge the feature map size and adjust its channels, and then fuses these features with skip connection features from the corresponding encoder level, thereby restoring spatial details during the generator's decoding process. Its core design balances efficient dimensional transformation with multi-scale feature integration, effectively preserving low-level details such as crack edges and fragment contours in tasks like generating photovoltaic panel defect images, thus improving the precision of the generated results.
[0092] The core operations of the module revolve around transposed convolution, simultaneously performing upsampling and channel adjustment in a single operation, such as... Figure 7 As shown, in the feature processing flow, the module first upsamples the input features through transposed convolution, then stabilizes the training distribution through batch normalization, and finally introduces nonlinearity through the ReLU activation function. The processed features are then concatenated with the skip connection features of the corresponding level of the encoder in the channel dimension to achieve the fusion of high-level semantic features and low-level detailed features.
[0093] Compared to the traditional combination of upsampling and convolution, transposed convolution completes both size and channel adjustments in a single operation, resulting in higher computational efficiency; the combination of batch normalization and ReLU effectively alleviates the gradient vanishing problem during training; and the feature concatenation of skip connections inherits the classic design of U-Net, ensuring that key details are not lost during decoding, making it stand out in generation tasks that require high-precision feature recovery.
[0094] Step 2: Use the defective photovoltaic panel image as the real target domain image, and the defect-free or other style photovoltaic panel image as the source domain image;
[0095] The real target domain image is input into the variational encoder to obtain the latent variable distribution; the latent variable distribution is reparameterized to obtain the first latent vector; the source domain image and the first latent vector are input into the generator to obtain the first target domain image.
[0096] The second latent vector is obtained by sampling through a standard normal distribution. The second latent vector and the source domain image are then input into the generator to obtain the second target domain image.
[0097] The source domain image is combined with the first target domain image and the second target domain image respectively, and then fed into the corresponding discriminator to determine the probability of authenticity, so as to obtain the identification result.
[0098] Step 3: Based on the identification results, construct the original loss function based on the BicycleGAN framework. Based on the first target domain image, the second target domain image, and the real target domain image, construct the perceptual loss, style loss, and total variation loss respectively.
[0099] The photovoltaic panel defect generation model is trained by weighted joint method of perceptual loss, style loss, total variation loss and original loss function. After training, the trained generator is retained and other components are discarded or disabled to obtain the trained photovoltaic panel defect generation model.
[0100] In this embodiment of the invention, the problem of feature weakening or disappearance that easily occurs in the generation of small targets, such as microcracks and tiny fragments in photovoltaic panels, using traditional loss functions is addressed. Specifically, this manifests as blurred edges, loss of details, or even complete non-generation of small targets. Based on the original BicycleGAN loss framework, this invention innovatively introduces perceptual loss, style loss, and total variation loss to construct a multi-dimensional loss function that focuses on preserving the features of small targets. This design strengthens the semantic saliency, stylistic uniqueness, and edge integrity of small targets, overcoming the shortcomings of traditional pixel loss in its insufficient sensitivity to small target features, and significantly improving the clarity and integrity of small targets in the generated images.
[0101] First, the traditional pixel loss (L1) averages the global pixel error, which can easily dilute the feature error of small targets by the background region, causing the model to ignore the structural integrity of small targets. Therefore, this invention introduces a perceptual loss based on VGG16, which enhances the semantic saliency of small targets through deep feature matching. This loss selects shallow to mid-level features from VGG16, such as ReLU1_2 (edge details) and ReLU2_2 (local structure), to calculate the feature L1 loss between the real image and the generated image:
[0102] ;
[0103] in, Indicates perceived loss. This represents the feature map of the i-th layer of VGG16; This represents the generated first target domain image or second target domain image; Represents the true target domain image; This represents the L1 norm, which calculates the sum of the absolute values of feature differences, enhancing sensitivity to errors in small target features. Shallow features are more sensitive to the edges and textures of small targets; by focusing on the differences in these features, the model is forced to pay attention to the structural integrity of small targets, preventing them from being overwhelmed by background features during generation.
[0104] Secondly, small targets typically possess unique stylistic features, such as the grayscale of cracks and the texture distribution of fragments. Traditional loss methods struggle to capture these fine-grained stylistic differences, leading to visual deviations between the generated small targets and real samples, such as cracks blending into the background. This invention designs a style loss based on the Gram matrix, specifically constraining the stylistic features of small targets. This loss quantifies the stylistic uniqueness of small targets by calculating the Gram matrix differences of VGG features:
[0105] ;
[0106] in, Indicating style loss, For Gram matrix calculation operations, ; The square of the L2 norm quantifies the degree of matching of style features (such as the grayscale difference between small targets and the background). For small targets, their features are represented by strong correlations in specific channels in the Gram matrix, such as the gradient channel corresponding to the crack edge. This loss strengthens this correlation matching to ensure that the generated small targets are consistent with the real samples in terms of grayscale distribution and texture details, avoiding visual disappearance due to style alienation.
[0107] Finally, because the edges of small targets are often fragile and susceptible to noise interference, edge blurring or breakage can easily occur during training, such as the disappearance of branches of tiny cracks. This invention introduces a total variation loss to protect the edge integrity of small targets by constraining local pixel smoothness.
[0108] ;
[0109] in, This represents the total variation loss. The weighting parameter represents the total variation loss; This represents the pixel value of the generated image at coordinates (h, w); The sum of the absolute differences between adjacent pixels in the horizontal direction constrains the integrity of the horizontal edge of the small target; The total variation loss is the sum of the absolute differences between adjacent pixels in the vertical direction, constraining the integrity of the vertical edges of small targets. By controlling the pixel differences in the horizontal and vertical directions, this loss suppresses background noise while preventing the edges of small targets from being overly smoothed. For example, for the fine branches of a crack in a photovoltaic panel, the total variation loss can maintain the gradient difference between the branch endpoints and surrounding pixels, preventing them from being dissolved by smoothing operations.
[0110] The original loss functions include the VAE adversarial loss function, the LR adversarial loss function, and the pixel loss function. Based on the original loss functions, perceptual loss, style loss, and total variation loss are introduced for weighted joint training to improve the total loss function. The formula for calculating the improved total loss function is as follows:
[0111] ;
[0112] in, This represents the adversarial loss function of VAE. This represents the LR adversarial loss function. Represents the pixel loss function. Denotes the KL divergence loss function. These represent the weights of the corresponding loss functions, which are set to 10, 0.01, 5, 10000, and 0.000001 in this embodiment.
[0113] The calculation process of the pixel loss function is based on the following relationship:
[0114] ;
[0115] The calculation process of the KL divergence loss function is based on the following relationship:
[0116] ;
[0117] in, Represents the logarithmic variance. This represents the average value of the encoder output;
[0118] The calculation process of the VAE adversarial loss function is based on the following relationship:
[0119] ;
[0120] in, This indicates the operation for calculating the mean square error. Represents the source domain image. Represents the first target domain image. This represents the cVAE discriminator;
[0121] The calculation process of the LR adversarial loss function is based on the following relationship:
[0122] ;
[0123] in, This represents the cLR discriminator. This represents the second target domain image.
[0124] The improved total loss function protects the features of small targets through multi-dimensional constraints. Perceptual loss ensures the structure of small targets is not ignored, style loss maintains their unique visual features, and total variation loss protects edge integrity. These three factors complement each other, addressing the core issues of low proportion, weak features, and easy vanishing of small targets. This allows the model to actively focus on and preserve details of small targets during generation, resulting in a significant improvement in the clarity and integrity of small targets such as minute cracks and fragments in the final generated photovoltaic panel defect image.
[0125] Step 4: Obtain the image of the photovoltaic panel to be tested and sample the second latent vector. Input the image of the photovoltaic panel to be tested and the second latent vector into the trained photovoltaic panel defect generation model to obtain a photovoltaic panel image with diverse defect features.
[0126] To verify the superiority and effectiveness of the present invention, this embodiment verifies the solution of the present invention, as follows:
[0127] The dataset used is the PVEL-AD industrial inspection dataset, which contains images of 12 types of defects, including cracks (linear and star-shaped), broken grids, black cores, misalignment, thick lines, scratches, fragments, broken corners, horizontal dislocations, lateral dislocations, printing errors, and short-circuit defects. The RGB image resolution is 1024×1024. Considering the high memory consumption, low training efficiency, unstable gradient optimization, and low generation quality associated with high-resolution images during training, this invention compresses the images to 512×512 pixels. The goal of this invention is to generate high-quality photovoltaic panel defect images even with limited data. Therefore, this invention selects six relatively rare categories from the dataset for semantic annotation: 19 images of star-shaped cracks, 3 images of scratches, 7 images of fragments, 7 images of broken corners, 2 images of printing errors, and 15 images of vertical misalignment.
[0128] To generate diverse photovoltaic panel defect images, this invention expands the semantic label images to improve the stability of the training process and the diversity of generated samples. First, conventional image enhancement operations such as flipping, cropping, and brightness adjustment are performed on the original images to achieve the initial expansion of the original dataset. Then, since the original dataset contains only a single defect category, to achieve diversified sample generation, defects and defect masks are separately selected and subjected to geometric operations such as mirroring, rotation, translation, and scaling to achieve basic expansion of the defect targets. Next, based on this, different extracted defect labels are combined and stitched onto the background image to achieve combined expansion of the photovoltaic panel defect data. Finally, 670 defect images were obtained, including 468 images in the training set, 134 images in the validation set, and 68 images in the test set. The semantic label images are shown below. Figure 8 As shown, where Figure 8 a in Figure 8 b in Figure 8 The 'c' in the equation is obtained by extending the basic equation, while... Figure 8 d in Figure 8 e in Figure 8 f in the equation comes from combinatorial expansion. Figure 8 The 'a' in the text represents a vertical misalignment; Figure 8 In the image, 'b' represents a star-shaped crack. Figure 8 The 'c' in the text indicates a printing error. Figure 8 In this context, 'd' represents star-shaped cracks and fragments. Figure 8 In this context, 'e' represents broken corners and fragments; Figure 8 In this context, 'f' represents broken corners and scratches.
[0129] The hardware environment used for model training was an NVIDIA GeForce RTX 3090 GPU (24GB), an AMD EPYC764248 Core Processor with 20V CPU, and an Ubuntu 20.04 system. The deep learning framework used was PyTorch version 2.0.0, the programming language was Python 3.8, CUDA version was 11.8, and CuDNN version was 8.9.5. The training parameters were set as follows: learning rate (lr) was 0.01, perceptual loss weights were 5, style loss weights were 1e-4, total variation regularization weights were 1e-6, VGG16 was used for feature extraction with pre-trained weights loaded, and other parameters were left as default. The image input size was 512×512 pixels, the training batch size was 4, and the number of training epochs was 200.
[0130] To comprehensively quantify the quality of generated photovoltaic panel defect images, peak signal-to-noise ratio (PSNR), structural similarity index (SSIM), and learned perceptual image patch similarity (LPIPS) were selected as evaluation indicators from three dimensions: pixel consistency, structural integrity, and subjective perception realism.
[0131] Peak Signal-to-Noise Ratio (PSNR) is a classic metric for measuring pixel-level distortion in images. Its core principle is to assess global consistency by quantifying the pixel differences between the real and generated images. This metric typically ranges from 20 to 40 dB; a higher value indicates a smaller pixel-level difference between the generated and real images. It can be used to initially verify the global pixel consistency of the generated image, and is particularly suitable for judging the degree of distortion in large background areas.
[0132] ;
[0133] in, and This represents two images, where i and j represent pixel indexes, MSE is the mean square error of the two images, and MAX represents the maximum possible pixel value in the image.
[0134] The Structural Similarity Index (SSIM) is designed based on the sensitivity of human vision to image structure, evaluating the structural integrity of generated images from three dimensions: brightness, contrast, and structure. The index ranges from -1 to 1, with values closer to 1 indicating better structural consistency. It can accurately capture the edge continuity and morphological integrity of photovoltaic panel defects, compensating for the shortcomings of PSNR in ignoring structural distortion.
[0135] ;
[0136] ;
[0137] ;
[0138] ;
[0139] in, These represent constant terms, used to prevent the denominator from being zero and to ensure the numerical stability of the calculation. , , , These represent the weights of the luminance component, contrast component, and structure component, respectively, with K1=0.01 and K2=0.03. and These represent the average values of image x and y within the local window, respectively. Indicates the brightness level of the image; and Let x and y represent the variances of the image within the local window, respectively. Indicates the contrast of an image; It is the covariance of the image x and y within the local window. This represents the structural similarity of images; L represents the dynamic range of pixel values. Typically... , .
[0140] Learning-Perceived Image Patch Similarity (LPIPS) is a deep learning-based subjective perception-level metric that evaluates the visual realism of generated images through high-level semantic feature matching. Its calculation uses a pre-trained VGG16 network as a feature extractor. A lower metric value indicates a smaller subjective perception difference, effectively identifying detail loss issues in small target defects. This aligns with human visual judgment standards for photovoltaic panel defect images, providing a quantitative basis for the subjective consistency of generated image quality.
[0141] ;
[0142] in, Indicates the first l Feature extraction function of the layer; This represents the learned weights; This represents the L2 norm.
[0143] This paper compares the overall performance and photovoltaic panel defect generation details of the present invention with those of seven advanced image translation networks: DualGAN (Dual Generative Adversarial Network), DiscoGAN (Associative Generative Adversarial Network), pix2pix (Pixel-to-Pixel), CycleGAN (Cyclic Consistent Generative Adversarial Network), BicycleGAN (Bidirectional Sampling Generative Adversarial Network), unit (Unsupervised Image-to-Image Translation Network), and munit (Multimodal Unsupervised Image-to-Image Translation Network). Typical images of various types of photovoltaic panel defects generated by each network are shown below. Figure 9 As shown in Table 1, the mean values of PSNR, SSIM, and LPIPS were calculated for the 68 images that did not participate in the training and validation process and their generated images.
[0144] Table 1. Comparative Experiment Results of Lightweight Networks
[0145]
[0146] When evaluating different GAN models, PSNR (Peak Signal-to-Noise Ratio), SSIM (Structural Similarity Index), and LPIPS (Learned Perceptual Patch Similarity) are important performance metrics. These data clearly show significant numerical differences among different models in these metrics, which also indicate varying performance characteristics of each model in real-world applications.
[0147] The results show that CycleGAN, belonging to unsupervised GAN networks, can learn the basic feature information of real photovoltaic panel images well. The grayscale value and brightness of the generated images maintain a high similarity with the real photovoltaic panel images. However, the generation effect in defect areas such as cracks is poor. For example, the edges of fine cracks are blurred, and small fragments show ablation. The defect distortion is serious. Its SSIM and PSNR values are as low as 0.3542 and 28.02dB, respectively, while the LPIPS value is as high as 0.7483. This indicates that the generated images have significant differences from the real samples in terms of structural consistency and subjective perception.
[0148] BicycleGAN and other models belong to the supervised GAN network category. Among them, the overall quality of photovoltaic panel defect images generated by BicycleGAN is better than that of unsupervised CycleGAN. The basic details such as the texture of the photovoltaic panel backsheet and the outline of the frame are clear in the images, but there is a common problem of background area generation distortion, such as irregular black shadows on the backsheet. Furthermore, there is still room for optimization in the defect details, such as blurred hidden crack branches and abrupt grayscale transitions at the edge of spots. Among them, BicycleGAN has a strong ability to reconstruct large-area background areas of photovoltaic panels, generating fine and uniform textures. Since the background area accounts for more than 90% of the total image area, its PSNR and SSIM values are 29.35dB and 0.6237, respectively, and its LPIPS value is about 0.3969. However, this network is not good at generating details of small target defects, such as fine cracks with a width of 1-2 pixels, and is prone to defect disappearance. The pix2pix network generates photovoltaic panel defect images with clear internal texture details and natural gray-scale transition between the defect and the background. However, the generated photovoltaic panel back panel has obvious distorted grid-like textures. The unit network generates photovoltaic panel defect images with high overall gray-scale values, bright illumination, and high information density of photovoltaic panel texture and defect features. Its PSNR and SSIM values are 28.61dB and 0.106, respectively, and its LPIPS value is about 0.6432. However, it has high computational complexity, large GPU memory requirements, and slow training convergence speed.
[0149] The photovoltaic panel defect images generated by the network of this invention exhibit the best performance in terms of feature saliency, detail realism, and edge sharpness. The branching structure of cracks is complete, with clearly identifiable endpoints, and the size and grayscale distribution of fragments closely match real samples. The generated background area has a fine and uniform texture, free of black shadows and blocky noise, and shows no obvious visual fragmentation. Objectively, the network of this invention outperforms the comparison networks overall. Compared to the basic BicycleGAN network, it improves PSNR by an average of approximately 2.84 dB, SSIM by an average of 35%, and LPIPS by an average of approximately 0.5662, fully validating the effectiveness of the improved multi-dimensional loss function and network structure of this invention in the photovoltaic panel defect generation task.
[0150] To verify the effectiveness of the improvement strategy for the original BicycleGAN network, this invention conducts ablation experiments using photovoltaic panel defect generation as the task. A network variant is constructed, incorporating various combined improvement strategies, including Adaptive Universal Normalization (Ada-DBIN), embedding AFGCA attention, replacing SPDConv downsampling, TransConv upsampling, and adding a defect-aware loss function. Single and mixed defects, such as point defects (e.g., star-shaped cracks), line defects (e.g., scratches), and surface defects (e.g., panel fragments), are selected as the generation objects. Clearly labeled semantic tags for photovoltaic panel defects are used as input image labels. The network generation results are shown below. Figure 10As shown in Table 2, the mean values of PSNR, SSIM, and LPIPS of the samples generated by each improved network under different defect types were calculated. The results quantify the contribution of each improved module to the defect generation quality of the photovoltaic panel, providing experimental basis for the subsequent fusion of multiple improvement strategies.
[0151] Table 2 Ablation Experiment Results
[0152]
[0153]
[0154] In Table 2, Experiment 1 is the original model, i.e., the original BicycleGAN network, which serves as the baseline. Experiments 3 and 2 are the present invention. √ indicates the presence of this component, and × indicates its absence. By comparing the PSNR, SSIM, and LPIPS metrics of the ablation experiment data, and considering the quality of some image samples generated by the network, the effects of Ada-DBIN, SPDConv, AFGCA, TransConv, and perceptual loss can be determined.
[0155] When Ada-DBIN is used alone (Experiment 2), compared to the baseline (Experiment 1), PSNR is improved by 0.55dB, SSIM is improved by 0.0233, and LPIPS is reduced by 0.0676. Although the improvement is not as significant as that of perceptual loss, it can effectively "amplify" the optimization effects of other modules in multi-module combinations: Experiment 22 (Ada-DBIN + TransConv + perceptual loss) compared to Experiment 16 (TransConv + perceptual loss) shows a PSNR improvement of 0.39dB and an SSIM improvement of 0.016. Its function is to reduce style conflicts between the photovoltaic panel background and defect areas by dynamically decoupling domain-independent and domain-dependent features, avoiding distortions such as black shadows and blocky noise in the background, while stabilizing the feature distribution during training and providing higher-quality input for feature learning of other modules.
[0156] SPDConv performed worst when used alone (Experiment 3), with a 0.59dB decrease in PSNR, a 0.0443 decrease in SSIM, and a 0.0242 increase in LPIPS compared to the baseline, indicating that its use alone easily leads to the loss of defect details. However, when combined with perceptual loss (Experiment 13), it showed only a slight performance fluctuation, with a 0.28dB decrease in PSNR, a 0.0044 decrease in SSIM, and a 0.0072 increase in LPIPS compared to Experiment 6 (perceptual loss only). Furthermore, Experiment 25 (SPDConv + TransConv + perceptual loss) further improved PSNR by 0.27dB and SSIM by 0.0249 compared to Experiment 16 (TransConv + perceptual loss). Its core function is to optimize the texture generation of large-area backgrounds of photovoltaic panels (such as backsheet uniformity) and reduce background noise. However, its ability to capture details of small target defects is weak, and it needs to rely on perceptual loss to compensate for defect details in order to avoid the contradiction of "high-quality background but distorted defects".
[0157] When used alone (Experiment 4), AFGCA improved PSNR by 0.16 dB, SSIM by 0.023, and LPIPS by 0.0187 compared to the baseline, with optimization focusing on structural consistency. When combined with perceptual loss (Experiment 15), compared to Experiment 6 (perceptual loss only), SSIM only decreased by 0.0131, but LPIPS increased by 0.0252, indicating that its structural optimization relies on the cooperation of other modules. The core function of this module is to enhance the edge structure of photovoltaic panel defects (such as crack direction and spot contour) through channel attention or feature filtering, reducing the problems of defect "discontinuity" and "ablation". However, it needs to be coordinated with modules such as perceptual loss and Ada-DBIN to balance structural integrity and perceptual realism.
[0158] TransConv is the only module whose performance significantly degrades when used alone: In Experiment 5 (TransConv only), compared to the baseline, PSNR decreased by 0.96 dB, SSIM decreased by 0.2176, and LPIPS increased by 0.0939, indicating that its standalone upsampling easily leads to blurred defect edges and structural breaks. However, when combined with perceptual loss (Experiment 16), the performance is "reversed," improving by 3.36 dB, 0.3844, and -0.2722 compared to Experiment 5. Its function is to achieve efficient upsampling through transposed convolution to restore the spatial resolution of the photovoltaic panel image, but it relies on the semantic constraints of perceptual loss and the feature stability of Ada-DBIN to avoid detail distortion during the upsampling process, ultimately achieving clearer defect edges and improved background resolution.
[0159] Perceptual loss has the most significant effect on improving the quality of photovoltaic panel defect generation. It is the only module among all modules that can achieve comprehensive optimization of all three indicators on its own: In Experiment 6 (with only perceptual loss added), compared with Experiment 1 (without any module), PSNR increased from 29.35dB to 31.56dB (+2.21dB), SSIM increased from 0.6237 to 0.7931 (+27.16%), and LPIPS decreased from 0.3969 to 0.2053 (-48.28%). In Experiment 32 (with all modules combined), the presence of perceptual loss enabled the three indicators to reach the optimal PSNR=32.19dB, SSIM=0.8422, and LPIPS=0.1821. Its core function is to enhance the semantic consistency of defects through VGG feature matching, accurately preserve details of small targets such as minor cracks and small spots, and optimize the grayscale transition between defects and the background, thereby greatly improving the subjective perception of realism.
[0160] The results show that the photovoltaic panel defect image generation network proposed in this invention achieves optimal performance in ablation experiments in terms of objective indicators. It can generate highly realistic images with delicate background textures, clear defect details, and natural edge transitions. At the same time, it avoids the limitations of single modules (such as insufficient defect details in SPDConv and performance degradation of TransConv) through module collaboration. It balances generation quality and engineering practicality, can generate scarce defect samples in batches to solve the "data scarcity" problem of photovoltaic panel detection models, and can also support the development of semi-supervised detection algorithms and defect simulation operation and maintenance scenarios, providing key data support for the intelligent upgrade of the entire photovoltaic panel defect detection process.
[0161] It should be understood that although the steps in the flowcharts of the various embodiments of the present invention are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated in the present invention, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least some steps in the various embodiments may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least a portion of the sub-steps or stages of other steps.
[0162] It should be understood that various parts of the present invention can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0163] In the description of this specification, references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0164] The embodiments described above are merely illustrative of several implementations of the present invention, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these modifications and improvements all fall within the scope of protection of the present invention. Therefore, the scope of protection of this patent should be determined by the appended claims.
Claims
1. A method for generating defects in photovoltaic panels based on an improved generative adversarial network, characterized in that, The method includes the following steps: Step 1: The encoding part of the generator is downsampled layer by layer using a spatial partitioning-based convolution module, the decoding part is upsampled layer by layer using transposed convolution, and the encoding part is connected to the output of the decoding part using a skip connection method. An adaptive fine-grained channel attention module is embedded in the spatial partitioning convolution module and the output of the transposed convolution; An adaptive normalization layer is set after the convolutional layer of the discriminator to dynamically adjust the normalization parameters according to the style of the input features in order to obtain the photovoltaic panel defect generation model. The adaptive normalization layer is an adaptive domain decoupling instance normalization layer, and its working process includes the following steps: Obtain the preliminary feature map extracted from the discriminator input layer, perform instance normalization on the preliminary feature map, and separate the domain-independent basic features and style residuals containing style information; The Gram matrix is calculated based on the style residuals to quantify the style correlation between channels; Based on the Gram matrix, the domain-independent weights of each channel are calculated; A lightweight importance predictor predicts the importance score of each channel based on the preliminary feature map, and then combines the importance score with domain-independent weights to obtain adaptive weights. The style residuals are weighted using adaptive weights and fused with domain-independent basic features. Then, activation operations are performed to obtain the output features of the current layer. Step 2: Use the defective photovoltaic panel image as the real target domain image, and the defect-free or other style photovoltaic panel image as the source domain image; The real target domain image is input into the variational encoder to obtain the latent variable distribution; The distribution of latent variables is reparameterized to obtain the first latent vector. The source domain image and the first latent vector are then input into the generator to obtain the first target domain image. The second latent vector is obtained by sampling through a standard normal distribution. The second latent vector and the source domain image are then input into the generator to obtain the second target domain image. The source domain image is combined with the first target domain image and the second target domain image respectively, and then fed into the corresponding discriminator to determine the probability of authenticity, so as to obtain the identification result. Step 3: Based on the identification results, construct the original loss function based on the BicycleGAN framework. Based on the first target domain image, the second target domain image, and the real target domain image, construct the perceptual loss, style loss, and total variation loss respectively. The photovoltaic panel defect generation model is trained by weighted joint method for perceptual loss, style loss, total variation loss and original loss function. After training, the trained generator is retained and other components are discarded or disabled to obtain the trained photovoltaic panel defect generation model. Step 4: Obtain the image of the photovoltaic panel to be tested and sample the second latent vector. Input the image of the photovoltaic panel to be tested and the second latent vector into the trained photovoltaic panel defect generation model to obtain a photovoltaic panel image with diverse defect features.
2. The photovoltaic panel defect generation method based on improved generative adversarial networks according to claim 1, characterized in that, The process involves obtaining the initial feature map extracted from the discriminator input layer, performing instance normalization on the feature map, and separating the domain-independent basic features from the style residuals containing style information. Specifically, this includes the following steps: The process of calculating the mean and variance of each channel in the feature map follows the following relationship: ; ; in, This represents the mean. Represents variance. This represents the preliminary feature map. N represents the batch size, C represents the number of channels, and H and W both represent spatial dimensions; This indicates the batch size, number of channels, height, and width of the input feature map; Based on the mean and variance, the domain-independent fundamental features are calculated, and the corresponding process follows the following relationship: ; in, The fundamental characteristic of domain independence, Represents a constant; By subtracting the domain-independent basic features from the feature map, we can separate the style residuals that contain style information. ; in, Indicates stylistic residuals.
3. The photovoltaic panel defect generation method based on improved generative adversarial networks according to claim 2, characterized in that, The Gram matrix is calculated based on the style residuals, specifically including the following steps: Flatten the stylistic residuals into The shape of the channel-space feature matrix is obtained, and the corresponding process has the following relationship: ; in, Represents the channel-space feature matrix; The spatial dimension of the channel-space feature matrix is L2 normalized to eliminate the scale effect, resulting in the normalized flattened features. The corresponding process has the following relationship: ; in, This represents the flattened feature after normalization. This represents the L2 normalization operation; Performing matrix multiplication on the normalized flattened features yields the Gram matrix, and the corresponding process follows the following relationship: ; in, Represents the Gram matrix, This indicates the transpose operation.
4. The photovoltaic panel defect generation method based on improved generative adversarial networks according to claim 3, characterized in that, Based on the Gram matrix, the domain-independent weights of each channel are calculated, specifically including the following steps: Removing the diagonal elements from the Gram matrix eliminates channel autocorrelation interference, resulting in the processed matrix. The corresponding process follows the following relationship: ; in, This represents the processed matrix. This indicates the operation of removing the corner element; The mean of each row of the processed matrix is calculated, and then the domain-independent weights are obtained by applying the Softmax function. The corresponding process follows the following relationship: ; in, Indicates domain-independent weights, This represents the normalized exponential function.
5. The photovoltaic panel defect generation method based on improved generative adversarial networks according to claim 4, characterized in that, A lightweight importance predictor predicts the importance score of each channel based on the input feature map. The importance score is then combined with domain-independent weights to obtain adaptive weights. The specific steps include the following: A lightweight importance predictor is constructed using adaptive average pooling, 1×1 convolution, and Sigmoid activation. The feature map is input into a lightweight importance predictor to obtain the importance score for each channel; The importance score of each channel is multiplied element-wise with the domain-independent weights to obtain the final adaptive weights.
6. The photovoltaic panel defect generation method based on improved generative adversarial networks according to claim 5, characterized in that, The style residuals are weighted using adaptive weights and then fused with domain-independent basic features to obtain the output features. The specific steps include: The final adaptive weights are extended to the feature map dimension through a broadcast operation to obtain the extended adaptive weights. The extended adaptive weights are multiplied element-wise with the style residuals to obtain the weighted style residuals; The basic features are added to the weighted style residuals to obtain the output features of the current layer.
7. The photovoltaic panel defect generation method based on improved generative adversarial networks according to claim 6, characterized in that, The adaptive fine-grained channel attention module works by including the following steps: Global feature compression is performed on the feature map at the current scale to obtain channel-level global feature vectors. The corresponding process has the following relationship: ; in, Indicates adaptive average pooling. Represents the channel-level global feature vector; The channel-level global feature vector is transposed and then processed by one-dimensional convolution, and then transposed back to the original dimension to obtain the channel-level global features; the channel-level global feature vector is then processed by 1X1 convolution to obtain the interaction information between channels. The channel-level global feature vector is transposed and then processed by one-dimensional convolution, and then transposed back to the original dimension to obtain the local relationship in the channel dimension; the channel-level global feature vector is then processed by two-dimensional 1X1 convolution to obtain the global relationship in the channel dimension. Design a dual-channel attention path, including a first-channel interaction path and a second-channel interaction path; The global features of the channel dimension and the interaction information between channels are input into the interaction path of the first channel. The global interaction is calculated by matrix multiplication and activated by Sigmoid to obtain the first attention weight. The corresponding process has the following relationship: ; in, and These represent the global features at the channel level and the interaction information between channels, respectively. Indicates the first attention weight. This represents the Sigmoid activation function. Represents matrix multiplication; The global features of the channel dimension and the interaction information between channels are input into the second channel interaction path. The reverse channel interaction is calculated by changing the matrix multiplication order to obtain the second attention weight. The corresponding process has the following relationship: ; in, Indicates the second attention weight; The first attention weight and the second attention weight are input into the Mix module for weighted fusion to obtain the channel interaction weights. The corresponding process has the following relationship: ; ; in, Represents the fusion coefficient. Indicates learnable parameters, Indicates the channel interaction weight; The channel interaction weights are transposed, then processed by one-dimensional convolution, transposed back to the original dimension, and activated by Sigmoid to obtain the final attention weights. The corresponding process has the following relationship: ; in, Represents one-dimensional convolution. This indicates that the two dimensions of the input are swapped. This represents the final attention weight; The final attention weights are multiplied element-wise with the feature map of the original input at the current scale to achieve channel weighting, so as to obtain the feature map enhanced at the current scale.
8. The photovoltaic panel defect generation method based on improved generative adversarial networks according to claim 7, characterized in that, The encoding part employs a layer-by-layer downsampling process using a spatially partitioned convolutional module, which includes: The source domain image is concatenated with either the first or second latent vector along the channel dimension to obtain the input feature map. The input feature map is used as the input to the spatial partitioning convolutional module. The input feature map is input into the first spatial partitioning convolutional module, which divides the space into multiple non-overlapping sub-regions. Multiple sub-regions are stitched together along the channel dimension to obtain an intermediate feature map with an increased number of channels and a halved spatial size. The intermediate feature map is convolved, the number of channels is adjusted, and then normalization and activation operations are performed sequentially to obtain the feature map output by the current spatial partition-based convolution module. The feature map output by the current spatial partitioning-based convolutional module is input into the next layer of spatial partitioning-based convolutional module. After passing through all spatial partitioning-based convolutional modules in sequence, the downsampling of the spatial partitioning-based convolutional module is completed.
9. The photovoltaic panel defect generation method based on improved generative adversarial networks according to claim 8, characterized in that, In the steps of constructing perceptual loss, style loss, and total variation loss based on the first target domain image, the second target domain image, and the real target domain image, the calculation process of perceptual loss follows the following relationship: ; in, Indicates perceived loss. This represents the feature map of the i-th layer of VGG16; This represents the generated first target domain image or second target domain image; Represents the true target domain image; Represents the L1 norm; The calculation of style loss follows the following formula: ; in, Indicating style loss, This indicates a Gram matrix calculation operation. ; Represents the square of the L2 norm; The calculation of total variation loss follows the following formula: ; in, This represents the total variation loss. The weighting parameter represents the total variation loss; This represents the pixel value of the generated image at coordinates (h, w).