Granular materials are used directly or as the primary ingredients of the mixtures in industrial manufacturing, agricultural production and civil engineering. It has been a challenging task to compute the porosity of a granular material which contains a wide range of particle sizes or shapes. Against this background, this paper presents a newly developed method for the porosity prediction of granular materials through Discrete Element Modeling (DEM) and the Back Propagation Neural Network algorithm (BPNN). In DEM, ball elements were used to simulate particles in granular materials. According to the Chinese specifications, a total of 400 specimens in different gradations were built and compacted under the static pressure of 600 kPa. The porosity values of those specimens were recorded and applied to train the BPNN model. The primary parameters of the BPNN model were recommended for predicting the porosity of a granular material. Verification was performed by a self-designed experimental test and it was found that the prediction accuracy could reach 98%. Meanwhile, considering the influence of particle shape, a shape reduction factor was proposed to achieve the porosity reduction from sphere to real particle shape.