An increasing focus was placed in the past few decades on accelerating flash calculations and a variety of acceleration strategies have been developed to improve its efficiency without serious compromise in accuracy and reliability. Recently, as machine learning becomes a powerful tool to handle complicated and time-consuming problems, it is increasingly appealing to replace the iterative flash algorithm, due to the strong nonlinearity of flash problem, by a neural network model. In this study, an NVT flash calculation scheme is established with a thermodynamically stable evolution algorithm to generate training and testing data for the proposed deep neural network. With a modified network structure, the deep learning algorithm is optimized by carefully tuning neural network hyperparameters. Numerical tests indicate that the trained model is capable of accurately estimating phase compositions and states for complex reservoir fluids under a wide range of environmental conditions, while the effect of capillary pressure can be captured well. Thermodynamic rules are preserved well through our algorithm, and the trained model can be used for various fluid mixtures, which significantly accelerates flash calculations in unconventional reservoirs.