Skip to main content
Other

Grape Leaf AI Platform - Two-Stage Swin Transformer + Explainable AI (XAI)

Syed Taimoor Hussain ShahPolitoBIOMed Lab, Department of Mechanical and Aerospace Engineering, Politecnico di Torino, Turin 10129, ItalySyed Adil Hussain ShahDepartment of Research and Development (R&D), GPI SpA, Trento 38123, ItalySilvia GodioPolitoBIOMed Lab, Department of Mechanical and Aerospace Engineering, Politecnico di Torino, Turin 10129, ItalyKarim KassemPolitoBIOMed Lab, Department of Mechanical and Aerospace Engineering, Politecnico di Torino, Turin 10129, ItalyShahzad Ahmad QureshiDepartment of Computer and Information Sciences, Pakistan Institute of Engineering and Applied Sciences (PIEAS), Islamabad 45650, PakistanSyed Bilal HussainSchool of Agriculture and Food Science, University College Dublin, Dublin 4, IrelandDeriu, Marco AgostinoPolytechnic University of Turin
ABI

Abstract

Title Explainable-AI based Two Stage Swin Transformer for Grapevine Leaf Variety Recognition and Disease Classification Authors Syed Taimoor Hussain Shah, Syed Adil Hussain Shah, Silvia Godio, Karim Kassem, Shahzad Ahmad Qureshi, Syed Bilal Hussain, and Marco Agostino Deriu Authors and Affiliations (Manuscript) PolitoBIOMed Lab, Department of Mechanical and Aerospace Engineering, Politecnico di Torino, Turin 10129, Italy Department of Research and Development (R&D), GPI SpA, Trento 38123, Italy Centro Medico Santagostino, Milan, Italy Department of Computer and Information Sciences, Pakistan Institute of Engineering and Applied Sciences (PIEAS), Islamabad 45650, Pakistan School of Agriculture and Food Science, University College Dublin, Dublin 4, Ireland Contact (Corresponding Authors) Syed Taimoor Hussain Shah — [email protected] Syed Bilal Hussain — [email protected] Zenodo DOI 10.5281/zenodo.18937850 Overview This Zenodo release provides a complete interactive platform for grapevine leaf analysis using a two-stage Swin Transformer (Swin-Tiny) pipeline: Stage 1 — Variety (Cultivar) Recognition: predicts the grapevine cultivar from a leaf image. Stage 2 — Disease Classification: predicts disease class using a fine-tuned Swin model. The platform includes a Flask web application with an XAI ON/OFF toggle. When enabled, it generates multiple explanation maps to highlight image regions contributing to predictions. Release Contents (Matches This Zenodo Archive) Your uploaded Zenodo package contains: Grape App/app.pyxai_utils.pycnn_agri.ymlModel Weights/swin_tiny_patch4_window7_224/best.pthlast.pthconfig.jsonclass_to_idx.jsonswin_tiny_patch4_window7_224__DISEASES_FT/best.pthlast.pthclass_to_idx.json (recommended; if present)templates/index.htmlstatic/css/styles.cssuploads/ (runtime output)xai/ (runtime output)Samples/Leaves/ (example cultivar images)Diseases/ (example disease images) Notes on folders Model Weights/ contains the pretrained (cultivar) and fine-tuned (disease) Swin-Tiny weights. Samples/ provides a small set of test images for quick verification and demonstration. static/uploads/ and static/xai/ are created/filled automatically during app usage. Installation (Conda Environment) This release includes a ready-to-use conda environment file: cnn_agri.yml Create and activate environment conda env create -f cnn_agri.ymlconda activate cnn_agri Optional (if not already included in your environment) Some XAI methods require additional packages: pip install shappip install scikit-image scikit-learn Running the Web Application From the project root folder: python app.py Then open in browser: http://127.0.0.1:5000 App workflow Choose task: Leaf cultivar Disease Upload an RGB image (PNG/JPG/JPEG/WEBP) Click Predict Enable XAI ON to generate explanation maps. Model Weights and Label Mapping Cultivar model (Stage 1) Weights: Model Weights/swin_tiny_patch4_window7_224/best.pth Labels: Model Weights/swin_tiny_patch4_window7_224/class_to_idx.json Disease model (Stage 2) Weights: Model Weights/swin_tiny_patch4_window7_224__DISEASES_FT/best.pth Labels: Model Weights/swin_tiny_patch4_window7_224__DISEASES_FT/class_to_idx.json (recommended) For full reproducibility, ensure both models have correct class_to_idx.json. Explainable AI (XAI) When XAI is enabled, the platform generates multiple explanation maps (depending on installed packages and configuration). Typical outputs include: Grad-CAM Grad-CAM++ Eigen-CAM Token-gradient / token-wise attribution (captures transformer token importance) Occlusion/Ablation sensitivity (grid-based) RISE (randomized mask-based saliency; computed in memory-safe batches) LIME (superpixel perturbations; requires scikit-image & scikit-learn) Attention rollout (SAA-style) using Swin WindowAttention Performance notes Some XAI methods can be slow/heavy (e.g., SHAP/LIME/RISE). The code is designed to: compute XAI sequentially, free GPU memory between methods, avoid large one-shot allocations (batched RISE). SHAP Notes (If Enabled) If SHAP is used, it requires a small background set for stable results.For a portable Zenodo release, a recommended approach is to include small background image sets inside the archive (optional): static/shap_bg/leaf/static/shap_bg/disease/ If these are not provided, the platform may fall back to a safe background strategy depending on configuration. Quick Testing Using Provided Samples You can test the app immediately with images from: Samples/Leaves/ Samples/Diseases/ These are included to help users verify the pipeline runs end-to-end without needing external datasets. Platform Independence and Paths This app is designed to be portable: Uses paths relative to the app directory for weights, templates, and static folders. No hard-coded absolute paths are required. If you deploy on a server or container, you can override model/weight paths via environment variables (if implemented in your app.py). Citation If you use this platform or its models/code, please cite the Zenodo release and the associated article. Zenodo citation Syed Taimoor Hussain Shah et al.Explainable-AI based Two Stage Swin Transformer for Grapevine Leaf Variety Recognition and Disease ClassificationZenodo. DOI: 10.5281/zenodo.18937850 License (Add the license you selected on Zenodo, e.g., MIT / Apache-2.0 / CC BY 4.0.) Troubleshooting CUDA out of memory Reduce RISE masks or batch size Disable SHAP/LIME if not needed Run CPU-only (set CUDA_VISIBLE_DEVICES="") LIME errors Install: pip install scikit-image scikit-learn SHAP errors Install: pip install shap Optionally add background images into static/shap_bg/....

Identifiers

Citations and references

Cited by 00 references