With the vigorous development of the solar photovoltaic industry, the operation and maintenance of photovoltaic power stations has ushered in huge challenges. To solve the problems of low efficiency, poor accuracy, and high cost of traditional manual inspection of photovoltaic power stations, the UAV inspection system for photovoltaic has become a new solution to solve the pain points of the industry, which can improve the inspection efficiency greatly. In photovoltaic inspection systems, defect detection is the most important goal. In this paper, a defect detection algorithm based on improved yolov5 for photovoltaic modules is proposed. The convolution block attention module (CBAM) is introduced to extract the attention area, and the weighted non-maximum suppression (NMS) is replaced by DIOU_NMS to improve the recognition accuracy of the model. The experimental results show that the algorithm can effectively identify the hot spots and diode defects of photovoltaic modules, which lays a solid foundation for the fully autonomous inspection of photovoltaic power stations.