A Closed-Loop Processing Method for Cow Behavior Monitoring that Integrates Intelligent Agents and Improved Detection Networks
By introducing an adaptive multi-scale attention and lightweight feature fusion detection network, combined with the BAER framework, the problems of unstable detection and difficult implementation of treatment in dairy cow behavior monitoring are solved, and highly robust detection and actionable treatment suggestions are generated.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- GUILIN UNIV OF ELECTRONIC TECH
- Filing Date
- 2026-03-25
- Publication Date
- 2026-07-31
AI Technical Summary
Existing dairy cow behavior monitoring technologies are unstable in densely obscured and small-target scenarios, and the detection results are difficult to directly translate into actionable treatment recommendations, lacking a closed-loop decision-making mechanism.
The detection robustness is improved by using the YOLO-ALFA detection network combined with Adaptive Multi-Scale Attention (AdaMSA) and Lightweight Weighted Feature Fusion (LwFPN). The BAER framework is used to realize closed-loop processing from detection results to treatment suggestions, including structured event recording, risk factor calculation and multi-dimensional scoring.
It improves the accuracy of behavior detection and the stability of localization in complex scenarios, generates actionable handling suggestions, and achieves quantitative evaluation of suggestion quality through multi-dimensional scoring and consistency measurement, supporting a traceable, reviewable, and iterative handling closed loop.
Smart Images

Figure CN122493380A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of smart agriculture technology, and more specifically, to a closed-loop processing method for monitoring dairy cow behavior that integrates intelligent agents and improved detection networks. Background Technology
[0002] In large-scale dairy farming, the core requirements for dairy cow behavior monitoring are typically: timely detection and intervention of abnormal interactions such as fighting and mating, while continuously recording daily behaviors such as feeding, drinking, lying down, and walking to support health assessment and production management. The closest existing technologies to this invention mainly focus on deep learning-based behavior detection and alerting solutions based on pasture videos, and are gradually attempting to use the recognition results for on-site management decision support, but overall, they still primarily focus on "detection / alarming."
[0003] In terms of its typical structure and signal transmission relationship, existing technologies generally include a video acquisition end, a transmission and computing end, a recognition model end, and an alarm / display end. Cameras capture video streams in key areas of the cattle shed, transmit them via network to edge computing devices or a central server, complete preprocessing such as decoding, frame extraction, and scale normalization, and then input the image frames into a target detection / behavior recognition network. The network outputs target bounding boxes, behavior categories, and confidence levels. Subsequently, alarms are triggered through threshold judgment, quantity statistics, or simple rules, and the alarm information is pushed to a display terminal or mobile device for manual review and handling. The signal flow of this link can be summarized as "video stream → extracted frame image → model inference output (box / class / confidence level) → rule / threshold judgment → alarm / display → manual handling." This structure aligns with the problem that detection results are difficult to directly translate into actionable actions.
[0004] On the recognition model side, to meet the requirements of real-time performance and multi-target scenarios, existing solutions often adopt a one-stage detection framework (such as YOLO-like) as the main structure. Internally, this framework typically involves a backbone network for multi-layer feature extraction, followed by cross-scale fusion using feature pyramids (FPN / PAN and their improvements), and finally, classification and regression results are output in the detection head. To improve feature representation capabilities, existing research has proposed embedding attention structures into the network. For example, CBAM uses sequential modeling of channel attention and spatial attention to highlight key feature regions. There are also lightweight channel attention approaches, such as ECA, which achieves efficient channel attention modeling through local cross-channel interactions. Regarding multi-scale fusion, existing work has proposed bidirectional feature fusion structures with learnable weights (such as BiFPN in EfficientDet) for more efficient fusion of features from different levels. These methods provide general enhancement tools for complex scene detection, but they may still suffer from insufficient robustness and localization quality when dealing with features such as dense occlusion in pastures, scale variations, and blurred behavioral boundaries.
[0005] Specifically, in the context of pasture video scenarios, the shortcomings of existing technologies are mainly reflected in the following aspects: when individual cows are densely packed, occlusion is frequent, and the proportion of small targets at a distance is high, the detection network is prone to missed detections, false detections, and localization drift; during the cross-layer feature fusion process, a unified fusion strategy may lead to insufficient alignment or noise backflow, thereby limiting the stability of boundary regression under high IoU thresholds. This is one of the practical motivations for emphasizing the use of a lighter and more aligned fusion structure to improve the overall detection quality.
[0006] Furthermore, many systems often trigger alarms using a single confidence threshold or the frequency of occurrence of a category, making it difficult to simultaneously address both "low-confidence but high-risk" occlusion scenarios and "high-confidence but low-risk" everyday scenarios. This can easily lead to anomaly omissions or alarm overload. Therefore, we introduce the lower quantile of the confidence distribution (such as P10) to represent uncertainty, and combine it with the number of targets in a fixed neighborhood and the average IoU to characterize local congestion, so as to more stably reflect the risk situation and serve the subsequent priority determination.
[0007] More importantly, from a management closed-loop perspective, most existing technologies end at the "detection output or alarm triggering" point: while the identification results provide information on "what happened," how to form executable steps, whether resources are feasible, and how to evaluate and review after execution, these typically still rely on human experience and lack a mechanism to translate detection evidence into structured handling suggestions and to quantitatively verify the quality and stability of the suggestions. Therefore, the BAER framework proposed in this invention introduces a chain of "suggestion generation agent—execution agent—evaluation agent" on top of the detection results, enabling the handling suggestions to have executable steps and achieving iterative optimization through multi-dimensional scoring and consistency measurement. Summary of the Invention
[0008] In view of this, the present invention proposes a closed-loop processing method for monitoring dairy cow behavior that integrates intelligent agents and improved detection networks, in order to solve the problems existing in the prior art.
[0009] To achieve the above objectives, this invention proposes a closed-loop processing method for monitoring dairy cow behavior that integrates intelligent agents and improved detection networks, comprising the following steps: Acquire the pasture video stream and preprocess it to form an image frame sequence; The YOLO-ALFA detection network is used to detect behavior in the image frames, and the behavior category, bounding box coordinates and confidence score of each individual cow in each frame are output. The detection output is organized into a structured event record, which includes image resolution information, target count for each category, bounding box coordinates for each target, corresponding behavior category label and confidence level; The lower quantile P10 is extracted from the detection confidence distribution as an uncertainty characterization quantity, and the crowding characterization quantity is extracted from the neighborhood target distribution. The crowding characterization quantity is obtained by counting the number of targets in a fixed neighborhood with the target box center as the anchor and calculating the average IoU of the target boxes in the neighborhood. Based on the structured event records and the risk factors, a handling suggestion is generated. The handling suggestion includes behavior type, handling priority, judgment basis and operation suggestion items. The handling priority is jointly determined by the prior risk of the anomaly category, the target count, the uncertainty characterization quantity and the crowding characterization quantity. Under resource constraints, the proposed solutions are transformed into a time-sequential sequence of executable steps. The chain from the proposed treatment to the sequence of executable steps is scored in multiple dimensions and a consistency index is calculated to generate feedback results that can be used for strategy iteration.
[0010] Furthermore, the YOLO-ALFA detection network includes a backbone feature extraction network, a feature fusion network, and a detection head. The adaptive multi-scale attention AdaMSA module is introduced in the key feature path to enhance the discrimination and localization feature expression in complex scenes, and cross-scale fusion and alignment are completed through a lightweight weighted feature pyramid network LwFPN.
[0011] Furthermore, the AdaMSA module includes: The dimension reduction mapping unit uses 1×1 convolution to reduce the dimensionality of the input features to the intermediate number of channels, with a scaling factor of 4.0; The channel attention unit uses the ECA mechanism to capture local cross-channel interactions through one-dimensional convolution, and the kernel length is adaptively adjusted according to the number of channels. The multi-scale context extraction unit includes at least three parallel branches, each branch employing depthwise separable convolutions with different dilation rates to extract context information at different scales, wherein the dilation rates are 1, 2, and 3, respectively. The soft-weighted fusion unit sets learnable weights and performs a weighted summation of the outputs of each branch after Softmax normalization, thereby achieving adaptive adjustment of contributions at different scales. The spatial attention unit generates a spatial weight map based on channel aggregation features to highlight the target region and suppress background interference. The shallow layers use 7×7 convolutional kernels to obtain a larger receptive field, while the deep layers use 3×3 convolutional kernels to reduce computational overhead.
[0012] Furthermore, the LwFPN includes multi-layer fusion nodes with top-down and bottom-up paths. Each fusion node sets learnable fusion weights for input features from different levels, performs weighted fusion after non-negative constraints and normalization, and then outputs fused features through convolution.
[0013] Furthermore, the LwFPN employs a fast weighted fusion mechanism, assuming the input feature map set is {X}. i}, fusion weight w i The weighted fusion output is the sum of the products of each input feature and its corresponding weight, calculated through ReLU activation and normalization. Finally, the fused feature is output through a convolutional layer.
[0014] Furthermore, the processing priority is divided into three levels: high, medium, and low. When the congestion level increases or the P10 decreases, the processing priority is increased and the review intensity is strengthened.
[0015] Furthermore, the closed-loop decision-making adopts the BAER framework, including: It is recommended to generate intelligent agents to transform structured event records into structured handling suggestions; An execution agent is used to transform disposal suggestions into a sequence of executable steps under resource constraints, including the number of available personnel, available equipment, accessible areas, and available disposal time windows. An evaluation agent is used to quantitatively evaluate the chain from the agent that generates the suggestion to the agent that executes it.
[0016] Furthermore, the evaluation agent performs multi-dimensional scoring, including clarity, feasibility, risk mitigation, welfare impact, timeliness, and overall evaluation, with a scoring range of 1-5 points.
[0017] Furthermore, Krippendorff's α coefficient is used to measure the consistency of multiple raters' ratings on interval types, and the 95% confidence interval is estimated using the bootstrap method to characterize the consistency uncertainty under finite sample conditions.
[0018] On the other hand, to achieve the above objectives, this invention proposes a closed-loop processing system for monitoring dairy cow behavior that integrates intelligent agents and improved detection networks, including... The video acquisition module is used to acquire video streams from fixed cameras on the ranch. The video preprocessing module, connected to the video acquisition module, is used to decode, extract frames, normalize scales, and enhance images of the video stream to form a continuous sequence of image frames. The behavior detection module, connected to the video preprocessing module, uses the YOLO-ALFA detection network to perform inference on each frame of the image and outputs detection results including behavior category, bounding box coordinates and confidence level. The event structuring module, connected to the behavior detection module, is used to convert the detection results into structured event records and calculate risk factors, including uncertainty representation and crowding representation. The suggestion generation module, connected to the event structuring module, is used to generate handling suggestions and give priorities based on structured event records; The execution regularization module, connected to the suggestion generation module, is used to transform disposal suggestions into a sequence of executable steps under resource constraints; The evaluation and feedback module, connected to the execution regularization module, is used to score the suggestion chain from multiple dimensions and calculate the consistency index. The result output module, connected to the suggestion generation module, execution regulation module, and evaluation feedback module, is used to output the handling suggestions, execution steps, and evaluation results to the display terminal, mobile terminal, or alarm system.
[0019] Compared with the prior art, the beneficial effects of the present invention are as follows: This invention provides a method, system, and storage medium for monitoring and handling dairy cow behavior based on pasture videos. Through an overall design of "highly robust detection + closed-loop decision-making," it simultaneously addresses two key technical challenges: unstable detection in complex scenarios and difficulties in implementing operational and maintenance measures. On the detection side, by introducing an adaptive multi-scale attention and lightweight weighted feature fusion mechanism, it improves feature representation and cross-layer alignment quality in scenarios with dense occlusion, small targets, and multi-scale variations, enhancing the accuracy and stability of behavior detection while controlling parameter scale and inference latency. On the decision-making side, the detection results are organized into a structured behavioral event stream, comprehensively utilizing category counting, bounding boxes, confidence levels, and their distribution features. It also introduces the P10 quantile under confidence levels to represent uncertainty and combines the number of targets within a fixed neighborhood with the average IoU to characterize local congestion, thereby classifying behavioral risks and determining handling priorities (high / medium / low). Furthermore, it generates executable handling suggestions and step sequences, and uses multi-dimensional scoring and consistency metrics to quantitatively evaluate the quality and stability of the suggestions, providing a basis for continuous optimization of handling strategies and threshold rules. Attached Figure Description
[0020] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit the invention. In the drawings: Figure 1 This is a diagram illustrating the overall framework of the closed-loop processing method for monitoring dairy cow behavior that integrates intelligent agents and improved detection networks, as described in this invention. Figure 2 This is a diagram of the overall architecture of the YOLO-ALFA detection network in an embodiment of the present invention; Figure 3 This is a schematic diagram of the AdaMSA module in an embodiment of the present invention; Figure 4This is a schematic diagram of the LwFPN structure in an embodiment of the present invention; Figure 5 This is a schematic diagram of the closed-loop decision-making BAER framework in an embodiment of the present invention. Detailed Implementation
[0021] Exemplary embodiments of the present disclosure will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the disclosure to those skilled in the art. It should be noted that, unless otherwise specified, the embodiments and features described herein can be combined with each other. The present invention will now be described in detail with reference to the accompanying drawings and embodiments.
[0022] This embodiment proposes a closed-loop processing method for monitoring cow behavior by integrating intelligent agents and an improved detection network. The technical solution of this embodiment follows a closed-loop process of "video acquisition—behavior detection—event structuring—recommendation generation—execution regularization—evaluation feedback." It enhances robustness in complex scenarios by introducing adaptive multi-scale attention and a lightweight weighted feature fusion mechanism on the detection side, and transforms detection evidence into executable solutions through multi-agent collaboration on the decision side. Simultaneously, it uses a consistency metric to quantitatively evaluate and iteratively optimize the quality of recommendations. Compared with existing solutions that only output detection results or rely on threshold alarms, this invention differs in two ways: firstly, it employs an AdaMSA module with soft-weighted multi-scale branches and spatial attention enhancement, and a LwFPN module with fast weighted fusion in the detection network, to improve feature representation and cross-layer alignment under conditions of dense occlusion and small targets; secondly, it establishes a recommendation priority mechanism driven by risk factors (uncertainty, crowding, etc.), and forms a traceable, replayable, and iterative closed-loop processing system through the "recommendation—execution—evaluation" link.
[0023] Figure 1 The overall process of this invention (YOLO-Agent overall process) is shown: after the pasture video stream is decoded and frame-stripped to form an image frame sequence, it enters the detection stage. The detection network outputs results such as behavior category, target bounding box and confidence level. Subsequently, the detection results are organized into structured event records and further enter the closed-loop decision-making stage. The link consisting of suggestion generation, execution regularization and evaluation feedback outputs priority disposal suggestions and executable steps, and at the same time forms evaluation results that can be used for iterative optimization, realizing closed-loop linkage from behavior perception to disposal decision.
[0024] In one embodiment, the system of the present invention includes at least: a video acquisition module, a video preprocessing module, a behavior detection module, an event structuring module, a suggestion generation module, an execution regularization module, an evaluation feedback module, and a result output module. The video acquisition module acquires video streams from fixed cameras in the ranch. The video preprocessing module, connected to the video acquisition module, decodes, extracts frames, normalizes scale, and performs necessary image enhancement on the video stream to form a continuous sequence of image frames. The behavior detection module, connected to the video preprocessing module, performs inference on each frame and outputs detection results including behavior category, bounding box coordinates, and confidence level. The event structuring module, connected to the behavior detection module, converts the detection results into structured event records and calculates risk factors. The suggestion generation module, connected to the event structuring module, generates disposal suggestions based on the structured event records and assigns priorities. The execution regularization module, connected to the suggestion generation module, converts disposal suggestions into a sequence of executable steps under resource constraints. The evaluation feedback module, connected to the execution regularization module, scores the suggestion chain from multiple dimensions and calculates consistency indicators. The result output module, connected to the suggestion generation module, execution regularization module, and evaluation feedback module, outputs the disposal suggestions, execution steps, and evaluation results to a display terminal, mobile device, or alarm system. The above modules can be deployed on edge computing devices or central servers. The video acquisition module is connected to the camera, and other modules realize data transmission through local bus or network interface. The overall signal flow is "video stream → frame sequence → detection output → structured event → handling suggestion → execution steps → evaluation feedback → output".
[0025] In one implementation, the method of the present invention includes at least the following steps: First, acquiring a pasture video stream and forming an image frame sequence; second, performing behavior detection on the image frames to obtain the bounding box, behavior category, and confidence level of each individual cow in each frame, and counting and statistically analyzing similar behaviors; subsequently, organizing the detection output into a structured event record, the structured event record including at least the fields of image resolution, count of each behavior category, bounding box coordinates and confidence level of each target, and behavior label; based on this, extracting uncertainty representation from the detection confidence distribution and crowding representation from the target distribution in the neighborhood, used to drive risk classification and disposal priority determination; then, the suggestion generation module outputs structured disposal suggestions, the disposal suggestions including at least: behavior type, disposal priority, judgment basis, and operation suggestion items; then, the execution regularization module outputs a time-sequential, implementable sequence of execution steps under resource constraints; finally, the evaluation feedback module performs multi-dimensional scoring on the suggestion chain and calculates a consistency index to form feedback results that can be used for strategy iteration.
[0026] (I) Structure, connection relationships and functions of the behavior detection module (YOLO-ALFA) Figure 2The overall architecture of the detection network of the present invention (YOLO-ALFA architecture) is shown: the architecture consists of a feature extraction backbone network, a feature fusion network and a detection head. The input image is processed by the backbone network to extract multi-level features and then enters the fusion path. An adaptive multi-scale attention module is introduced in the key feature path to enhance the discrimination and localization feature expression in complex scenes. Cross-scale fusion and alignment are completed through a lightweight weighted feature pyramid structure. Finally, the detection head outputs the classification results, bounding box regression results and confidence scores at each scale, thereby maintaining more stable detection performance in dense occlusion and small target scenes.
[0027] The behavior detection module employs an improved one-stage detection network, YOLO-ALFA, to simultaneously perform multi-target localization and behavior category recognition on a single frame image. YOLO-ALFA comprises three parts: a backbone feature extraction network, a feature fusion network, and a detection head. The backbone network performs multi-layer convolutions on the input image to extract feature maps at different scales. The feature fusion network performs cross-scale fusion of features from different levels and outputs multi-scale fused features. The detection head outputs classification results, bounding box regression results, and confidence scores on the fused features at each scale. To improve detection robustness in scenarios with dense occlusion, small targets, and scale variations, this invention introduces an adaptive soft-weighted multi-scale attention module, AdaMSA, into the key layers or feature fusion paths of the backbone network. Furthermore, it replaces or modifies the conventional FPN / PAN structure with a lightweight weighted feature pyramid network, LwFPN, to improve cross-layer alignment quality and control computational overhead.
[0028] Figure 3 The Adaptive Soft-Weighted Multi-Scale Attention Module (AdaMSA) is illustrated: the input features are first dimensionality-reduced to reduce computational overhead, and then channel responses are modulated through channel attention; subsequently, multi-scale contextual information is extracted by multiple depthwise separable convolutional branches with different dilation rates, and soft-weighted fusion is achieved through Softmax normalization of learnable weights, enabling the network to adaptively adjust the contribution of information at different scales; finally, spatial attention is used to generate a spatial weight map to highlight key regions and suppress background interference, and residual connections and dimensionality upscaling are used when necessary to restore the number of channels, thereby enhancing the distinguishable features of occluded regions and small targets.
[0029] The AdaMSA module enhances the multi-scale expressive power of single-layer features and the response intensity of key regions. Its structure includes a dimensionality reduction mapping unit, a channel attention unit, a multi-scale context extraction unit, a soft-weighted fusion unit, and a spatial attention unit connected in sequence. The dimensionality reduction mapping unit performs channel compression on the input features to reduce computational cost; the channel attention unit can use an efficient channel attention mechanism to obtain channel weights and recalibrate the input features; the multi-scale context extraction unit includes at least three parallel branches, each branch using depthwise separable convolutions with different dilation rates to extract contextual information at different scales; the soft-weighted fusion unit sets learnable weights and performs weighted summation on the outputs of each branch after Softmax normalization to achieve adaptive adjustment of contributions at different scales; the spatial attention unit generates a spatial weight map based on channel aggregation features to highlight the target region and suppress background interference, where shallow layers can use larger convolution kernels to obtain a larger receptive field, and deep layers can use smaller convolution kernels to reduce computational cost. The mathematical expressions related to AdaMSA correspond to formulas (1)–(7).
[0030] (1) Dimensionality reduction mapping: To reduce computational overhead, AdaMSA first performs pointwise convolution (1×1 convolution) on the input feature map. Dimensionality reduction to intermediate channel number ,in This is the scaling factor (default 4.0). The process consists of convolutional layers, batch normalization (BatchNorm), and the SiLU activation function to generate dimensionality-reduced features. :
[0031] (2) Channel Attention Modulation: AdaMSA uses ECA (Efficient Channel Attention) as the channel attention module. ECA attention captures local cross-channel interactions through one-dimensional convolution, without the need for dimensionality reduction, and its kernel length is... Adaptive adjustment:
[0032] in This mechanism significantly reduces the number of parameters while maintaining channel sensitivity. If the CBAM style is chosen, channel weights are generated using a multilayer perceptron (MLP) with dimensionality reduction, combining average pooling and optional max pooling branches. Channel attention output. for:
[0033] in This represents element-wise multiplication, and CA is the channel attention function.
[0034] (3) Multi-scale branch soft weighting: To capture multi-scale contextual information, AdaMSA employs three depthwise separable convolution (DWConv) branches with different dilation rates of 1, 2, and 3, respectively. The equivalent receptive fields are approximately equal to 3×3, 5×5, and 7×7 convolutions. The outputs of each branch are processed by learnable weights. Soft-weighted fusion is performed, with weights normalized using Softmax:
[0035] This mechanism enables the model to adaptively adjust contributions at different scales, enhancing its ability to represent small targets and occluded regions. The learnable fusion weights in Equation (5) Initially, the vectors are set to all 1s. After Softmax normalization, the three branches are fused with equal weights in the initial training phase (each branch is about 1 / 3), and then the weights of each scale are adaptively adjusted by data.
[0036] (4) Spatial Attention Enhancement: The spatial attention module calculates the mean and maximum feature maps along the channel dimension and concatenates them. A spatial weight map is then generated via convolutional layers to highlight key regions. Shallow layers (P2–P4 fusion path) use 7×7 convolutional kernels to obtain a larger spatial receptive field, while deep layers (P4–P5 refinement path) use 3×3 convolutional kernels to reduce computational overhead.
[0037] SA is the spatial attention function, whose output is multiplied element-wise with the multi-scale features to obtain the spatial augmented features.
[0038] (5) Feature fusion and dimensionality enhancement: outputting spatial attention With channel attention output The data is added together to achieve complementary fusion of multi-scale and channel information. Then, an upscaling layer (1×1 convolution + BatchNorm) is used to restore the number of channels. If residual connections are enabled, then for the input... Perform a 1×1 convolution projection, add it to the up-dimensional output, and then activate it using SiLU:
[0039] Figure 4The Lightweight Weighted Feature Pyramid Network (LwFPN structure) is shown: while retaining bidirectional cross-scale connections, dedicated fusion modules are constructed for different target levels from P2 to P5. A fast weighted fusion mechanism is used at the fusion nodes to assign learnable weights to the input features. Stable weighted fusion output is achieved through non-negative constraints and normalization. This structure dynamically selects more complementary combinations of input features through a hierarchical adaptive fusion strategy to improve cross-layer alignment quality and boundary regression stability, while avoiding the additional operator overhead caused by complex normalization, making it more suitable for real-time deployment scenarios.
[0040] LwFPN is used to improve the alignment quality and numerical stability of cross-layer feature fusion. Its structure can include multi-layer fusion nodes with top-down and bottom-up paths. Each fusion node sets learnable fusion weights for input features from different layers, and performs weighted fusion after non-negativity constraints and normalization, and then outputs fused features through convolution. Unlike traditional feature pyramids with fixed topology and fixed fusion weights, LwFPN uses a fast weighted fusion method to make the contributions of features from different layers during fusion learnable, reducing localization instability caused by noise backflow and excessive smoothing; at the same time, it can adopt a restricted neighborhood fusion strategy for different layers to make the fusion range more match the distribution characteristics of the target at that layer scale, thereby improving the stability of bounding box regression under high IoU threshold. The mathematical expression of LwFPN's fast weighted fusion and normalization corresponds to the original formulas (9)–(11).
[0041] (1) Fast Weighted Fusion Mechanism: The core innovation of LwFPN lies in the Fast Weighted Fusion module, which is mathematically expressed as follows: Let the set of input feature maps be... ,in The number of input feature maps, Fusion weights Calculated through the following process:
[0042] in This is the numerical stability constant. Weighted fusion output. for:
[0043] Finally, the output is obtained through the convolutional layer:
[0044] For different target levels, LwFPN adopts a specific level-adaptive fusion strategy.
[0045] (II) The structure, connections, and functions of event structuring and risk factor calculation The event structuring module receives the detection results of each frame output by the behavior detection module and converts them into unified structured event records. The event record at least includes: image resolution information, the count of various types of targets, the bounding box coordinates of each target, the corresponding behavior category label and confidence. To make the disposal decision not rely on a single threshold but reflect the scene complexity and detection uncertainty, the present invention further calculates risk factors in the event structuring stage: the uncertainty characterization quantity can be obtained from the lower quantile P10 of the confidence distribution of the same frame, which is used to reflect the low-confidence risk in occluded or confused scenes; the crowding degree characterization quantity can be obtained by counting the number of targets in a fixed neighborhood with the center of the target box as the anchor and calculating the average IoU of the target boxes in the neighborhood, which is used to reflect the degree of local occlusion overlap and potential conflict risk.
[0046] (III) Structure, connection relationship and function of the closed-loop decision-making module (BAER) Figure 5 The closed-loop decision-making framework (BAER agent framework) is shown: after the structured behavior record enters the recommendation generation agent, a structured plan including behavior type, disposal priority (high / medium / low), judgment basis and operation recommendation items is output, and the priority is jointly determined by perception evidences such as abnormal category, target quantity, local crowding degree and detection confidence; then the execution agent performs secondary regularization on the plan under the condition of limited resources such as personnel and equipment, converts the abstract recommendation into an executable step sequence with time sequence constraints, and attaches feasibility evaluation and brief execution feedback; finally, in the evaluation stage, multiple evaluation agents score the recommendation chain in multiple dimensions and calculate the consistency index and its confidence interval, which are used to characterize the recommendation quality and decision stability and provide a basis for rule iteration.
[0047] The closed-loop decision-making module includes a recommendation generation sub-module, an execution regularization sub-module and an evaluation feedback sub-module. The recommendation generation sub-module (Behavior Advisor) is connected to the event structuring module and is used to convert the structured event record into a structured disposal recommendation. The disposal recommendation at least includes: behavior type, disposal priority, judgment basis, and recommendation items for on-site operation. The determination of the disposal priority is not limited to "whether a certain type is detected", but comprehensively maps the risk levels by combining the prior risk of the abnormal category, target count, uncertainty characterization quantity and crowding degree characterization quantity, so as to output priorities such as high / medium / low, and the review intensity and disposal strength can be adjusted accordingly.
[0048] The Execution Agent submodule, connected to the suggestion generation submodule, transforms action suggestions into a sequence of executable steps under resource constraints. Resource constraints may include, but are not limited to, the number of available personnel, available equipment, accessible areas, and available time windows for action. The step sequence output by the Execution Agent submodule may include: operation order, key checkpoints, optional branches, and resource feasibility descriptions, enabling the suggestions to be directly implemented on-site, rather than remaining at the level of abstract description.
[0049] The Review submodule is connected to the Execution Regulation submodule and is used to quantitatively evaluate the "behavior-recommendation-execution" chain and output consistency measurement results. The evaluation dimensions include at least clarity, feasibility, risk mitigation, welfare impact, timeliness, and overall evaluation, with a scoring range of 1–5 points. To assess the stability of the multiple evaluators' judgments on the quality of the recommendations, the Review submodule calculates Krippendorff's α and can further estimate its confidence interval through bootstrap to quantify the consistency level and provide a basis for adjusting rules or cue constraints. The consistency measurement and confidence interval calculation correspond to formulas (21)–(24).
[0050] Reporting only the average score may mask the issue of consensus among raters. Therefore, this paper introduces Krippendorff's α to measure the consistency of multiple raters on interval ratings. Krippendorff's α typically ranges from -∞ to 1; the closer α is to 1, the higher the consistency. When α ≈ 0, the consistency is close to random; when α < 0, the consistency is below randomness. Its core idea is to compare observed disagreements. Disagreement with expectations If the ratings from the evaluators are highly consistent, then Significantly smaller than Therefore, α is higher when the sample size is larger and lower when the sample size is smaller; conversely, α is lower when the sample size is smaller. This paper calculates α according to equations (21)–(24) and uses bootstrap to give a 95% confidence interval to characterize the consistency uncertainty under finite sample conditions. Krippendorff's method is used to calculate α. (Interval rating) measures the consistency of the three ratings and reports a 95% confidence interval. To observe the "coincidence matrix", The expected "coincidence matrix" obtained by marginal independence:
[0051] (iv) Alternative implementation methods and alternative technical requirements Without departing from the overall concept of this invention, the following alternative solutions can achieve the same or similar technical effects: First, the baseline network of the behavior detection module is not limited to a specific version of a one-stage detector, but can be replaced by a similar real-time detection network, as long as the combination idea of "adaptive multi-scale attention enhancement + lightweight weighted feature fusion" is retained; Second, the number of multi-scale branches in AdaMSA can be expanded from three branches to two or four branches, and the dilation rate can be adjusted according to the camera height and target scale distribution; Third, the convolution kernel size of spatial attention can be switched between larger and smaller kernels according to the deployed computing power, so as to make a trade-off between receptive field and computational cost; Fourth, the fusion of LwFPN. The topology can be adjusted by adding or removing fusion nodes based on the number of output scales, and the constraint method for fusion weights can adopt other numerical stabilization strategies based on non-negative normalization; fifth, in addition to P10, other lower quantiles or quantile interval indicators can be selected for the uncertainty representation in the event structuring module, as long as they can stably represent low confidence risk; sixth, in addition to "number of neighboring targets + average IoU", equivalent indicators such as neighborhood density, center distance, or occlusion ratio can be introduced for the crowding representation; seventh, the number of agents in the closed-loop decision module can be adjusted, the scoring dimensions can be merged or expanded without changing the principle of "multi-dimensional quantification + consistency measurement", and the output format can be connected to the alarm system or work order system to achieve automatic dispatch.
[0052] The specific implementation methods and effects of the key modules in this embodiment are as follows: 1) Implementation and function of the AdaMSA module In a feasible implementation, the AdaMSA module is concatenated after the shallow or mid-level feature outputs of the backbone network. The input is a feature map, and the output is a feature map enhanced by attention. This module includes: 1×1 convolutional dimensionality reduction mapping, ECA channel attention, multi-scale branches (using depthwise separable convolutions with different dilation rates), soft-weighted fusion of learnable weights normalized by Softmax, and spatial attention enhancement; where shallow spatial attention can use 7×7 convolutional kernels to expand the receptive field, and deep spatial attention can use 3×3 convolutional kernels to balance efficiency. This structure can suppress background noise and highlight key regions in both channel and spatial dimensions, and adaptively enhance information at different scales through the soft weighting mechanism of multi-scale branches, thereby improving the discrimination and localization stability under occlusion and small target conditions. The relevant mathematical expressions of AdaMSA correspond to formulas (1)–(7).
[0053] 2) Implementation and Function of the LwFPN Module In a feasible implementation, LwFPN is deployed as a feature fusion network between the backbone network and the detection head to perform weighted fusion of multi-level feature maps. LwFPN sets learnable fusion weights for the input features at each fusion node, constrains them to non-negativity using ReLU or equivalent methods, normalizes them, performs weighted summation, and then outputs the fused features via convolution. It can also employ a restricted neighborhood fusion strategy to make the fusion range of different levels more closely match the target scale distribution, reducing noise backflow and excessive smoothing. This improves cross-layer alignment quality and boundary regression stability, especially enhancing localization accuracy under high IoU threshold evaluation. The fast weighted fusion and normalization calculations of LwFPN correspond to formulas (9)–(11).
[0054] 3) Implementation methods and functions of risk factor calculation and priority mapping After calculating P10 and local congestion during the event structuring phase, both can be used together with the prior anomaly category for risk classification. P10 is used to characterize low-confidence risk, and congestion is used to characterize occlusion and overlap complexity. When congestion increases or P10 decreases, the system tends to increase the intensity of review or the priority of handling, so that it can still maintain sensitivity to potential risks in scenarios with severe occlusion and uncertain evidence.
[0055] 4) Implementation methods and functions of evaluation and feedback The evaluation feedback module outputs multi-dimensional scores and consistency measurement results, so that the disposal recommendations no longer rely solely on subjective experience judgments, but have quantifiable, comparable, and iterative evidence. This module uses Krippendorff's α and bootstrap confidence intervals to measure consistency, corresponding to formulas (21)–(24), to determine the stability of different evaluation subjects' judgments on the quality of recommendations, and adjusts the recommendation generation constraints, thresholds, or priority rules accordingly.
[0056] In summary, this invention addresses two key technical challenges in complex scenarios—instable detection and difficult implementation of operational and maintenance measures—through a holistic design of "highly robust detection + closed-loop decision-making." On the detection side, it introduces adaptive multi-scale attention and a lightweight weighted feature fusion mechanism to improve feature representation and cross-layer alignment quality in scenarios with dense occlusion, small targets, and multi-scale variations, thereby enhancing the accuracy and stability of behavior detection while controlling parameter scale and inference latency. On the decision-making side, the detection results are organized into a structured behavioral event flow, comprehensively utilizing category counting, bounding boxes, confidence levels, and their distribution features. It also introduces the P10 quantile under confidence levels to represent uncertainty and combines the number of targets within a fixed neighborhood with the average IoU to characterize local congestion. This allows for the classification of behavioral risks and the determination of handling priorities (high / medium / low), further generating executable handling suggestions and step sequences. Multi-dimensional scoring and consistency metrics are used to quantitatively evaluate the quality and stability of the suggestions, providing a basis for continuous optimization of handling strategies and threshold rules.
[0057] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the specific implementation of the present invention. Any modifications or equivalent substitutions that do not depart from the spirit and scope of the present invention should be covered within the protection scope of the claims of the present invention.
Claims
1. A closed-loop processing method for monitoring dairy cow behavior by integrating intelligent agents and improved detection networks, characterized in that, Includes the following steps: The ranch video stream is acquired and preprocessed to form an image frame sequence; The YOLO-ALFA detection network is used to detect behavior in the image frames, and the behavior category, bounding box coordinates and confidence score of each individual cow in each frame are output. The detection output is organized into a structured event record, which includes image resolution information, target count for each category, bounding box coordinates for each target, corresponding behavior category label and confidence level; The lower quantile P10 is extracted from the detection confidence distribution as an uncertainty characterization quantity, and the crowding characterization quantity is extracted from the neighborhood target distribution. The crowding characterization quantity is obtained by counting the number of targets in a fixed neighborhood with the target box center as the anchor and calculating the average IoU of the target boxes in the neighborhood. Based on the structured event records and the risk factors, a handling suggestion is generated. The handling suggestion includes behavior type, handling priority, judgment basis and operation suggestion items. The handling priority is jointly determined by the prior risk of the anomaly category, the target count, the uncertainty characterization quantity and the crowding characterization quantity. Under resource constraints, the proposed solutions are transformed into a time-sequential sequence of executable steps. The chain from the proposed treatment to the sequence of executable steps is scored in multiple dimensions and a consistency index is calculated to generate feedback results that can be used for strategy iteration.
2. The method according to claim 1, characterized in that, The YOLO-ALFA detection network includes a backbone feature extraction network, a feature fusion network, and a detection head. The adaptive multi-scale attention AdaMSA module is introduced into the key feature path to enhance the discrimination and localization feature expression in complex scenes, and cross-scale fusion and alignment are completed through a lightweight weighted feature pyramid network LwFPN.
3. The method according to claim 2, characterized in that, The AdaMSA module includes: The dimension reduction mapping unit uses 1×1 convolution to reduce the dimensionality of the input features to the intermediate number of channels, with a scaling factor of 4.0; The channel attention unit uses the ECA mechanism to capture local cross-channel interactions through one-dimensional convolution, and the kernel length is adaptively adjusted according to the number of channels. The multi-scale context extraction unit includes at least three parallel branches, each branch employing depthwise separable convolutions with different dilation rates to extract context information at different scales, wherein the dilation rates are 1, 2, and 3, respectively. The soft-weighted fusion unit sets learnable weights and performs a weighted summation of the outputs of each branch after Softmax normalization, thereby achieving adaptive adjustment of contributions at different scales. The spatial attention unit generates a spatial weight map based on channel aggregation features to highlight the target region and suppress background interference. The shallow layers use 7×7 convolutional kernels to obtain a larger receptive field, while the deep layers use 3×3 convolutional kernels to reduce computational overhead.
4. The method according to claim 2, characterized in that, The LwFPN includes multi-layer fusion nodes with top-down and bottom-up paths. Each fusion node sets learnable fusion weights for input features from different levels, performs weighted fusion after non-negative constraints and normalization, and then outputs fused features through convolution.
5. The method according to claim 4, characterized in that, The LwFPN employs a fast weighted fusion mechanism, assuming the input feature map set is {X}. i }, fusion weight w i The weighted fusion output is the sum of the products of each input feature and its corresponding weight, calculated through ReLU activation and normalization. Finally, the fused feature is output through a convolutional layer.
6. The method according to claim 1, characterized in that, The processing priority is divided into three levels: high, medium, and low. When the congestion level increases or the P10 decreases, the processing priority is increased and the review intensity is strengthened.
7. The method according to claim 1, characterized in that, The closed-loop decision-making adopts the BAER framework, including: It is recommended to generate intelligent agents to transform structured event records into structured handling suggestions; An execution agent is used to transform disposal suggestions into a sequence of executable steps under resource constraints, including the number of available personnel, available equipment, accessible areas, and available disposal time windows. An evaluation agent is used to quantitatively evaluate the chain from the agent that generates the suggestion to the agent that executes it.
8. The method according to claim 7, characterized in that, The evaluation agent performs multi-dimensional scoring, including clarity, feasibility, risk mitigation, welfare impact, timeliness, and overall evaluation, with a scoring range of 1-5 points.
9. The method according to claim 8, characterized in that, Krippendorff's α coefficient is used to measure the consistency of multiple raters on interval ratings, and the 95% confidence interval is estimated by the bootstrap method to characterize the consistency uncertainty under finite sample size.
10. A closed-loop processing system for monitoring dairy cow behavior that integrates intelligent agents and improved detection networks, characterized in that, include: The video acquisition module is used to acquire video streams from fixed cameras on the ranch. The video preprocessing module, connected to the video acquisition module, is used to decode, extract frames, normalize scales, and enhance images of the video stream to form a continuous sequence of image frames. The behavior detection module, connected to the video preprocessing module, uses the YOLO-ALFA detection network to perform inference on each frame of the image and outputs detection results including behavior category, bounding box coordinates and confidence level. The event structuring module, connected to the behavior detection module, is used to convert the detection results into structured event records and calculate risk factors, including uncertainty representation and crowding representation. The suggestion generation module, connected to the event structuring module, is used to generate handling suggestions and give priorities based on structured event records; The execution regularization module, connected to the suggestion generation module, is used to transform disposal suggestions into an executable sequence of steps under resource constraints; The evaluation and feedback module, connected to the execution regularization module, is used to score the suggestion chain from multiple dimensions and calculate the consistency index. The result output module, connected to the suggestion generation module, execution regulation module, and evaluation feedback module, is used to output the handling suggestions, execution steps, and evaluation results to the display terminal, mobile terminal, or alarm system.