Abstract With the rapid development of China’s economy, the demand for oil and gas resources is continuously increasing, leading to the expansion of the scale of oil and gas long-distance pipelines. Consequently, the risk of safety incidents in oil and gas pipelines is on the rise. Welding defects are identified as one of the significant factors contributing to safety incidents in long-distance oil and gas pipelines. In comparison to traditional conventional ultrasonic detection techniques, which exhibit low efficiency and accuracy, ultrasonic phased array detection technology has the capability to accurately detect welding defects in oil and gas long-distance pipelines. This is particularly true with the development of total focusing method imaging technology, enabling quantitative defect analysis and localization in oil and gas long-distance pipelines.However, in the current scenario, analyzing the types of defects in massive data from long-distance pipelines requires human intervention, leading to low detection efficiency and subjective influence on result analysis. Addressing challenges such as low efficiency in human evaluation of defects in ultrasonic phased array detection, low accuracy in traditional image recognition methods, strong subjectivity in manually extracting features, and the absence of a standardized industrial dataset for ultrasonic phased array detection defects, especially in the case of limited data on ultrasonic phased array detection of welding defects, this study focuses on small sample defects in phased array detection images. The study proposes an improved ResNet50 algorithm through domain adaptation in a deep neural network, trained on a large-scale model data, and then applied to ultrasonic phased array detection data. This approach achieves accurate identification and classification of typical volumetric defects (such as pores) and typical area defects (such as cracks) in the phased array detection of welding defects, laying the foundation for intelligent recognition of defects in long-distance oil and gas pipelines.