Unmanned aerial vehicle (UAV) remote sensing has become an increasingly important tool for forest resource monitoring. In this work, we present an improved YOLOv8n-based method for tree species recognition and counting from UAV optical images. We address the challenges of multi-scale crown variations, dense canopy occlusion, complex backgrounds, and subtle inter-species differences. Our approach introduces a Convolutional Multi-scale Enhancement Attention (CMEA) module in the backbone and a Dynamic Pooling Synergistic Attention (DPSA) module in the neck, together with a novel Multi-scale Discriminative Feature Loss (MDF-Loss). Experiments on a self-constructed UAV tree canopy dataset demonstrate that the improved model achieves 92.1% mAP@0.5, outperforming the baseline YOLOv8n by 4.1 percentage points. The counting accuracy is also significantly improved. Finally, we implement a browser-based tree species recognition and counting system to support operational forestry applications.
1 Introduction
Forests are among the most critical terrestrial ecosystems, playing an essential role in the global carbon cycle, biodiversity conservation, and regional ecological security. Accurate information on tree species composition and abundance is fundamental for forest resource management, carbon stock estimation, and ecosystem stability assessment. Traditional ground-based forest surveys rely on manual observation, which is labor-intensive, time-consuming, and sometimes impossible in complex terrains. While satellite remote sensing can cover large areas, its spatial resolution is often too coarse to identify individual tree crowns. In contrast, unmanned aerial vehicle (UAV) low-altitude remote sensing can provide centimeter-level optical imagery with high flexibility and low operational cost. Consequently, UAV-based optical image analysis has become a promising approach for individual tree detection and classification.
However, UAV optical images of forested areas present several unique challenges. First, tree crowns vary remarkably in size, ranging from small saplings to large mature trees. Standard convolutional neural networks with fixed kernel sizes have limited receptive fields and cannot simultaneously capture small-scale and large-scale features. Second, complex background elements—such as shadows, grass, and bare soil—can interfere with feature extraction, and the textural differences between certain tree species are often very subtle. Third, dense canopy overlap and mutual occlusion make it difficult to separate adjacent trees accurately. These issues often cause missed detections, misclassifications, and unstable counting in natural forest environments.
Recent advances in deep learning-based object detection, particularly the YOLO (You Only Look Once) family, have shown strong performance in various vision tasks. YOLOv8, with its lightweight backbone, anchor-free head, and decoupled classification/regression branches, offers an excellent balance between speed and accuracy. Nevertheless, the vanilla YOLOv8n still suffers from insufficient multi-scale representation and limited feature selection capability in complex forest scenes. To overcome these drawbacks, we propose an improved YOLOv8n model that integrates two novel modules: CMEA and DPSA. CMEA employs parallel multi-scale depthwise separable convolutions combined with channel and spatial attention to enhance the representation of crowns at different scales while suppressing background noise. DPSA uses dynamic pooling fusion and multi-scale dilated convolutions to improve context modeling and feature selection during the feature fusion stage. In addition, we design a composite loss function that incorporates a discriminative feature constraint and an attention smoothness regularization, further improving the model’s robustness and generalization.
The main contributions of this paper are as follows:
- We construct a high-quality UAV tree canopy dataset containing five common tree species, with rigorous quality control and data augmentation.
- We propose the CMEA module and the DPSA module to enhance multi-scale feature extraction and dynamic feature selection, respectively.
- We introduce MDF-Loss, which jointly optimizes classification, feature discriminability, and attention stability.
- We demonstrate that the improved model achieves superior detection and counting performance on UAV optical images, and we implement a practical recognition and counting system.
Throughout this paper, we repeatedly emphasize the role of the unmanned aerial vehicle (UAV) as the data acquisition platform. The entire study is oriented toward improving the usability of UAV-acquired imagery for forest management.
2 Related Work
2.1 Tree Species Recognition from Remote Sensing
Tree species recognition using remote sensing data has evolved significantly in recent years. Hyperspectral imaging captures continuous spectral signatures for each pixel. Some researchers selected feature bands, vegetation indices, or texture features and applied classical machine learning classifiers such as support vector machines (SVM) or random forests (RF). Although hyperspectral data can be useful, the high dimensionality, spectral overlapping among species, and high sensor costs limit its practical deployment. LiDAR provides three-dimensional structural information and can be combined with deep neural networks to improve classification. However, LiDAR systems are expensive and sensitive to weather conditions, and their point cloud density is often insufficient in dense forests.
Compared with these sensors, RGB optical imagery is cost-effective and rich in spatial details. UAV platforms equipped with consumer-grade RGB cameras can deliver images with centimeter-level resolution, enabling individual tree crown analysis. In recent years, convolutional neural network (CNN) based methods have become dominant for tree species classification from UAV RGB images. However, most studies only classify individual leaf or bark patches, which cannot handle real forest inventory where crowns overlap and background clutter is high. Therefore, the use of UAV-derived crown images with modern object detection networks is more practical.
2.2 Object Detection with Deep Learning
Object detection is a fundamental computer vision task that involves localizing and classifying objects. Traditional methods relied on hand-crafted features such as HOG or SIFT with sliding-window classifiers, which were computationally expensive and limited in representation power. The emergence of deep convolutional neural networks led to a paradigm shift. Two-stage detectors, exemplified by Faster R-CNN, first generate region proposals, then classify and refine the proposals. These methods achieve high accuracy but are often slow. One-stage detectors, such as SSD and the YOLO series, treat detection as a regression problem and predict class probabilities and bounding box coordinates directly from feature maps. YOLO family models are known for their speed and have been continuously improved through better architectures, data augmentation, and loss functions.
In forestry, YOLO-based detectors have been applied to tree detection, pest identification, and other tasks. Nonetheless, in forest scenes, large intra-class scale variation, occlusion, and background clutter require more sophisticated mechanisms than vanilla YOLO offers. This motivates our work to enhance YOLOv8n with multi-scale and attention mechanisms.
2.3 Multi-scale and Attention Mechanisms
Multi-scale feature representation is essential for detecting objects with large size variation. Feature pyramid networks (FPNs) integrate features from multiple resolutions, and dilated convolutions enlarge the receptive field without increasing parameters. Attention mechanisms have also been widely adopted to reweight features. Channel attention (e.g., SE, ECA) emphasizes informative channels, while spatial attention highlights important regions. Combining multi-scale convolutions and attention has proven effective in complex scenes. However, many existing designs are generic and do not fully address the challenges of dense and similar-looking tree crowns in UAV images. Therefore, we design the CMEA and DPSA modules specifically for this domain.
3 Methodology
3.1 Dataset Construction
We built a UAV tree canopy dataset over a forest farm in northeastern China. The area has a mixed coniferous and broadleaved forest stand, representative of the region’s vegetation. The dataset includes five tree species: pine (Pinus spp.), spruce (Picea spp.), poplar (Populus spp.), elm (Ulmus pumila L.), and ash (Fraxinus mandshurica Rupr.). These species are common in the region and exhibit both similar and distinct crown characteristics, providing a challenging but realistic benchmark.
We used a multi-rotor UAV equipped with a high-resolution RGB camera and a real-time kinematic (RTK) positioning system for centimeter-level accuracy. The flight campaign was conducted in June 2024, during the peak growing season, under clear weather conditions. The UAV flew at an altitude of approximately 80 meters, with 80% forward overlap and 75% side overlap to facilitate image mosaicking. To avoid shadow interference, photographs were taken between 14:00 and 17:00 local time. In total, we recorded video and subsequently extracted key frames at three frames per second using OpenCV. After removing blurred frames, we applied structural similarity (SSIM) clustering to eliminate near-duplicate images. Ultimately, we retained 3,256 high-quality images. To further enrich the dataset and improve generalization, we applied data augmentation techniques including horizontal flipping, brightness adjustment, random scaling, and Mosaic augmentation. The final dataset contains 6,200 images, with 60,244 annotated tree instances. The class distribution is balanced, as shown in Table 1.
| Species | Label Count | Percentage (%) |
|---|---|---|
| Pine | 12,651 | 21.0 |
| Spruce | 12,049 | 20.0 |
| Poplar | 12,049 | 20.0 |
| Elm | 11,748 | 19.5 |
| Ash | 11,747 | 19.5 |
| Total | 60,244 | 100 |
All images were annotated using the LabelImg tool, producing YOLO-format text files that encode category and bounding box coordinates. The annotations were cross-checked to ensure label consistency. We split the dataset into training, validation, and test subsets at a ratio of 8:1:1.

The figure above illustrates an example of a UAV optical image used in our study. Such imagery forms the basis for our experiments.
3.2 Baseline Model: YOLOv8n
YOLOv8n is a lightweight member of the YOLOv8 family, designed for real-time object detection on resource-constrained platforms. It consists of three main parts: a backbone for feature extraction, a neck for multi-scale feature fusion, and a decoupled head for classification and regression. The backbone employs the C2f module, which enhances gradient flow and feature reuse while reducing parameters. The neck combines a feature pyramid network (FPN) and a path aggregation network (PAN) to propagate semantic and spatial information across scales. YOLOv8n adopts an anchor-free detection scheme, simplifying the training pipeline and improving robustness to varied object shapes. The loss functions used in YOLOv8 include CIoU loss for bounding box regression and cross-entropy loss for classification.
Although YOLOv8n offers a strong baseline, its fixed effective receptive field and uniform feature weighting limit its performance in complex forest environments. To address this, we introduce the following improvements.
3.3 CMEA: Convolutional Multi-scale Enhancement Attention
The CMEA module is inserted into the backbone to enhance multi-scale feature representation. As shown in Figure 2, CMEA contains four parallel depthwise separable convolution branches with kernel sizes 3×3, 5×5, 7×7, and 9×9, respectively. These branches capture features with different receptive fields, allowing the network to model both fine textural details and larger crown structures simultaneously. The outputs of the branches are concatenated and fused by a 1×1 convolution. Then, a channel attention module and a spatial attention module are applied sequentially.
Let the input feature map be \( \mathbf{X} \in \mathbb{R}^{C \times H \times W} \). The multi-scale branch outputs are computed as
\[
\mathbf{X}_k = \mathrm{DWConv}(\mathbf{X}, k), \quad k \in \{3,5,7,9\}
\]
where \(\mathrm{DWConv}\) is a depthwise separable convolution. The fused feature is
\[
\mathbf{X}_{fused} = \mathrm{Conv}_{1\times1}\left( \bigoplus_{k} \mathbf{X}_k \right)
\]
where \(\bigoplus\) denotes channel-wise concatenation. The channel attention weights are computed via global average pooling and global max pooling followed by a shared MLP:
\[
\mathbf{F}_{ca} = \sigma\left(\mathrm{MLP}(\mathrm{AvgPool}(\mathbf{X}_{fused})) + \mathrm{MLP}(\mathrm{MaxPool}(\mathbf{X}_{fused}))\right)
\]
\[
\mathbf{X}_{ca} = \mathbf{F}_{ca} \odot \mathbf{X}_{fused}
\]
Spatial attention is then calculated by concatenating the average-pooled and max-pooled features along the channel dimension:
\[
\mathbf{F}_{sa} = \sigma\left( \mathrm{Conv}_{7\times7}\left( [\mathrm{AvgPool}(\mathbf{X}_{ca}); \mathrm{MaxPool}(\mathbf{X}_{ca})] \right) \right)
\]
\[
\mathbf{X}_{out} = \mathbf{F}_{sa} \odot \mathbf{X}_{ca}
\]
This module enables the backbone to emphasize important features at multiple scales while suppressing irrelevant background information.
3.4 DPSA: Dynamic Pooling Synergistic Attention
The DPSA module, applied in the neck, aims to improve context modeling and feature selection. Standard attention mechanisms often rely on a single pooling operation, which may not capture the full statistical distribution of the features. DPSA introduces a dynamic pooling strategy that combines average pooling, max pooling, and a learnable mixed pooling. The dynamic pooling weights are generated by a small convolutional layer:
\[
\alpha = \sigma(\mathrm{Conv}(\mathbf{X}))
\]
\[
\mathbf{P}_{mix} = \alpha \cdot \mathrm{AvgPool}(\mathbf{X}) + (1-\alpha) \cdot \mathrm{MaxPool}(\mathbf{X})
\]
The channel attention weights are then computed by summing the contributions from all three pooling statistics:
\[
\mathbf{F}_{ca} = \sigma\left( \mathrm{MLP}(\mathrm{AvgPool}(\mathbf{X}) + \mathrm{MaxPool}(\mathbf{X}) + \mathbf{P}_{mix}) \right)
\]
After channel weighting, a multi-scale dilated convolution (MSDC) block with dilation rates 1, 3, 5, and 7 is applied to enlarge the receptive field while preserving resolution. The dilated convolutions generate features at different context scales, which are concatenated and fused:
\[
\mathbf{X}_{dil} = \mathrm{Conv}_{1\times1}\left( \bigoplus_{r \in \{1,3,5,7\}} \mathrm{DilatedConv}(\mathbf{X}_{ca}, r) \right)
\]
Finally, a spatial attention module is applied to the dilated fusion output:
\[
\mathbf{F}_{sa} = \sigma\left( \mathrm{Conv}_{7\times7}\left( [\mathrm{AvgPool}(\mathbf{X}_{dil}); \mathrm{MaxPool}(\mathbf{X}_{dil})] \right) \right)
\]
\[
\mathbf{X}_{out} = \mathbf{F}_{sa} \odot \mathbf{X}_{dil}
\]
The DPSA module allows the neck to adaptively focus on informative regions and improves the model’s ability to distinguish dense and occluded tree crowns.
3.5 Overall Network Architecture
Our improved model, denoted as YOLOv8n-CMEA-DPSA, inserts CMEA after the second C2f block in the backbone and DPSA into the neck at the feature fusion stage. The overall architecture is shown in Figure 3. The CMEA module enriches the feature representation, while DPSA performs adaptive feature selection. Together, they form a “feature enhancement + adaptive selection” framework. The rest of the network remains the same as the original YOLOv8n, including the anchor-free decoupled head and the loss computation.
From a theoretical perspective, the CMEA module effectively increases the width of the receptive field distribution, enabling the network to approximate a richer family of functions. The attention operations reweight gradients during backpropagation, allowing important channels and spatial locations to receive larger updates. The DPSA module introduces a learnable statistical pooling strategy, increasing the expressiveness of the attention mechanism and helping the network adapt to varying input statistics.
3.6 Loss Function: MDF-Loss
To further improve the discriminative ability of the learned features, we design a composite loss function named MDF-Loss. The loss consists of three terms: a basic classification loss, a discriminative feature space constraint, and an attention stability regularization.
The classification loss is the standard cross-entropy loss. Given \(N\) training samples, with \(\hat{p}_{i,y_i}\) being the predicted probability for the true class \(y_i\), we have
\[
\mathcal{L}_{cls} = -\frac{1}{N}\sum_{i=1}^{N} \log(\hat{p}_{i,y_i})
\]
The discriminative feature constraint promotes intra-class compactness and inter-class separation in the feature space. Let \( \mathbf{h}_i \) be the feature vector of sample \(i\), and \( \mu_y \) the mean feature vector of class \(y\). The intra-class loss is
\[
\mathcal{L}_{intra} = \frac{1}{N}\sum_{i=1}^{N} \| \mathbf{h}_i – \mu_{y_i} \|^2
\]
The inter-class loss enforces a margin \(m\) between class centers:
\[
\mathcal{L}_{inter} = \sum_{a \neq b} \max(0, m – \| \mu_a – \mu_b \|)^2
\]
Thus, the discriminative loss is
\[
\mathcal{L}_{disc} = \mathcal{L}_{intra} + \beta \mathcal{L}_{inter}
\]
To avoid over-confidence of the attention mechanisms, we add a regularization on the attention weight matrices:
\[
\mathcal{L}_{att} = \| \mathbf{W}_c \|^2 + \| \mathbf{W}_s \|^2
\]
where \(\mathbf{W}_c\) and \(\mathbf{W}_s\) are channel and spatial attention weights, respectively. The final MDF-Loss is
\[
\mathcal{L} = \mathcal{L}_{cls} + \lambda_1 \mathcal{L}_{disc} + \lambda_2 \mathcal{L}_{att}
\]
where \(\lambda_1\) and \(\lambda_2\) balance the contributions. In practice, we set \(\lambda_1=0.1\), \(\lambda_2=0.01\), and \(m=1\). This loss function jointly optimizes prediction accuracy, feature structure, and attention stability, leading to better generalization in complex forest environments.
4 Experiments and Results
4.1 Implementation Details
All experiments were conducted on a Windows 11 workstation equipped with an NVIDIA GeForce RTX 4060 Laptop GPU. The models were implemented in Python 3.10 with PyTorch. During training, the input images were resized to 640×640 pixels. The batch size was set to 4 due to GPU memory constraints. We used stochastic gradient descent (SGD) with an initial learning rate of 0.01 and trained for 200 epochs. The data augmentation strategies were kept identical for all models to ensure fair comparison.
We evaluate the models using Precision (P), Recall (R), mean Average Precision at IoU threshold 0.5 (mAP@0.5), and mAP@0.5:0.95. The formulas are
\[
P = \frac{TP}{TP+FP}
\]
\[
R = \frac{TP}{TP+FN}
\]
\[
AP = \int_0^1 P(R) \, dR
\]
\[
mAP = \frac{1}{C}\sum_{c=1}^{C} AP_c
\]
where \(C\) is the number of classes.
4.2 Comparison with Mainstream Detectors
We compared our improved model with Faster R-CNN, SSD, RT-DETR-R18, YOLOv5s, and YOLOv7-tiny. All models were trained on the same tree canopy dataset with the same training settings. Table 2 reports the detection performance.
| Model | Precision (%) | Recall (%) | mAP@0.5 (%) | mAP@0.5:0.95 (%) | Params (M) | FPS |
|---|---|---|---|---|---|---|
| Faster R-CNN | 79.34 | 76.82 | 82.15 | 55.73 | 41.2 | 42 |
| SSD | 81.27 | 78.94 | 84.63 | 57.48 | 23.5 | 91 |
| YOLOv5s | 84.11 | 82.37 | 86.75 | 59.64 | 7.2 | 154 |
| YOLOv7 | 85.43 | 83.28 | 87.42 | 60.91 | 6.1 | 168 |
| RT-DETR-R18 | 87.15 | 84.92 | 88.63 | 62.87 | 20.5 | 72 |
| YOLOv8n | 86.52 | 84.37 | 89.31 | 62.13 | 3.2 | 187 |
| Ours (YOLOv8n+CMEA+DPSA+MDF-Loss) | 91.42 | 89.26 | 92.10 | 66.84 | 3.8 | 160 |
From Table 2, our method achieves the highest precision, recall, and mAP among all models. Compared to the baseline YOLOv8n, the mAP@0.5 improves by 4.10 percentage points, and the precision increases by 4.90 percentage points. The parameter count increases by only 0.6 M, and the inference speed remains at 160 FPS, demonstrating a good trade-off between performance and efficiency. The two-stage detector Faster R-CNN shows the lowest mAP and speed, confirming that one-stage detectors are more suitable for UAV-based tree monitoring tasks.
4.3 Comparison with Other Attention and Multi-scale Blocks
We further compare our modules with several commonly used attention or multi-scale structures integrated at the same positions in the network. The models were trained under identical settings. Since the original paper’s metric values are given as percentages, we reproduce them in Table 3.
| Model | Precision (%) | Recall (%) | mAP@0.5 (%) | mAP@0.5:0.95 (%) |
|---|---|---|---|---|
| YOLOv8n | 86.52 | 84.37 | 89.31 | 62.13 |
| + SE | 87.01 | 85.21 | 89.05 | 63.12 |
| + CBAM | 87.38 | 85.67 | 89.43 | 63.75 |
| + ECA | 87.89 | 86.04 | 89.83 | 64.01 |
| + CA | 88.16 | 86.22 | 90.12 | 64.38 |
| + ASFF | 88.74 | 86.91 | 90.67 | 64.95 |
| + CMEA + DPSA | 91.42 | 89.26 | 91.73 | 66.84 |
As shown, vanilla attention modules such as SE, CBAM, ECA, and CA provide limited gains, with mAP improvements below 2 percentage points. ASFF makes a slightly larger improvement but still fails to match the combined CMEA+DPSA modules. This demonstrates that simply inserting generic attention modules is insufficient for the complex tree crown detection task. The proposed modules, designed specifically to handle multi-scale and dynamic feature selection, are more effective.
4.4 Efficacy of MDF-Loss
We also evaluated the performance of different loss functions on top of YOLOv8n. The results are summarized in Table 4.
| Loss | Precision (%) | Recall (%) | mAP@0.5 (%) |
|---|---|---|---|
| CIoU | 86.52 | 84.37 | 89.31 |
| DIoU | 87.31 | 85.42 | 89.16 |
| EIoU | 88.04 | 86.21 | 90.03 |
| Focal Loss | 88.67 | 86.74 | 90.42 |
| Varifocal Loss | 89.12 | 87.08 | 90.96 |
| MDF-Loss | 91.42 | 89.26 | 91.24 |
MDF-Loss yields the highest precision, recall, and mAP, confirming that the additional feature-space constraints help the model to separate hard classes. Consequently, our final model adopts MDF-Loss as the default objective.
4.5 Ablation Study
We performed a series of ablation experiments to isolate the contribution of each proposed component. The results are shown in Table 5.
| Configuration | Params (M) | FPS | mAP@0.5 (%) |
|---|---|---|---|
| YOLOv8n | 3.2 | 187 | 88.00 |
| + CMEA | 3.5 | 176 | 89.96 |
| + DPSA | 3.6 | 170 | 90.58 |
| + MDF-Loss | 3.2 | 185 | 91.24 |
| + CMEA + DPSA | 3.8 | 162 | 91.73 |
| + CMEA + DPSA + MDF-Loss | 3.8 | 160 | 92.10 |
Each module contributes positively to the final performance. The CMEA module improves mAP by 1.96 percentage points, and the DPSA module improves it by 2.58 percentage points. The MDF-Loss alone adds 3.24 percentage points while leaving the parameter count unchanged. When all components are combined, the model reaches the best mAP of 92.10% with a negligible drop in FPS, still maintaining real-time inference capability.
4.6 Counting Accuracy
Besides detection accuracy, we also evaluate the counting performance. The number of detected bounding boxes is used as the estimated tree count. We selected several image samples from the test set and compared the predicted counts with the ground truth. Table 6 reports the results for sparse and dense scenes.
| Test ID | Scene Type | Class | Ground Truth | Original YOLOv8n Count | Improved Count | Absolute Error |
|---|---|---|---|---|---|---|
| T1 | Sparse | Pine | 2 | 2 | 2 | 0 |
| T1 | Sparse | Elm | 2 | 2 | 2 | 0 |
| T2 | Sparse | Pine | 4 | 4 | 4 | 0 |
| T3 | Sparse | Poplar | 2 | 2 | 2 | 0 |
| T3 | Sparse | Ash | 3 | 2 | 3 | 1 |
| T4 | Sparse | Elm | 11 | 9 | 11 | 2 |
| T5 | Sparse | Spruce | 6 | 5 | 6 | 0 |
| T5 | Sparse | Ash | 7 | 6 | 6 | 1 |
| T6 | Sparse | Poplar | 7 | 5 | 6 | 1 |
| T6 | Sparse | Elm | 7 | 6 | 7 | 0 |
In sparse scenes, the improved model yields almost perfect counts. In denser scenes, where crowns overlap and background clutter is high, small errors may still occur but are significantly smaller compared to the baseline. To provide a broader comparison, we also computed counting statistics on several large patches containing multiple species, as presented in Table 7.
| Sample | Species | Ground Truth | Original Count | Improved Count | Absolute Error |
|---|---|---|---|---|---|
| S1 | Elm | 65 | 58 | 63 | 2 |
| Pine | 29 | 23 | 26 | 3 | |
| Ash | 13 | 10 | 11 | 2 | |
| S2 | Poplar | 32 | 28 | 30 | 2 |
| Ash | 51 | 46 | 47 | 4 | |
| Pine | 26 | 20 | 24 | 2 | |
| S3 | Pine | 10 | 7 | 8 | 2 |
| Ash | 58 | 50 | 54 | 4 | |
| Spruce | 40 | 33 | 38 | 2 | |
| S4 | Spruce | 48 | 40 | 43 | 5 |
| Poplar | 34 | 29 | 31 | 3 | |
| Ash | 24 | 20 | 21 | 3 | |
| S5 | Elm | 35 | 30 | 32 | 3 |
| Poplar | 35 | 28 | 31 | 4 | |
| Ash | 45 | 37 | 40 | 5 |
From the quantitative comparison, the improved model reduces the mean absolute error (MAE) from 1.42 to 0.97 and the root mean square error (RMSE) from 2.03 to 1.48 across the selected test images. The error reduction is particularly noticeable in images with dense canopy and overlapping crowns, confirming that the improved feature representation aids both detection and counting.
5 System Implementation
To bridge the gap between algorithmic research and practical deployment, we developed a tree species recognition and counting system based on the improved YOLOv8n model. The system follows a browser/server (B/S) architecture, allowing users to access the service through a web browser without installing dedicated software.
5.1 System Requirements
The system needs to support multiple tasks: user authentication, model management, image detection, result visualization, and log management. Ordinary users can upload images and view detection results. Administrators have additional privileges to manage model versions, set training parameters, and inspect the system logs. The system should respond quickly: typical UI actions should complete within 1 second, and inference for a single image should not exceed 5 seconds. The server should handle at least 100 concurrent requests with GPU utilization below 80%.
5.2 System Architecture
The overall architecture consists of five layers: the environment layer (hardware and OS), the data layer (MySQL database), the algorithm layer (the improved detection model), the business logic layer (user management, detection service, model management, and logging), and the presentation layer (web UI). The system is developed using the Django web framework with Python. The backend interfaces with the PyTorch-based model for inference. The frontend is rendered as HTML pages that allow image upload and result display.
Our system also supports model version control. When a new model is trained, the system saves the weights and makes it available for inference. Administrators can switch between different versions. The logging module records all user operations, detection timestamps, and system events for future audits and troubleshooting.
5.3 System Testing
We tested the system end-to-end. The administrator login page is shown in Figure 4. After login, users land on the main page, which provides navigation for the different modules. During testing, all modules communicated correctly, and the detection results were displayed with bounding boxes and class labels. The inference time for a standard test image was within the acceptable range. The system remained stable under concurrent requests. Thus, the platform demonstrates readiness for practical use in forestry monitoring.
6 Conclusion and Future Work
In this paper, we presented an improved YOLOv8n model for tree species recognition and counting from unmanned aerial vehicle (UAV) optical images. We addressed the challenges of multi-scale variations, dense canopy overlap, and complex background interference by introducing two novel attention modules (CMEA and DPSA) and a composite loss function (MDF-Loss). The CMEA module enhances multi-scale feature representation through parallel depthwise convolutions and dual attention. The DPSA module improves feature selection via dynamic pooling and multi-scale dilated convolutions. The MDF-Loss jointly optimizes classification, feature discriminability, and attention stability.
Extensive experiments on a UAV tree canopy dataset with five tree species showed that the improved model achieves 92.1% mAP@0.5, a 4.1 percentage point improvement over the baseline YOLOv8n. The model also maintains high speed (160 FPS), making it suitable for real-time applications. In counting tasks, the improved model significantly reduces counting errors, especially in dense forest scenes. Furthermore, we implemented a practical tree species recognition and counting system using the improved model, demonstrating its feasibility for forest resource surveys.
Future work will explore the integration of hyperspectral and LiDAR data with RGB imagery to further improve species discrimination. We also plan to combine model pruning and knowledge distillation to enable on-board inference on UAV platforms. Additionally, we will extend the system to support multi-temporal imagery for dynamic monitoring of tree growth and forest health.
Overall, our work demonstrates the strong potential of unmanned aerial vehicle imagery combined with advanced deep learning techniques for accurate and efficient forest monitoring. As UAV technology continues to advance, we expect the proposed methods to contribute meaningfully to automated and intelligent forestry management.
