Buried pipelines play a crucial role in the transportation of oil and gas. However, they are invisible and prone to corrosion accumulation, leading to potential leakage that can impact safety and the economy. Currently, the most commonly used detection methods for buried pipelines are intrusive and destructive, making it difficult to provide efficient and accurate corrosion status. To solve this issue, this study used the transient electromagnetic method (TEM) to detect the corrosion depth of buried pipelines, and a multistrategy improvement dung beetle optimized bidirectional long short-term memory network algorithm (MSDBO-BiLSTM) is proposed to predict the corrosion depth of buried pipelines. Due to the difficulty of collecting corrosion data from buried pipelines with multiple degrees of corrosion under actual working conditions, there is an imbalance in the data which can lead to overfitting of prediction models. In this paper, a corrosion data set for buried pipelines is constructed by combining simulation and experimentation. Grey relational analysis (GRA) is utilized to determine the importance of feature values in TEM detection signals to obtain the best feature set. Furthermore, improvements are made to the dung beetle optimized (DBO)-BiLSTM algorithm through a Chebyshev chaotic map improvement strategy, a golden sine improvement strategy, and a weight coefficient improvement strategy to improve accuracy and stability and reduce model error. Finally, to validate the advantages of the model proposed in this paper, machine learning models utilizing different neural networks, improvement measures, and optimization algorithms were selected to predict the data set of buried pipeline corrosion depth. The results indicate that the corrosion depth prediction model proposed in this paper exhibits superior accuracy and stability. The model achieves mean absolute error (MAE), mean absolute percentage error (MAPE), mean squared error (MSE), RMS error (RMSE), and standard deviation (STD) values of 0.2561, 0.0668, 0.1026, 0.3202, and 0.3245, respectively, with an R2 value of 0.9642.