Skip to content
TQT
Earlier computer vision system 2024

Leaf-Based Plant Disease Detection: PyTorch classification with segmentation-assisted preprocessing and visual explanations

A PyTorch computer-vision pipeline for plant disease classification that combines image preprocessing, CNN inference, class-specific thresholds, and Grad-CAM++ explanations behind a FastAPI service.

Overview

A computer-vision pipeline for leaf-image analysis.

This project implements a plant-disease analysis prototype around leaf images. The service accepts image payloads, checks whether the input is a leaf, runs disease classification for supported plant models, and returns prediction metadata with an explanation image.

The current service configuration includes disease models for tomato and potato, plus a separate leaf-versus-non-leaf classifier.

System flow

Preprocessing, inference, explanation, and persisted analysis.

Image inputFastAPI receives a base64 image with garden and plant metadata.
Leaf checkA classifier filters non-leaf inputs before disease inference.
InferenceSAM-assisted preprocessing feeds ResNet-based disease classifiers.
ExplanationGrad-CAM++ produces heatmaps and the service persists analysis data.

Technical contribution

Training and serving are both represented in the repository.

  • Built train, validation, and test pipelines with PyTorch ImageFolder and DataLoader.
  • Trained and served ResNet-based classifiers for tomato and potato disease categories.
  • Combined SAM-assisted preprocessing with Grad-CAM++ to produce interpretable prediction heatmaps.
  • Used cross-entropy loss, SGD optimization, StepLR scheduling, and multiclass accuracy evaluation in the training pipeline.
  • Exposed analysis, garden, user, history, and statistics workflows through FastAPI and SQLite-backed data access.

Limitations

Results are framed without unsupported performance claims.

The repository supports model training, inference, explainability, and API integration, but it does not provide enough public evidence for a specific accuracy, dataset size, production deployment, mobile deployment, or real agricultural usage claim.

Stack

PyTorchTorchvisionResNetGrad-CAMFastAPISQLitePandasNumPy