Despite past decades have witnessed many successes of machine learning methods in physical sciences, prediction of the Hamiltonian, and thus electronic properties, is still unsatisfactory. Here, based on graph neural network architecture, we present an extendable neural network model to determine the Hamiltonian from ab initio data, with only local atomic structures as inputs. The local coordinates information, encoded using the convolutional neural network and designed to preserve Hermitian symmetry, is used to map hopping parameters onto local structures. We demonstrate the performance of our model using graphene and SiGe random alloys as examples. We show that our neural network model, although trained using small-size systems, can predict the Hamiltonian, as well as electronic properties such as band structures and densities of states (DOS) for large-size systems within the ab initio accuracy, justifying its extensibility. In combination with the high efficiency of our model, which takes only seconds to get the Hamiltonian of a 1728-atom system, present work provides a general framework to predict electronic properties efficiently and accurately, which provides new insights into computational physics and will accelerate the research for large-scale materials.