The study aims to detect the defects in the production line of compressor, promote the development of convolution neural network (CNN) in defect diagnosis and recognition, and expand the application of intelligent algorithm tools in the detection and recognition of defect and fault. The detection and recognition of the defects in the compressor workpiece were discussed based on the optimization of CNN. First, the active learning under the background of machine learning (ML) was introduced into the selection of sample training model for the annotation of massive data sets in diagnosing the compressor defect, and compared with the random selection method. Second, aiming at the limitation of deep CNN, through the introduction of deep separable convolution and reverse residual structure, an improved space-separable residual CNN model was proposed, and its training process was observed and analyzed. Finally, the improved space-separable residual CNN model was applied to the defect detection and recognition of compressor workpiece, and the effect of defect recognition was evaluated. The results showed that the accuracy of the active learning was higher than that of the random selection, and it can save about 18.76% of the cost of manual annotation data. The recognition accuracy of the improved CNN model is more than 90%, and the accuracy curve of the training set and the test set basically coincided in the later training period. The average recognition accuracy of the compressor defect detection model was 96.87%, and the normal workpiece could be fully recognized. The combination of improved and optimized CNN and ML has great potential in the detection of compressor defect.