AI-Based Nitrogen Deficiency Detection and Precision Fertilization System

System Demonstration

System Workflow
Figure 1: End-to-End System Workflow

This project presents a proof-of-concept precision agriculture system that combines deep learning, web technologies, and embedded systems to detect nitrogen (N) deficiency in corn leaves and recommend fertilizer application based on actual plant requirements.

Nitrogen deficiency is a major limiting factor in crop productivity. Conventional fertilizer application methods typically apply nitrogen uniformly across fields, which can result in excessive fertilizer use, increased cost, and environmental pollution. This project explores how computer vision and AI-driven decision-making can enable need-based nitrogen management, improving efficiency and sustainability.

Dataset and Model Development

The system is trained using a publicly available corn leaf nitrogen deficiency dataset from Mendeley Data https://data.mendeley.com/datasets/g7xnn2bm4g/1 . A ResNet-18 convolutional neural network was implemented and trained using PyTorch to classify corn leaf images into different nitrogen deficiency levels, such as high deficiency, mild deficiency, and no deficiency.

After training, the model was saved as a .pth file and optimized for inference in a lightweight application environment suitable for deployment on edge devices.

Web-Based Inference System

A Flask-based web application was developed to deploy the trained deep learning model. The web interface allows users to drag and drop or upload corn leaf images, which are then analyzed in real time. The system displays:

Embedded System Integration

To demonstrate system-level integration, the prediction results generated by the Flask application are transmitted wirelessly to an ESP8266 microcontroller. The ESP8266 displays the classification result and fertilizer recommendation on an OLED display, such as:

“Mild N Deficiency – Spray 2 g Nitrogen”

Although no physical spraying mechanism is currently implemented, this step validates real-time communication between AI software and embedded hardware, which is critical for field deployment.

Real-World Implementation Scenario

In a real agricultural deployment, this system can be integrated with a side-dressing tractor or fertilizer application machine to enable real-time, plant-specific nitrogen spraying.

A camera mounted on the side of the tractor continuously captures images of corn leaves as the vehicle moves along crop rows. These images are sent in real time to an on-board edge computing device, such as an NVIDIA Jetson Nano or Raspberry Pi, installed on the machine.

The edge computer runs the trained deep learning model locally, allowing low-latency, offline inference without dependence on cloud connectivity. Each image is analyzed to determine the nitrogen deficiency level of the plant. Based on the model’s output, a control algorithm computes the required fertilizer dosage.

The computed decision is then converted into actuation commands, which are sent to electronically controlled sprayers or solenoid valves mounted on the tractor. This enables nitrogen fertilizer to be applied only where and in the amount needed, rather than uniformly across the field.

Significance and Future Scope

This project demonstrates the feasibility of transforming AI-based crop health analysis into actionable agricultural decisions. While the current implementation focuses on image classification and decision communication, the system architecture is fully extensible.

Future work may include:

Technologies Used

This mini-project serves as a foundational step toward AI-driven precision farming, demonstrating how deep learning, edge computing, and embedded systems can work together to enable efficient, sustainable agricultural practices.

Model Evaluation Metrics

Confusion Matrix
Figure 2: Confusion Matrix of Nitrogen Deficiency Classification

The nitrogen deficiency classification model was evaluated using precision, recall, F1-score, and a confusion matrix to understand how reliably the system can support AI-driven, need-based fertilizer decisions.

Overall, the confusion matrix shows that the model performs best at detecting extreme conditions—high deficiency (N0) and no deficiency (NFull)—which are the most critical for real-world actuation decisions. Despite limitations in mild deficiency detection, the results validate the feasibility of using computer vision–based AI models for actionable, plant-specific nitrogen management in precision farming systems.

Explainable AI Using Grad-CAM

To ensure the transparency and interpretability of the nitrogen deficiency detection model, Grad-CAM (Gradient-weighted Class Activation Mapping) was employed. Grad-CAM is a visualization technique that highlights the regions of an input image that are most influential in the model’s decision-making process.

In this project, Grad-CAM generates heatmaps over corn leaf images, indicating the specific leaf areas that the ResNet-18 model focuses on when classifying nitrogen deficiency levels. For instance: