CropGuardNet: A Unified Lightweight CNN-Transformer Framework with Multi-Scale Attention and Explainable AI for Cross-Crop Leaf Disease Detection
Abstract
Crop diseases threaten food security, yet deep detectors remain single-crop, heavyweight, or opaque for edge deployment. We propose CropGuardNet, a lightweight Convolutional Neural Network (CNN) and Transformer framework on MobileNetV3-Small (alpha = 0.50) with 481,574 parameters, 1.84 MB FP32 weights, and 63.8M FLOPs, running at 5.00 ms (200.0 FPS) in single-thread CPU ONNX inference. It unites a dilated multi-scale feature pyramid, depthwise separable refinement, squeeze-and-excitation attention, a two-head Transformer, dual-path pooling, crop-aware conditioning, and four explainable AI (XAI) methods: Grad-CAM++, LayerCAM, LIME, and GradientSHAP. After purging 80,238 PlantVillage duplicates via specimen Universally Unique Identifier (UUID) grouping and 64-bit perceptual hash auditing, evaluation on 35,420 unique images spanning 38 classes and 8 crops (n = 5,314 test) reaches 99.17% accuracy, 0.9874 F1-macro, 0.9914 Matthews correlation coefficient (MCC), and 0.9998 AUC-ROC, leading F1-macro across seven models at 3.2x-279.1x fewer parameters than five baselines and 6.0x larger than LeafXNet at 18.1x fewer FLOPs. Top models match on 35 non-Rice classes, whereas species conditioning eliminates cross-crop errors, supports 99.79% automatic crop routing, and lifts minority Rice accuracy to 94.44%. CropGuardNet leads 20-regime corruptions at 83.61% mean accuracy (severe Wilcoxon p = 0.0020 vs. LeafXNet), 8-fold leave-one-crop-out probing (n = 7,072) at 81.22% accuracy and 0.8879 binary AUC-ROC, and XAI faithfulness with LayerCAM Deletion AUC 0.7262 and GradientSHAP Insertion AUC 0.9259. On PlantDoc field images, guided Mode A1 reaches 40.63%-45.91% zero-shot accuracy vs. 16.06%-17.58% unguided, 60.62% unmasked vs. 62.18% masked head adaptation under Mode A1-Auto (tying ResNet-50 behind LeafXNet at 63.73%), and 62.20% Enhanced or 63.66% Raw RGB accuracy after 20-epoch tuning.
Key Findings & Contributions
- Designed a compact 481,574-parameter hybrid CNN-Transformer combining parallel dilated multi-scale convolutions (r in {1, 2, 4}), depthwise separable refinement, squeeze-and-excitation recalibration, and dual-path GAP fusion at 63.8M FLOPs.
- Introduced a learnable 8-species crop-aware conditioning module eliminating cross-crop false positives under guided inference and supporting two-stage automatic crop routing (Mode A1-Auto) at 99.79% species accuracy.
- Constructed a leak-free multi-crop benchmark of 35,420 unique leaf images across 38 classes and 8 crops by purging 80,238 offline-augmented PlantVillage duplicate copies via specimen UUID grouping and auditing cross-split similarity via 64-bit DCT perceptual hashing.
- Evaluated four complementary XAI families (Grad-CAM++, LayerCAM, LIME, GradientSHAP) through 20-step Deletion/Insertion faithfulness curves alongside 20-regime corruption stress tests, 8-fold leave-one-crop-out probing, and external PlantDoc field adaptation.
Key Empirical Figure
Benchmark Results
Unified 8-Crop, 38-Class Benchmark Comparison (Test n = 5,314)
CropGuardNet ranks first in 38-class F1-Macro, Macro-Precision, and Macro-Recall while achieving the lowest FLOPs across all seven architectures.
| Model | Params | Size (MB) | FLOPs (M) | Acc (%) | F1-Macro | MCC | CPU Lat. (ms) |
|---|---|---|---|---|---|---|---|
| VGG-16 | 134,416,230 | 512.76 | 30,932.6 | 97.95 | 0.9703 | 0.9787 | 414.72 ± 17.82 |
| ResNet-50 | 23,585,894 | 89.97 | 8,174.4 | 99.13 | 0.9751 | 0.9910 | 78.03 ± 2.38 |
| MangoXNet | 4,426,374 | 16.89 | 273.8 | 99.15 | 0.9746 | 0.9912 | 16.36 ± 0.75 |
| EfficientNet-B0 | 4,056,226 | 15.47 | 769.2 | 99.21 | 0.9834 | 0.9918 | 30.79 ± 1.78 |
| MobileNetV3-Small | 1,556,806 | 5.94 | 111.1 | 99.23 | 0.9740 | 0.9920 | 11.38 ± 0.53 |
| LeafXNet | 79,782 | 0.30 | 1,156.6 | 97.27 | 0.9558 | 0.9717 | 22.64 ± 0.55 |
| CropGuardNet (Ours) | 481,574 | 1.84 | 63.8 | 99.17 | 0.9874 | 0.9914 | 11.49 (PyTorch) / 5.00 (ONNX) |
Layer-by-Layer Architecture & Trainable Parameter Breakdown
Total trainable parameters: 481,574 (1.84 MB FP32, 0.92 MB FP16, 0.46 MB raw INT8).
| Stage / Module | Configuration | Output Shape | Params | Share (%) |
|---|---|---|---|---|
| 1. Backbone | MobileNetV3-Small (α = 0.50, features-only, stride 32) | B × 288 × 7 × 7 | 272,288 | 56.54 |
| 2. MSFP Pyramid | 3 parallel branches (1×1; 3×3 r=2; 3×3 r=4) + 1×1 fuse | B × 32 × 7 × 7 | 178,432 | 37.05 |
| 3. DSR Refinement | DWConv 3×3 (288) + PWConv 1×1 (1,024) + BN + SiLU | B × 32 × 7 × 7 | 1,376 | 0.29 |
| 4. SE Attention | GAP + bias-free FC 32→8→32 + Sigmoid | B × 32 × 7 × 7 | 512 | 0.11 |
| 5. Compact ViT | PosEmbed (1,568) + 2-head MHSA (4,224) + FFN + 3×LN | B × 32 × 7 × 7 | 10,176 | 2.11 |
| 6. Dual-Path Fusion | GAP(F_SE) || GAP(F_Trans) parameter-free pooling | B × 64 | 0 | 0.00 |
| 7. Crop Conditioning | Embed(8×16) + Linear 80→64 + SiLU + Drop(0.1) | B × 64 | 5,312 | 1.10 |
| 8. Classifier Head | Linear 64→128 + SiLU + BN + Drop(0.3) + Linear 128→38 | B × 38 | 13,478 | 2.80 |
| Total | Complete CropGuardNet (1.84 MB FP32) | B × 38 | 481,574 | 100.00 |
BibTeX
@misc{nyalala2026cropguardnet,
title={CropGuardNet: A Unified Lightweight CNN-Transformer Framework with Multi-Scale Attention and Explainable AI for Cross-Crop Leaf Disease Detection},
author={Nyalala, Innocent},
howpublished={Manuscript Under Peer Review (SAAIL Lab)},
year={2026},
url={https://saaillab.github.io/papers/cropguardnet/}
} Nyalala, I. (2026). CropGuardNet: A Unified Lightweight CNN-Transformer Framework with Multi-Scale Attention and Explainable AI for Cross-Crop Leaf Disease Detection. Manuscript Under Peer Review. https://saaillab.github.io/papers/cropguardnet/