# Lem-Detector: An Efficient Detector for Photovoltaic Panel Defect Detection
## 3 Methods
### Linear Feature Augmentation (LFA)  
The photovoltaic panel dataset encompasses both large-scale global defects and small-scale local defects with linear texture features. Large-scale defects, such as Black core, Horizontal dislocation, Vertical dislocation, and Short circuit, exhibit distinct and easily recognizable features, leading to higher detection accuracy. In contrast, small-scale defects, including Crack, Star crack, and Finger, pose significant challenges due to their high similarity to the background, complex and variable shapes, and scattered nature with strong background interference. These factors contribute to lower detection accuracy and hinder model performance improvement. Furthermore, the dataset exhibits an imbalance in the distribution of samples, with a relative scarcity of small-scale linear texture defects. While data augmentation can modestly enhance the detection accuracy of Crack and Star crack defects, random processing of darker regions may negatively impact the accuracy of other easily recognizable defect types. Additionally, improper data augmentation can lead to overfitting, reducing model accuracy and consuming substantial computational resources, thereby lowering efficiency. To address these challenges, a targeted approach is employed, leveraging the distribution characteristics of defect samples. A cosine similarity function is utilized to filter linear texture training samples with similar features. Subsequently, targeted data augmentation is applied specifically to these similar linear texture features, effectively addressing the issue of data imbalance and enhancing the model's ability to detect small-scale defects while minimizing negative impacts on the detection of other defect types. The cosine similarity function is a commonly used method for measuring the angle between two vectors. This similarity metric is achieved by calculating the cosine of the angle between the two vectors, which can be expressed mathematically as follows:  
\[C=\frac{A\cdot B}{\parallel A\parallel\parallel B\parallel}=\frac{\sum_{i=1} ^{n}A_{i}B_{i}}{\sqrt{\sum_{i=1}^{n}A_{i}^{2}}\sqrt{\sum_{i=1}^{n}B_{i}^{2}}} \tag{1}\]  
Figure 2: Overall framework of the LEM-Detector. The cosine similarity \(C\) is defined as the cosine of the angle between two vectors, where \(A\) and \(B\) denote the dot product of the vectors, and \(A\cdot B\) are the magnitudes of the vectors \(\|A\|\) and \(\|B\|\), respectively. The advantage of cosine similarity is that it considers only the direction of the vectors, without being affected by vector length. During data augmentation, cosine similarity is calculated between training samples to select suitable candidates for augmentation. Samples with a cosine similarity exceeding a threshold \(\delta\), indicating similar features, are selected for augmentation. This approach preserves the crucial characteristics of linear defects while increasing the diversity of the training set, without significantly altering the original features. As depicted in Figure 3, if a training sample has at least one remaining sample with a cosine similarity exceeding \(\delta\), it proceeds to the next step of data augmentation; otherwise, no augmentation is performed. The LFA incorporates a range of contemporary data augmentation techniques, including Affine, BboxSafeRandomCrop, Mosaic, Erase, and Mixup. These methods enhance the diversity of linear features in the photovoltaic panel dataset, simulating the impact of dark spot regions and increasing the complexity of the dataset. This enhanced data diversity improves the robustness of the detection model. The LFA was applied to the PVEL-AD [36] dataset, ensuring that the generated samples remain sufficiently close to the real samples within the vector space. This approach enhances the diversity of training samples while preserving the actual data distribution, enabling the selection of appropriate linear feature training samples for targeted data augmentation.