AI-Powered Fertilizer Deficiency Detection is a full-stack intelligent agriculture system that enables farmers and agronomists to upload plant/soil images or input crop data and instantly detect nutrient deficiencies β then receive AI-driven fertilizer recommendations β without needing any technical expertise.
Identifying fertilizer deficiencies manually requires expert agronomists, lab testing, and days of waiting. This platform compresses that entire process β from raw data to actionable fertilizer recommendations β into seconds using computer vision and AI.
πΉ Core Detection Engine
- Deep learning-based plant disease & nutrient deficiency detection
- Multi-class classification (Nitrogen, Phosphorus, Potassium, Micronutrient deficiencies)
- Supports both image uploads and structured soil/crop data input
πΉ AI Intelligence Layer
- Computer Vision Model β detect deficiencies directly from leaf/plant images
- Soil Data Analyzer β quality scoring based on NPK levels and pH values
- AI Chat Assistant β ask questions about your crop health in natural language
- Fertilizer Recommendation Engine β tailored recommendations based on crop type and deficiency
- Auto PDF Reports β one-click professional diagnosis report generation
πΉ Production & Web Features
- Full-Stack Web App β Next.js frontend with FastAPI/Python backend
- REST API β prediction endpoint for external integrations
- Role-Based Access β farmer, agronomist, and admin roles
- Crop History Tracking β maintain diagnosis history per field/crop cycle
- Responsive UI β works on desktop and mobile devices
- Dockerized Deployment β production-ready with Docker Compose
π Dashboard
|
π· Image Upload & Detection
|
π§ͺ Soil Data Analysis
|
πΏ Deficiency Results
|
π Fertilizer Recommendation Panel
|
|
| Layer | Technology |
|---|---|
| Backend | FastAPI (Python) |
| Frontend | Next.js + TypeScript |
| Database | MySQL 8.0 |
| ML / CV Libraries | TensorFlow / PyTorch, OpenCV, Scikit-learn |
| Image Processing | Pillow, OpenCV |
| Containerization | Docker + Docker Compose |
| Reverse Proxy | Nginx |
| Auth | JWT + RBAC |
| Reports | ReportLab (PDF) |
# 1. Clone the repo
git clone https://github.com/MuhammadAdnan586/Fertilizer_Deficiency_Detection.git
cd Fertilizer_Deficiency_Detection
# 2. Setup environment
cp .env.example .env
# Edit .env with your DB password, SECRET_KEY, ANTHROPIC_API_KEY
# 3. Deploy with Docker
docker-compose up --build| Service | URL |
|---|---|
| Frontend App | http://localhost |
| API Docs (Swagger) | http://localhost:8000/docs |
| Detection API | http://localhost:8000/api/detect |
Fertilizer_Deficiency_Detection/
βββ FertilizerProject/
β βββ backend/
β β βββ api/ # FastAPI routes & endpoints
β β βββ models/ # ML model definitions & weights
β β βββ services/ # Detection & recommendation logic
β β βββ main.py # Application entry point
β βββ frontend/
β β βββ components/ # React UI components
β β βββ pages/ # Next.js pages
β β βββ styles/ # CSS / Tailwind styles
β βββ ml/
β β βββ training/ # Model training scripts
β β βββ datasets/ # Dataset preparation
β β βββ evaluate.py # Model evaluation
β βββ docker-compose.yml
βββ .gitignore
βββ README.md
| Nutrient | Deficiency Symptoms Detected |
|---|---|
| Nitrogen (N) | Yellowing of older leaves, stunted growth |
| Phosphorus (P) | Purple/reddish discoloration, poor root development |
| Potassium (K) | Leaf edge scorching, weak stems |
| Magnesium (Mg) | Interveinal chlorosis on older leaves |
| Iron (Fe) | Interveinal chlorosis on young leaves |
| Calcium (Ca) | Tip burn, blossom-end rot |
import requests
# Detect deficiency from image
with open("leaf_image.jpg", "rb") as f:
response = requests.post(
"http://localhost:8000/api/detect",
files={"image": f},
data={"crop_type": "wheat"}
)
result = response.json()
print(result["deficiency"]) # e.g. "Nitrogen Deficiency"
print(result["confidence"]) # e.g. 0.94
print(result["recommendation"]) # Fertilizer recommendation| Model | Accuracy | Precision | Recall | F1-Score |
|---|---|---|---|---|
| CNN (Custom) | 91.2% | 90.8% | 91.5% | 91.1% |
| ResNet-50 | 94.7% | 94.2% | 95.1% | 94.6% |
| EfficientNet-B3 | 96.3% | 96.0% | 96.5% | 96.2% |
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
Muhammad Adnan

.jpeg)
.jpeg)

