X-ray nondestructive testing technology is widely used for inspecting welds and identifying defects, and is crucial in the manufacturing industry. However, the diversity of welding defects and the imbalanced defect samples reduce defect classification model accuracy and can cause classifier overfitting. This paper proposes an improved DCGAN model for generating welding defect samples by integrating deep convolutional neural networks to enhance the training relationship between the generator and discriminator, thus increasing the number of training samples. We introduce a lightweight DG-MobileNet model to address low accuracy in welding defect identification and poor model convergence. Dilated convolution modules and Squeeze-and-Excitation self-attention mechanisms expand the convolutional receptive field and improve feature extraction capabilities. The fully connected layer is replaced by a global average pooling layer, reducing training parameters and mitigating overfitting. Additionally, combining DropBlock technology with Batch Normalization optimizes the feature extraction process, enhancing generalization ability. The experimental results demonstrate that the proposed model achieves a recognition accuracy of 98.78% and exhibits superior performance in terms of efficiency and lightweight design, highlighting its potential for deployment in real-world industrial applications.