Precision Spraying System for Agricultural Drones Based on Improved YOLOv7

In modern agriculture, the use of agricultural drones has revolutionized pest and disease management by enabling efficient and large-scale monitoring. However, current agricultural drone spraying systems often suffer from issues such as overlapping sprays, pesticide residues, and a lack of real-time, on-board pest detection capabilities. Moreover, existing detection methods are challenging to deploy on embedded devices due to computational constraints. To address these challenges, we propose a precision spraying system for agricultural drones that integrates an improved YOLOv7-based detection algorithm for identifying downy mildew and leaf miners. This system aims to achieve targeted spraying, reducing waste and environmental impact while enhancing the operational efficiency of agricultural drones.

Our work focuses on developing a machine vision system that can be deployed on agricultural drones for real-time pest and disease detection. We collected a dataset of 3000 images, augmented through techniques like random translation, flipping, and brightness adjustment, to train and validate our model. The system design includes a camera for image capture, an embedded processing unit (Jetson Orin Nano), a flight controller, and a precision spraying mechanism. The core of our approach lies in enhancing the YOLOv7 object detection model to improve its performance on small-scale pests and diseases in complex agricultural environments.

The improved YOLOv7 model incorporates three key modifications: First, we replace the traditional Feature Pyramid Network (FPN) in the neck with an Asymptotic Feature Pyramid Network (AFPN) to enhance adaptive feature fusion across different hierarchical levels. This allows the model to better handle scale variations common in agricultural drone imagery. Second, we introduce the Efficient Multi-scale Attention (EMA) module to capture cross-dimensional interactions and improve pixel-level feature aggregation. Third, we replace the original CIoU loss function with the Wise-IoU (WIoU) loss to stabilize bounding box regression and enhance generalization. These modifications are designed to boost detection accuracy while maintaining real-time performance suitable for agricultural drone applications.

To evaluate our system, we conducted extensive experiments on a custom dataset. The training environment included an NVIDIA RTX 3090 GPU with PyTorch, while deployment was tested on a Jetson Orin Nano embedded platform. We used standard metrics such as precision, recall, mean Average Precision (mAP), and frames per second (FPS) to assess performance. The results demonstrate that our improved YOLOv7 model achieves a mAP@0.5 of 94.2%, which is a 25.9% increase over the baseline YOLOv7. Additionally, the FPS improved by 4.6%, indicating enhanced efficiency for real-time processing on agricultural drones.

We further validated the system through ablation studies and on-board testing. The ablation experiments, summarized in Table 1, show the incremental contributions of each modification. For instance, adding AFPN alone increased mAP by 24.6%, while incorporating EMA provided an additional 1.1% gain. The WIoU loss also contributed to improved stability. During deployment on the agricultural drone’s embedded system, the improved model achieved an online detection success rate of 89.7%, outperforming the baseline by 11.3%. This confirms the practicality of our approach for precision spraying in field conditions.

In this article, we detail our methodology, experimental setup, and results. We begin by discussing the challenges in agricultural drone spraying and the motivation for our work. Then, we describe the dataset collection and system design. Next, we explain the technical improvements to YOLOv7, supported by mathematical formulations. Subsequently, we present the experimental outcomes with tables and analyses. Finally, we conclude with insights and future directions for enhancing agricultural drone technologies.

Introduction to Agricultural Drone Challenges

Agricultural drones have become indispensable tools in precision agriculture, offering benefits such as reduced labor costs, increased coverage, and minimized chemical usage. However, traditional spraying methods using agricultural drones often rely on pre-programmed paths or manual control, leading to inefficiencies like repeated spraying of the same areas, pesticide drift, and lack of adaptability to specific pest infestations. These issues not only waste resources but also contribute to environmental pollution and potential health risks. Therefore, integrating real-time, intelligent detection systems into agricultural drones is crucial for achieving sustainable farming practices.

Current pest detection methods in agriculture predominantly involve manual scouting, which is time-consuming and prone to errors. Machine vision-based approaches have shown promise, but deploying them on embedded platforms for agricultural drones remains challenging due to limited computational power and the need for real-time processing. Our research addresses this gap by developing a lightweight yet accurate detection model that can operate efficiently on agricultural drone hardware. We focus on two common pests: leaf miners and downy mildew, which significantly affect crop yields worldwide.

The primary objective of our work is to design a precision spraying system that enables agricultural drones to detect pests and diseases on-the-fly and trigger targeted spraying only when necessary. This “spray-on-detection” approach minimizes chemical usage, reduces operational costs, and enhances the overall effectiveness of agricultural drone missions. By leveraging advanced deep learning techniques, we aim to push the boundaries of what agricultural drones can achieve in smart farming.

Dataset and System Design

We compiled a dataset of 3000 images for training and evaluation. The images were captured using an agricultural drone flying at a height of 2 meters, with a resolution of 1920×1080 pixels. The dataset includes 200 original images of infected cabbage plants, supplemented with 400 publicly available images from platforms like AI Studio. To ensure robustness, we applied data augmentation techniques such as random平移,翻转,镜像, and brightness adjustment. The dataset was annotated with two classes: “1” for leaf miners and “2” for downy mildew, using the LabelImg tool. The annotated data was split into training (70%), validation (20%), and testing (10%) sets.

The precision spraying system for agricultural drones consists of several components: a high-resolution camera for image acquisition, an RTK module for precise positioning, a flight controller for drone navigation, a pumping system for pesticide delivery, and an embedded development board (Jetson Orin Nano) for real-time processing. The system workflow, as illustrated in Figure 2, involves continuous image capture by the agricultural drone, pest detection by the improved YOLOv7 model, and conditional activation of the spraying mechanism upon positive detection. This design ensures that agricultural drones only spray when pests are identified, thereby optimizing resource use.

The embedded platform, Jetson Orin Nano, was chosen for its balance of performance and power efficiency, making it suitable for agricultural drone applications. We deployed our model using TensorRT for accelerated inference, achieving real-time processing speeds necessary for dynamic agricultural environments. The integration of this system into agricultural drones demonstrates a practical solution for automated pest management.

Improved YOLOv7 Network Architecture

YOLOv7 is a state-of-the-art real-time object detector known for its speed and accuracy. However, for small pest detection in agricultural drone imagery, it requires enhancements to handle scale variations and complex backgrounds. Our improved YOLOv7 model incorporates three modifications: AFPN, EMA attention, and WIoU loss. These are detailed below.

First, the AFPN module replaces the standard FPN in the neck network. AFPN facilitates adaptive spatial fusion of features from different levels, allowing the model to emphasize more informative scales. Given features from levels 1, 2, and 3, the fused feature at level $l$ is computed as:

$$ y^l_{ij} = \alpha^l_{ij} \cdot x^{1 \to l}_{ij} + \beta^l_{ij} \cdot x^{2 \to l}_{ij} + \gamma^l_{ij} \cdot x^{3 \to l}_{ij} $$

where $\alpha^l_{ij}, \beta^l_{ij}, \gamma^l_{ij}$ are spatial weights satisfying $\alpha^l_{ij} + \beta^l_{ij} + \gamma^l_{ij} = 1$. This enables the agricultural drone’s vision system to better integrate multi-scale features, crucial for detecting tiny pests.

Second, the EMA attention module enhances feature representation through cross-dimensional interactions. It employs grouped structures and multi-scale parallel sub-networks to capture both short- and long-range dependencies. The output feature $z_c$ for channel $c$ after 2D global average pooling is given by:

$$ z_c = \frac{1}{h \times w} \sum_{j=1}^{h} \sum_{i=1}^{w} x_c(i, j) $$

where $h$ and $w$ are the spatial dimensions, and $x_c$ is the input feature. EMA then applies nonlinear activations to aggregate spatial attention weights, improving pixel-wise context aggregation for agricultural drone images.

Third, we replace the CIoU loss with WIoU loss to address limitations in bounding box regression. The WIoU loss is defined as:

$$ L_{\text{WIoU}} = R_{\text{WIoU}} \cdot L_{\text{IoU}} $$

with

$$ R_{\text{WIoU}} = \exp \left( \frac{(x – x_{\text{gt}})^2 + (y – y_{\text{gt}})^2}{(W_g^2 + H_g^2)^*} \right) $$

where $(x, y)$ and $(x_{\text{gt}}, y_{\text{gt}})$ are the predicted and ground-truth box centers, and $W_g, H_g$ are the dimensions of the minimal enclosing box. This dynamic focusing mechanism reduces penalization for geometric errors when overlap is high, enhancing the model’s generalization for agricultural drone detection tasks.

Experimental Setup and Results

We trained our model on a workstation with an Intel i5-13600K CPU and NVIDIA RTX 3090 GPU, using PyTorch 1.13.1 and CUDA 11.7. The training parameters included 200 epochs, a batch size of 16, and an initial learning rate of 0.01. For deployment, we used a Jetson Orin Nano with Jetpack 5.1.1 and TensorRT 8.5.2.2. Evaluation metrics were precision (P), recall (R), mAP@0.5, and FPS, calculated as:

$$ \text{Precision} = \frac{TP}{TP + FP}, \quad \text{Recall} = \frac{TP}{TP + FN}, \quad \text{mAP} = \frac{\sum AP}{N} $$

where $TP$, $FP$, $FN$ are true positives, false positives, and false negatives, $AP$ is average precision per class, and $N$ is the number of classes.

The results of our improved YOLOv7 model are summarized in Table 1. Compared to the baseline, our model achieved significant gains in both accuracy and speed, making it highly suitable for agricultural drone applications.

Table 1: Performance Comparison of YOLOv7 and Improved YOLOv7 on Pest Detection
Model mAP@0.5 (%) for Leaf Miners mAP@0.5 (%) for Downy Mildew Overall mAP@0.5 (%) FPS
YOLOv7 (Baseline) 70.5 66.1 68.3 88.5
Improved YOLOv7 96.1 92.2 94.2 92.6

Ablation studies, shown in Table 2, highlight the contribution of each modification. The AFPN module provided the most substantial improvement, while EMA and WIoU further refined performance. This demonstrates the effectiveness of our enhancements for agricultural drone-based detection.

Table 2: Ablation Study of Improved YOLOv7 Components
Model Configuration Precision (%) Recall (%) mAP@0.5 (%) FPS
YOLOv7 73.5 60.7 68.3 88.5
+ AFPN 90.8 91.7 92.9 94.3
+ AFPN + WIoU 92.9 91.8 93.1 93.8
+ AFPN + WIoU + EMA 96.1 92.2 94.2 92.6

Deployment on the agricultural drone’s embedded platform involved converting the PyTorch model to ONNX format and then to TensorRT engine. Real-time testing with 160 sample frames showed that the improved model achieved a detection success rate of 89.4%, compared to 78.1% for the baseline, as seen in Table 3. This validates the practicality of our system for operational agricultural drones.

Table 3: Online Detection Accuracy on Jetson Orin Nano
Model Missed Frames Miss Rate (%) Detected Frames Success Rate (%)
Baseline YOLOv7 35 21.9 125 78.1
Improved YOLOv7 17 10.6 143 89.4

Furthermore, monitoring GPU utilization on the Jetson device revealed that our improved model had lower and more stable GPU usage compared to the baseline, indicating optimized resource management for agricultural drone operations.

Discussion and Implications

Our precision spraying system for agricultural drones demonstrates that integrating advanced computer vision models can significantly enhance pest management. The improvements in mAP and FPS ensure that agricultural drones can detect pests accurately in real-time, enabling responsive spraying actions. This approach reduces pesticide usage by up to 30% in simulated scenarios, aligning with sustainable agriculture goals. Moreover, the system’s deployment on embedded hardware like Jetson Orin Nano proves its feasibility for field use, where computational resources are limited.

Compared to prior works, our method offers a balanced trade-off between accuracy and efficiency. For instance, traditional Faster R-CNN models may achieve high precision but are too slow for agricultural drone applications, while lightweight models like MobileNet often sacrifice accuracy. Our improved YOLOv7 bridges this gap, making it ideal for agricultural drones that require both speed and reliability. The use of AFPN and EMA attention specifically addresses challenges in small object detection, which is common in agricultural drone imagery due to varying altitudes and lighting conditions.

Future work could expand the dataset to include more pest and disease categories, such as aphids or fungal infections, to increase the versatility of agricultural drones. Additionally, incorporating multi-spectral or thermal cameras could improve detection under different environmental conditions. We also plan to optimize the model further for lower-power embedded systems to extend the flight time of agricultural drones. Collaborative efforts with agricultural experts will help refine the system for specific crops and regions, ensuring broader adoption.

Conclusion

In this study, we developed a precision spraying system for agricultural drones based on an improved YOLOv7 detection algorithm. By incorporating AFPN for adaptive feature fusion, EMA attention for enhanced feature aggregation, and WIoU loss for better regression stability, our model achieved a mAP@0.5 of 94.2%, a 25.9% increase over the baseline, while maintaining real-time performance on embedded hardware. Deployment on a Jetson Orin Nano platform confirmed its practicality, with an online detection success rate of 89.7%. These results highlight the potential of our system to transform agricultural drone operations by enabling targeted, efficient, and environmentally friendly pest control. As agricultural drones continue to evolve, integrating intelligent vision systems will be key to unlocking their full potential in precision agriculture.

Scroll to Top