Software defect prediction usually is regarded as a classification problem, but classification models will face the class imbalance problem. Although there are many methods to solve the class imbalance problem, there is no method that can fundamentally solve the problem currently. In addition, supervised learning algorithms are always used to train defect prediction models, but obtaining a large amount of high-quality labelled data requires a lot of time and labor cost. In order to solve the class imbalance problem and eliminate the disadvantage of supervised learning, this paper attempts to predict software defects from a new perspective of anomaly detection. We propose an Anomaly Detection Model Based on BiGAN for Software Defect Prediction (ADGAN-SDP). The model proposed in this paper not only does not need to consider the class imbalance problem but also uses a semi-supervised method to train the model. Eight classification-based software defect prediction models are used as the baseline models and compared with ADGAN-SDP model. We evaluate ADGAN-SDP on 19 projects from NASA, AEEEM, and ReLink repositories. The experimental results show that the ADGAN-SDP model, which has a higher recall, outperforms all baseline models. It is suggested that the anomaly detection approach can be applied to the software defect prediction to fundamentally solve the class imbalance problem.