AI-Powered Apple Leaf Specialist

Hi Everyone​ :waving_hand:

I wanted to share a computer vision app I recently built using Streamlit + PyTorch that detects common apple leaf diseases from a single photo and provides tailored care recommendations for each predicted condition.

:link: Try the app here
:laptop: Github repository

What’s under the hood?

  • Fine-tuned ResNet-18

  • Calibrated probability outputs (temperature scaling)

  • TorchScript export for fast, lightweight CPU inference

  • Deterministic preprocessing pipeline (resize → center crop → normalize)

  • Confidence threshold routing to an "unknown" label when the model isn’t confident

The model classifies leaf images into:

  • Healthy

  • Scab

  • Rust

  • Black Rot

If the prediction confidence is below a defined threshold, it safely returns “unknown” instead of over-committing. I wanted to keep it practical and conservative for real-world usage.

Smart input handling:

The app supports:

  • Image upload

  • Live camera capture

For camera images, I added:

  • Brightness validation

  • Leaf-likeness gating (green coverage + texture checks)

  • Optional bypass for edge cases

This helps reduce false positives and noisy captures before inference even runs.

Tailored Recommendations:

After prediction, the app doesn’t just stop at a label.

Each class triggers specific, actionable care guidance:

  • Airflow improvement strategies

  • Fungicide timing suggestions

  • Irrigation best practices

  • Host management considerations

So the output becomes a decision-support tool, not just a classifier.

Built With:

  • Streamlit (UI + interaction layer)

  • PyTorch

  • Torchvision

  • TorchScript (for production-ready model deployment)

  • Custom probability rendering and structured class mapping

Everything runs locally on CPU, so no cloud dependency.

Would love feedback from the community, especially around:

  • UI/UX improvements

  • Model calibration strategies

  • Additional validation layers

  • Ideas for expanding to other crops

Appreciate any thoughts!