Method for recognizing cattle leaving their sheds

By using a single wide-angle camera and an improved YOLOv8 model to identify key points on the head and torso of cattle, and combining this with the Deepsort algorithm, the problem of existing cattle monitoring systems being unable to judge dynamic behavior in real time has been solved, achieving high-precision and low-cost monitoring of cattle leaving the pen.

CN120673447BActive Publication Date: 2025-11-14CHANGZHOU WUITU SMART TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511188520.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-08-25
Publication Date
2025-11-14
Estimated Expiration
2045-08-25

AI Technical Summary

Technical Problem

Existing cattle entry and exit monitoring systems cannot judge the dynamic behavior of cattle in real time, and the hardware settings are complex, resulting in a high stress rate and low animal welfare.

Method used

Using a single wide-angle camera combined with an improved YOLOv8 model, the P-CBS module and I-MAB multi-scale attention mechanism are used to identify key points on the head and torso of cattle. Combined with the Deepsort algorithm, the cattle's trajectory is tracked to achieve high-precision monitoring of cattle leaving the pen.

Benefits of technology

Real-time inference was achieved on edge devices, reducing the number of devices and energy consumption, improving the accuracy of cattle behavior recognition, reducing false detection rate, and lowering overall costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120673447B_ABST
    Figure CN120673447B_ABST
Patent Text Reader

Abstract

This application relates to the field of animal behavior monitoring technology, and in particular to a method for recognizing the trajectory of cattle leaving their barns. It employs a single wide-angle camera to acquire images of the entrance and exit positions within the barn; identifies key points on the head and torso of the cattle based on an improved YOLOv8 model, and obtains head and torso detection boxes; the convolutional layers in the backbone network of the improved YOLOv8 model are replaced with P-CBS modules, and an I-MAB multi-scale attention mechanism is added to the neck network. The MAB comprises two parts: a lightweight multi-scale large kernel attention (I-MLKA) module and an I-GSAU gate space attention unit; the movement trajectory of the cattle is determined based on the head and torso detection boxes. By adopting a hardware deployment scheme using a single camera and an edge computing box, convenient device installation is achieved. Lightweight computation is achieved through model pruning using P-CBS + lightweight neck, enabling real-time inference on edge devices, reducing the number of model parameters while improving recognition accuracy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of animal behavior monitoring technology, and in particular to a method for identifying the trajectory of cattle leaving their sheds. Background Technology

[0002] In modern ranch management, cattle need to enter and exit the barn multiple times a day to complete standardized production activities such as milking and feeding. In the traditional model, equipment control relies heavily on manual operation, or multiple cameras are used to monitor the entrances and exits, or sensors are used to detect whether cattle are passing through.

[0003] However, existing cattle entry and exit monitoring systems can only determine the presence of a target object, not the dynamic behavior of the cattle. Furthermore, multi-camera monitoring methods are complex to set up and require empty cattle sheds. To achieve real-time monitoring of cattle dynamic behavior and avoid human error, there is an urgent need to research a high-precision method for monitoring cattle entry and exit from cattle sheds that can reduce stress rates and improve animal welfare. Summary of the Invention

[0004] This invention aims to solve one of the problems existing in the background art.

[0005] Therefore, the present invention provides a method for recognizing the trajectory of cattle leaving their sheds.

[0006] The technical solution adopted by this invention to solve its technical problem is:

[0007] A method for recognizing the trajectory of cattle leaving their sheds, comprising,

[0008] Step 1: Use a single wide-angle camera to acquire images of the entrance and exit locations in the cattle shed;

[0009] Step 2: Based on the improved YOLOv8 model, identify key points of the cow's head and torso, and obtain the head detection box and torso detection box.

[0010] The convolutional layers in the backbone network of the improved YOLOv8 model are replaced with P-CBS modules, and the I-MAB multi-scale attention mechanism is added to the neck network. The I-MAB multi-scale attention mechanism consists of two parts: a lightweight multi-scale large kernel attention module and a gate space attention unit.

[0011] Step 3: Determine the movement trajectory of the cattle based on the head detection box and torso detection box.

[0012] Furthermore, the lightweight multi-scale large kernel attention module includes a GhostConv branch, an expanded DW-Conv branch, and a reparameterized large kernel branch. The features are processed by the GhostConv branch, the expanded DW-Conv branch, and the reparameterized large kernel branch, respectively, and then concatenated and output.

[0013] Furthermore, the GhostConv branch compresses channels using 1×1 pointwise convolutions and then generates pseudo-features using 3×3 depthwise separable convolutions; the dilated DW-Conv branch uses 7×7 depthwise separable convolutions with an inflation rate of 2 to 3, resulting in an equivalent receptive field of approximately 19×19; the reparameterized large kernel branch uses two levels of 3×3 or 5×5 separable convolutions stacked during training and merges them into a static 11×11 depthwise convolution kernel during inference.

[0014] Furthermore, in the gate spatial attention unit, after feature input, a two-branch prior is first performed, which includes spatial / orientation prior and channel prior. After the two-branch prior is completed, the output results of the two branches are fused through multiplicative gating. The fused features are then convolved using geometric alignment. Finally, the output of the geometrically aligned convolution is added to the residual of the original input element-wise to obtain the final output of the gate spatial attention unit.

[0015] Furthermore, in step three, the center points of the head detection frame and the torso detection frame of the cow are taken respectively, and the head coordinates and tail coordinates are obtained respectively. Then they are connected into a straight line L, and the direction of the cow is determined with the head coordinates as the front.

[0016] Furthermore, in step three, when the cow moves, Deepsort is used to track the unique ID on each cow's ear tag to obtain the pixel value of the position movement. Points whose movement exceeds the threshold are added to the trajectory calculation, and the trajectory is smoothed. The direction of entry and exit is determined by the offset direction of the straight line L. The initial judgment window is set to 10, and the movement threshold is set to 25. When the judgment window reaches the set value, the head and tail coordinates are subtracted, the tangent value is calculated, and the straight line of the direction is fitted.

[0017] Furthermore, the P-CBS module in the backbone network inputs a feature map, which is first divided, then passes through a sparse partial convolution to reduce parameters, and then passes through batch normalization and silu activation functions to finally obtain the feature map.

[0018] A computer device, comprising:

[0019] processor;

[0020] Memory, used to store executable instructions;

[0021] The processor is configured to read the executable instructions from the memory and execute the executable instructions to implement the cattle leaving the pen trajectory recognition method as described above.

[0022] A computer-readable storage medium storing a computer program that, when executed by a processor, causes the processor to implement the cattle leaving the pen trajectory recognition method as described above.

[0023] The beneficial effects of this invention are that by employing P-CBS + a lightweight neck for model pruning, lightweight computation is achieved, enabling real-time inference on edge devices (response latency ≤200ms). Specifically, this application improves accuracy by 3% while reducing the number of model parameters by replacing some convolutional layers with P-CBS modules and improving the backbone structure. By adding the I-MAB multi-scale attention mechanism to the neck part and designing I-MLKA and I-GSAU modules, more accurate extraction and recognition of head and torso features of cattle are achieved. By increasing the IOU threshold of the initial YOLO model data and combining it with the Deepsort tracking algorithm, accurate judgment and tracking of cattle trajectories are achieved with a false detection rate of <1%.

[0024] By employing object detection combined with a multi-object Deepsort tracking algorithm, a high-accuracy identification rate (up to 98.7%) of cattle entry and exit behavior in high-density cattle herd scenarios was achieved, maintaining an accuracy rate of 97% even when multiple cattle overlapped.

[0025] By adopting a hardware deployment scheme of a single camera and an edge computing box, convenient equipment installation was achieved (the construction window was shortened to 20 minutes), the number of devices was reduced by 90%, energy consumption was reduced by 95%, the overall cost was reduced by 90%, and redundant data was avoided. Attached Figure Description

[0026] The present invention will be further described below with reference to the accompanying drawings and embodiments.

[0027] Figure 1 This is a schematic diagram of the structure of the improved YOLOv8 model in this invention.

[0028] Figure 2 This is a schematic diagram of the P-CBS module in this invention.

[0029] Figure 3 This is a schematic diagram of the lightweight multi-scale large-core attention module in this invention.

[0030] Figure 4 This is a schematic diagram of the gate spatial attention unit in this invention.

[0031] Figure 5 This is a schematic diagram illustrating the implementation process of the I-MAB multi-scale attention mechanism in this invention.

[0032] Figure 6 This is a schematic diagram of the trajectory recognition of cattle leaving the pen in this invention.

[0033] Figure 7 This is a schematic diagram of the trajectory recognition of cattle entering the barn in this invention. Detailed Implementation

[0034] The present invention will now be described in further detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, illustrating only the basic structure of the invention, and therefore only show the components relevant to the invention.

[0035] In the description of this invention, it should be understood that the terms "center," "longitudinal," "lateral," "length," "width," "thickness," "upper," "lower," "front," "rear," "left," "right," "vertical," "horizontal," "top," "bottom," "inner," "outer," "clockwise," "counterclockwise," "axial," "radial," and "circumferential," etc., indicating orientation or positional relationships, are based on the orientation or positional relationships shown in the accompanying drawings and are only for the convenience of describing the invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of the invention. Furthermore, features defined with "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this invention, unless otherwise stated, "a plurality of" means two or more.

[0036] In the description of this invention, it should be noted that, unless otherwise explicitly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in this invention based on the specific circumstances.

[0037] A method for recognizing the trajectory of cattle leaving their sheds includes the following steps:

[0038] Step 1: Image Acquisition and Preprocessing

[0039] A single wide-angle camera is installed above the entrance and exit of the cattle shed, covering the area of ​​the gate, to capture video streams in real time. The camera must be capable of low-light adaptation (≤1 Lux), with a frame rate ≥30 fps and a resolution ≥1080P. Environmental interference (such as changes in lighting and fixed obstacles) is eliminated through background modeling, and dynamic targets (cattle outlines) are extracted.

[0040] Step 2, Trajectory Recognition Algorithm

[0041] Key points of the head and torso of cattle were identified using an improved YOLOv8 model.

[0042] The S2.1YOLOv8 model includes a backbone network, a neck network, and a head network. Specifically, this application proposes a new module, P-CBS, in the head part, such as... Figure 2 As shown, the convolutional layer part of the backbone of the YOLOv8 model is transformed into a P-CBS module. The specific P-CBS process is as follows: the input feature map is then passed through a sparse partial convolution to reduce the parameters, followed by batch normalization and silu activation functions to obtain the feature map. The multiple layers are stacked to form the backbone of the variant YOLO, which improves the accuracy by 3% while ensuring a reduction in the number of original parameters. Subsequent features at different scales are then fed into the improved I-MAB module of the neck part.

[0043] The feature input and output process in backbone is as follows:

[0044] Image (640×640) input, enter C2f: first use 1×1 convolution to expand the channel to a wider intermediate dimension (to facilitate information mixing), then split into multiple sub-branches, one of which is directly connected and retained, and the remaining branches enter P-CBS in sequence;

[0045] P-CBS sub-branch: First, divide the channels into the "convolution-participating" backbone and identity bypasses according to a ratio r (e.g., 0.5–0.6); perform 3×3 lightweight convolution Partial-Conv → BN (Batch Normalization) → SiLU activation function on the backbone channels, and directly add the bypasses; in this way, only the r·Cin convolution is calculated (Cin: the number of channels in the input feature map, r: the participation ratio of Partial-Conv (between 0 and 1), meaning "only the r-r proportion of channels are convolved, and the rest (1-r) take the identity bypass", r·Cin is "the number of channels that actually participate in the 3×3 convolution calculation"). This significantly reduces the number of parameters and the number of multiply-ACcumulate operations (used to measure the computational cost of convolution / network);

[0046] Concat & 1×1 back-compression: Concatenate the direct-connect branches with each P-CBS output, and then use 1×1 convolution to compress the channels back to 256, resulting in C3 (80×80×256).

[0047] StageC4 (40×40×512) Downsample: Downsample C3 by 3×3 with stride=2 to obtain 40×40 features;

[0048] Entering C2f (same as above): the same "1×1 expansion → Split → multi-channel P-CBS → Concat → 1×1 backpressure", outputting C4 (40×40×512). Stage C5 (20×20×1024) is downsampled to 20×20. Entering C2f+multi-channel P-CBS: the same process, outputting C5 (20×20×1024).

[0049] The input feature map is first divided into three scales. Then, in the P-CBS part of the backbone, sparse lightweight convolutional partial convolution (P-Conv) is used to reduce parameters. The main idea is that the backbone generally has feature redundancy, and parameters need to be simplified for deployment at the edges. To compensate for the decrease in accuracy caused by parameter reduction, "width" is replaced with "depth + residual + multi-scale". P-Conv removes redundant convolutional weights, thus making the channels sparse. The three scales are parallelized to decompose the missing spatial semantics into different resolutions for processing. Multiple layers of residual stacking make up for the reduced expressive power from the depth direction. SiLU + BN recalibration maintains the dynamic range of features. Results: Nearly half the number of operators are used, but the information flow is more focused and the regularization is stronger. Objective indicators not only do not decrease but actually increase.

[0050] After passing through BN and Silu activation functions, the feature maps are finally obtained. Multiple layers are stacked to form the backbone of the variant YOLO, which improves the accuracy by 3% while reducing the number of original parameters. Subsequent features at different scales are then fed into the I-MAB module of the neck part.

[0051] The YOLOv8 model in this application employs a specialized neck network designed for the head and torso features of cattle. An I-MAB multi-scale attention mechanism is added to the existing neck network. I-MAB comprises two parts: a lightweight multi-scale large kernel attention module (I-MLKA) and a gate space attention unit (I-GSAU), as shown below. Figure 3 As shown.

[0052] (1)

[0053] (2)

[0054] (3)

[0055] (4)

[0056] Where LN represents layer norm, and feature X is normalized by ln to obtain N, as shown in equation (1); then it enters the I-MLKA module. The multi-head I-MLKA divides the feature into two in the channel dimension to obtain sub-features. , For a learnable scaling factor, one of the sub-features After different convolutional groups, finally... Multiplying and adding the characteristic X of the residual, corresponds to equation (2); as shown in equation (4), where As a learnable scaling factor, I-GSAU uses Ghost to double the number of channels, performs depthwise convolution on one half and feature weighting on the other half, and finally adds residual connections. It involves fusing the results of the I-MLKA branch and projecting them back to the channel consistent with X. It is a spatial a priori, It is a channel prior. It is geometric alignment DCN-Lite refinement and channel projection.

[0057] The designed I-MLKA combines large kernel decomposition and multi-scale learning, including the GhostConv branch, the DilatedDW-Conv branch, and the Reparameterized Large Kernel (RepLK) branch. The GhostConv branch compresses channels using 1×1 pointwise convolutions and then generates "cheap" pseudo-features using 3×3 depthwise separable convolutions. The DilatedDW-Conv branch uses 7×7 depthwise separable convolutions with a dilation rate of 2-3, resulting in an equivalent receptive field of approximately 19×19. The Reparameterized Large Kernel (RepLK) branch uses two levels of stacked 3×3 or 5×5 separable convolutions during training and merges them into a static 11×11 depthwise convolution kernel during inference.

[0058] Compared to the original MLKA, the I-MLKA module Ghost+DilatedDW+RepLK (small training kernel, large inference kernel) maintains the same receptive field, but reduces parameters / FLOPs by about 35–45%, and is cache-friendly.

[0059] Specifically, I-GSAU includes the following process: After feature input, a two-branch prior is performed, which includes spatial / orientation prior and channel prior. After completing the two-branch prior, the outputs of the two branches are fused using multiply gating. The fused features are then convolved using geometric alignment (DCN-Lite). Finally, the output of DCN-Lite is added element-wise with the residual of the original input (Skip) to obtain the final output of I-GSAU.

[0060] Spatial / Orientation Prior (CoordAtt): First, global aggregation is performed along the height and width axes respectively to obtain the context of "rows" and "columns", and then a spatial attention map is restored using a lightweight 1×1 convolution. This step encodes strongly oriented structures such as corridors and railings, telling the network "where is more important".

[0061] Channel Prior (ECA): Global average pooling is performed on the input to obtain statistics for each channel, and then a small convolution (1D, k=3 / 5) is used to interact with neighboring channels to output a channel weight vector. It has a very low cost, but can characterize "which type of channel is more important" (pattern, fur color, edge texture).

[0062] Multiply gating multiplies the spatial attention map and channel weights in a broadcast manner, resulting in a position-by-position × channel-by-channel gated map. This map is then used to scale the input features element-by-element. Intuitively, only features that are both "positionally important" and "channel important" will be amplified, while noise and irrelevant regions will be suppressed.

[0063] Geometric alignment (DCN-Lite) involves applying a lightweight deformable convolution (3×3, grouped or depthwise separable, offset predicted by a small convolution layer, modulation mask optional) to the already noise-filtered features. This step allows the sampling points to be micro-aligned with oblique shots, edge distortions, and slight occlusions, making the features closer to the true boundaries and contours. Residual addition (Skip) involves element-wise adding the output of DCN-Lite to the original input (if the number of channels is different, 1×1 alignment is used first) as the final output of I-GSAU. The residuals ensure direct gradient reachability, avoiding information loss due to excessive gating suppression.

[0064] The original GSAU is a single-path spatial attention, while I-GSAU is multi-path, considering both "where" and "what type of features". It also incorporates DCN-Lite for micro-alignment, specifically addressing issues like oblique shots, perspective distortion, and edge distortion. It's more stable for situations involving cow bodies touching edges or passing through fences. Finally, all components are 1×1, 1D convolutions, grouped / depthmial convolutions, and DCN-Lite, with INT8 / FP16 quantization friendliness and minimal incremental changes on edge devices.

[0065] The specific process of feature processing in the neck network is as follows: the feature maps are processed by the backbone to output three scales, C3, C4, and C5:

[0066] Among them, C5 size is 20×20×1024 → I-MLKA5. C5 enhances long dependencies in the I-MLKA multi-scale large kernel attention module, with the size unchanged and rich feature context; I-MLKA5 (20×20×1024) → Up2 upsampling ×2 to get 40×40×1024, and then 1×1 compressed to 256 channels;

[0067] C4 size is 40×40×512 → I-MLKA4 is enhanced as above and kept at 40×40×512 → C5 (size is 40×40×256) after upsampling ⊕ I-MLKA4 (40×40×512), and Concat spliced ​​to 40×40×768, then 1×1 compressed to 256 → finally P4 (40×40×256);

[0068] P4 (40×40×256) → Up2 upsampled ×2 to get 80×80×256;

[0069] C3 (80×80×256) → I-MLKA3 enhancement still 80×80×256 → upsampling to obtain P4 (80×80×256) ⊕ I-MLKA3 (80×80×256) → Concat splicing 80×80×512, 1×1 compressed to 256 → obtaining P3 (80×80×256);

[0070] P3 (80×80×256) → Down2 downsampling ×2 to get 40×40×256 and then input into Add4 (simple feature matrix summation);

[0071] P4 (40×40×256) → I-GSAU4 coordinates + channel attention + light DCN correction of distortion, output 40×40×256;

[0072] Add4: Down-P3 (40×40×256) ⊕ I-GSAU4 (40×40×256) elements are added and fused to generate P4′ (40×40×256);

[0073] P4′ (40×40×256) → Down2 downsamples ×2 to get 20×20×256 and sends it to Add5;

[0074] P5 (20×20×1024) (P5 is the structure of YOLOv8 itself) → 1×1 compressed to 256, and then output 20×20×256 through I-GSAU5;

[0075] Add5: Down-P4′(20×20×256)⊕I-GSAU5(20×20×256) elements are added and fused to generate P5′(20×20×256) (Neck final stage).

[0076] The final model structure is as follows: Figure 1 As shown.

[0077] Step 3, Trajectory Determination

[0078] The image, detected by the YOLO model, yields two types of targets: the head bounding box and the torso bounding box. The center points of these boxes are taken as the coordinates of the head and tail, respectively, and then connected by a straight line L. When the cow moves, Deepsort tracks the unique ID on each cow's ear tag, allowing for the acquisition of pixel values ​​indicating the movement. Points whose movement exceeds a threshold are added to the trajectory calculation. Furthermore, the IOU threshold is increased based on the initial data obtained by the YOLO model, better serving Deepsort's tracking needs.

[0079] The trajectory is smoothed, and the direction of entry / exit (rounding out / rounding in) is determined by the offset direction of the straight line L. The initial judgment window is set to 10, and the movement threshold is set to 25. When the judgment window reaches the set value, the head and tail coordinates are subtracted, the tangent value is calculated, and a straight line is fitted to the direction. With the head end as the front, an arrow is used to indicate the direction of the cow's movement trajectory.

[0080] Once a cow is detected to have completed its entry / exit action (e.g., completely passed through the gate), a command can be sent to the controller (e.g., start the milking equipment or close the gate). Response time: The delay from detection to signal transmission is ≤200ms, meeting real-time requirements.

[0081] Taking a 200-meter cattle shed on a ranch as an example, a single camera (model: HikvisionDS-2CD2347G2-LSU / SL) installed directly above the gate, covering a 10-meter field of view, can achieve cattle behavior recognition calculations using only a single camera and an edge computing box (processor). (Refer to...) Figure 4 , 5 Using the aforementioned cattle entry and exit trajectory recognition method for cattle monitoring, 500 entry and exit behaviors were detected, with a behavior recognition accuracy of 98.7%. Existing conventional models only have a recognition rate of 95%, and the false negative rate is 10% when multiple cattle overlap. Our model can still guarantee an accuracy of 97% even in the case of multiple cattle overlapping. In terms of hardware deployment, the proposed solution for cattle behavior recognition uses a single camera, eliminating the need for a cattle-free environment during installation, simplifying operation, and shortening the construction window to 20 minutes, adapting to the daily management rhythm of the ranch. Furthermore, the number of devices is reduced by 90%, and the computing power requirement is only an edge computing box (RK3588 chip). The edge computing device consumes only 10W, which is 95% lower than the energy consumption of traditional server solutions (200W), resulting in a 90% reduction in overall cost. Moreover, a single camera uses a wide-angle lens to cover key areas, avoiding redundant data caused by overlapping perspectives from multiple cameras.

[0082] In this application, an object detection + multi-object DeepSort tracking algorithm is adopted, with a false detection rate of <1%. Compared with the traditional DeepSort, this part mainly takes into account the dense distribution characteristics of cattle herds, and feeds the YOLO output box coordinates into vertical segments and reorders the adjacent IoUs before feeding them into DeepSort, reducing redundant matching in the same frame. This is mainly to adapt to cattle herd scenarios and prevent trajectory breakage caused by short occlusion of multiple cattle. The solution meets the requirements of high-density cattle herd scenarios. P-CBS + lightweight neck is used for model pruning to reduce computational parameters and achieve lightweight computation, enabling real-time inference on edge devices.

[0083] Example 2

[0084] This application provides a computer device including a processor and a memory. The memory stores at least one instruction or at least one program, which is loaded and executed by the processor to implement a method for recognizing the trajectory of cattle leaving their sheds as provided in the above method embodiments.

[0085] Example 3

[0086] This application embodiment also provides a computer-readable storage medium, which can be disposed in a server to store at least one instruction or at least one program segment related to implementing a cattle exit trajectory recognition method provided in the method embodiment. The at least one instruction or at least one program segment is loaded and executed by the processor to implement the cattle exit trajectory recognition method provided in the above method embodiment. Optionally, in this embodiment, the storage medium can be located in at least one of multiple network servers in a computer network. Optionally, in this embodiment, the storage medium can include, but is not limited to, various media capable of storing program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.

[0087] Based on the above-described preferred embodiments of the present invention, and through the foregoing description, those skilled in the art can make various changes and modifications without departing from the inventive concept. The technical scope of this invention is not limited to the contents of the specification, but must be determined by the scope of the claims.

Claims

1. A method for recognizing the trajectory of cattle leaving their sheds, characterized in that, include, Step 1: Use a single wide-angle camera to acquire images of the entrance and exit locations in the cattle shed; Step 2: Based on the improved YOLOv8 model, identify key points of the cow's head and torso, and obtain the head detection box and torso detection box. The convolutional layers in the backbone network of the improved YOLOv8 model are replaced with P-CBS modules, and the I-MAB multi-scale attention mechanism is added to the neck network. The I-MAB multi-scale attention mechanism consists of two parts: a lightweight multi-scale large kernel attention module and a gate space attention unit. The P-CBS module includes Partial-Conv, BN, and SiLU activation functions set sequentially. After the input feature map is input, the feature map is first divided into three scales, and then the parameters are reduced by Partial-Conv in the P-CBS module of the backbone network, and then the BN and SiLU activation functions are applied to obtain the feature map. The lightweight multi-scale large kernel attention module includes a GhostConv branch, an expanded DW-Conv branch, and a reparameterized large kernel branch. The features are processed by the GhostConv branch, the expanded DW-Conv branch, and the reparameterized large kernel branch, respectively, and then concatenated and output. In the gate spatial attention unit, after feature input, a two-branch prior is first performed, which includes spatial / orientation prior and channel prior. After the two-branch prior is completed, the outputs of the two branches are fused through multiplicative gating. The fused features are then convolved using geometric alignment. Finally, the output of the geometrically aligned convolution is added element-wise to the original input to obtain the final output of the gate spatial attention unit. The lightweight multi-scale large kernel attention module is configured with three modules: I-MLKA3, I-MLKA4, and I-MLKA5. The gate space attention unit is configured with two modules: I-GSAU4 and I-GSAU5. The backbone network outputs features C3, C4, and C5 at three scales, which are used as inputs to the three lightweight multi-scale large kernel attention modules. The outputs of the two modules I-MLKA4 and I-MLKA5 are concatenated and then input into I-GSAU4 via P4. C5 is the input of I-GSAU5. The output of P4 is upsampled and concatenated with the output of I-MLKA3 to obtain P3, which serves as one output of the head network of the model. The output of I-GSAU4 is fused with the downsampled P3 to obtain P4', which serves as the second output of the head network of the model. The output of I-GSAU5 is fused with the downsampled P4' to obtain P5', which serves as the third output of the head network of the model. Step 3: Determine the movement trajectory of the cattle based on the head detection box and torso detection box.

2. The method for recognizing cattle leaving their sheds according to claim 1, characterized in that, The GhostConv branch compresses channels using 1×1 pointwise convolutions and then generates pseudo-features using 3×3 depthwise separable convolutions; the dilated DW-Conv branch uses 7×7 depthwise separable convolutions with an inflation rate of 3, resulting in an equivalent receptive field of 19×19; the reparameterized large kernel branch uses two levels of 3×3 or 5×5 separable convolutions stacked during training and merges them into a static 11×11 depthwise convolution kernel during inference.

3. The method for recognizing cattle leaving their sheds according to claim 1, characterized in that, In step three, the center points of the head detection frame and the torso detection frame of the cow are taken respectively, and the head coordinates and tail coordinates are obtained respectively. Then they are connected into a straight line L. The direction of the cow is determined with the head coordinates as the front.

4. The method for recognizing cattle leaving their sheds according to claim 3, characterized in that, In step three, when the cow moves, Deepsort is used to track the unique ID on each cow's ear tag to obtain the pixel value of the position movement. Points whose movement exceeds the threshold are added to the trajectory calculation, and the trajectory is smoothed. The direction of entry and exit is determined by the offset direction of the straight line L. The initial judgment window is set to 10, and the movement threshold is set to 25. When the judgment window reaches the set value, the head and tail coordinates are subtracted, the tangent value is calculated, and a straight line of direction is fitted.

5. A computer device, characterized in that, include: processor; Memory, used to store executable instructions; The processor is configured to read the executable instructions from the memory and execute the executable instructions to implement the cattle exit trajectory recognition method as described in any one of claims 1 to 4.

6. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, causes the processor to implement the cattle exit trajectory recognition method as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Multi-head cattle identification and tracking algorithm based on improved YOLOv10s

    CN119418396A

  • Transformer substation secondary circuit intelligent identification method based on multi-scale large kernel attention YOLOV8

    CN119625708A