The continuous scaling-down size of interconnects should be accompanied with ultra-thin diffusion barrier layers, which is used to suppress Cu diffusion into the dielectrics. Unfortunately, conventional barrier layers with thicknesses less than 4 nm fail to perform well. With the advent of 2D layered materials, graphene and hexagonal boron nitride have been proposed as alternative Cu diffusion barriers with thicknesses of ≈1 nm. However, defects such as vacancies may evolve into a Cu diffusion path, which is a challenging problem in design of diffusion barrier layers. The energy barrier of Cu atom diffused through a di-vacancy defect in graphene and hexagonal boron nitride is calculated by density functional theory. It is found that graphene offers higher energy barrier to Cu than hexagonal boron nitride. The higher energy barrier is attributed to the stronger interaction between Cu and C atoms in graphene as shown by charge density difference and Bader’s charge. Furthermore, we use the energy barriers of different vacancy structures and generate a dataset that will be used for machine learning. Our trained convolutional neural network is used to predict the energy barrier of Cu migration through randomly configured defected graphene and hexagonal boron nitride with $R^{2}$ of >99% for $4 \times 4$ supercell. These results provide guides on choosing between 2D materials as barrier layers, and applying deep learning to predict the 2D barrier performance.