Surrogate-based optimization has been used in aerodynamic shape optimization, but it has been limited due to the curse of dimensionality. Although a large number of variables are required for the shape parameterization, many of the shapes that the parameterization can produce are abnormal and do not add meaningful information to a surrogate model. To improve the efficiency of surrogate-based optimization, recent machine learning techniques are applied in this study to reduce the abnormality of both initial and infill samples. This paper proposes a new sampling method for airfoils and wings, which is based on a deep convolutional generative adversarial network. This network is trained to learn the underlying features among the existing airfoils and is able to generate sample airfoils that are notably more realistic than those generated by other sampling methods. In addition, a discriminative model is developed based on convolutional neural networks. This model detects the geometric abnormality of airfoils or wing sections quickly without using expensive computational fluid dynamic models. These machine learning models are embedded in a surrogate-based aerodynamic optimization framework and perform aerodynamic shape optimization for airfoils and wings. The results demonstrate that, compared with the conventional methods, our proposed models can double the optimization efficiency.