Efficient mechanical casting defect detection based on state space modeling and multiscale attention
摘要
Automated defect detection in mechanical castings is critical for ensuring product quality in modern manufacturing. However, existing methods struggle to simultaneously achieve micro-defect sensitivity, global contextual understanding, and computational efficiency. In this paper, we propose CastMamba, a novel encoder–decoder network that integrates selective state-space modeling with multi-scale attention mechanisms for high-precision casting defect detection. The encoder employs a micro-defect attention module (MDAM) that leverages multi-scale dilated convolutions with a Bilinear Attention Module to capture fine-grained defect features across varying scales. A state-space global context module (SSGCM) serves as the bottleneck, harnessing the selective state-space mechanism to model long-range spatial dependencies with linear computational complexity. A local-global dual-branch fusion module (LGDFM) further enriches feature representations through patch-based attention at multiple granularities. The decoder utilizes a global-local feature decoding module (GLFDM) that combines dilated convolutions with vision transformers for comprehensive feature reconstruction. Extensive experiments on three benchmarks demonstrate that CastMamba achieves state-of-the-art performance, attaining 88.4% mAP@50 on MCDD, 91.2% mAP@50 on BDD, and 99.4% image-level AUROC on MVTec-AD, consistently surpassing seventeen competitive baselines. The source code is publicly available at https://github.com/wfcyliyuheng-dev/CastMamba.