Agri-Vision is an AI-powered system that analyzes cotton crop images to determine growth stages and health conditions.
It helps farmers and researchers make informed decisions about crop management and harvest timing.
🚀 This module prepares the complete AI-powered crop analysis workflow by handling image preprocessing, initializing prediction models, and validating uploaded crop images before analysis.
|
|
Agri-Vision uses deep learning and computer vision techniques to:
- Detect cotton growth phases
- Identify cotton crop diseases
- Provide confidence scores and actionable recommendations
- Offer both a web interface and a REST API
- Overview
- Features
- Tech Stack
- Dataset Information
- Model Information
- Model Performance & Benchmarking
- Project Structure
- Setup & Execution
- API Reference
- Future Enhancements
- Contributing
- 🌿 Growth Phase Detection (Supported for cotton and 🍅 Tomato)
- 💚 Health Assessment (disease & damage detection)
- 🤖 AI-Powered Analysis using deep learning
- 🌐 Web Interface (Flask-based)
- 📊 REST API Support for programmatic access
- 🎯 Smart Recommendations for farmers
- ⚡ Fast Processing (< 2 seconds per image)
Built using modern AI, deep learning, and computer vision technologies for precision agriculture.
The datasets used for training the Growth Stage Prediction and Crop Disease Classification models were sourced from Roboflow.
https://universe.roboflow.com/p-project-ebvkg/cotton-boll-growth-detection/dataset/5
*The above dataset is also having appropriate labels for YOLO model training
https://universe.roboflow.com/deep-learning-nygzt/tomato-crop-diseases
- Cotton Blossom
- Cotton Bud
- Early Boll
- Matured Cotton Boll
- Split Cotton Boll
- Healthy
- Aphids
- Army Worm
- Bacterial Blight
- Cotton Boll Rot
- Green Cotton Boll
- Powdery mildew
- Target spot
The datasets used for training the Growth Stage Prediction and Crop Disease Classification models were sourced from Roboflow.
https://www.kaggle.com/datasets/arjunsudheer326/tomato-plant-stages-dataset
https://universe.roboflow.com/deep-learning-nygzt/tomato-crop-diseases
- Early Vegetative
- Flowering initiation
- Early Blight
- Healthy
- Late blight
- Leaf miner
- Leaf mold
- Mosaic virus
- Septoria
- Spider mites
- Yellow leaf curl virus
The datasets used for training the potato disease classification model were taken from kaggle
https://www.kaggle.com/datasets/faysalmiah1721758/potato-dataset
- Early Blight
- Late Blight
- Healthy Leaf
Download the dataset from the given URL and make sure to split the it into training data, testing data and validation data.
The app requires a strong SECRET_KEY when running in production. This key signs session cookies and other secrets — keep it private.
To generate a key:
python -c "import secrets; print(secrets.token_urlsafe(64))"
Create a .env file in the project root and add at least:
SECRET_KEY=your-generated-secret
OPENWEATHER_API_KEY=your-openweather-key
Run the app in production mode locally:
export SECRET_KEY="$(python -c 'import secrets; print(secrets.token_urlsafe(64))')"
export FLASK_ENV=production
python -m flask run --host=0.0.0.0 --port=5000
During development the app will create a temporary key if SECRET_KEY is not set — do not use that value in production.
Model Used - YOLOv8
Parameters - ~3M
Layers - 73
Model Used - ResNet50
Parameters - 25.6M
Successful cotton disease classifications can include a Grad-CAM heatmap overlay generated from the final ResNet50 convolutional block (layer4[-1]). Generated visualizations are saved under static/generated/gradcam/ and surfaced in the results page and API responses when available.
Check training curves and result snapshots inside the results/ directory.
For confusion matrices, benchmark tables, and reproducibility notes, see Model Performance & Benchmarking.
mAP50 - 60.06%
mAP95 - 34.8%
R - 53.8%
P - 62.7%
Inference Time - 3.3ms
Accuracy - 99.83%
Precision - 99.83%
Recall - 99.83%
F1 Score - 99.83%
ROC AUC - 99.98%
Model Used - YOLOv8
Parameters - ~3M
Layers - 73
Model Used - ResNet50
Parameters - 25.6M
Check training curves and result snapshots inside the results/ directory.
mAP50 - 95.4%
mAP95 - 86.2%
R - 88.5%
P - 92.3%
Inference Time - 1.3ms
Accuracy - 100%
Precision - 100%
Recall - 100%
F1 Score - 100%
Agri-Vision/
│
├── app/
│ ├── __init__.py
│ │
│ ├── routes/
│ │ ├── auth.py
│ │ ├── admin.py
│ │ ├── dashboard.py
│ │ ├── disease.py
│ │ ├── reports.py
│ │ ├── weather.py
│ │ └── yield_prediction.py
│ │
│ ├── services/
│ │ ├── disease_prediction_service.py
│ │ ├── recommendation_engine.py
│ │ ├── report_service.py
│ │ ├── weather_service.py
│ │ ├── yield_service.py
│ │ ├── image_quality.py
│ │ └── gradcam.py
│ │
│ ├── database/
│ │ └── models.py
│ │
│ ├── templates/
│ └── static/
│
├── ai_models/
│ ├── cotton/
│ ├── potato/
│ ├── tomato/
│ └── growth_stage/
│
├── training/
│ ├── notebooks/
│ │ ├── cotton_crop_disease_prediction.ipynb
│ │ ├── potato_crop_disease_classification.ipynb
│ │ ├── tomato_crop_disease_classification.ipynb
│ │ ├── tomato_growth_stages_classification.ipynb
│ │ └── cotton_growth_stage_prediction.ipynb
│ │
│ ├── train.py
│ ├── model_config.json
│ └── model_registry.py
│
├── database/
│ ├── create_admin.py
│ ├── add_sample_data.py
│ ├── populate_disease_data.py
│ └── populate_historical_data.py
│
├── tasks/
│ ├── celery_tasks.py
│ └── celery_worker.py
│
├── results/
│ ├── cotton/
│ ├── potato/
│ ├── tomato/
│ └── growth_stage/
│
├── docs/
│ ├── architecture.md
│ ├── MODEL_VERSIONING.md
│ ├── PDF_FEATURE_INTEGRATION.md
│ ├── PDF_IMPLEMENTATION_SUMMARY.md
│ ├── PDF_QUICK_START.md
│ ├── security.md
│ ├── model-benchmarking.md
│ └── api-documentation.md
│
├── deployment/
│ ├── Dockerfile
│ ├── docker-compose.yml
│ ├── nginx.conf
│ └── runtime.txt
│
├── tools/
│ ├── check_quotes.py
│ ├── check_tags.py
│ ├── count_brackets.py
│ └── find_unmatched.py
│
├── tests/
│ ├── test_admin_auth.py
│ ├── test_app.py
│ ├── test_config.py
│ ├── test_explain.py
│ ├── test_recommendations.py
│ ├── test_weather.py
│ └── test_yield.py
│
├── client/
├── .github/
│
├── run.py
├── requirements.txt
├── requirements_minimal.txt
├── requirements_no_versions.txt
├── README.md
├── LICENSE
├── CONTRIBUTING.md
├── Code_Of_Conduct.md
├── .env.example
├── .gitignore
└── pytest.ini
There are two ways to run this project: using Docker (Recommended) or setting it up locally with Python.
Using Docker is the easiest way to run Agri-Vision as it avoids system dependency issues and automatically sets up the environment.
- Ensure you have Docker Desktop installed.
- Clone the repository and navigate into it:
git clone https://github.com/neeru24/Agri-Vision cd
python -m venv venv
Be careful with the markdown formatting/backticks.
### Activate Virtual Environment
For Windows:
```bash
venv\Scripts\activateFor macOS/Linux:
source venv/bin/activate
### Install Dependencies
```bash
pip install -r requirements.txt
python app.pyhttp://127.0.0.1:5000/- Build and start the container:
docker-compose up --build
- Access the web interface at
http://localhost:5000.
If you prefer to run the project natively using Python (requires Python 3.8+):
git clone https://github.com/neeru24/Agri-Vision.git
cd Agri-Visionpython3 -m venv venv
source venv/bin/activatepython -m venv venv
venv\Scripts\activateCreate a .env file in the project root and add a SECRET_KEY entry.
This value is required in production—the app will not start without it. To generate a secure key locally, run:
python -c 'import secrets; print(secrets.token_urlsafe(64))'Then add the generated value to .env:
SECRET_KEY=your_generated_secret_hereInstall all the required Python packages using:
pip install -r requirements.txtStart the application explicitly by running:
python app.pyThe project should now be running successfully on your local machine at http://localhost:5000.
Agri-Vision includes a comprehensive unit and integration testing suite built using pytest and pytest-cov.
The test suite runs programmatically in-memory, requiring no external files or slow deep learning model loading. This ensures tests run in less than 1 second with 89%+ code coverage.
Thanks to the pre-configured pytest.ini, you don't need to pass long command line arguments. Running a single command will execute all 28 tests, generate verbose progress, check code coverage, and produce an HTML report automatically:
python -m pytestExpected Output:
tests/test_app.py::test_preprocess_image_for_resnet PASSED [ 3%]
tests/test_app.py::test_infer_disease_fallback PASSED [ 7%]
...
tests/test_app.py::test_post_api_analyze_exception PASSED [100%]
=============================== tests coverage ================================
Name Stmts Miss Cover Missing
--------------------------------------
app.py 201 22 89% 81-83, 88-90, 159, 406-420
--------------------------------------
TOTAL 201 22 89%
Coverage HTML written to dir htmlcov
============================= 28 passed in 1.06s ==============================
When you run the tests, a beautiful interactive HTML coverage report is automatically created in the htmlcov/ directory.
To visually inspect which lines are covered (in green) and which are missed (in red) line-by-line:
- Open the folder
htmlcov/in your file explorer. - Double-click
index.htmlto open it in any web browser. - Click on
app.pyto view the beautiful interactive code visualization.
A GitHub Actions workflow is fully set up. It will automatically run your entire unit test suite and verify code quality/coverage metrics on every single push or pull_request to the main branch.
curl -X POST -F "file=@cotton_image.jpg" http://localhost:5000/api/analyze{
"status": "success",
"analysis": {
"stage": "Bursting (Ripped)",
"stage_confidence": 0.87,
"health_status": "Pink Bollworm Damage",
"health_confidence": 0.76,
"health_score": 68.5,
"is_ripped": true,
"has_damage": true
},
"recommendations": ["..."]
}- Go to
/analyze - Upload a cotton crop image
- View detailed analysis results
- Download the JSON report if needed
- 📱 Mobile application support
- 🎥 Real-time video analysis
- 🌾 Multi-crop support (Cotton, Tomato, and Potato fully integrated)
- ☁️ Weather data integration
- 📊 Yield prediction system
- 🧠 Improved AI models
Contributions are welcome to improve Agri-Vision and make it more useful for farmers, researchers, and developers.
Feel free to:
- Fork the repository
- Create a feature branch
- Submit a pull request
- Follow the project structure and coding style.
- Avoid spam or duplicate PRs/issues.
- Be respectful during code reviews and discussions.
- Beginners are welcome — feel free to ask questions if stuck ✨
This project is licensed under the MIT License.
See the LICENSE file for more details.
Special thanks to:
- TensorFlow
- Flask
- OpenCV
- Open-source contributors
- Agricultural research datasets
- Ultralytics
- PyTorch
❤️ Made with Passion by neeru24
⭐ If you found this project helpful, consider giving it a star. ⭐


































































