To improve pipeline transportation efficiency, long-distance pipelines need to be cleaned regularly. Pipeline inspection gauges (PIGs) are widely used in pigging operations. The traditional PIG localization method generally has a large error and cannot achieve continuous tracking. To solve the problem of PIG real-time tracking and localization, this paper proposes a method of PIG localization for oil pipelines based on a denoising autoencoder(DAE). The attention deconvolution residual block (ADR) is introduced in the decoder part of the DAE, so that this model can learn and use global information to selectively emphasize key features, suppress useless features, and improve the noise removal performance of the model. After denoising, the negative pressure wave(NPW) signal is normalized, the time delay is extracted, and the PIG is located using the NPW localization formula. Experiments show that this method can effectively achieve real-time PIG localization. Compared with the EMD and DAE positioning methods, the relative positioning accuracy is increased by 3.5 times and 8.4 times, respectively.