Inspiration

I once tried to grow basil in my dorm room. It started beautiful and vibrant, thriving in the morning sunlight. But over the course of two weeks, something went wrong. The leaves yellowed, then turned brown. They drooped and curled inward. Eventually, my little basil plant died.

I remember staring at it, completely lost. Was it too much water? Not enough light? Wrong temperature? A disease? I didn't know what went wrong, and more importantly, I didn't know how to save it.

That feeling of helplessness inspired this project. There are millions of plant lovers out there—from dorm room gardeners to community farmers—who struggle to keep their plants alive. They don't have access to agricultural experts or plant pathologists. They just have their phones and a dying plant.

Plant Health Guardian was built to be that expert in their pocket. It's an AI tool that understands plants and helps people save them before it's too late. Because every plant deserves a chance.

What it does

Plant Health Guardian is an intelligent plant disease detection system that:

  1. Analyzes plant photos - Users upload a photo of their leaf or plant
  2. Identifies diseases instantly - AI detects which of 40 plant diseases it might have
  3. Shows confidence scores - Displays top 5 predictions with probability percentages
  4. Provides care recommendations - Gives specific, actionable steps to save the plant
  5. Supports 14 plant types - Apple, Basil, Cherry, Corn, Grape, Orange, Peach, Pepper, Potato, Raspberry, Soybean, Squash, Strawberry, Tomato

Key Features:

  • 99.87% accuracy - Near-perfect disease classification
  • Real-time inference - 1-2 seconds on GPU, results instantly
  • 40 disease types - Covers common diseases across plant types
  • Beautiful web interface - Built with Streamlit for easy accessibility
  • Personalized care tips - Disease-specific treatment recommendations
  • Confidence visualization - Users understand model certainty

Special Feature: Basil Focus The app has special treatment for basil—both healthy and unhealthy states—with personalized encouragement messages to help people save their struggling basil plants (just like the inspiration story!).

How I built it

Data Collection & Preparation

Model Training

  • Architecture: Swin Transformer
  • Transfer Learning: Fine-tuned pre-trained ImageNet weights on plant diseases
  • Optimization: AdamW optimizer with cosine annealing learning rate scheduler
  • Augmentation: Random rotations, flips, color jitter to prevent overfitting
  • Hardware: L4 GPU in Google Colab
  • Result: 99.87% test accuracy

Web Interface

  • Built with Streamlit for beautiful, responsive UI
  • Features:
    • Image upload with drag-and-drop
    • Real-time prediction display
    • Confidence bars for top 5 predictions
    • Color-coded disease cards
    • Step-by-step care recommendations
    • Developer story in sidebar

Deployment

  • Created production-ready project structure
  • Auto-run scripts for /Mac/Linux with run.sh
  • Comprehensive documentation (README, setup guides)
  • Git-friendly with .gitignore

Challenges I ran into

Data Imbalance Problem: Some disease classes had 1 image, others had 5,000+. This could cause the model to overfit on well-represented classes. Solution:

  • Used stratified train/val/test splits
  • Applied data augmentation (flips, rotations, color jitter)
  • Used class weights in loss function (though balanced dataset helped too)

Model Size & Inference Time Problem: The Swin model has 87.7M parameters. Would it run in real-time? Solution:

  • Froze earlier layers, fine-tuned only last layers (transfer learning)
  • Used GPU for inference (L4 GPU: 1-2 seconds per image)
  • Optimized batch processing

Resolution Mismatch Problem: Pre-trained Swin expects 224×224 images, but we had varying sizes. Solution:

  • Added ignore_mismatched_sizes=True to allow classifier head resizing
  • Implemented proper image preprocessing in the app

Label Mapping Across Datasets Problem: PlantVillage and custom basil datasets had different naming conventions and structures. Solution:

  • Created unified label mapping system
  • Standardized class names (Plant___Disease format)
  • Generated JSON mapping file for consistent inference

Streamlit Compatibility Problem: Deprecated Streamlit parameters and undefined variable errors. Solution:

  • Updated use_column_widthuse_container_width
  • Fixed variable scoping by passing id2label to prediction function
  • Tested thoroughly on latest Streamlit version

Accomplishments that I'm proud of

Technical Achievements:

  1. 99.87% Accuracy
    • Achieved near-perfect classification on test set
    • Better than expected for multi-class problem with 40 classes
    • Demonstrates strong transfer learning effectiveness
  2. Rapid Training & Deployment
    • Trained model in 2 hours on L4 GPU
    • Fine-tuned from pre-trained weights (smart engineering)
    • Deployed working app within 5 hours total
  3. Comprehensive Disease Database
    • 40 plant-disease combinations
    • Each with detailed symptoms, care tips, treatment recommendations
    • Special focus on basil (the inspiration!)
  4. Production-Ready Code
    • Clean, well-organized project structure
    • Works on Mac, and Linux
    • Auto-run scripts and comprehensive documentation
    • Git-ready with proper .gitignore

Impact Achievements:

  1. Authentic Problem-Solving

    • Built from real personal experience (failed basil)
    • Solves genuine pain point for millions of plant lovers
    • Makes agricultural expertise accessible to everyone
  2. Beautiful User Experience

    • Intuitive Streamlit interface
    • Clear confidence visualization
    • Personalized care recommendations
    • Emotional encouragement messages (especially for basil!)
  3. Scalability

    • Architecture can easily add more plant types
    • Can be deployed to cloud (AWS, GCP, Vercel)
    • Ready for mobile app wrapping
    • Can integrate with MCP for future enhancements

What I learned

Machine Learning Insights:

  1. Transfer Learning is Powerful

    • Starting from ImageNet pre-trained weights was crucial
    • Fine-tuning with 5 epochs achieved 99.87% accuracy
    • Much more efficient than training from scratch
  2. Data Augmentation is Essential

    • Random rotations, flips, color jitter prevented overfitting
    • Real-world plant photos have varied lighting, angles, scales
    • Augmentation made model robust to variations
  3. Confidence Scores Matter

    • Users need to understand model certainty
    • Top-5 predictions more useful than single prediction
    • Helps build trust in AI system

Software Engineering Insights:

  1. Project Structure is Critical

    • Clear separation of models/, data/, app.py
    • Documentation reduces onboarding time
    • Auto-run scripts improve user experience
  2. Cross-Platform Compatibility

    • Python 3 on Mac uses python3 not python
    • Bash scripts need proper fallbacks
    • Testing on multiple OSs catches bugs early
  3. Streamlit is Powerful for Rapid Deployment

    • Can build ML web apps in hours
    • Beautiful UI without CSS/HTML expertise
    • Perfect for hackathons and MVPs

Domain Knowledge:

  1. Plant Diseases are Diverse

    • Different diseases have different causes (fungal, bacterial, viral)
    • Treatment varies significantly by disease type
    • Visual symptoms can be subtle and varied
  2. Context Matters

    • Basil care is different from tomato care
    • Temperature, humidity, light all crucial
    • Personalized recommendations more helpful than generic tips

Personal Growth:

  1. Problem-Driven Development

    • Real inspiration (failed basil) drove better product
    • Authenticity resonates with users
    • Solving real problems > solving technical challenges
  2. Rapid Prototyping Skills

    • Completed full ML pipeline in 5 hours
    • Prioritized what matters (accuracy, UX, story)
    • Cut scope appropriately (no MCP integration yet)

What's next for plant-disease-detector

Short-Term (2-4 weeks):

  1. Mobile App Wrapper

    • Wrap Streamlit app in Flutter/React Native
    • Better mobile UX with camera integration
    • iOS and Android support
  2. Enhanced Detection

    • Add pest detection (spider mites, aphids, mealybugs)
    • Support more plant types (houseplants, herbs, vegetables)
    • Expand to ~100 plant-disease combinations
  3. User Feedback Loop

    • Add rating system for predictions
    • Collect user feedback to improve model
    • Build community around app

Medium-Term (1-2 months):

  1. MCP Integration (as mentioned in hackathon)

    • Real-time weather integration for care tips
    • Plant database API lookups
    • Care reminder scheduling
  2. Cloud Deployment

    • Host on AWS/GCP/Vercel
    • Public URL for judges and users
    • Scalable infrastructure
  3. Advanced Features

    • Time-series tracking (upload photos over weeks)
    • Treatment progress monitoring
    • Success rate analytics

Long-Term (3-6 months):

  1. Monetization Options

    • Freemium model (basic detection free, premium features paid)
    • Partnership with garden centers / nurseries
    • B2B agricultural consulting integration
  2. Research Contributions

    • Publish findings on transfer learning for plant diseases
    • Contribute improvements back to open-source community
    • Patent novel augmentation techniques if applicable
  3. Social Impact

    • Partner with nonprofits for community gardens
    • Educational curriculum for schools
    • Global expansion (disease data for different regions)

Built With

Share this project:

Updates