Merging is potentially the dominant process in galaxy formation, yet there is still debate about its history over cosmic time. To address this, we classify major mergers and measure galaxy merger rates up to z ~ 3 in all five CANDELS fields (UDS, EGS, GOODS-S, GOODS-N, COSMOS) using deep learning convolutional neural networks trained with simulated galaxies from the IllustrisTNG cosmological simulation. The deep learning architecture used is objectively selected by a Bayesian optimization process over the range of possible hyperparameters. We show that our model can achieve 90% accuracy when classifying mergers from the simulation and has the additional feature of separating mergers before the infall of stellar masses from post-mergers. We compare our machine-learning classifications on CANDELS galaxies and compare with visual merger classifications from Kartaltepe et al., and show that they are broadly consistent. We finish by demonstrating that our model is capable of measuring galaxy merger rates, , that are consistent with results found for CANDELS galaxies using close pairs statistics, with . This is the first general agreement between major mergers measured using pairs and structure at z < 3.