As the main way of energy transportation, long-distance oil and gas pipeline safety is very important. As one of the important methods of pipeline defect detection, pipeline magnetic flux leakage internal detection technology plays an important role in pipeline safety. Artificial intelligence technology can realize the automatic identification of pipeline inspection data, which is of great significance to reduce human workload, reduce human error and improve the accuracy of data interpretation. The distance IOU loss function is introduced to improve the yolov5 algorithm, and the improved yolov5 algorithm is used to train the pipeline magnetic flux leakage data, so that it can automatically identify the magnetic flux leakage signal. Through experiments, the actual MFL internal detection data are identified. The results show that the improved yolov5 algorithm can realize the automatic identification and detection of pipeline defects. Under the same training conditions, the accuracy of the improved model is significantly higher than that of the original model. The accuracy of defect identification is 92.8%, which is 3.22% higher than that of the original model. The average loss rate of the improved model is 3.6%, which is 2.2% lower than that of the original model, The results show that the method is feasible in automatic identification and detection of pipeline defect magnetic flux leakage data.