方向对齐惩罚(DAP):改进YOLOv8边界框回归的轻量化定位损失(原标题:Directional Alignment Penalty: A Lightweight Localization Loss for Improved Bounding Box Regression in YOLOv8)
针对农业场景提出改进YOLOv8定位损失的新方法,有具体实验支撑,但属于细分技术进展,影响范围有限。
精准农业视觉流水线下游任务(形态特征提取、生长监测、数字孪生同步)直接依赖检测框的几何质量,因此精确定位(而非单纯正确分类)成为关键性能因素。本研究提出方向对齐惩罚(DAP)作为辅助定位正则化项,在不修改检测器架构的情况下将独立加权的归一化中心位移项引入边界框回归目标。DAP-YOLOv8使[email protected]:0.95从51.69%提升至53.76%、[email protected]从80.03%提升至80.36%,在真实世界智能温室采集的牡蛎蘑菇数据集上重复种子实验进一步表明细粒度定位的提升在不同随机初始化下一致。
1. Introduction
Smart agriculture applications rely on computer-vision systems as the backbone for continuous visual monitoring, enabling tasks such as yield estimation, disease detection, autonomous harvesting, and environmental control. Object detection is rarely the final goal of these pipelines: the detected bounding boxes are an intermediate representation from which morphological descriptors (object size, count, maturity, and spatial distribution) are automatically derived and fused with other data streams. Thus, the quality of these descriptors is limited by the geometric accuracy of the detected boxes, and accurate localization (rather than just correct classification) becomes the key performance factor.
The YOLO family of single-stage detectors [1] is widely used in this area because it predicts object locations and class probabilities in a single forward pass, providing real-time inference with competitive accuracy. In particular, YOLOv8 [2] combines a decoupled detection head, a multi-scale feature aggregation neck and a hierarchical backbone, and has proven effective for continuous agricultural monitoring. The localization component of such detectors is driven by a bounding-box regression loss, and the design of this loss has a strong influence on both the convergence speed and the final localization quality.
Most modern regression losses are formulated based on the intersection-over-union (IoU) between the predicted boxes and ground-truth boxes. To improve gradient behavior, IoU-based variants such as GIoU [3], DIoU [4] and CIoU [4,5] add geometric constraints based on an enclosing area, a center-distance term or an aspect-ratio penalty. However, in DIoU and CIoU, the normalized center-distance term is integrated into a single objective function with an implicit weight of one (or, for the aspect-ratio term of CIoU, with an adaptive trade-off coefficient), so it cannot be tuned, scheduled or monitored independently of the overlap and aspect-ratio terms. This limitation is most pronounced in agricultural scenes, where objects usually have irregular contours, partial occlusion and dense spatial clustering, as exemplified by the detection of oyster mushroom clusters in a cultivation chamber. To this end, we propose a Directional Alignment Penalty (DAP), an additional lightweight regularization term that explicitly encourages the predicted boxes to move toward their corresponding ground-truth boxes. DAP is measured as the Euclidean distance between the predicted and ground-truth box centers, normalized by the diagonal of the smallest box encapsulating both. We show in Section 3.4 that this quantity is, up to a square root, exactly the center-distance factor already used inside DIoU and CIoU [4,5]. The contribution of DAP is to decouple that factor from the composite loss and re-express it as a separately weighted additive term whose effect on optimization can be tuned and logged independently of the base regression loss the detector already uses.
This work makes three contributions. We reformulate the normalized center-distance factor used in DIoU/CIoU [4,5] as an independently weighted additive regularization term that can be incorporated into existing localization losses without modifying the detector architecture. Second, we demonstrate a practical integration of the penalty into the YOLOv8 training and validation pipeline, including the separate logging of the penalty term for interpretability. Third, we evaluate the method on a dedicated oyster mushroom (Pleurotus ostreatus) dataset collected from a real-world smart greenhouse and demonstrate that stacking DAP on top of the existing CIoU-based box loss of YOLOv8 results in an additional measurable improvement in fine-grained localization, most notably a 2.07 percentage-point improvement in [email protected]:0.95, while preserving precision, recall, and the computational efficiency of the base detector.
The remainder of the paper is organized as follows. Section 2 reviews related work on single-stage detection and bounding-box regression losses. In Section 3, we describe the dataset, the YOLOv8 detector, the proposed DAP formulation, its formal relation to DIoU and CIoU, its integration into the detector, and the training protocol. The experimental results are presented in Section 4. The implications and limitations of the results are discussed in Section 5. Section 6 concludes the paper.
2. Related Work
2.1. Deep Learning-Based Object Detection
Deep learning has revolutionized object detection by replacing hand-engineered feature extraction with end-to-end trainable convolutional neural networks (CNNs). Modern object detectors are commonly classified into two-stage and one-stage architectures. Two-stage detectors such as Faster R-CNN first generate region proposals and then classify and refine them, resulting in high localization accuracy but at the cost of increased computational complexity [1]. In contrast, one-stage detectors perform object localization and classification in a single step, enabling substantially faster inference and making them suitable for real-time applications [2].
Among one-stage detectors, the YOLO (You Only Look Once) family of detectors has become one of the most influential object detection frameworks due to its excellent speed-accuracy trade-off. The original YOLO architecture [2] and its subsequent versions have continuously improved feature extraction, label assignment, multi-scale representation and localization accuracy. The most recent version, YOLOv8, is now one of the most popular object detectors in real-time computer vision applications [3], thanks to its anchor-free detection approach, decoupled detection heads, improved feature fusion, and optimized training processes. However, despite these architectural improvements, the overall detection performance of YOLOv8 continues to depend strongly on the effectiveness of its bounding-box regression loss.
2.2. IoU-Based Bounding Box Regression Losses
Bounding-box regression is critical to object detection because it directly determines localization accuracy. Early object detectors used coordinate-based regression losses (e.g., L1 loss and Smooth L1 loss), which considered each coordinate independently. These losses are computationally efficient but correlate weakly with the actual localization quality as measured by the Intersection over Union (IoU) metric. To overcome this limitation, Rezatofighi et al. proposed Generalized IoU (GIoU) [3], which extends the conventional IoU metric by accounting for the smallest enclosing box and can be optimized even when the predicted and ground-truth boxes do not overlap. Later, Zheng et al. proposed Distance IoU (DIoU) to speed up convergence and improve localization accuracy by adding the normalized Euclidean distance between the centers of bounding boxes [4]. The same authors further proposed Complete IoU (CIoU) [5] by incorporating aspect-ratio consistency, resulting in faster convergence and better localization performance than previous IoU-based losses.
Based on the success of DIoU and CIoU, many variants have been proposed to further improve bounding-box regression. Alpha-IoU [6] introduces a power transformation of the IoU term to enable tunable optimization of different localization accuracies and improve robustness against noisy annotations and small datasets. MPDIoU [7] replaces the classical center-distance constraint with the minimum point distances between the corresponding corners of the predicted and ground-truth boxes, which is simpler to compute and also considers the overlap, center displacement, and width-height difference [7]. Among these methods, DIoU and CIoU already include a normalized center-distance term, but this term is merged into a single composite objective with an implicit, fixed weight, so its contribution to optimization is not tunable, schedulable, or monitorable independently of the overlap and aspect-ratio components. Alpha-IoU and MPDIoU jointly reweight or restructure the geometric factors, but the center-alignment contribution is still entangled with the rest of the loss. This limitation is particularly relevant for small, densely distributed, or partially occluded objects, for which the relative weight assigned to center alignment during optimization can be as important as the geometric factor itself.
Motivated by this observation, we revisit the normalized center-distance term already present in DIoU and CIoU [4,5] and reformulate it as the Directional Alignment Penalty (DAP): an externally added, independently weighted, unsquared regularization component that penalizes the normalized displacement between predicted and ground-truth bounding-box centers. The contribution of DAP is not to introduce a new geometric localization signal but to decouple this factor from the composite DIoU/CIoU formulation. This decoupling allows its weight to be controlled, scheduled, and logged independently of the base regression loss while maintaining full compatibility with existing IoU-based regression losses.
2.3. Object Detection in Precision Agriculture
Precision agriculture has become one of the most promising application domains of artificial intelligence by enabling data-driven crop monitoring, disease diagnosis, yield estimation, and autonomous harvesting. The rapid development of computer vision and deep learning has significantly improved the ability of agricultural systems to detect, classify, and monitor agricultural products under real-world environmental conditions. Compared with traditional machine vision methods based on handcrafted features, deep learning-based object detectors provide greater robustness to variations in illumination, object scale, occlusion, and background complexity, making them highly suitable for agricultural applications [8,9].
Recent studies have demonstrated the successful application of deep learning-based object detection across numerous agricultural tasks, including fruit counting, crop growth monitoring, weed identification, disease detection, livestock monitoring, and greenhouse automation [10,11]. Among the available detection frameworks, the YOLO family has become particularly attractive because of its favorable trade-off between detection accuracy and computational efficiency. Consequently, various YOLO-based architectures have been adopted for detecting apples, tomatoes, strawberries, cucumbers, peppers, grapes, citrus fruits, wheat heads, rice panicles, and other agricultural products under challenging field conditions [12,13,14]. These applications require detectors capable of maintaining high localization accuracy despite illumination changes, cluttered backgrounds, overlapping objects, and varying viewing angles.
One of the most challenging agricultural detection problems is mushroom monitoring in greenhouse environments. Unlike many fruits that are relatively well separated, oyster mushrooms typically grow in dense clusters, exhibit irregular shapes, and frequently overlap at different growth stages. In addition, variations in illumination, shadows, and moisture, together with occlusion by neighboring mushrooms, further complicate accurate localization. These characteristics often reduce the effectiveness of conventional object detectors because even small localization errors may lead to inaccurate size estimation, incorrect maturity assessment, or missed detections during automated harvesting [15].
Several recent studies have explored the application of deep learning to mushroom detection and yield estimation. YOLO-based detectors have demonstrated promising performance in identifying mushroom caps, estimating maturity stages, and supporting automated harvesting systems. Researchers have also investigated improvements in feature extraction, attention mechanisms, data augmentation, and image preprocessing to increase detection accuracy under greenhouse conditions [16,17,18,19]. Despite these advances, relatively little attention has been devoted to improving the bounding-box regression objective, even though localization quality directly influences downstream measurements such as mushroom diameter estimation, growth analysis, and digital twin-based monitoring systems. Bounding-box localization is particularly important in mushroom cultivation because multiple mushrooms frequently appear in close proximity and have partially overlapping boundaries. Under these conditions, conventional IoU-based regression losses may produce predicted bounding boxes with similar overlap scores despite differing spatial alignments with the ground truth. Such localization inconsistencies can propagate to subsequent processing stages, affecting object tracking, phenotypic measurements, and yield estimation. Therefore, improving the regression objective rather than modifying the detector architecture offers a lightweight yet effective strategy for enhancing localization accuracy while preserving real-time performance.
Motivated by these difficulties, this work aims to enhance the localization capability of YOLOv8 by reinterpreting the normalized center-distance factor in DIoU/CIoU as the Directional Alignment Penalty (DAP), an additional, independently weighted, unsquared regularization term rather than a novel geometric localization signal. Instead of adding network modules or increasing model complexity, DAP augments the regression loss with this decoupled and independently weighted term. Since the proposed method is only active during training and does not modify the inference pipeline, it maintains the computational efficiency of YOLOv8 while delivering more accurate bounding-box localization, as shown by the observed gains in fine-grained localization (Section 4). This feature makes DAP particularly well-suited for precision agriculture applications where lightweight models deployable in real time on embedded platforms are highly desirable.
3. Materials and Methods
3.1. Dataset
The oyster mushroom (Pleurotus ostreatus) image dataset was specifically constructed in a real-world smart mushroom greenhouse equipped with an RGB camera system and IoT-based monitoring infrastructure [15]. Unlike many of the existing mushroom datasets collected under laboratory conditions or with sparse annotations, this dataset was designed to capture mushrooms in production environments, under variations in illumination, growth stage, object density, and environmental conditions. Images were acquired from two consecutive cultivation cycles in a greenhouse in Mersin, Türkiye, between late December 2022 and late April 2023 using two Full-HD (1920 × 1080) IP cameras. Images were taken during the day and at night to capture varied growth stages and lighting conditions. Each image was time-stamped to match environmental sensor readings.
During the two cultivation cycles described above, about 1200 raw greenhouse frames were collected. After frames with no visible mushrooms and images of poor visual quality were excluded, 555 representative full-frame images were retained for object-detection experiments. These images were then split into training and validation subsets containing 499 images and 56 images, respectively. Bounding-box annotations were generated for mushroom instances visible in these full-frame images using the open-source LabelMe [20] tool. Each bounding box was then refined to tightly enclose the mushroom while including minimal background. This procedure improved localization quality during supervised training. One annotation in the training set was excluded from the released label set because its class ID (2) did not match the declared two-class (immature/mature) configuration; this record was removed before training, rather than remapped, because the correct class could not be determined retrospectively.
A separate, substantially larger set of approximately 8282 maturity-labeled samples was also derived from the same underlying image collection by manually cropping individual mushrooms into separate images assigned to two maturity classes, immature (5124) and mature (3158), with a balanced distribution of day (~4000) and night (~3963) instances. These cropped samples support downstream maturity-related analyses (e.g., per-instance maturity classification) and should not be interpreted as the number of full-frame images used to train the YOLO detector reported in this paper; the YOLOv8 and DAP-YOLOv8 localization experiments in Section 4 used only the 555-image, full-frame detection dataset (499 training/56 validation) described above. Annotations for the full-frame detection dataset were exported in PASCAL VOC (XML), COCO (JSON), and YOLO Darknet (TXT) formats for compatibility with several detection frameworks.
3.2. YOLOv8 Detector
YOLOv8 [2] was adopted as the base detector because its single-pass design maintains high localization accuracy while greatly reducing computational cost, thereby meeting the real-time monitoring and digital-t