This paper presents an automated refactoring technique for improving the efficiency of deep learning (DL) systems. Existing deferred execution-based DL frameworks have excellent scalability, but they have the disadvantages of being error-prone, unintuitive, and difficult to debug. On the other hand, eager execution is easy to develop, but slow to execute. In this paper, we propose a technique to automatically identify and refactor parts of eager execution-based DL codes that can be efficiently executed based on graphs. This is implemented using static implicit tensors and side-effect analysis based on Python, and uses keyword-based predictive analytics to address uncertainty due to the dynamic nature of Python. This technique, implemented as a PyDev Eclipse IDE plugin, was evaluated on 19 DL projects (132 KLOC), and achieved an average speedup of 2.16x by refactoring 326 out of 766 candidate functions (42.56%). There was almost no difference in model accuracy.