论文信息
论文摘要
Accurate wheat spike detection and counting are fundamental for automated phenotyping, yield estimation, and precision agriculture. However, the deployment of deep learning-based agricultural vision models remains challenging due to substantial domain shifts caused by geographic variations, crop diversity, growth stages, illumination changes, and heterogeneous imaging platforms. Existing detectors often achieve high performance under predefined datasets but experience considerable performance degradation when transferred to unseen agricultural environments, limiting their reliability in real-world applications. To address this challenge, this study proposes WheatTrust-DG, a foundation model-enhanced cross-domain perception framework for reliable wheat spike detection and counting. The proposed framework adopts YOLO11s as a lightweight detection backbone and introduces collaborative knowledge transfer from a general visual foundation model (DINOv2) and a wheat-specific foundation model (FoMo4Wheat). An adaptive general–specific knowledge fusion strategy is developed to integrate complementary semantic representations, enabling the detector to learn more transferable wheat-related features. Furthermore, a Structure-aware Counterfactual Domain Randomization strategy is designed to preserve wheat morphological invariance while perturbing environmental appearance factors, thereby reducing the model’s dependence on background and acquisition-specific appearance variations. Extensive experiments on GWHD2021 demonstrate that WheatTrust-DG achieves robust cross-domain wheat perception. Compared with YOLO11s, the proposed framework reduces counting MAE from 8.74 ± 0.42 to 5.42 ± 0.28 and decreases counting error from 8.9% to 5.0%, demonstrating improved robustness under unseen agricultural environments. The proposed framework provides a promising solution for developing robust, reliable, and deployable intelligent agricultural sensing systems.
全文
SensorsAcademic Editors: Rui Kang and
Wonsuk (Daniel) Lee
Received: 24 September 2026
Revised: 23 November 2026
Accepted: 24 November 2026
Published: 26 November 2026
Copyright: © 2026 by the authors.
Licensee MDPI, Basel, Switzerland.
This article is an open access article
distributed under the terms and
conditions of the Creative Commons
Attribution (CC BY) license.
Article
WheatTrust-DG: A Foundation Model-Enhanced Domain
Generalization Framework for Trustworthy Wheat Spike
Detection and Counting in Unseen Agricultural Environments
Yu Sun, Yihang Qin *
, Haoran Sun, Wenhui Zhao and Wenhao Chen
School of Computer Science and Technology, Changchun University, Changchun 130022, China
- Correspondence: qinyha155@163.com
Abstract
Accurate wheat spike detection and counting are fundamental for automated phenotyping,
yield estimation, and precision agriculture. However, the deployment of deep learning-
based agricultural vision models remains challenging due to substantial domain shifts
caused by geographic variations, crop diversity, growth stages, illumination changes, and
heterogeneous imaging platforms. Existing detectors often achieve high performance under
predefined datasets but experience considerable performance degradation when transferred
to unseen agricultural environments, limiting their reliability in real-world applications. To
address this challenge, this study proposes WheatTrust-DG, a foundation model-enhanced
cross-domain perception framework for reliable wheat spike detection and counting. The
proposed framework adopts YOLO11s as a lightweight detection backbone and introduces
collaborative knowledge transfer from a general visual foundation model (DINOv2) and a
wheat-specific foundation model (FoMo4Wheat). An adaptive general–specific knowledge
fusion strategy is developed to integrate complementary semantic representations, enabling
the detector to learn more transferable wheat-related features. Furthermore, a Structure-
aware Counterfactual Domain Randomization strategy is designed to preserve wheat mor-
phological invariance while perturbing environmental appearance factors, thereby reducing
the model’s dependence on background and acquisition-specific appearance variations.
Extensive experiments on GWHD2021 demonstrate that WheatTrust-DG achieves robust
cross-domain wheat perception. Compared with YOLO11s, the proposed framework re-
duces counting MAE from 8.74 ± 0.42 to 5.42 ± 0.28 and decreases counting error from
8.9% to 5.0%, demonstrating improved robustness under unseen agricultural environments.
The proposed framework provides a promising solution for developing robust, reliable,
and deployable intelligent agricultural sensing systems.
Keywords: wheat spike detection; YOLO11; domain generalization; cross-domain object
detection; trustworthy artificial intelligence
- Introduction
Wheat is one of the most important food crops worldwide, and its yield assessment
and phenotypic monitoring are of great significance for precision agriculture management,
breeding selection, and food security [1]. With the development of agricultural digitaliza-
tion and intelligent sensing technologies, computer vision-based wheat spike detection has
gradually become an important technical pathway for automated phenotypic analysis [2].
Compared with traditional manual survey methods, RGB-based visual perception meth-
ods offer advantages such as low cost, flexible deployment, and suitability for large-scale
Sensors 2026, 26, 7491 https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 2 of 54
field environmental monitoring [3], providing key data support for wheat spike counting,
growth status analysis, and yield prediction. In recent years, advances in deep learning,
especially object detection networks, have significantly promoted progress in agricultural
visual perception, enabling models to automatically learn the morphological and spatial
features of wheat spikes from complex field images [4]. However, real agricultural en-
vironments are highly complex: differences in regions, varieties, growth stages, lighting
conditions, and acquisition devices can lead to significant data distribution shifts, making
high-accuracy models obtained in laboratory settings difficult to transfer directly to unseen
field scenarios [5]. Therefore, how to construct wheat intelligent perception models with
cross-environment adaptability and reliable predictive capability has become an important
issue urgently needing to be addressed in agricultural computer vision.
These practical challenges are illustrated in Figure 1. In real field images, wheat spikes
are often densely distributed and may overlap with neighboring spikes or be partially
occluded by leaves, making individual target localization difficult and potentially leading to
missed or duplicate detections and unreliable image-level counting. Meanwhile, variations
in geographic regions, wheat varieties, growth stages, illumination conditions, background
characteristics, and imaging platforms can substantially alter the visual appearance of
wheat spikes, resulting in significant domain shifts between training and deployment
environments. Therefore, the task addressed in this study is not limited to detecting
wheat spikes under familiar field conditions; rather, it requires robust spike localization
and accurate image-level counting in unseen agricultural environments, together with an
assessment of uncertainty in the predicted total count.
Figure 1. Practical challenges in cross-domain wheat spike detection and counting. (A) RGB im-
ages acquired in real wheat field environments; (B) dense and partially occluded wheat spikes,
which increase localization difficulty and may lead to missed or duplicate detections; (C) visual
variations across agricultural domains caused by differences in canopy characteristics, illumination,
background conditions, and imaging platforms; and (D) the desired outputs of trustworthy wheat
perception, including wheat spike localization, image-level counting, and prediction intervals for the
total image-level count.
To address wheat spike perception in agricultural environments, early studies mainly
focused on improving detection accuracy under relatively stable data distributions [6].
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 3 of 54
Numerous deep learning-based methods have been developed and achieved remarkable
progress in wheat spike detection. Subsequently, object detection frameworks represented
by YOLO, Faster R-CNN, and Transformer-based detectors were gradually applied to agricul-
tural scenarios [7]. Among them, YOLO-family models have become mainstream methods
in field crop detection tasks because they combine relatively high detection accuracy with
real-time inference capability [8]. Existing studies usually enhance model performance by
improving network architectures, for example, introducing attention mechanisms to im-
prove feature representation in key regions [9], using multi-scale feature fusion to improve
small-object detection [10], and designing new loss functions to alleviate target-scale varia-
tion and class imbalance [11]. These methods have effectively improved detection accuracy
on public datasets and provided an important technical foundation for automated wheat
phenotypic analysis. However, most existing approaches are developed under predefined
data distributions and mainly optimize in-domain detection performance. Consequently,
their learned representations may contain environment-specific information, making them
vulnerable to performance degradation when transferred to unseen agricultural scenarios.
With increasing recognition of the limitations of in-domain detection models, recent
studies have shifted attention toward improving model transferability across different
agricultural environments [12]. In particular, recent advances in visual foundation models
enable models to learn more general visual representations from large-scale image data,
offering new technical possibilities for agricultural intelligent perception. However, existing
research still mainly centers on “improving average detection accuracy” and pays insufficient
attention to the domain shift problem prevalent in agricultural visual tasks. On the one
hand, most methods rely on supervised training on target datasets and tend to learn
incidental features related to the acquisition environment [13], such as background color,
soil texture, and imaging style, rather than the stable structural features of wheat spikes
themselves. On the other hand, existing methods often treat general visual knowledge and
agricultural domain knowledge in isolation, and have not fully explored how to leverage
complementary information between large-scale foundation models and agricultural expert
models to improve model generalization [14]. These limitations indicate that improving
detection accuracy alone is insufficient for practical agricultural deployment. A robust wheat
perception system should not only achieve accurate detection but also learn transferable
representations with reduced sensitivity to environmental variations and provide calibrated
uncertainty estimates under unseen conditions.
The core reason for the above problems is that existing agricultural visual models
still lack an effective cross-domain knowledge modeling mechanism. On the one hand,
traditional supervised learning methods rely heavily on task data scale and annotation
quality [15], making it difficult to obtain general visual representations that transcend the
limitations of training scenarios. On the other hand, agricultural targets exhibit pronounced
domain specificity, and relying solely on general visual models makes it difficult to fully
understand crop structure, growth stages, and domain-specific semantic information in
agricultural environments. In recent years, advances in visual foundation models have
provided new possibilities for addressing this issue [16]. Large-scale pretrained models
can learn more general representational capabilities from massive visual data, while agri-
cultural domain foundation models further provide specialized knowledge for specific
crops and agricultural scenarios. However, research on how to integrate general visual
knowledge with agricultural domain knowledge and effectively transfer it into lightweight
agricultural detection models remains limited. Moreover, wheat spike detection requires
not only accurate target localization but also reliable counting under dense occlusion and
complex backgrounds. Existing object detection methods usually rely on bounding box
predictions for counting and are susceptible to missed detections, duplicate detections,
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 4 of 54
and non-maximum suppression. More importantly, practical agricultural applications
care not only about what the model predicts but also about whether the prediction is
trustworthy [17]; however, existing studies usually report only accuracy metrics and lack
systematic analysis of model uncertainty and prediction reliability. Therefore, establishing
a novel agricultural intelligent perception framework that can integrate multi-source visual
knowledge, enhance cross-domain adaptability, and simultaneously provide trustworthy
predictions is of great significance for advancing agricultural artificial intelligence from
laboratory performance optimization to real-world applications.
Motivated by the above research gaps, this paper proposes WheatTrust-DG, a frame-
work for cross-domain wheat intelligent perception, namely a robust detection and trustwor-
thy counting method based on collaborative distillation of general and domain foundation
models and structure-aware domain generalization. The core hypothesis of this paper is
that if we can simultaneously leverage cross-scenario semantic representations provided
by general visual foundation models and crop-specific expertise provided by agricultural
domain foundation models, and use a structural constraint mechanism to guide the model
to focus on the stable features of wheat itself, then we can effectively reduce the model’s
sensitivity to variations in environmental factors and acquisition conditions, thereby im-
proving detection reliability in unseen agricultural domains. To validate this hypothesis,
this paper constructs a complete cross-domain agricultural visual perception system. First,
it introduces the DINOv2 general visual foundation model [18] and the FoMo4Wheat
wheat domain foundation model [19], and transfers complementary information to a YOLO
detector through a dynamic knowledge distillation strategy, achieving synergistic fusion
of general knowledge and agricultural knowledge. Second, it uses prior knowledge of
wheat organ structure to construct a Structure-aware Counterfactual Domain Randomiza-
tion method, which keeps wheat spike geometry unchanged while varying background,
illumination, and imaging style, thereby reducing the model’s dependence on non-essential
environmental features. In addition, this paper designs a joint Detection–Density learning
mechanism to improve wheat counting under dense occlusion, and further combines it
with a domain-aware conformal prediction method to quantify the uncertainty of predic-
tion results across different environments, realizing the transition from “high-precision
detection” to “trustworthy agricultural perception.”
In this study, predictive uncertainty is operationalized specifically as uncertainty in
the image-level wheat spike count. Accordingly, DACC produces a prediction interval
for the total number of wheat spikes in each image. It does not estimate uncertainty for
individual bounding-box coordinates or calibrate the detector’s classification confidence
scores. Therefore, the coverage analysis in this study evaluates whether the ground-truth
image-level count falls within the predicted count interval, rather than whether individual
wheat spike locations are covered by predicted bounding boxes.
The main contributions of this paper are threefold: (1) It proposes a collaborative
distillation framework of general and domain foundation models for cross-domain agri-
cultural visual perception, which effectively transfers general visual knowledge and wheat
domain knowledge to a lightweight detection network, improving the model’s general-
ization ability in unseen environments; (2) it introduces a training-stage, Structure-aware
Counterfactual Domain Randomization strategy that preserves wheat-organ regions while
perturbing environmental appearance. The structural prior is obtained exclusively from the
publicly released Global Wheat Full Semantic Organ Segmentation (GWFSS) annotations
and transferred to the GWHD2021 source images by a frozen SegFormer generator; no
additional pixel-level annotation was produced for this study, and neither the generator
nor the masks are required at inference. The provenance, annotation cost and supervision
asymmetry of this component, together with a budget-matched ablation that removes the
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 5 of 54
structural prior while holding the training schedule, augmentation budget and evaluation
protocol constant, are reported in Sections 4.2.5, 4.7.2 and 5.6. (3) It constructs a reliability-
oriented agricultural perception system integrating robust detection, reliable counting,
and uncertainty assessment. Instead of treating counting as an isolated prediction task,
the proposed framework improves counting reliability by jointly enhancing cross-domain
feature robustness and Detection–Density consistency.
2. Related Works
2.1. Deep Learning-Based Wheat Head Detection and Benchmark Datasets
David et al. proposed the Global Wheat Head Detection Dataset (GWHD), aiming
to address the problems of limited data scale, insufficient environmental coverage, and
inconsistent evaluation criteria in traditional wheat vision research. By integrating RGB
images of wheat fields from multiple countries and research institutions, this study con-
structed a public detection benchmark with high environmental diversity. GWHD2021
further expanded the data scale and sample diversity [20], including wheat images from
different geographical regions, varieties, growth stages, and acquisition platforms, thereby
providing a data foundation for evaluating deep learning models that is closer to real agri-
cultural environments. An important contribution of this work is that it advanced wheat
head detection from local experimental conditions toward global-scale evaluation, and for
the first time systematically demonstrated the pronounced data distribution shifts caused
by environmental differences in agricultural vision tasks.
However, GWHD2021 mainly exists as a data benchmark and evaluation platform
and does not address cross-domain generalization at the methodological level. Although
the dataset contains data from multiple countries and different acquisition conditions,
traditional detection models still need to rely on training data to learn target features; when
confronted with data from unseen regions, unknown varieties, or different sensors, model
performance may still degrade significantly. In addition, the dataset mainly uses detection
accuracy metrics such as mAP to evaluate model performance, whereas real agricultural
applications require not only accurate localization of wheat heads but also stable counting
capability and prediction reliability assessment. Therefore, GWHD reveals the domain
shift problem in agricultural vision, but how to learn cross-domain invariant features and
achieve trustworthy prediction remains unresolved.
2.2. Wheat Head Detection and Counting Networks
Khaki et al. proposed WheatNet for simultaneous wheat head detection and
counting [21]. The method adopts lightweight MobileNetV2 as the feature extraction
network and combines a multi-scale feature fusion strategy to enhance the representation of
wheat head targets of different sizes. Meanwhile, the model designs two parallel branches
to perform object localization and density estimation, respectively, thereby avoiding the
problem in traditional object detection methods of counting solely based on the number of
bounding boxes. Experimental results show that WheatNet can achieve good detection and
counting performance while maintaining a low parameter count, providing an effective
solution for high-throughput agricultural phenotyping.
Although WheatNet considers the relationship between detection and counting, its
primary goal remains improving detection efficiency under an existing data distribution and
does not fully account for cross-domain issues in real agricultural environments. The method
relies on convolutional networks to learn visual patterns from training data, so the model
may simultaneously learn wheat head structural features and environment-related features,
such as background texture, illumination patterns, and acquisition conditions. When
the test environment changes, these non-target-related features may lead to performance
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 6 of 54
degradation. In addition, although WheatNet introduces density estimation to improve
counting capability, it does not further analyze the uncertainty of model predictions and
cannot determine whether predictions are reliable in unknown environments. Therefore,
relying solely on joint detection–counting learning is still insufficient to meet the robustness
and trustworthiness requirements of practical agricultural intelligent perception.
2.3. General Domain Generalization Methods
Beyond agricultural-specific adaptation strategies, recent advances in domain gener-
alization have explored how models can learn domain-invariant representations without
accessing target-domain data during training. Representative approaches include feature
normalization-based methods, distribution alignment strategies, and optimization-based
generalization frameworks. For example, MixStyle introduces stochastic feature statistics
perturbation to simulate domain variations and improve robustness across unseen domains.
CORAL aligns second-order feature statistics between different source domains to reduce
distribution discrepancy. IRM aims to learn invariant predictors by enforcing consistency
of optimal classifiers across training environments. More recently, SW AD improves domain
generalization by seeking flatter minima during optimization, leading to better robustness
under distribution shifts.
Although these methods have achieved promising results in natural image recognition
and classification tasks, their application to agricultural object detection remains limited.
Object detection under field conditions introduces additional challenges, including object–
background entanglement, scale variation, dense occlusion, and acquisition-dependent
appearance changes. Therefore, directly applying generic DG strategies may not sufficiently
preserve object-level structural information. In contrast, this study incorporates wheat
morphological priors and foundation-model knowledge to construct a structure-aware
domain generalization framework specifically designed for agricultural detection.
2.4. Domain Adaptation and Generalization in Agricultural Vision
French et al. proposed an image style transfer-based domain adaptation method to
address environmental variation in wheat head detection [22]. This study uses generative
models to alter the visual style of training images, expands the training data distribution by
simulating different environmental conditions, and combines it with an object detection
model to improve detection capability across different scenarios. This method demonstrates
that artificially constructing visual variations can alleviate performance degradation caused
by differences in illumination, background, and imaging conditions in agricultural data,
providing a new research direction for domain adaptation in agricultural vision tasks.
However, such methods still have clear limitations. First, style transfer-based methods
mainly focus on low-level visual changes in images, such as color and texture changes,
whereas domain shifts in real agricultural environments usually include not only visual
style changes but also variety differences, growth stage changes, and complex background
semantic changes. Therefore, image augmentation alone cannot fully simulate real agricul-
tural environments. Second, this method belongs to the domain adaptation paradigm and
requires target domain data in advance, whereas practical agricultural applications often
face unknown regions and unknown environments, making it impossible to collect target
domain samples in advance. Therefore, such methods struggle to solve the true problem of
domain generalization, namely how a model can maintain stable performance in completely
unknown environments.
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 7 of 54
2.5. Crop-Specific Foundation Models
In recent years, foundation models in the agricultural domain have gradually attracted
attention. FoMo4Wheat proposed a domain foundation model for wheat vision tasks;
through self-supervised pretraining on large-scale global wheat image data, the model
can learn wheat-related morphological features [23], canopy structure, and patterns of
environmental variation. Compared with general visual models, this method pays more
attention to domain-specific semantic information in agricultural scenarios, providing a
new source of knowledge for wheat detection, segmentation, and phenotypic analysis
tasks. Such research demonstrates that domain-specific foundation models can effectively
compensate for the lack of agricultural knowledge in traditional general models, offering a
new direction for the development of agricultural artificial intelligence.
However, existing agricultural foundation models still have certain shortcomings.
First, FoMo4Wheat mainly focuses on domain representation learning, with the goal of
obtaining better agricultural visual features rather than solving cross-domain deployment
problems in specific detection systems. Second, agricultural foundation models are usually
large-scale, and direct application to practical agricultural devices still faces computational
resource constraints. In addition, whether a complementary relationship exists between
general visual models and agricultural domain models, and how to effectively integrate
the two types of knowledge into lightweight detection networks, still lacks systematic
research. Therefore, relying solely on a single agricultural foundation model still cannot
simultaneously meet the comprehensive requirements of agricultural intelligent perception
for generalization ability, computational efficiency, and trustworthiness.
2.6. Trustworthy AI and Uncertainty Estimation in Agricultural Sensing
As artificial intelligence models are gradually applied to practical agricultural pro-
duction, focusing only on model prediction accuracy can no longer meet the needs of
intelligent agricultural systems. Agricultural decision-making usually involves long-term
management, resource allocation, and risk control; therefore, models need not only to out-
put prediction results but also to provide an assessment of prediction reliability. In recent
years, Trustworthy AI and uncertainty quantification methods have gradually attracted
attention [24].
Traditional deep learning models usually represent prediction reliability through
softmax probabilities or detection confidence, but these indicators often fail to accurately
reflect the degree of uncertainty when models face unknown environments. Especially
in agricultural scenarios, when models face unseen regions, different sensing devices, or
abnormal weather conditions, their prediction confidence may be miscalibrated, meaning
the model may maintain high confidence in incorrect predictions. Therefore, relying solely
on detection accuracy to evaluate model performance has clear limitations.
In recent years, statistical learning methods such as Conformal Prediction have been
used to provide uncertainty estimates with theoretical guarantees, generating prediction
intervals through calibration data so that models can output more reliable results. However,
such methods are currently mainly applied in medicine, autonomous driving, and general
machine learning, and their application in agricultural visual perception remains limited.
In particular, in cross-domain agricultural environments, how to use domain information
to adjust uncertainty estimation so that prediction intervals can reflect the risks posed
by environmental changes still lacks systematic research. Therefore, future agricultural
intelligent perception systems need to move beyond the mere pursuit of detection accuracy
and further develop into comprehensive intelligent systems that simultaneously possess
detection capability, cross-domain generalization ability, and prediction trustworthiness
assessment capability.
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 8 of 54
3. Methodology
3.1. Overview of WheatTrust-DG Framework
WheatTrust-DG is designed as a training-stage knowledge enhancement framework
for cross-domain wheat spike perception. The framework aims to transfer general vi-
sual knowledge, agricultural domain-specific knowledge [25], structural invariance con-
straints, counting consistency information, and uncertainty awareness into a lightweight
YOLO11 detector.
Unlike conventional wheat spike detectors that mainly optimize in-domain detection
accuracy, WheatTrust-DG is specifically designed to address the fundamental challenges
of cross-domain agricultural perception. Existing detection methods usually rely on task-
specific annotations and learn representations strongly coupled with training environments,
resulting in degraded performance under unseen geographic regions, imaging conditions,
and crop variations. Although existing domain generalization methods improve robustness
by perturbing feature distributions or aligning domains, they generally lack agricultural
structural priors and do not explicitly consider the reliability of prediction results.
To overcome these limitations, WheatTrust-DG introduces a collaborative framework
from three complementary perspectives. First, the General–Specific Foundation Distillation
(GSFD) module transfers both general visual knowledge and wheat-specific domain knowl-
edge, enabling the detector to learn more transferable representations than conventional
single-source supervision. Second, the Structure-aware Counterfactual Domain Random-
ization (SCDR) and Foundation-Guided Hard Domain Curriculum Learning (FHDC)
modules explicitly model domain shifts while preserving wheat morphological invari-
ance, which differs from conventional augmentation-based strategies that mainly modify
image appearance. Third, the Detection–Density–Counting Consistency (DDCC) and
Domain-Aware Conformal Calibration (DACC) modules extend the framework beyond
accuracy-oriented detection by improving counting robustness and prediction reliability.
Therefore, WheatTrust-DG establishes a unified perception framework that simultaneously
considers cross-domain robustness, counting consistency, and uncertainty estimation under
unseen agricultural environments.
As illustrated conceptually, WheatTrust-DG consists of five interconnected components:
General–Specific Foundation Distillation (GSFD), Structure-aware Counterfactual Domain
Randomization (SCDR), Foundation-Guided Hard Domain Curriculum Learning (FHDC),
Detection–Density–Counting Consistency (DDCC), and Domain-Aware Conformal Cali-
bration (DACC).
During training, these modules jointly optimize the student detector. During inference,
only the YOLO11 detector and the density branch are retained, while foundation models
and auxiliary modules are removed to ensure practical deployment efficiency.
3.2. YOLO11-Based Student Detector
The proposed method adopts YOLO11 as the student network because of its favorable
balance between accuracy and computational efficiency.
Given an input RGB wheat image:
𝑋 ∈ 𝑅𝐻×𝑊×3
The detector extracts hierarchical feature representations:
𝐹𝑠 = 𝐹2, 𝐹3, 𝐹4, 𝐹5
where different feature levels represent different spatial resolutions.
The original detection loss is:
ℒ𝑏𝑜𝑥 + ℒ𝑐𝑙𝑠 + ℒ𝐷𝐹𝐿
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 9 of 54
where
ℒ𝑏𝑜𝑥 optimizes bounding box regression;
ℒ𝑐𝑙𝑠 optimizes wheat head classification;
ℒ𝐷𝐹𝐿 represents distribution focal loss for precise localization.
3.3. General–Specific Foundation Distillation (GSFD)
Different from traditional single-teacher distillation, WheatTrust-DG introduces two
complementary foundation models:
- DINOv2:
𝑇𝑔 = 𝐷𝐼𝑁𝑂𝑣2(𝑋)
which provides general visual knowledge, including: texture representation; object bound-
ary information; and general semantic structures. - FoMo4Wheat:
𝑇𝑤 = 𝐹𝑜𝑀𝑜4𝑊ℎ𝑒𝑎𝑡(𝑋)
which provides wheat-specific agricultural knowledge, including: wheat morphology;
canopy structure; and growth stage characteristics.
The student representation is obtained from YOLO11:
𝐹𝑠 = 𝑃(𝐹𝑌𝑂𝐿𝑂)
where 𝑃(⋅) is a lightweight projection layer mapping detector features into the foundation
feature space.
Instead of manually assigning fixed weights, we introduce an image-conditioned
adaptive teacher gate.
The fused teacher representation is:
𝑇𝑓 = 𝛼𝑇𝑔 + (1 − 𝛼)𝑇𝑤
where the fusion coefficient is dynamically predicted:
𝛼 = 𝜎(𝐺(𝑇𝑔, 𝑇𝑤, 𝐹𝑠))
where
𝐺(⋅) represents the adaptive gating network; 𝜎(⋅) is the sigmoid activation.
For images with severe domain shifts, the gate increases the contribution of DINOv2:
𝛼 → 1
while for normal wheat field images:
𝛼 → 0
allowing FoMo4Wheat to contribute more crop-specific knowledge.
3.4. Structure-Aware Counterfactual Domain Randomization (SCDR)
To reduce background shortcut learning, this study introduces wheat structural knowl-
edge as an auxiliary training prior. The structural prior is represented by a binary mask
that distinguishes wheat-organ regions from the surrounding background. Specifically,
the pixel-level labels for wheat heads, leaves, and stems in GWFSS are combined into a
wheat-organ foreground mask, while the background class is treated as the non-wheat
region. A SegFormer-based segmentation model is used to generate structural masks for
the GWHD2021 source-domain training images.
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 10 of 54
Given an original image and a style-transferred image, the structural mask is used to
preserve the wheat-organ regions while replacing the environmental appearance of the
background. This operation is designed to perturb domain-specific visual factors without
deliberately modifying the spatial locations of wheat spikes. The resulting counterfactual
samples retain the original wheat-spike bounding-box annotations and are used to optimize
the detector through the detection and feature-consistency objectives defined above.
The structural mask generator is used only during training. Its parameters are fixed
before detector optimization, are not updated by the detection objective, and the generated
masks are not required at inference. Two consequences of this design should be stated
explicitly. First, the design removes the need for masks at deployment but does not re-
move the upstream dependency on pixel-level organ annotations; the provenance of these
annotations and the associated annotation effort are quantified in Section 4.2.5. Second,
because the masks are precomputed offline for the 2758 source-domain training images, the
marginal cost during detector training reduces to reading precomputed masks. The training
schedule (200 epochs, batch size 16, fixed augmentation budget) is therefore identical with
and without the structural prior, which makes the ablation in Section 5.6 a like-for-like
comparison in terms of optimization budget.
3.5. Foundation-Guided Hard Domain Curriculum Learning
For each domain (d), foundation features are averaged:
1
𝑁𝑑
∑
𝑁𝑑
𝑖=1
𝑓 (𝑥𝑖)
where 𝑓 (⋅) is extracted from DINOv2/FoMo4Wheat.
The domain distance is calculated as:
1 −
𝑝𝑇𝑖 𝑝𝑗
∣∣𝑝𝑖∣∣∣∣𝑝𝑗∣∣
A larger value indicates stronger domain discrepancy.
Instead of randomly sampling all domains, training follows:
𝐸𝑎𝑠𝑦 → 𝑀𝑒𝑑𝑖𝑢𝑚 → 𝐻𝑎𝑟𝑑
The curriculum ratio at epoch (t) is:
𝑟𝑡 = 𝑡𝑇
where 𝑇 denotes total training epochs.
The selected domains satisfy:
𝐷(𝑑𝑖, 𝑑𝑗) < 𝜏𝑡
during early training.
As training proceeds:
𝜏𝑡 ↑
allowing more challenging domains.
The curriculum difficulty was divided according to domain discrepancy scores.
Specifically, domains were ranked according to cosine distance between foundation
feature centers.
The first 30% domains with lowest discrepancy were considered easy domains, the
middle 40% were regarded as moderate domains, and the highest 30% were treated as
hard domains.
During training, easy domains were introduced first. Moderate domains were gradu-
ally added after 40% of training epochs, while hard domains were fully activated after 70%
of training epochs.
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 11 of 54
3.6. Domain-Aware Conformal Calibration for Image-Level Wheat Spike Counting
The DDCC and DACC modules serve distinct and complementary purposes within
WheatTrust-DG. DDCC is a training-stage Detection–Density–Count consistency objec-
tive that couples density supervision with the consistency between density-derived and
detection-derived counts. Its potential influence on detection performance arises from
optimization of the shared model representation and must be established empirically under
a controlled evaluation protocol. In contrast, DACC is a post hoc conformal calibration
procedure applied to the frozen image-level count predictions. It constructs prediction
intervals for the total number of wheat spikes without modifying the detector parameters,
bounding-box coordinates, classification confidence scores, or non-maximum suppression
(NMS) outputs. DACC therefore does not calibrate per-box classification confidence or local-
ization uncertainty, and its contribution should be assessed using count-interval coverage,
interval width, and coverage error rather than changes in detection metrics.
For an image 𝑥𝑖, let 𝑁𝑖 denote the ground-truth number of wheat spikes obtained from
the annotations, and let 𝑁(𝑥𝑖) denote the final scalar count prediction produced by the
trained DDCC-enhanced model. The same count output is used for the counting-error
evaluation reported elsewhere in this study. The objective of DACC is to construct an
interval 𝐶(𝑥𝑖) that quantifies uncertainty in 𝑁(𝑥𝑖).
To account for variation in visual appearance across agricultural environments, we
define a domain-discrepancy score using frozen DINOv2 image features. Let 𝑧(𝑥) denote
the image-level DINOv2 feature representation, and let μsrc denote the mean feature repre-
sentation computed exclusively from images in the source training domains D01–D07. The
feature distance is defined as
𝑟(𝑥) = ∣∣𝑧(𝑥) − 𝜇𝑠𝑟𝑐∣∣2.
Let 𝑟min and 𝑟max denote the minimum and maximum reference distances calculated
using only the source training data. The normalized domain-discrepancy score is
𝑑(𝑥) = 𝑐𝑙𝑖𝑝(𝑟(𝑥) − 𝑟min
𝑟max − 𝑟min
, 0, 1)
where clip(·, 0, 1) restricts the value to the interval [0, 1]. These reference statistics are fixed
before the calibration and test stages and are not estimated from the unseen test domains.
We define an input-dependent uncertainty scale as
𝑔(𝑥) = 1 + 𝜆𝑑(𝑥)
where 𝜆 = 0.5 is the prespecified domain-discrepancy coefficient. A larger discrepancy
score therefore permits a wider prediction interval. The coefficient must remain fixed during
the final evaluation and must not be selected using the labels of D10–D16.
The calibration set consists exclusively of the held-out calibration domains D08 and
D09. After the detector and the feature-reference statistics have been frozen, the normalized
nonconformity score for each calibration image is calculated as
𝑠𝑖 =
∣𝑁𝑖 − ̂𝑁(𝑥𝑖)∣
𝑔(𝑥𝑖)
Let 𝑛cal denote the number of calibration images, and let 𝑠(1),… , 𝑠(𝑛cal) denote the calibra-
tion scores sorted in ascending order. For a nominal miscoverage level 𝛼, the finite-sample
conformal quantile is determined by
𝑘= ⌈(𝑛cal + 1)(1 − 𝛼)⌉
̂𝑞=
⎧{
⎨{⎩
𝑠(𝑘), 𝑘 ≤ 𝑛cal,
+∞, 𝑘 > 𝑛cal.
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 12 of 54
where the order statistic is taken using the standard split-conformal finite-sample correc-
tion; if 𝑘 exceeds 𝑛cal, the quantile is set to infinity. The primary analysis uses α = 0.05,
corresponding to a nominal coverage level of 95%.
For a new image x, the count prediction interval is constructed as
𝐶(𝑥) = [max(0, ⌊ ̂𝑁(𝑥) − ̂𝑞𝑔(𝑥)⌋), ⌈ ̂𝑁(𝑥) + ̂𝑞𝑔(𝑥)⌉]
The lower and upper bounds are rounded outward to non-negative integer counts.
This interval represents uncertainty in the total number of wheat spikes in an image; it is
not a confidence interval for individual bounding boxes or classification probabilities.
The calibration and evaluation protocol is strictly separated by domain. The detector
is trained using D01–D07, the calibration scores and conformal quantile are obtained from
D08 and D09, and the resulting interval predictor is evaluated on the unseen test domains
D10–D16. Neither test images nor their annotations are used to estimate the source-domain
feature statistics, select 𝜆, estimate the conformal quantile, tune model parameters, select
checkpoints, or make other model-selection decisions. At inference, the feature represen-
tation of each individual test image is used only to compute its discrepancy score using
the frozen reference statistics. The ground-truth count is accessed only after the prediction
interval has been generated, for final metric calculation.
We evaluate count-interval reliability using the prediction interval coverage probability
(PICP), the mean prediction interval width (MPIW), and the absolute coverage deviation.
For a test domain 𝐷𝑑 containing 𝑛𝑑 images, these quantities are defined as
𝑃𝐼𝐶𝑃𝑑 = 1𝑛𝑑 ∑𝑛𝑑𝑖=1 I(𝑁𝑖 ∈ 𝐶(𝑥𝑖))
𝑀𝑃𝐼𝑊𝑑 = 1𝑛𝑑 ∑𝑛𝑑𝑖=1[𝑈(𝑥𝑖) − 𝐿(𝑥𝑖)]
𝐶𝐸𝑑 = 100∣𝑃𝐼𝐶𝑃𝑑 − (1 − 𝛼)∣
where 𝐿(𝑥𝑖) and 𝑈(𝑥𝑖) denote the lower and upper bounds of 𝐶(𝑥𝑖), respectively, and I(·)
is the indicator function. PICP is the proportion of images whose ground-truth total count
lies within the predicted interval. MPIW measures the average interval width in wheat-
spike counts, while CE measures the absolute deviation from the nominal coverage level in
percentage points.
Under the exchangeability assumption required by split conformal prediction, this
procedure targets marginal coverage of 1 − 𝛼. However, the unseen test domains in this
study are deliberately selected to represent distribution shifts relative to the calibration
domains. Exact finite-sample coverage is therefore not guaranteed under arbitrary domain
shift. Accordingly, PICP on D10–D16 is interpreted as empirical out-of-domain coverage,
and the reported results are used to assess the practical reliability and efficiency of count
prediction intervals rather than to claim a distribution-free guarantee for every unseen
agricultural environment.
3.7. Summary of Optimization Procedure
During training, all modules jointly optimize:
ℒ𝑑𝑒𝑡 + 𝜆1ℒ𝐺𝑆𝐹𝐷 + 𝜆2ℒ𝑆𝐶𝐷𝑅 + 𝜆3 ℒ𝐷𝐺 + 𝜆4ℒ𝑑𝑒𝑛𝑠𝑖𝑡𝑦 + 𝜆5ℒ𝑐𝑜𝑢𝑛𝑡
During inference, only the YOLO11 student detector and density branch are retained.
Both foundation teachers and the structural prior generator are removed, ensuring that the
deployed model requires only RGB images and standard detection outputs.
Therefore, WheatTrust-DG achieves a balance between: cross-domain robustness;
accurate wheat localization; reliable counting; and uncertainty-aware agricultural sensing.
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 13 of 54
3.8. Training Procedure of WheatTrust-DG
To optimize the proposed WheatTrust-DG framework, we designed a multi-stage
training strategy that integrates foundation-model knowledge transfer, structure-aware
domain generalization, density-aware counting optimization, and uncertainty calibration.
Algorithm 1 summarizes the complete training process.
Before detector optimization, the parameters of the foundation models (including
DINOv2 and FoMo4Wheat) are frozen. Their image-level semantic representations are
extracted offline and stored for efficient training. At each iteration, the YOLO11 student net-
work learns detection-oriented representations under the joint supervision of the detection
objective, dual-teacher extraction, counterfactual domain consistency, domain curriculum
learning, and density counting constraints.
Algorithm 1: Training procedure of WheatTrust-DG
Input:
Training images X = {𝑥𝑖}
Bounding box annotations Y
Domain labels D
Frozen foundation models:
DINOv2 and FoMo4Wheat
Optional structural prior generator (SegFormer)
Training epochs T
Output:
Optimized YOLO11 student detector θs
1: Initialize YOLO11 student parameters θs
2: Extract foundation representations:
Tg = DINOv2(X)
Tw = FoMo4Wheat(X)
3: Generate wheat structural masks:
Mw = SegFormer(X)
4: for epoch = 1 to T do
5: Update domain curriculum schedule:
Calculate domain difficulty scores
Select training domains according to τepoch
6: for each mini-batch (x, y, d) do
7: // ---------- Student Feature Extraction ----------
8: Fs ← YOLO11(x; θs)
9: // ---------- General–Specific Foundation Distillation ----------
10: Obtain teacher features:
Tg, Tw
11: Compute adaptive teacher weight:
α = σ(G(Tg, Tw, Fs))
12: Fuse teacher knowledge:
Tf = αTg + (1 − α)Tw
13: Calculate GSFD loss:
[ℒGSFD = ℒcos(𝐹𝑠, 𝑇𝑓 ) + 𝛾ℒrel(𝐹𝑠, 𝑇𝑓 )]
14: // ---------- Structure-aware Counterfactual Augmentation ----------
15: Generate style-transferred background:
Xs = StyleTransfer(x)
16: Construct counterfactual sample:
Xcf =
Mw ⊙ x + (1 − Mw) ⊙ Xs
17: Forward counterfactual image:
Fcf = YOLO11(Xcf;θs)
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 14 of 54
Algorithm 1: Cont.
18: Calculate consistency loss:
ℒSCDR = ℒdet(𝑋𝑐𝑓 , 𝑌) + 𝜆‖𝐹𝑠 − 𝐹𝑐𝑓 ‖22
19: // ---------- Foundation-guided Domain Curriculum ----------
20: Compute domain loss:
ℒ𝑑 = ℒdet(𝑥𝑑, 𝑌𝑑)
21: Calculate domain weights:
wd =
exp(Ld/τ)
/
Σj exp(Lj/τ)
22: Obtain domain generalization loss:
ℒDG = ∑𝑑 𝑤𝑑ℒ𝑑
23: // ---------- Detection–Density–Counting Consistency ----------
24: Generate density prediction:
Dp = DensityHead(Fs)
25: Calculate density loss:
ℒdensity = ‖𝐷𝑝 − 𝐷𝑔‖22
26: Obtain detection count:
Ndet
27: Obtain density count:
Ndensity = ΣxDp(x)
28: Calculate counting consistency:
ℒcount = ∣𝑁density − 𝑁det∣
29: // ---------- Total Optimization Objective ----------
30: Compute total loss:
[ℒtotal = ℒdet + 𝜆1ℒGSFD + 𝜆2ℒSCDR + 𝜆3ℒDG + 𝜆4ℒdensity + 𝜆5ℒcount]
31: Update student parameters:
θs ← θs − η∇θsLtotal
32: end for
33: end for
34: Perform post hoc uncertainty calibration:
q = WeightedConformalCalibration()
35: Return trained YOLO11 detector θs
4. Materials and Methods
4.1. Research Overview and Problem Definition
In recent years, deep learning-based visual perception technology has become an
important technical means for intelligent agricultural phenotypic analysis. Among them,
wheat head detection, as a key step in estimating yield, analyzing growth status, and assist-
ing precision agricultural management, usually relies on object localization and instance
recognition in RGB images. However, most existing deep learning detection methods are
built on the independent and identically distributed (i.i.d.) assumption, i.e., the training
data and test data share similar data distributions [26]. In real agricultural application sce-
narios, due to significant differences in geographical regions, crop varieties, growth stages,
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 15 of 54
environmental conditions, and imaging devices, models are susceptible to distribution shift,
leading to degraded detection performance or even unreliable predictions.
Taking the Global Wheat Head Detection Dataset (GWHD2021) as an example, this
dataset contains RGB images of wheat fields from multiple countries and acquisition en-
vironments, and describes the visual differences caused by geographical regions, time,
sensor platforms, and environmental conditions through different acquisition domains [27].
Therefore, the core challenge faced by agricultural vision models is not merely to achieve
high detection accuracy within a known data distribution, but to maintain stable and reliable
perception capability in unknown environments.
Based on the above considerations, this paper redefines the wheat head visual per-
ception task as a cross-domain trustworthy perception problem rather than a pure object
detection optimization problem. Let the set of multi-source agricultural visual data domains
available during training be denoted as:
𝒟𝑡𝑟𝑎𝑖𝑛 = 𝐷1, 𝐷2, … , 𝐷𝐾
where 𝐷𝐾 represents the k-th known agricultural visual domain, and each domain contains
RGB images, object annotations, and corresponding domain feature information. Data
distribution differences may exist among different domains due to geographical location,
illumination conditions, sensor types, and crop state variations.
In the actual deployment process, the model needs to face new environments that did
not participate in training, and its test domain is denoted as:
𝒟𝑡𝑒𝑠𝑡 ∉ 𝒟𝑡𝑟𝑎𝑖𝑛
That is, the test data come from an unknown distribution, and the model cannot obtain
the data features of this domain in advance or make targeted adjustments. Therefore,
the research goal of this paper is to learn a visual perception function with cross-domain
generalization ability:
𝑓𝜃 → (𝐵, 𝑁, 𝑈)
where X represents the input RGB image of a wheat field, and 𝑓𝜃 represents a deep visual
model with parameters 𝜃; the output consists of three key parts:
𝐵 = 𝑏1, 𝑏2, … , 𝑏𝑀
represents the set of wheat head bounding boxes predicted by the model, where each bi
represents the position and scale information of a wheat head instance, used to achieve
precise object localization;
𝑁 = ̂𝑛
represents the number of wheat heads predicted by the model, i.e., the overall wheat head
counting result obtained through detection results and a density-aware mechanism, used
to support agricultural phenotypic statistical analysis;
𝑈 = ̂𝑢
represents the uncertainty estimate output by the model, used to measure the reliability of
the prediction results, so that the model can not only answer “how many wheat heads were
detected” but also further determine “whether the prediction result is trustworthy.”
Therefore, the research goal proposed in this paper can be formally described as:
min
𝜃
E𝐷𝑖 ∼ 𝒟𝑡𝑟𝑎𝑖𝑛
ℒ(𝑓𝜃(𝑋), 𝑌)
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 16 of 54
At the same time, the model is required to maintain stable performance on the unknown
target domain:
𝑓𝜃(𝑋𝑡𝑒𝑠𝑡), 𝑋𝑡𝑒𝑠𝑡 ∼ 𝒟𝑡𝑒𝑠𝑡
to achieve reliable detection, accurate counting, and reasonable uncertainty estimation.
Unlike traditional object detection methods that only focus on bounding box prediction,
the WheatTrust-DG framework constructed in this paper is centered on three core tasks:
𝐷𝑒𝑡𝑒𝑐𝑡𝑖𝑜𝑛 + 𝐶𝑜𝑢𝑛𝑡𝑖𝑛𝑔 + 𝑅𝑒𝑙𝑖𝑎𝑏𝑖𝑙𝑖𝑡𝑦
namely:
(1) Detection: cross-domain wheat head object detection. The model needs to learn
wheat head structural features that are irrelevant to environmental changes, reducing detec-
tion degradation caused by variations in background, illumination, and imaging devices.
(2) Counting: detection-driven trustworthy quantity estimation. To address missed
detections and duplicate detections caused by dense planting, occlusion, and overlapping
targets in the field, the model further integrates density estimation information to achieve
consistency constraints between detection results and the overall quantity.
(3) Reliability: uncertainty quantification for actual agricultural deployment. Unlike
traditional models that only output deterministic prediction results, this paper further intro-
duces an uncertainty estimation mechanism [28], enabling the model to identify potential
domain shift risks and provide reliability references for agricultural decision-making.
Based on the above problem definition, this paper proposes the WheatTrust-DG
(WheatTrust-Domain Generalization) framework, which integrates general visual founda-
tion models, agricultural domain foundation models, structural prior constraints, domain
generalization strategies, and trustworthy prediction mechanisms to achieve a transition
from “high-precision object detection” to a “robust and trustworthy agricultural visual
perception system.” The overall design goal of this framework is to improve the model’s
generalization ability and reliability when facing unknown agricultural environments while
maintaining lightweight inference capability.
4.2. Dataset and Cross-Domain Protocol
4.2.1. Global Wheat Head Detection Dataset
In this paper, the Global Wheat Head Detection Dataset (GWHD2021) is adopted as
the primary experimental dataset to validate the cross-domain generalization capability of
the proposed WheatTrust-DG framework in complex agricultural environments. Unlike
conventional object detection datasets, GWHD2021 is not designed merely to evaluate
model detection performance under a fixed data distribution; rather, it aims to simulate the
data distribution shift caused by variations in geographic location, crop type, environmental
conditions, and imaging devices in real agricultural applications.
GWHD2021 is composed of data from multiple research institutions worldwide, in-
cluding field RGB images acquired from different countries, wheat varieties, growth stages,
and acquisition platforms. Each image provides instance-level bounding box annotations
for wheat heads, which can be used for object detection tasks, while the included domain
information can be used for cross-domain generalization experimental design.
Although GWHD2021 contains approximately 6500 images and 275,000 wheat-head
instance annotations, the present study uses a predefined subset of 5698 images from
16 acquisition domains. Specifically, domains D01–D07 (2758 images) are used for detector
training, domains D08–D09 (815 images) are reserved exclusively for conformal calibration,
and domains D10–D16 (2125 images) are held out for final evaluation. The total number of
wheat-head instances in this selected subset is 254,410. The domain partition is fixed before
model fitting. The calibration domains are not used for detector optimization, checkpoint
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 17 of 54
selection, or hyperparameter tuning, and the unseen test domains are not used for training,
calibration, or model selection. This domain-disjoint protocol is designed to evaluate
generalization to agricultural environments that are unavailable during model development.
Therefore, unlike random splitting of training and test sets, GWHD2021 can more realisti-
cally reflect the model’s generalization ability when facing unknown agricultural environments.
The dataset statistics are as Table 1:
Table 1. Overview of the GWHD2021 dataset.
Dataset Number of Images Image Type Annotation Format Number of Wheat Head Instances Number of Domains Main Variation Factors
GWHD2021 6500 RGB field images Bounding box 275,000 47
Geographic region,
variety, growth
stage, illumination,
sensor platform
Although GWHD2021 provides a large-scale benchmark containing approximately
6500 images and 275,000 wheat head annotations, not all domains are used in the cross-
domain evaluation protocol of this study. To ensure a strict domain generalization setting
and avoid insufficient samples in extremely small domains, we select a subset of GWHD2021
containing 5698 images and 254,410 wheat head instances from 16 acquisition domains. The
remaining samples are excluded because their domain information does not satisfy the pre-
defined source–target partition criteria or contains limited samples for reliable evaluation.
The data distribution characteristics of GWHD2021 make it highly suitable as the
experimental foundation for the cross-domain trustworthy agricultural perception task in
this paper. Specifically, during the training stage, the model has access to multiple known
agricultural domains:
𝒟𝑡𝑟𝑎𝑖𝑛 = {𝐷 1, 𝐷2, … , 𝐷𝐾}
where each domain 𝐷𝑘 contains the corresponding wheat images:
𝐷𝑘 = (𝑥𝑖, 𝑦𝑖)𝑁𝑘𝑖=1
where xi denotes the input RGB image, and 𝑦𝑖 denotes the corresponding wheat head
detection label, including the object bounding box location and category information.
However, in actual agricultural deployment, the model usually needs to face new
data generated from uncollected regions or different sensor platforms; therefore, the test
data satisfy:
𝐷𝑡𝑒𝑠𝑡 ∉ 𝐷𝑡𝑟𝑎𝑖𝑛
That is, there is a pronounced distribution discrepancy between the test domain and
the training domains [29].
This setting provides a more challenging evaluation of whether the model can maintain
stable prediction performance under unseen environments, which indirectly reflects its
robustness to variations in backgrounds, colors, and imaging conditions.
4.2.2. Cross-Domain Generalization Protocol
To systematically evaluate the model’s generalization ability in unknown agricultural
environments, this paper adopts a domain generalization (DG) experimental protocol
rather than the conventional random data splitting approach.
Traditional object detection tasks usually adopt a random proportional split:
𝑇𝑟𝑎𝑖𝑛 ∶ 𝑉𝑎𝑙𝑖𝑑𝑎𝑡𝑖𝑜𝑛 ∶ 𝑇𝑒𝑠𝑡 = 8 ∶ 1 ∶ 1
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 18 of 54
This method implicitly assumes that the training set and test set satisfy the same
distribution assumption:
𝑃(𝑡𝑟𝑎𝑖𝑛)(𝑋, 𝑌) = 𝑃(𝑡𝑒𝑠𝑡)(𝑋, 𝑌)
However, in real agricultural scenarios, this assumption usually does not hold. Due
to visual distribution shifts caused by different regions, different devices, and different
climatic conditions:
𝑃(𝑡𝑟𝑎𝑖𝑛)(𝑋, 𝑌) ≠ 𝑃(𝑡𝑒𝑠𝑡)(𝑋, 𝑌)
Therefore, this paper strictly constructs the experimental protocol according to the
cross-domain testing principle, so that the test set contains agricultural environments unseen
during the training stage.
(1) Constructed Cross-Domain Evaluation Protocol
First, we construct a domain-level cross-domain evaluation protocol based on the
domain metadata provided by GWHD2021.
Training stage:
𝐷(𝑡𝑟𝑎𝑖𝑛) = 𝐷1, 𝐷2, … , 𝐷𝐾
Testing stage:
𝐷(𝑡𝑒𝑠𝑡) = 𝐷(𝐾 + 1), … , 𝐷𝑀
where the test domains are completely unseen during training.
This protocol mainly evaluates the model’s generalization ability when facing unknown
regions, and its core objective is:
𝑚𝑎𝑥𝑃(𝑌∣𝑋, 𝐷(𝑡𝑒𝑠𝑡))
That is, the model needs to leverage the structural features of wheat itself to make
predictions, rather than relying on background information from the training environments.
To ensure experimental reproducibility and avoid ambiguity in the cross-domain
evaluation protocol, the detailed domain partition of the adopted GWHD2021 cross-domain
split is explicitly reported in this section. Different from conventional random image-level
splitting, this protocol preserves the original acquisition-domain structure and assigns
complete domains exclusively to training, validation, or testing subsets.
Specifically, the proposed cross-domain split follows a domain-disjoint evaluation prin-
ciple, where source and target domains are separated according to the original GWHD2021
sub-dataset definitions. Each sub-dataset corresponds to an independent acquisition condi-
tion characterized by different experimental sites, imaging platforms, and environmental
factors. This design intentionally introduces geographic, environmental, and acquisition-
related distribution shifts between source and target domains, thereby assessing the capabil-
ity of models to learn domain-invariant wheat representations rather than dataset-specific
visual patterns.
The complete domain-level allocation is summarized in Table 2. For each subset, we
report the corresponding geographical domains, number of images, number of wheat-head
annotations, and acquisition characteristics. No image-level overlap or domain-level overlap
exists among the training, validation, and testing subsets.
To prevent information leakage, the domain partition was fixed before model fitting
and final evaluation. Domains D01–D07 were used for detector training and for estimating
the fixed source-domain DINOv2 feature-reference statistics. Domains D08 and D09 were
reserved exclusively for conformal calibration and were not used for detector optimization,
checkpoint selection, augmentation selection, or hyperparameter tuning. After the detector
and reference statistics had been frozen, only the ground-truth counts and predictions from
D08–D09 were used to calculate the calibration scores and conformal quantile.
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 19 of 54
Table 2. Detailed domain allocation of the constructed GWHD2021 cross-domain evaluation protocol.
Split Domain ID Original GWHD2021 Sub-Dataset Acquisition Platform Images Wheat Head Instances Role
Training D01 Canada Ground RGB 420 18,356 Source domain
Training D02 France Ground RGB 385 16,927 Source domain
Training D03 United Kingdom Ground RGB 412 19,843 Source domain
Training D04 Switzerland Ground RGB 356 15,672 Source domain
Training D05 Germany Ground RGB 328 14,935 Source domain
Training D06 Australia (source subset) Ground RGB 372 16,581 Source domain
Training D07 Other Europe regions Ground RGB 485 21,746 Source domain
Training
subtotal 7 domains Europe + Canada - 2758 124,060 Model optimization
Calibration D08 Europe held-out region Ground RGB 420 18,932 Conformal calibration only
Calibration D09 Canada held-out acquisition session Ground RGB 395 17,845 Conformal calibration only
Calibration
subtotal 2 domains Held-out source domains - 815 36,777 Calibration only
Testing D10 United States Ground RGB 380 16,324 Unseen target domain
Testing D11 Japan Ground RGB 310 13,956 Unseen target domain
Testing D12 China Ground RGB 295 12,748 Unseen target domain
Testing D13 Kenya Ground RGB 260 11,423 Unseen target domain
Testing D14 Australia/New Zealand Ground RGB 335 15,087 Unseen target domain
Testing D15 Africa additional regions Ground RGB 240 10,625 Unseen target domain
Testing D16 Asia additional regions Ground RGB 305 13,410 Unseen target domain
Domains D10–D16 were reserved exclusively for final testing. No images or annotations
from these domains were used to train the detector, estimate feature-reference statistics,
determine normalization bounds, select the discrepancy coefficient, estimate calibration
quantiles, tune thresholds, or select model configurations. During inference, each test
image’s own DINOv2 feature was used only to calculate its discrepancy score using the
previously frozen reference statistics. The test annotations were accessed only after the
prediction intervals had been generated, to calculate the final evaluation metrics. No test-
domain labels or aggregate statistics computed from the test domains were used to fit or
tune the calibration procedure. This protocol therefore evaluates the application of a fixed
calibration procedure to unseen domains without target-label adaptation.
Importantly, the validation and testing subsets are never used for model optimization,
including parameter updating, augmentation selection, or training-domain construction.
Therefore, the reported results represent a strict domain generalization setting where the
target environments remain completely inaccessible during training.
(2) Leave-One-Domain-Out Evaluation
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 20 of 54
To further analyze the model’s adaptability under extreme domain shift, this paper
further adopts the Leave-One-Domain-Out (LODO) experimental strategy.
For any target domain 𝐷𝑗, all remaining domains are used during training:
𝐷(𝑡𝑟𝑎𝑖𝑛)𝑗 = 𝐷 𝐷𝑗
Testing stage:
𝐷(𝑡𝑒𝑠𝑡)𝑗 = 𝐷𝑗
That is:
𝐷𝑗 ∉ 𝐷(𝑡𝑟𝑎𝑖𝑛)𝑗
This experiment can evaluate the model’s performance variation when facing a single
unknown environment in a more fine-grained manner.
Compared with overall average metrics, the LODO experiment can reveal the model’s
performance stability across different agricultural environments, such as: high-humidity
environments; high-illumination environments; different wheat varieties; different imaging
devices; and dense occlusion scenes.
4.2.3. Potential External Generalization Evaluation
To further investigate the potential cross-data-source transferability of WheatTrust-DG,
independent wheat datasets, including UWHD (UA V Wheat Head Dataset), are considered
as potential external evaluation benchmarks.
Different from conventional domain adaptation settings, no target-domain images,
annotations, or fine-tuning operations were used during external testing. WheatTrust-DG
was trained exclusively on GWHD2021 and directly transferred to external datasets with
unchanged model parameters.
Compared with GWHD2021, UWHD introduces additional distribution shifts caused
by aerial acquisition perspectives and scale variations, providing an additional evaluation
of the model’s transferability beyond the original benchmark domain.
Therefore, the external evaluation provides an additional evaluation of whether
WheatTrust-DG can maintain transferable detection capability beyond the original bench-
mark distribution.
The external dataset settings are shown in Table 3:
Table 3. External dataset used for zero-shot generalization evaluation.
Dataset Data Source Image Type Main Challenge Purpose
UWHD Collected by UA V platform Aerial RGB Viewpoint variation, scale variation Potential evaluation of platform transferability
4.2.4. Dataset Role in WheatTrust-DG
The roles of different datasets and experimental protocols in the framework of this
paper are as Table 4:
The structural prior used by SCDR is derived from wheat-organ segmentation infor-
mation rather than from the bounding-box annotations alone. To ensure transparency
and reproducibility, the source of the segmentation supervision, the segmentation model
configuration, and the procedure used to obtain the structural masks should be explicitly
documented. In particular, the manuscript distinguishes publicly available segmentation
annotations, automatically generated segmentation masks, and any additional manually
annotated masks produced specifically for this study. The structural masks are used only
to construct training-time counterfactual samples and are not required by the deployed
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 21 of 54
detector. The annotation burden associated with the structural prior is therefore reported
separately from the bounding-box annotation burden of the detection benchmark.
Table 4. Role of different datasets in the WheatTrust-DG framework.
Data Source Functional Module Primary Purpose
GWHD2021 Main detection training Learn wheat head detection capability
GWHD Domain Metadata Domain Generalization Establish cross-domain training protocol
GWFSS Optional structural prior extraction Learn structural priors of wheat heads, leaves, and stems
UWHD Cross-platform Transfer Evaluation Validate real-world deployment generalization capability
Among them, GWHD2021 is mainly used to train the lightweight detection model,
while GWFSS is used to provide agricultural structural prior information. By integrating
data knowledge from different sources, this paper aims to reduce the model’s dependence
on background color, illumination variation, and differences in acquisition devices, enabling
the model to focus more on the morphological and structural characteristics of wheat itself.
In summary, the dataset design and evaluation protocol of this paper revolve around
the core issue of “reliable agricultural perception in unknown environments.” Through
multi-domain training, unknown-domain testing, and external data transfer evaluation,
the comprehensive capability of WheatTrust-DG in detection, counting, and reliability
assessment is fully validated.
The problem definition and data distribution shifts are illustrated in Figure 2.
Figure 2. Cross-domain trustworthy wheat perception problem formulation and data distribution
shifts in agricultural environments.
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 22 of 54
4.2.5. Provenance, Cost, and Supervision Accounting of the Structural Prior
The structural prior used by SCDR is derived from wheat-organ segmentation labels
rather than from bounding-box annotations, and its provenance is therefore documented
separately from the detection benchmark. Four aspects are reported: label source, transfer
to the detection benchmark, annotation cost, and the cost of extending the component to a
new crop.
(1) Label source. All pixel-level labels originate from the publicly released Global
Wheat Full Semantic Organ Segmentation (GWFSS v1.0) dataset, which provides semantic
annotations of wheat heads, leaves and stems for high-resolution field images. GWFSS is
distributed openly for research use through the Global Wheat Dataset repository (DOI:
10.1016/j.plaphe.2025.100084). For the present study the wheat-head, leaf and stem classes
were merged into a single wheat-organ foreground class and all remaining pixels were
assigned to the background class.
(2) Transfer to the detection benchmark. Because GWFSS and GWHD2021 differ in
imaging setup, GWFSS labels cannot be used directly as masks for GWHD2021 images. A
SegFormer segmentation network was therefore trained once on the full released GWFSS
training split for the three-class organ task (40,000 iterations at 512 × 512 with batch size
8, approximately 6 GPU-hours on a single NVIDIA RTX 4090), frozen, and applied to the
2758 source-domain training images (D01–D07). One-off inference over these 2758 images,
including mask post-processing and storage, required approximately 1.5 GPU-minutes. The
resulting masks were generated once and reused across all five random seeds, all ablation
variants and all baseline controls; consequently, this cost is incurred once, is not repeated
per run, and does not enter the detector training budget.
(3) Annotation cost. The upstream annotation effort was borne entirely by the GWFSS
consortium and is not attributable to this study. Because the GWFSS publication does not
report person-hours, the cost is bounded here from the annotation protocol rather than left
unquantified. Organ-level polygon annotation of a single field image containing densely
overlapping heads, leaves and stems requires approximately 20–40 min per image for a
trained annotator, including quality control. At this rate every 1000 annotated images
represent 330–670 person-hours, i.e., 41–84 person-days at 8 h per day. For comparison,
bounding-box annotation of the same image requires approximately 2–4 min, so the struc-
tural prior is roughly one order of magnitude more expensive per image than the detection
labels. This ratio, rather than an absolute figure, is the quantity that governs whether the
component is affordable in a new setting.
(4) Cost of extension to a new crop or region. If an equivalent organ-segmentation
resource were unavailable, the structural prior would require pixel-level annotation of the
source-domain training images, i.e., the per-image cost in (3) multiplied by 2758 images,
which corresponds to approximately 920–1840 person-hours (115–230 person-days) at
20–40 min per image. This is the practical barrier to transferring SCDR to crops without a
comparable segmentation dataset, and it is stated as a limitation in Section 6.
(5) Scope of the claim. The structural prior is therefore an optional training-time
enhancement that converts an existing public annotation resource into a regularizer. It
removes the need for structural masks at deployment but does not remove the dependency
on external annotation during development. The resulting supervision asymmetry relative
to the compared methods, and the controls used to separate it from the contribution of the
mechanism, are described in Section 4.7.2 and evaluated in Section 5.6.
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 23 of 54
4.3. Implementation Details of WheatTrust-DG
The implementation of WheatTrust-DG follows the framework described in Section 3.
The student detector is based on YOLO11s, while DINOv2 ViT-B/14 and FoMo4Wheat
ViT-B/14 are employed as frozen teacher models during training.
All auxiliary modules, including foundation-model teachers and structural prior gener-
ators, are only involved in the training stage. During inference, the deployed model consists
of the YOLO11 detector and density estimation branch [30].
The detailed training configuration, feature extraction settings, and optimization pa-
rameters are described below.
The implementation pipeline of WheatTrust-DG is illustrated in Figure 3. During
training, foundation models and auxiliary modules provide knowledge supervision, while
only the YOLO11-based detector is retained during inference.
Figure 3. Overall architecture of WheatTrust-DG.
The overall framework structure is as follows:
𝑋𝑅𝐺𝐵 → 𝐹𝐷𝐼𝑁𝑂, 𝐹𝐹𝑜𝑀𝑜, 𝐹𝑌𝑂𝐿𝑂 → 𝐹𝐷𝐺 → 𝑌𝑑𝑒𝑡 + 𝑌𝑐𝑜𝑢𝑛𝑡 + 𝑈
Here, 𝑋𝑅𝐺𝐵 denotes the input RGB wheat image, 𝐹𝐷𝐼𝑁𝑂 and 𝐹𝐹𝑜𝑀𝑜 denote the high-
level semantic features extracted by the general visual foundation model and the wheat
domain foundation model, respectively, 𝐹𝑌𝑂𝐿𝑂 denotes the local visual features of the
lightweight detector, and 𝐹𝐷𝐺 denotes the domain-invariant feature representation after
domain generalization optimization. The final outputs include wheat head detection boxes,
quantity estimation results, and prediction confidence information.
All compared detectors were evaluated using the same domain-disjoint training, vali-
dation, and test protocol, with identical target-domain test data and evaluation metrics. The
standard detection baselines were trained using the available wheat-head bounding-box an-
notations and their respective prescribed training procedures. In contrast, WheatTrust-DG
additionally uses frozen foundation-model teachers for representation distillation and a
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 24 of 54
structural prior for counterfactual sample construction. These auxiliary information sources
are therefore explicitly distinguished from the common detection supervision.
To avoid attributing performance gains solely to the availability of additional super-
vision, we evaluate the structural prior through controlled ablations in which the student
architecture, data splits, initialization, optimization schedule, training duration, and evalua-
tion protocol are held constant. The results are interpreted as evidence of the contribution
of the structural-prior mechanism under the specified training setting, rather than as proof
that all competing methods receive identical auxiliary supervision. The provenance of
the additional supervision is documented separately to facilitate reproducibility and a
transparent assessment of the associated resource requirements.
(1) Lightweight Detection Backbone Based on YOLO11
To ensure practical agricultural deployment capability, WheatTrust-DG adopts YOLO11
as the base detection network. This paper does not make extensive structural modifications
to the YOLO11s-based student detector; instead, it uses YOLO11 as a lightweight student
network (Student Detector) and focuses on enhancing its cross-domain representation
capability through external knowledge [31].
Given an input image:
X ∈ R(H×W×3)
YOLO11 first extracts multi-scale features:
𝐹𝑠 = 𝐹2, 𝐹3, 𝐹4, 𝐹5
The features at different scales are used to detect wheat head targets of different sizes.
Shallow features mainly contain object edge and texture information, while deep features
encode more abstract semantic information.
However, due to pronounced domain variation in agricultural environments, features
learned solely by YOLO11 are susceptible to background color, soil texture, and illumi-
nation changes, resulting in shortcut learning. Therefore, this paper further introduces a
foundation-model knowledge enhancement mechanism.
(2) General–Specific Foundation Model Distillation
To simultaneously leverage general visual knowledge and agricultural domain knowl-
edge, this paper designs a General–Specific Foundation Distillation (GSFD) module. This
module employs two teacher networks with different knowledge sources:
DINOv2 ViT-B/14
FoMo4Wheat ViT-B/14
Among them, DINOv2 provides general visual priors, including: object structure
information; edge and texture relationships; and cross-scenario semantic representations.
FoMo4Wheat, as an agricultural domain foundation model trained on global wheat
images, can provide: wheat head morphological features; canopy structure information;
growth-stage-related semantics; and agricultural environmental features.
The research plan indicates that the two types of foundation models are clearly comple-
mentary. Therefore, instead of simply fusing the two features, this paper designs a dynamic
teacher weighting mechanism that enables the model to adaptively select knowledge sources
according to the characteristics of the input image.
Specifically, the outputs of the two teachers are respectively denoted as:
𝑇𝑔 = 𝐷𝐼𝑁𝑂(𝑋)
𝑇𝑠 = 𝐹𝑜𝑀𝑜(𝑋)
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 25 of 54
To dynamically adjust their contributions, a teacher gate is introduced:
𝛼 = 𝜎(𝑔(𝑇𝑔, 𝑇𝑠, 𝐹𝑠))
The final knowledge target is expressed as:
𝑇 = 𝛼𝑇𝑔 + (1 − 𝛼)𝑇𝑠
where
𝛼 ∈ [0, 1]
denotes the weight of general knowledge.
When the input image exhibits pronounced domain shift, such as images acquired
from an unknown country or an unknown sensor, the model increases the contribution of
DINOv2, whereas in typical agricultural scenarios, it increases the weight of FoMo4Wheat,
thereby obtaining more precise wheat structural representations.
Subsequently, through the feature distillation constraint:
𝐿𝐺𝑆𝐹𝐷 = 1 − 𝑐𝑜𝑠(𝐹𝑠, 𝑇)
the YOLO11 student network gradually learns cross-domain semantic knowledge from the
foundation models.
For teacher feature extraction, the final transformer block output of both foundation
models was used as the semantic representation. For DINOv2 ViT-B/14, the CLS token and
patch tokens were extracted from the last transformer layer. For FoMo4Wheat ViT-B/14, the
corresponding last-layer wheat semantic representation was extracted.
To maintain spatial correspondence with YOLO11 feature maps, patch-level features
were retained rather than only using image-level embeddings.
The structural mask generator used in SCDR is based on SegFormer. The model
parameters are fixed before the training of the YOLO11s detector. For each source-domain
training image, the segmentation output is converted into a structural mask by combining
the wheat-head, leaf, and stem regions into a single wheat-organ foreground mask and
treating the surrounding background as the non-wheat region, consistent with the structural
prior described in Section 3.4. The resulting masks are used to guide counterfactual image
construction and are not used as direct object-detection labels.
The SegFormer model is used only to provide training-stage structural guidance. Its
parameters are not updated by the detector loss, and neither the segmentation model
nor its generated masks is required during inference. The structural-prior information is
sourced from GWFSS, which provides wheat-organ structural information for wheat heads,
leaves, and stems, while SegFormer serves as the structural-mask generator. The SegFormer
parameters are fixed before YOLO11s detector training. The structural-mask generator
used in SCDR was based on SegFormer. Publicly available pixel-level annotations from the
Global Wheat Full Semantic Organ Segmentation (GWFSS) dataset were used to obtain the
structural prior. Specifically, the annotated wheat-head, leaf, and stem regions were merged
into a single wheat-organ foreground class, while the surrounding background was treated
as the non-wheat region. The resulting structural masks were used to guide counterfactual
image construction for the GWHD2021 source-domain training images and were not used as
direct object-detection targets. The SegFormer model was frozen before YOLO11s detector
training, and its parameters were not updated by the detector loss. Neither the segmentation
model nor its generated masks was required during inference.
(3) Overall Optimization Objective
Integrating the above modules, the final training objective of WheatTrust-DG is
defined as:
𝐿 = 𝐿𝑑𝑒𝑡 + 𝜆1𝐿𝐺𝑆𝐹𝐷 + 𝜆2𝐿𝑐𝑓 + 𝜆3𝐿𝐷𝐺 + 𝜆4𝐿𝑑𝑒𝑛𝑠𝑖𝑡𝑦 + 𝜆5𝐿𝑐𝑜𝑢𝑛𝑡
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 26 of 54
where
𝐿𝑑𝑒𝑡 = 𝐿𝑏𝑜𝑥 + 𝐿𝑐𝑙𝑠 + 𝐿𝐷𝐹𝐿
The overall loss function simultaneously optimizes: detection accuracy; cross-domain
generalization ability; wheat structural representation capability; counting capability in
dense scenes; and model prediction trustworthiness.
It is worth noting that DINOv2 and FoMo4Wheat exist only as knowledge teach-
ers during the training stage and are removed during inference. Therefore, the final de-
ployed model still maintains the computational efficiency of YOLO11. This design of
“large-model enhancement during training and lightweight deployment during inference”
enables WheatTrust-DG to balance scientific innovation and practical agricultural applica-
tion value [32].
It should be emphasized that DACC operates differently from detection-oriented
modules such as GSFD, SCDR, FHDC, and DDCC. The former focuses on improving
prediction reliability under distribution shifts, whereas the latter directly modify feature
learning or detection optimization. Therefore, the performance gain brought by DACC
should be interpreted as an improvement in cross-domain prediction stability rather than a
direct enhancement of localization capability.
The detailed training configurations and loss weighting coefficients used in all experi-
ments are summarized in Table 5. These parameters were fixed for all experiments to ensure
fair comparison and reproducibility.
Table 5. Training configurations of WheatTrust-DG.
Category Parameter Value
Backbone Student detector YOLO11s
Input Image resolution 640 × 640
Training Epochs 200
Training Batch size 16
Training Optimizer AdamW
Training Initial learning rate 5 × 10−4
Training Final learning rate factor 0.01
Training Weight decay 5 × 10−4
Training Warm-up epochs 3
Training Learning rate scheduler Cosine annealing
Training Mixed precision Enabled
Training Deterministic training Enabled
GSFD Cosine distillation weight 𝜆𝑐𝑜𝑠 0.30
GSFD Relational distillation weight 𝜆𝑟𝑒𝑙 0.05
SCDR Counterfactual detection loss weight 𝜆𝑐𝑓 −𝑑𝑒𝑡 0.25
SCDR Counterfactual feature consistency weight 𝜆𝑐𝑓 −𝑓 𝑒𝑎𝑡 0.05
DDCC Density estimation loss weight 𝜆𝑑𝑒𝑛𝑠𝑖𝑡𝑦 0.10
DDCC Counting regression loss weight 𝜆𝑐𝑜𝑢𝑛𝑡 0.03
DDCC Detection–counting consistency weight 𝜆𝑑𝑒𝑡−𝑐𝑜𝑢𝑛𝑡 0.01
Calibration Confidence level 95%
Calibration Domain uncertainty coefficient 0.5
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 27 of 54
4.4. General–Specific Foundation Distillation
4.4.1. Dual Foundation Knowledge Extraction and Representation Alignment
To achieve effective interaction between the feature spaces of different models, this
paper first employs feature projection layers to map representations from different sources
into a unified dimension:
𝐹𝑖 = 𝑃𝑖(𝐹𝑖), 𝑖 ∈ 𝑔, 𝑤, 𝑠
where 𝑃𝑖(⋅) denotes a learnable mapping function [33]. After alignment of spatial and
channel dimensions, features from different sources can be further fused in a unified
semantic space.
Specifically, DINOv2 ViT-B/14 and FoMo4Wheat ViT-B/14 generate patch-level rep-
resentations with an original embedding dimension of 768. Since YOLO11s produces
multi-scale feature maps with different channel dimensions, a lightweight projection head
is introduced for feature alignment.
The projection head consists of a 1 × 1 convolution layer followed by Layer Normal-
ization and GELU activation. All feature representations are projected into a unified 256-
dimensional embedding space:
[𝐹′𝑠, 𝐹′𝑔, 𝐹′𝑤 ∈ 𝑅256]
where 𝐹′𝑠, 𝐹′𝑔, and 𝐹′𝑤 denote the projected student, general teacher, and wheat-specific
teacher representations, respectively.
The projection dimension was selected based on the trade-off between knowledge
preservation and computational efficiency.
4.4.2. Feature Extraction and Alignment
By maintaining consistency in the relational structure between the Student and the
Teacher, the model not only learns the semantic representation of individual samples
but also inherits the foundation model’s ability to model relationships between different
visual patterns.
The General–Specific Foundation Distillation objective, denoted as ℒGSFD, is defined as:
ℒGSFD = ℒcos + 𝜆𝑟ℒrel
where
𝜆𝑟
denotes the weight coefficient of the relational distillation term.
Through the above design, GSFD effectively combines the general visual priors pro-
vided by DINOv2 with the wheat domain knowledge provided by FoMo4Wheat, and
compresses and transfers them into the lightweight YOLO11 detector [34]. Unlike methods
that directly increase network scale or introduce additional detection modules, this strategy
optimizes the model’s internal representations through knowledge transfer, enabling the
detector to learn more domain-invariant visual features and providing a more reliable
feature foundation for the subsequent structure-aware domain generalization module.
The core innovation points used in this study are shown in Figure 4.
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 28 of 54
Figure 4. General–specific foundation distillation.
4.5. Structure-Aware Counterfactual Consistency Objective
The generated counterfactual image pairs satisfy an important semantic consistency
constraint:
𝑌(𝑋) = 𝑌(𝑋𝑐𝑓 )
where Y denotes detection annotations. This indicates that although the visual distribu-
tion between the original image and the counterfactual image changes significantly, the
underlying wheat spike locations and target structures remain unchanged [35]. There-
fore, the detector is encouraged to learn representations that are less sensitive to domain-
specific appearance variations and potentially more related to stable wheat characteristics,
rather than relying heavily on spurious correlations between background appearance and
target categories.
In addition, to improve the robustness of feature representations, a counterfactual
consistency constraint is introduced between original and transformed samples:
𝐿𝑐𝑓 = 𝐿𝑑𝑒𝑡(𝑋𝑐𝑓 , 𝑌) + 𝜆∣∣𝐹(𝑋) − 𝐹(𝑋𝑐𝑓 )∣|2
where ℒdet denotes the original detection loss, F(·) denotes the extracted feature representa-
tion, and λ controls the strength of consistency regularization. The first term ensures that the
generated samples retain detection capability, while the second term reduces unnecessary
feature variations caused by domain-specific factors.
Unlike traditional domain randomization methods that assume arbitrary visual pertur-
bations are beneficial, SCDR introduces structure awareness into the randomization process.
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 29 of 54
By explicitly separating stable wheat morphology from unstable environmental appearance,
the proposed strategy reduces shortcut learning and improves the model’s generalization
ability to unseen geographic regions, imaging platforms, and field conditions. This design
is particularly suitable for agricultural perception scenarios, in which the same biological
target may exhibit significant appearance variations under different environments while
maintaining relatively stable structural characteristics.
As illustrated in Figure 5, the proposed SCDR strategy introduces structural priors into
domain randomization by disentangling invariant wheat structures from domain-specific
appearance factors.
Figure 5. Overview of the proposed Structure-aware Counterfactual Domain Randomization (SCDR).
4.6. Detection–Density–Counting Consistency
Specifically, for an input image X, the detection branch outputs a set of predicted
bounding boxes, the number of which is denoted as 𝑁det , while the density branch generates
a density map D(x) by learning the spatial distribution of wheat spikes, and obtains the
estimated count by integrating the density map:
𝑁𝑑𝑒𝑛𝑠𝑖𝑡𝑦 = ∑𝑥 𝐷(𝑥)
where the ground-truth density map is generated from annotated wheat spike centers using
adaptive normalized Gaussian kernels:
𝐷(𝑥) = ∑
𝑖
𝑒𝑥𝑝(−∣∣𝑥 − 𝑐𝑖∣∣2/(2𝜎𝑖2))
where ci denotes the center position of the 𝑖-th wheat spike, and 𝜎i is dynamically ad-
justed according to the object scale, enabling the model to adapt to wheat spike objects of
different sizes.
To ensure the reproducibility of density supervision, the ground-truth density maps
are generated following the standard point annotation-based density estimation paradigm.
Specifically, each wheat spike instance is represented by its annotated center point
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 30 of 54
𝑐𝑖 = (𝑥𝑖, 𝑦𝑖), and the density contribution of each spike is modeled using a normalized
Gaussian kernel:
𝐺(𝑥, 𝑦) = 1/(2𝜋𝜎𝑖2)𝑒𝑥𝑝(−((𝑥 − 𝑥𝑖)2 + (𝑦 − 𝑦𝑖)2)/(2𝜎𝑖2))
where σi controls the spatial spread of the density response. Considering the considerable
variation in wheat spike size caused by different growth stages, imaging distances, and
acquisition platforms in GWHD2021, an adaptive kernel width strategy is adopted instead
of a fixed Gaussian bandwidth. Specifically, σi is determined according to the local object
scale estimated from the corresponding bounding box:
𝜎𝑖 = 𝛽√(𝑤𝑖ℎ𝑖)
where 𝑤𝑖 and ℎ𝑖 denote the width and height of the 𝑖-th wheat spike bounding box, respec-
tively, and β is a scaling coefficient empirically set to 0.15. This adaptive formulation enables
large wheat spikes to generate wider density responses while preserving sharper responses
for small spikes, thereby improving the robustness of density learning under multi-scale
agricultural scenarios.
The final ground-truth density map is obtained by accumulating the contributions of
all wheat spikes:
𝐷𝑔𝑡(𝑥, 𝑦) = Σ𝑖𝐺𝑖(𝑥, 𝑦)
where 𝐷𝑔𝑡 represents the generated density supervision map. The density map is normal-
ized such that the integral of the density responses equals the actual number of wheat spikes:
∑ 𝑥, 𝑦𝐷𝑔𝑡(𝑥, 𝑦) = 𝑁𝑔𝑡
where 𝑁𝑔𝑡 denotes the ground-truth wheat spike count. Therefore, the density value represents
the expected spike number within each spatial location rather than a classification probability.
During training, the density maps are generated at the same spatial resolution as the
output feature map of the density branch. Specifically, the input RGB images are resized to
640 × 640 pixels following the YOLO11 training pipeline, and the density supervision maps
are generated at a 1/8 resolution (80 × 80 pixels) through average pooling after Gaussian
rendering. This design provides a suitable balance between spatial localization capability
and computational efficiency.
For densely planted wheat fields, multiple spikes may exhibit strong spatial overlap or
partial occlusion. Instead of assigning exclusive regions to individual instances, the pro-
posed density generation strategy allows Gaussian responses from different spike centers
to naturally accumulate in overlapping regions. Therefore, overlapping spikes produce
higher density values rather than being suppressed, preserving the underlying population
information. For partially occluded spikes, the original instance annotations provided by
GWHD2021 are retained, and the corresponding center points are still included during den-
sity map generation. This treatment prevents density supervision from being biased toward
visible regions only and enables the model to learn robust population-level representations
under dense and occluded agricultural conditions.
Furthermore, to reduce the deviation between the detection count and the true
count [36], this paper introduces a three-way consistency constraint among detection,
density, and ground-truth annotations. Given the ground-truth wheat spike count NGT , the
model optimization objective requires not only that the detection results be close to the true
count but also that the density estimation remain consistent:
𝐿𝑐𝑜𝑢𝑛𝑡 =∣𝑁𝑑𝑒𝑛𝑠𝑖𝑡𝑦 − 𝑁𝐺𝑇∣+𝜆∣𝑁𝑑𝑒𝑛𝑠𝑖𝑡𝑦 − 𝑁𝑑𝑒𝑡∣
where the first term constrains the difference between the density estimation and the ground-
truth wheat spike count, and the second term establishes a complementary information
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 31 of 54
relationship between the detection results and the density prediction. Through this joint
constraint, the detection branch can obtain more stable count feedback, while the density
branch can also be guided by instance-level localization information, thereby avoiding count
estimation that relies solely on local texture.
Therefore, the DDCC module provides the explicit counting optimization mechanism
in WheatTrust-DG by reducing the inconsistency between instance detection and density
estimation [37]. Meanwhile, the domain generalization modules improve the quality and
stability of detection representations under unseen environments, which further reduces
counting errors caused by missed or duplicated detections. The final counting capability is
achieved through the cooperation between robust representation learning and Detection–
Density consistency optimization.
Importantly, DDCC is a training-stage consistency mechanism rather than an inference-
time confidence calibration or post-processing module. It does not apply a separate transfor-
mation to per-box confidence scores and does not modify the NMS or confidence-threshold
settings used during evaluation. Its primary objective is to improve consistency between
density-based count estimation and detection-derived counts. Because the density branch
and detector are jointly optimized through the shared representation, DDCC may indirectly
influence the learned detection features and the resulting predictions. However, such an
effect on detection accuracy cannot be inferred from the module definition alone and must
be verified by comparing the corresponding trained models under identical inference and
post-processing settings. Accordingly, DDCC is not interpreted as a confidence–error align-
ment mechanism, and any detection-side improvement is reported as an empirical result
rather than an assumed consequence of count consistency.
4.7. Experimental Setup and Statistical Protocol
To ensure the reproducibility of WheatTrust-DG, all experimental configurations,
hyperparameters, and optimization settings are explicitly described in this section.
The proposed framework was implemented using PyTorch 2.1 with CUDA 12.1. All
experiments were conducted on an NVIDIA RTX 4090 GPU with 24 GB memory. The
YOLO11s detector was adopted as the student network and initialized with official COCO
pretrained weights.
The input images were resized to 640 × 640 pixels. The model was optimized using the
AdamW optimizer with an initial learning rate of 5 × 10−4, weight decay of 5 × 10−4, and
cosine annealing learning rate scheduling. The batch size was set to 16, and the total training
epoch number was 200. Early stopping was not applied to ensure consistent comparison
among different methods.
The foundation models, including DINOv2 ViT-B/14 and FoMo4Wheat ViT-B/14,
were frozen during training. Their feature representations were extracted offline to avoid
additional computational overhead during detector optimization. The student detector and
all newly introduced lightweight modules were optimized jointly.
One complete training run (200 epochs, i.e., 34,600 iterations over 2758 images at batch
size 16) required approximately 8 GPU-hours on a single NVIDIA RTX 4090 with 24 GB of
memory (7–9 h across runs and seeds). A plain YOLO11s baseline trained under the same
schedule requires approximately 4.5 GPU-hours; the additional cost of WheatTrust-DG
arises from the counterfactual branch, which performs one additional forward–backward
pass per iteration. No variant received additional epochs, additional augmented samples
or per-variant schedule tuning, and neither early stopping nor checkpoint selection on
the evaluation domains was applied. Offline foundation-feature extraction and structural-
mask generation are one-off costs that precede detector training (Section 4.2.5) and are
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 32 of 54
therefore excluded from the per-run budget, but they are reported separately so that the
total development cost remains auditable.
To assess whether the observed improvements are statistically meaningful rather than
caused by random training fluctuations, all quantitative experiments were repeated with
five independent random seeds. In addition to reporting the mean ± standard deviation,
statistical significance analysis was performed between WheatTrust-DG and the strongest
baseline models.
For each evaluation metric, an independent two-sided Student’s t-test was conducted
using the results from five repeated runs. The null hypothesis assumes that there is no
significant performance difference between WheatTrust-DG and the compared baseline
model. A significance level of 𝑝 < 0.05 was adopted.
Furthermore, 95% confidence intervals (CIs) were calculated based on the five
independent runs:
𝐶𝐼95% = 𝑥 ± 𝑡0.975,𝑛−1
𝑠
𝑛
where 𝑥 and 𝑠 denote the mean and standard deviation of five runs, respectively, 𝑛 = 5, and
𝑡0.975,𝑛−1 represents the critical value of Student’s t-distribution.
These statistical analyses provide additional evidence that the performance improve-
ments achieved by WheatTrust-DG are robust and statistically reliable.
4.7.1. Controlled Detection Evaluation and Post-Processing Protocol
To isolate the effect of DDCC from potential differences in inference-time post-
processing, all detector variants were evaluated on the same held-out test domains
(D10–D16) using identical input pre-processing, an input resolution of 640 × 640 pixels, and
the same evaluation implementation. For average precision (AP) computation, a minimum
pre-NMS confidence threshold of 0.001, an NMS intersection-over-union (IoU) threshold
of 0.70, and a maximum of 300 detections per image were used for every model. Class-
agnostic NMS and test-time augmentation were disabled. AP was calculated from the
confidence-ranked detections retained under this common evaluation protocol.
To assess performance at a fixed operating point, precision, recall, and F1-score were
additionally calculated using a fixed confidence threshold of 0.25 and the same NMS IoU
threshold of 0.70 for all models. These metrics were computed directly from detections
retained at the specified threshold rather than from model-specific, F1-optimal thresholds.
No confidence threshold or NMS parameter was tuned separately for individual models or
selected using annotations from the unseen test domains.
The models trained with and without DDCC have different optimization objectives
and may therefore produce different raw detector outputs. Accordingly, the controlled
comparison holds the test images, input pre-processing, inference configuration, and post-
processing pipeline constant rather than requiring identical predictions from separately
trained models. For the DACC comparison, the same frozen detector checkpoint and its
original predictions are used before and after interval calibration, because DACC is not
intended to modify detection outputs. The detection metrics must consequently remain
unchanged after DACC is applied.
4.7.2. Supervision Accounting and Fairness Controls
Because WheatTrust-DG uses information that is not available to conventional detectors,
the comparison in Table 6 is a method-level comparison and is reported as such. The
accounting below makes the difference explicit.
https://doi.org/10.3390/s26237491
Sensors 2026, 26, 7491 33 of 54
Table 6. Cross-domain generalization comparison on GWHD2021†. Values are reported as mean ± standard deviation over five independent runs. Statistical
significance was evaluated using a two-sided Student’s t-test.
Method mAP50 (%) mAP50:95 (%) Precision Recall Mean Domain AP (%) Worst Domain AP (%) Domain STD ↓ D10 (USA) (%) D11 (Japan) (%) D13 (Kenya) (%) 95% CI
Faster R-CNN 82.7 ± 0.9 55.4 ± 0.8 0.862 ± 0.012 0.821 ± 0.015 52.8 ± 1.3 38.6 ± 2.1 9.7 ± 0.8 67.4 ± 0.2 65.4 ± 0.5 57.5 ± 0.5 [51.19, 54.41]
RetinaNet 86.1 ± 0.8 57.6 ± 0.7 0.874 ± 0.011 0.836 ± 0.013 55.1 ± 1.1 40.9 ± 1.8 8.9 ± 0.7 68.6 ± 0.3 66.7 ± 0.4 58.9 ± 0.3 [53.73, 56.47]
YOLOv8s 86.3 ± 0.6 63.5 ± 0.6 0.903 ± 0.009 0.884 ± 0.010 61.7 ± 0.9 47.2 ± 1.5 7.6 ± 0.6 69.4 ± 0.5 67.5 ± 0.3 59.8 ± 0.2 [60.58, 62.82]
YOLO11s 87.6 ± 0.5 65.8 ± 0.5 0.918 ± 0.008 0.901 ± 0.009 64.5
论文原文与出版信息
Sensors