Amine El Hanafy, Abdelaaziz Hessane, Yousef Farhaoui
Deep learning has become a powerful tool for diagnosing pests and plant diseases, although conventional convolutional neural networks (CNNs) generally suffer from limited interpretability and suboptimal focus on important image features. This study examines the integration of attention mechanisms into two prevalent CNN architectures—ResNet50 and MobileNetV2—to improve the interpretability and classification of diseases impacting date palm trees. Four attention modules—Squeeze-and-Excitation (SE), Efficient Channel Attention (ECA), Soft Attention, and the Convolutional Block Attention Module (CBAM)—were systematically integrated into ResNet50 and MobileNetV2 and assessed on the Palm Leaves dataset. Using transfer learning, the models were trained and evaluated through accuracy, F1-score, Grad-CAM visualizations, and quantitative metrics such as entropy and Attention Focus Scores. Analysis was also performed on the model’s complexity, including parameters and FLOPs. To confirm generalization, we tested the improved models on field data that was not part of the dataset used for learning. The experimental results demonstrated that the integration of attention mechanisms substantially improved both predictive accuracy and interpretability across all evaluated architectures. For MobileNetV2, the best performance and the most compact attention maps were obtained with SE and ECA (reaching 91%), while Soft Attention improved accuracy but produced broader, less concentrated activation patterns. For ResNet50, SE achieved the most focused and symptom-specific heatmaps, whereas CBAM reached the highest classification accuracy (up to 90.4%) but generated more spatially diffuse Grad-CAM activations. Overall, these findings demonstrate that attention-enhanced CNNs can provide accurate, interpretable, and robust detection of palm tree diseases and pests under real-world agricultural conditions.