A sow farrowing detection system based on space-time action positioning and a detection method thereof
By integrating two-dimensional spatial features and three-dimensional spatiotemporal features through the CP-YOWO model, the problems of high false alarm rate and imprecise labor assessment in sow farrowing detection are solved, achieving efficient and accurate monitoring of the sow farrowing process, which is suitable for large-scale pig farming.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHONGQING ACAD OF ANIMAL SCI
- Filing Date
- 2026-04-17
- Publication Date
- 2026-07-14
AI Technical Summary
Existing sow farrowing detection technologies suffer from problems such as high false alarm rates due to static feature confusion, lack of refined assessment of the farrowing process, and poor robustness in complex environments, making it difficult to achieve efficient and accurate sow farrowing monitoring in large-scale pig farming.
The CP-YOWO model is adopted, which integrates two-dimensional spatial features and three-dimensional spatiotemporal features through a dual-stream feature extraction module, an action-guided attention fusion module, and a feature bridging and decoupling detection head. This enables accurate differentiation between parturition actions and background activities, and continuous quantitative assessment of the completeness of piglet birth.
It significantly reduces the false alarm rate, enables accurate differentiation between labor movements and background activities, timely identifies abnormalities in the labor process, improves the accuracy and robustness of detection, is suitable for deployment on edge devices, and reduces the computational load.
Smart Images

Figure CN122049996B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of intelligent animal husbandry and computer vision technology, specifically to a sow farrowing detection system and its detection method based on spatiotemporal motion localization. Background Technology
[0002] With the rapid development of intensive and large-scale pig farming, sow farrowing management has become a key aspect of pig farm production efficiency. The farrowing process lasts for several hours, during which unexpected situations such as dystocia, apparent death of piglets, and sow crushing piglets can easily occur. Timely detection of farrowing movements and assessment of the progress of labor can significantly reduce piglet mortality and improve the economic benefits of pig farming.
[0003] Traditional methods of monitoring sow farrowing rely on manual inspections or attaching contact sensors (such as wearable ear tags and thermometers) to sows. However, these methods are labor-intensive, inefficient, and cannot provide 24 / 7 monitoring, leading to missed detections and delays. In recent years, with advancements in non-contact computer vision technology, camera-based automated monitoring solutions have gradually replaced contact sensors. This avoids the stress caused by contact with equipment and has become the mainstream technology for monitoring sow farrowing.
[0004] Current visual monitoring technologies mainly include two categories: image classification-based methods and object detection-based methods. However, significant technical bottlenecks still exist in the specific and complex scenario of sow farrowing: 1) High false alarm rate due to static feature confusion: Existing solutions mostly use single-frame image 2D (two-dimensional) object detection algorithms such as the "You Only Look Once" series, which only focus on object texture and geometry, and cannot distinguish between "piglets in farrowing" and "piglets that have already been born and are moving behind the sow". This easily leads to misjudging background piglets as new farrowing events, generating a large number of repeated alarms and interfering with the farmer's judgment; 2) Lack of refined assessment of the completeness of the farrowing state: Farrowing is a continuous dynamic process from the emergence of the amniotic sac to the complete departure of the piglet from the birth canal, rather than a binary state of "not born / born". Existing technologies lack a refined assessment of the completeness of the farrowing state. The logic of class cannot quantify the progress of labor, cannot identify signs of dystocia such as piglets getting stuck in the birth canal, and the detection results are prone to drastic changes at the critical point; 3) Insufficient utilization of spatiotemporal features and weak resistance to complex environmental interference: Pig houses are subject to interference such as changes in lighting, fence obstruction, and excrement. Simple 2D spatial features are difficult to capture the "pushing" and "sliding" actions of childbirth. Although simple 3D (i.e., three-dimensional) video classification networks contain time information, they have poor localization effect for small targets and large computational load, making it difficult to implement on edge devices. How to integrate 2D and 3D features and suppress background noise has become an urgent problem to be solved.
[0005] For example, Chinese patent application CN117197902A discloses an intelligent prediction system and method for sow farrowing, relating to the pig farming industry. The system includes an AI edge device module, an environmental factor acquisition module, a network transmission module, a video image data storage module, a local server, a cloud server, and a terminal real-time display module. The network transmission module includes a switch and a sensor gateway. The switch is connected to the AI edge device module, the video image data storage module, and the local server via network cables. The sensor gateway is connected to the local server via a network cable. The environmental factor acquisition module is communicatively connected to the sensor gateway. The local server is communicatively connected to the cloud server.
[0006] Chinese patent application CN117095327A discloses a method and device for monitoring the farrowing status of sows. The method includes: acquiring a farrowing video of a sow, the farrowing video including the farrowing process of the sow; inputting the farrowing video into a preset sow farrowing status classification network model to obtain the sow's farrowing status and record farrowing information; wherein the sow farrowing status classification network model includes a YOLO V5 classification network model, and an SAC module is added to the YOLO V5 classification network model.
[0007] These technologies all use the YOLO model, which obviously suffers from the technical problems mentioned above. Summary of the Invention
[0008] To address the problems existing in the prior art, the present invention aims to provide a sow farrowing detection system based on spatiotemporal motion localization. This system effectively solves problems such as repeated alarms caused by static feature confusion, lack of refined assessment of the labor process, and poor detection robustness in complex environments. It achieves accurate differentiation between farrowing actions and background activities, continuous quantitative assessment of the completeness of piglet birth, while taking into account the model detection accuracy and computing power adaptability, facilitating the deployment of edge devices, and improving the accuracy of farrowing detection.
[0009] The objective of this invention is achieved through the following technical solution:
[0010] A sow farrowing detection system based on spatiotemporal motion localization employs a CP-YOWO (Completeness-Perceived YOWO; YOWO stands for You Only WatchOnce, referring to a model) model to detect the sow's farrowing in real time. The input to this model is monitoring video. The CP-YOWO model is an improvement on the YOWO3 model and includes a dual-stream feature extraction module, an action-guided attention fusion module, and a feature bridging and decoupling detection head.
[0011] The dual-stream feature extraction module includes a two-dimensional spatial branch and a three-dimensional spatiotemporal branch, which extract video spatial texture features and spatiotemporal motion features respectively; the action-guided attention fusion module uses the spatiotemporal motion features to generate a spatial motion mask and performs weighted suppression on the background region of the two-dimensional spatial branch; the feature bridging and decoupling detection head is used to fuse geometric morphological features and semantic features to determine the piglet birth status.
[0012] Based on further optimization of the above scheme, in the dual-stream feature extraction module, the two-dimensional spatial branch extracts features from key frames in the video segment to obtain a spatial feature map containing texture, edges and geometric shapes; the three-dimensional spatiotemporal branch extracts three-dimensional features from the entire video segment to obtain a spatiotemporal motion feature map containing information on changes in the time dimension.
[0013] Based on further optimization of the above scheme, the action-guided attention fusion module is used to connect the two-dimensional spatial branch and the three-dimensional spatiotemporal branch, and its processing flow includes:
[0014] A1. Dynamic Mask Generation: Receives the 3D spatiotemporal feature map output from the 3D spatiotemporal branch. , where C 3D H represents the number of spatiotemporal channels in a three-dimensional spatiotemporal feature map. 3D W 3D The height and width of the 3D spatiotemporal feature map are represented respectively; after processing by the following lightweight action gating sub-network, an action mask M is generated. motion :
[0015] ;
[0016] In the formula: Indicates F 3D The 3×3 convolution operation is used to extract local action context; δ represents the batch normalization operation; δ represents the SiLU activation function operation. σ represents a 1×1 convolution operation; σ represents the Sigmoid function, used to map the output value to the [0,1] interval;
[0017] in, The set consists of multiple pixel values m i,j Composed of [0,1], each pixel value m i,j The mask value representing the childbirth action at the corresponding position in the i-th row and j-th column;
[0018] A2. Cross-scale spatial alignment: Extracting two-dimensional spatial feature maps F 2D Features, among which C 2D H represents the number of channels in a two-dimensional spatial feature map. 2D W2D These represent the height and width of the feature map in the two-dimensional space, respectively; a bilinear interpolation algorithm is used to interpolate M... motion and F 3D Perform upsampling alignment:
[0019] ;
[0020] ;
[0021] In the formula: This represents the action mask after the upsampling operation; This represents the 3D spatiotemporal feature map after the upsampling operation; Upsample() represents the bilinear interpolation upsampling operation; size() represents the target space size of the upsampling operation;
[0022] A3. Feature gating for motion guidance: Upsampling the motion mask For F 2D Element-wise multiplication yields a spatially gated two-dimensional spatial feature map:
[0023] ;
[0024] In the formula: It represents the Hadamardi (or Hadama) stack; Generated by the Sigmoid activation function, its value is a continuous floating-point number in the interval (0,1). When the mask value approaches 1, the spatial texture features at the corresponding position are completely preserved and transmitted; similarly, when the mask value approaches 0, the feature response is significantly suppressed, thereby eliminating background noise interference; for the intermediate value in the interval (0,1), the model scales the feature amplitude proportionally according to its probability to achieve a smooth feature transition.
[0025] A4. Cross-modal feature fusion and reconstruction: and The splicing is performed along the channel dimension to obtain the splicing spatial feature map F. concat :
[0026] ;
[0027] In the formula: Concat() represents the channel dimension concatenation operation; dim=Channel indicates that the target dimension of the concatenation operation is the channel dimension;
[0028] The spliced F concat Input a channel feature aggregation block with a channel attention mechanism, adaptively adjust the channel weights through the following operations, and finally output the fused multi-scale spatial feature map F. final :
[0029] ;
[0030] In the formula: This represents the channel attention operation, which captures channel dependencies by calculating the covariance matrix between channels; Indicates the input convolution transformation operation; Indicates the output convolution transformation operation;
[0031] The final output multi-scale spatial feature map F final It is then fed into a subsequent detection head for decoupling detection.
[0032] Based on further optimization of the above scheme, the feature bridging and decoupling detection head is used to map the fused features output by the action-guided attention fusion module to the final detection result. The process includes:
[0033] B1. Feature Decoupling and Primary Extraction: Receiving and Fusing Feature Maps Then, the features are decoupled into bounding box regression features through the decoupling head. and category classification features :
[0034]
[0035]
[0036] Among them, F box It contains geometric information about the target's boundaries and aspect ratio, F cls It contains the target's texture and category semantic information; among which and The decoupling operation yields the bounding box regression features and the category classification features, respectively. in Represents input channel, C mid This represents the channel after decoupling.
[0037] B2, "H" type feature bridging: Connecting F box With F cls By splicing along the channel dimension, a bridging feature is formed. :
[0038] ;
[0039] In the formula: Concat() represents the channel dimension concatenation operation; dim=Channel indicates that the target dimension of the concatenation operation is the channel dimension;
[0040] B3. Enhanced Coordinate Attention: For F bridge Apply coordinate attention processing to capture spatial location information:
[0041] First, feature aggregation is performed along the horizontal and vertical directions using adaptive average pooling kernels to obtain feature vectors in the height and width directions respectively:
[0042] ;
[0043] In the formula: This represents the average pooling characteristic of the c-th channel along row h in the height direction; The c-th channel represents the average pooling feature along the width column w; W and H represent the bridging feature F, respectively. bridge The width and height of the feature map; Represents the pixel value of the c-th channel of the bridging feature map at position (h,i) or (j,w);
[0044] Then, the feature vectors from the two directions are concatenated, dimensionality reduction is performed using a shared 1×1 convolution function, and SiLU activation is applied. The result is then split into two independent tensors to obtain the height-direction feature g. h and width direction feature g w :
[0045] ;
[0046] In the formula: [z h ,z w ] represents the height-direction feature z h With width direction feature z w The splicing features in the channel dimension; This indicates that a 1×1 convolutional layer operation is performed on the spliced feature, and then it is processed. Batch normalization; finally, δ represents the SiLU function activation; Split() indicates that the channel dimension is split to obtain the height and width features g. h and g w ;
[0047] The height and width features are then mapped to attention weights through convolutional layers. Finally, the generated coordinate attention weights are applied to the original bridging features to obtain the final complete feature F. comp :
[0048] ;
[0049] ;
[0050] In the formula: A h A w These represent the attention weights in the height and width directions, respectively. () () represent the height and width features g respectively. h g wA 1×1 convolutional layer that maps the original output of attention weights in the height and width directions; σ represents the attention weights between [0,1] obtained by the Sigmoid function operation;
[0051] B4. Multi-task prediction output: Three independent convolutional layers are used to map features into target box regression output, category classification output, and completeness evaluation output, respectively, to achieve simultaneous detection of multiple tasks.
[0052] Based on further optimization of the above scheme, the completeness assessment output is graded as follows: 0.1-0.3 is "just emerging", 0.3-0.5 is "head emerging", 0.5-0.7 is "truncation emerging", 0.7-1.0 is "about to be fully delivered", and 1.0 is "fully delivered". If the completeness remains at a certain level for a long time and exceeds the preset time threshold, it is judged as labor stagnation / dystocia.
[0053] Based on further optimization of the above scheme, the CP-YOWO model uses a hybrid ordinal loss function to calculate the error between the predicted value and the true label. The hybrid ordinal loss function is composed of a weighted average of label smoothing cross-entropy loss and expected value regression loss.
[0054] Label smoothing cross-entropy loss: the smoothed true probability distribution q of the i-th sample i :
[0055] ;
[0056] In the formula: Indicates the smoothing factor; This indicates an indicator function, meaning that the value is 1 if the condition inside the parentheses is true and 0 if it is false; This represents the actual category index; K represents the number of categories;
[0057] Label smoothing cross-entropy loss function L ce :
[0058] ;
[0059] In the formula: p i (k) is the probability of belonging to the k-th unit as output by the model after Softmax;
[0060] Expected value regression loss: Model predicts expected value for:
[0061] ;
[0062] In the formula: v k Represents a discrete gear vector;
[0063] Expected value regression loss function L reg:
[0064] ;
[0065] In the formula: t i Indicates a true floating-point label;
[0066] The label smoothing cross-entropy loss is weighted with the expected value regression loss to obtain the completeness branch loss function L. comp :
[0067] ;
[0068] In the formula: λ reg Indicates the balance coefficient;
[0069] Overall model loss function L total :
[0070] ;
[0071] In the formula: L cls λ represents the category classification loss. cls L represents the category classification loss balance coefficient; dfl λ represents the distribution focus loss. dfl λ represents the distribution focus loss balance coefficient; comp L represents the balance coefficient of branch loss in terms of completeness; box λ represents the bounding box position loss. box This represents the boundary box position loss balance coefficient.
[0072] Preferably, the smoothing factor ε is 0.2, the number of categories K is 6, and the balance coefficient λ is... reg The class classification loss balance coefficient is 2.0. cls The distribution focus loss balance coefficient λ is 0.5. dfl The integrity branch loss balance coefficient λ is 1.5. comp It is version 2.0.
[0073] Preferably, the CP-YOWO model uses I3D as the 3D backbone and YOLOv11m as the 2D backbone.
[0074] Finally, the present invention also provides a method for detecting farrowing in sows using the detection system described herein.
[0075] The following are the technical effects of the present invention:
[0076] The sow farrowing detection system based on spatiotemporal motion localization of this invention has the following significant advantages compared to existing technologies:
[0077] 1. Significantly reduce false alarm rate and achieve accurate differentiation between parturition actions and background activities: By integrating two-dimensional spatial features and three-dimensional spatiotemporal features through the MGAF module, and using action masks to suppress interference from background piglets without parturition actions, the problem of repeated alarms caused by static feature confusion is solved, and the accuracy of parturition event detection is improved.
[0078] 2. Achieve continuous quantitative assessment of piglet birth integrity and timely identification of birth abnormalities: Through the "H-type" feature bridging and coordinate attention mechanism of FBD-Head, the birthing process is subdivided into 6 discrete levels from 0.1 to 1.0, and continuous integrity prediction values are output. This breaks through the limitations of traditional binary classification, accurately quantifies the progress of birth, and timely identifies signs of dystocia such as piglets getting stuck in the birth canal and birth stagnation.
[0079] 3. Enhanced robustness in complex environments, balancing accuracy and computational adaptability: The model integrates spatial details of 2D texture features and temporal variation information of 3D motion features, effectively resisting environmental interference such as lighting, shading, and excrement in pigsties. A model configuration using I3D as the 3D backbone and YOLOv11m as the 2D backbone achieves a high mAP@50 (mean Average Precision at IoU=0.5, where mAP represents mean Average Precision and IoU represents Intersection over Union) of 0.9284, while having only 59.90M parameters, far lower than backbone networks like ResNeXt101. This results in low computational load and facilitates deployment on edge devices.
[0080] 4. The model prediction results have good temporal continuity and high stability: The hybrid ordinal loss function combines the discriminative power of classification loss and the orderliness of regression loss, avoiding drastic jumps in detection results at the critical point. The completeness assessment MAE is 0.1245, and the average prediction deviation is less than one quantization level, achieving smooth and stable prediction of labor progress.
[0081] 5. Adapt to the needs of large-scale pig farming and improve the economic benefits of farming: The model can be connected to the cameras in the farrowing room of the pig farm to realize 24-hour automated monitoring of the sow's farrowing process without the need for manual inspection, reducing the labor costs of farming. At the same time, it can give timely warnings of abnormalities in the farrowing process, help the farmers to quickly assist in the delivery, significantly reduce the mortality rate of piglets, and improve the production efficiency of the pig farm. Attached Figure Description
[0082] Figure 1a This is a single frame from the original video during the sow's farrowing process. Figure 1b This is a single frame from the original video after the sow has given birth. Figure 1c For the corresponding Figure 1a A magnified view of the cropped section; Figure 1d For the corresponding Figure 1b A magnified view of the cropped section.
[0083] Figure 2 This is a schematic diagram of the dual-stream feature extraction module and the action-guided attention fusion module (MGAF) of the overall framework of the CP-YOWO model of this invention.
[0084] Figure 3 A schematic diagram of the individual structure of the action-guided attention fusion module (MGAF) of the CP-YOWO model of this invention.
[0085] Figure 4 This is a schematic diagram of the individual structure of the Feature Bridging Decoupling Detection Head (FBD-Head) of the CP-YOWO model of the present invention.
[0086] Figure 5 This is a schematic diagram of the individual structure of the integrity branch of the CP-YOWO model of the present invention. Detailed Implementation
[0087] The following detailed description provides further details through specific embodiments. However, it should be noted that the embodiments described below are merely for illustrating the content of the invention and do not represent that the invention is limited to the described embodiments. Therefore, non-essential improvements and adjustments made to the implementation schemes by those skilled in the art based on the above-described invention still fall within the protection scope of the invention, and the scope of protection of the appended claims shall prevail.
[0088] The model used in this invention is named CP-YOWO, which is an abbreviation for Completeness-Perceived YOWO, an improvement on the existing YOWO3 model. Those skilled in the art will understand that YOWO stands for You Only Watch Once, a single-stage real-time detection framework specifically designed for spatio-temporal action detection (STAD) in video; YOWO3 refers to version v3 of the YOWO model. The YOWO model is an open-source model in this field and can be obtained through GitHub or other channels, or trained directly on common platforms such as PyTorch or Python.
[0089] The feature maps used in this invention refer to a set of regular tensors formed by extracting relevant features through operations such as convolution, including: three-dimensional spatiotemporal feature maps F. 3D This refers to extracting the three-dimensional height H from consecutive video frames using operations such as 3D convolution. 3D 3D width W 3D and three-dimensional channel C3D A feature set formed by equal dimensions; two-dimensional spatial feature map F2D refers to extracting the two-dimensional height H from a single frame image using operations such as 2D convolution. 2D 2D width W 2D and two-dimensional channel C 2D A feature set formed by equal dimensions; a three-dimensional spatiotemporal feature map after upsampling. This refers to using the bilinear interpolation algorithm to interpolate F... 3D The feature set is formed by upsampling and alignment, an operation well known to those skilled in the art; spatially gated two-dimensional spatial feature map. This refers to F 2D and the upsampled action mask (The definition of this action mask is given below) The feature set is formed by performing a Hadamard product gating operation, which is well known to those skilled in the art; the spatial feature map F is then stitched together. concat This refers to and The feature set is formed by concatenating elements along the channel dimension (C), an operation well-known to those skilled in the art; multi-scale spatial feature map F final This refers to F concat The feature set formed by fusion after adaptive adjustment of channel weights through channel attention enhancement, etc., is specifically operated as described in the embodiments, and each individual operation is well known to those skilled in the art; receiving the fused feature map F in This refers to F final The input channel (i.e., C) when the feature bridging decoupling detection head is fed into it in Feature set (height H and width W remain unchanged); target bounding box regression feature map Fbox refers to the Fbox feature set (height H and width W remain unchanged). in The feature set formed by decoupling the target's boundary, aspect ratio, and other geometric information (at this point, the channel is adjusted to C). mid This represents the channel after decoupling intermediate processing (with height H and width W remaining unchanged). This decoupling operation is well known to those skilled in the art; Category classification feature map F cls Indicate F in The feature set formed by decoupling the texture and category semantic information of the target (at this time, the channel is adjusted to C) mid (Represents the channel after decoupling, with height H and width W remaining unchanged); bridging feature map F bridge This refers to F box With F cls In the channel dimension (C mid The feature set formed by splicing is well known to those skilled in the art; Represents the bridging feature map F bridgeThe pixel value of the c-th channel at position (h,i) or (j,w) (i.e., the position at row h, column i and row j, column w, where i takes values within the width W and j takes values within the height H); the final complete feature map F comp This refers to F bridge The feature set formed after coordinate attention weighting is operated as described in the embodiments, and each individual operation is well known to those skilled in the art. Those skilled in the art will understand that the letter F can generally refer to the feature map as a whole (in which case it can be represented in bold italics) or a specific feature within it (in which case it can be represented in regular italics). In this invention, no such distinction is made, and regular italics are used for all representations. Unless otherwise specified, both can refer to the feature map as a whole or a specific feature within it, and those skilled in the art can fully understand from the context whether it refers to the feature map as a whole or a specific feature.
[0090] The various specific operations used in this invention include: Convolution operations, including one-dimensional, two-dimensional, and three-dimensional convolution operations, refer to extracting local features such as edges, textures, shapes, and motion from images / videos while filtering out useless information and retaining key information. σ represents batch normalization, which forcibly pulls the output of each convolutional layer back to a mean of approximately 0 and a variance of approximately 1. In model training, it is used to alleviate the internal covariate shift problem of deep networks, stabilize gradient backpropagation, accelerate model convergence, and has a certain regularization effect, effectively improving the robustness of spatiotemporal feature extraction. σ represents the Sigmoid operation, which compresses features to the [0,1] interval and is used for weight scoring. δ represents the SiLU operation, which is used for backbone feature extraction and hidden layer activation. Upsample() represents the bilinear interpolation upsampling operation, which achieves smooth enlargement of spatial size by weighted fitting of the feature values of four adjacent points, ensuring that shallow detailed features and deep semantic features can be accurately aligned and fused, while avoiding the checkerboard distortion problem caused by transposed convolution. The `Hadamard` operation is used to perform element-wise multiplication. It can be used to implement gating, enhance effective spatiotemporal features, suppress redundant information, and improve the precision and completeness of feature representation. `Concat()` is a concatenation operation that concatenates two or more feature maps in a specified dimension, such as the channel dimension, while keeping the spatial dimensions (height H and width W) of the feature maps unchanged and only adding and merging the number of channels. and The decoupling operation, which yields target bounding box regression features and category classification features respectively, refers to separating and splitting the fused features into multiple branch feature information. This represents the average pooling characteristic of the c-th channel along the height direction (row h). The c-th channel represents the average pooling feature along the width direction (column w). Adaptive average pooling is used to achieve multi-scale feature aggregation. By automatically adapting the convolution kernel and stride, spatial features of arbitrary size are compressed into a fixed-dimensional global representation. While preserving channel semantic information, a large range of contextual features are fused, enhancing the model's ability to perceive the overall contour and global information. Split() represents a splitting operation on a specified dimension, which is the inverse operation of splicing. All the individual operations used in this invention are well known to those skilled in the art and can be obtained through GitHub or other channels, or trained directly on common platforms such as PyTorch or Python.
[0091] Example 1
[0092] This invention provides a sow farrowing detection system based on spatiotemporal action localization. It employs the CP-YOWO (Completeness-Perceived YOWO) model to detect sow farrowing in real time, with monitoring video as input. The CP-YOWO model of this invention is an improvement upon the existing YOWO3 model, including a dual-stream feature extraction module, an action-guided attention fusion module, and a feature bridging and decoupling detection head. Furthermore, it uses a hybrid ordinal loss function to calculate the error between the predicted value and the true label.
[0093] The dual-stream feature extraction module of this invention is divided into a two-dimensional spatial branch and a three-dimensional spatiotemporal branch, which respectively extract the spatial texture features of video keyframes and the spatiotemporal motion features of video segments; the two-dimensional spatial branch performs feature extraction on keyframes in video segments, extracting spatial feature maps containing texture, edges and geometric shapes; the three-dimensional spatiotemporal branch performs three-dimensional feature extraction on the entire video segment, extracting spatiotemporal motion feature maps containing information on changes in the time dimension.
[0094] The Motion-Guided Attention Fusion (MGAF) module of this invention generates a spatial motion mask using motion features extracted from the 3D spatiotemporal branch. This spatial motion mask is then used to weight and suppress the background region of the 2D spatial branch, preserving features of regions with significant birthing actions (such as pushing and sliding), and outputting a fused multi-scale feature map. The MGAF module is the core component connecting the 2D spatial branch and the 3D spatiotemporal branch. Its main function is to dynamically weight the spatial texture features extracted from the 2D spatial branch using the "spatiotemporal motion saliency" extracted from the 3D spatiotemporal branch, thereby suppressing static interference targets in the background without birthing actions (such as piglets that have already been born and are at rest).
[0095] The processing flow of the attention fusion module for action guidance in this invention includes:
[0096] A1. Dynamic Mask Generation: Receives high-level spatiotemporal feature maps from the output of the 3D spatiotemporal branch. (where C) 3D H represents the number of channels in the spatiotemporal action feature map. 3D W 3D (representing the height and width of the spatiotemporal action feature map, respectively), processed by the following lightweight action gating sub-network (including 3×3 convolution → Batch normalization → SiLU activation → 1×1 convolution → Sigmoid function), generating action mask M. motion :
[0097] ;
[0098] In the formula: Indicates F 3D The 3×3 convolution operation is used to extract local action context; This indicates a batch normalization operation; Indicates the SiLU activation function operation; This represents a 1×1 convolution operation, used to compress channels to 1 dimension; This represents the Sigmoid function, which maps output values to the interval [0,1].
[0099] in, The set consists of multiple pixel values m i,j Composed of [0,1], each pixel value m i,j The mask value represents the childbirth action at the corresponding position in the i-th row and j-th column, indicating the salience of the childbirth action at the corresponding position in the i-th row and j-th column (such as pushing or sliding).
[0100] A2. Cross-scale spatial alignment: Due to the two-dimensional spatial feature map F 2D The resolution is higher than F 3D , (where C) 2D H represents the number of channels in a two-dimensional spatial feature map. 2D W 2D (representing the height and width of the feature map in two-dimensional space, respectively), and then using the bilinear interpolation algorithm to... motion and F 3D Perform upsampling alignment:
[0101] ;
[0102] ;
[0103] In the formula: This represents the action mask after the upsampling operation; This represents the spatiotemporal action feature map after the upsampling operation; Upsample() represents the bilinear interpolation upsampling operation; size() represents the target space size of the upsampling operation.
[0104] A3. Feature gating for motion guidance: Upsampling the motion mask For F 2D Element-wise multiplication yields a spatially gated two-dimensional spatial feature map:
[0105] ;
[0106] In the formula: It represents the Hadamardi (or Hadama) stack. Generated by the Sigmoid activation function, its value is a continuous floating-point number in the interval (0,1). When the mask value approaches 1, the spatial texture features at the corresponding position are completely preserved and transmitted; similarly, when the mask value approaches 0, the feature response is significantly suppressed, thereby eliminating background noise interference; for the intermediate value in the interval (0,1), the model scales the feature amplitude proportionally according to its probability to achieve a smooth feature transition.
[0107] A4. Cross-modal feature fusion and reconstruction: fusing and reconstructing the gated features... Aligned with upsampling The splicing is performed along the channel dimension to obtain the splicing spatial feature map F. concat :
[0108] ;
[0109] In the formula: Concat() represents the channel dimension splicing operation; dim=Channel represents the target dimension of the splicing operation (i.e., splicing is performed with a fixed channel dimension Channel, while the width, height, batch, etc. remain unchanged).
[0110] The spliced F concat Input a channel feature aggregation block with a channel attention mechanism, adaptively adjust the channel weights through the following operations, and finally output the fused multi-scale spatial feature map F. final :
[0111] ;
[0112] In the formula: This represents the channel attention operation, which captures channel dependencies by calculating the covariance matrix between channels; This indicates the input convolution transformation operation (i.e., the concatenation of features F). concat (Perform 1×1 convolution, batch normalization, and SiLU activation). This indicates the output convolution transformation operation (i.e., channel attention enhancement). The features after this process are then subjected to 1×1 convolution, batch normalization, and SiLU activation.
[0113] The final output multi-scale spatial feature map F final It is then fed into a subsequent detection head for decoupling detection.
[0114] The Feature-Bridged Decoupled Head (FBD-Head) described in this invention comprises three parallel branches: a bounding box regression branch, a category classification branch, and a completeness evaluation branch. The FBD-Head is primarily responsible for integrating the multi-scale features FBD-Head output by the action-guided attention fusion module. final The mapping to the final detection result addresses the lack of spatial geometric constraints in integrity assessment. The process includes:
[0115] B1. Feature Decoupling and Primary Extraction: Receiving and Fusing Feature Maps Then, the features are decoupled into bounding box regression features through the decoupling head. and category classification features Eliminate feature conflicts between regression and classification tasks:
[0116]
[0117]
[0118] Among them, F box It contains geometric information about the target's boundaries and aspect ratio, F cls It contains the target's texture and category semantic information; among which and The decoupling operation yields the bounding box regression features and the category classification features, respectively. in Represents input channel, C mid This represents the channel after decoupling.
[0119] B2, "H" type feature bridging: Connecting F box With F cls By splicing along the channel dimension, a bridging feature is formed. This enables cross-task feature interaction, allowing integrity assessment to utilize both geometric morphology and semantic texture features simultaneously.
[0120] ;
[0121] In the formula: Concat() represents the channel dimension splicing operation; dim=Channel represents the target dimension of the splicing operation (i.e., splicing is performed with a fixed channel dimension Channel, while the width, height, batch, etc. remain unchanged).
[0122] B3. Enhanced Coordinate Attention: Addressing the correlation between piglet integrity and the spatial location, aspect ratio, and height of the birth canal opening, the bridging feature F... bridge Apply coordinate attention processing to capture spatial location information:
[0123] First, adaptive average pooling kernels are used to aggregate features along the horizontal (X-axis) and vertical (Y-axis) directions respectively, obtaining feature vectors in the height and width directions. The following formula represents the vectorization operation:
[0124] ;
[0125] In the formula: This represents the average pooling characteristic of the c-th channel along the height direction (row h); The c-th channel represents the average pooling feature along the width direction (column w); W and H represent the bridging feature F, respectively. bridge The width and height of the feature map; Represents the pixel value at position (h,i) or (j,w) of the c-th channel of the bridging feature map (i.e., the position at row h, column i and row j, column w, where i takes values within the width W and j takes values within the height H).
[0126] Then, the feature vectors from the two directions are concatenated, dimensionality reduction is performed using a shared 1×1 convolution function, and SiLU activation is applied. The result is then split into two independent tensors to obtain the height-direction feature g. h and width direction feature g w :
[0127] ;
[0128] In the formula: [z h ,z w ] represents the height-direction feature z h With width direction feature z w The splicing features in the channel dimension; This indicates that a 1×1 convolutional layer operation is performed on the spliced feature, and then it is processed. Batch normalization, and finally δ represents the SiLU function activation; Split() indicates that the channel dimension (f) is split to obtain the height and width features g. h and g w The splitting operation is the opposite of the splicing operation, and both are known operations familiar to those skilled in the art.
[0129] The height and width features are then mapped to attention weights through convolutional layers. Finally, the generated coordinate attention weights are applied to the original bridging features to obtain the final feature F. comp :
[0130] ;
[0131] ;
[0132] In the formula: A h A w These represent the attention weights in the height and width directions, respectively. () () represent the height and width features g respectively. h g w A 1×1 convolutional layer that maps the original output of attention weights in the height and width directions; σ represents the attention weights between [0,1] obtained by operating the Sigmoid function.
[0133] B4. Multi-task prediction output: Three independent convolutional layers are used to map features into target box regression output, category classification output, and completeness evaluation output, respectively, to achieve simultaneous detection of multiple tasks.
[0134] The Hybrid Ordinal Loss function is used to supervise the training of the completeness evaluation branch. It is composed of a weighted sum of label smoothing cross-entropy loss and expectation regression loss.
[0135] Label smoothing cross-entropy loss: Due to the ambiguity of the visual boundaries of the labor state (e.g., between 0.3 and 0.5), a label smoothing strategy is introduced to prevent model overconfidence and improve generalization ability. This strategy aims to prevent model overconfidence and enhance generalization. The smoothed true probability distribution q of the i-th sample is then used. i :
[0136] ;
[0137] In the formula: ε represents the smoothing factor (usually 0.2); This indicates an indicator function, meaning that the value is 1 if the condition inside the parentheses is true and 0 if it is false; Indicates the actual category index; K represents the number of categories (usually 6).
[0138] Label smoothing cross-entropy loss function L ce :
[0139] ;
[0140] In the formula: p i (k) is the probability of belonging to the k-th unit after the model is processed by Softmax; Softmax output refers to the transformation into a standard probability distribution with a sum of 1, where each output is ∈(0,1). This operation is well known to those skilled in the art and can be obtained through conventional code calculation.
[0141] Expected value regression loss: To introduce time order constraints, the expected value of the prediction is calculated using the probability distribution of the model output, and this expected value is forced to approximate the true floating-point label; discrete gear vector V=[v1,v2,…,v k ] = [0.1, 0.3, ..., 1.0], the expected value predicted by the model. for:
[0142] ;
[0143] Expected value regression loss function L reg :
[0144] ;
[0145] In the formula: t i The label represents the true floating-point value; this loss function uses the overall information of the probability distribution to impose a greater penalty on "skip" errors (the center of gravity of the prediction distribution deviates far from the true value), thereby maintaining the continuity of the prediction results in time.
[0146] Label smoothing cross-entropy loss function L ce With expected value regression loss function L reg Weighted summation yields the completeness branch loss function L. comp :
[0147] ;
[0148] In the formula: λ reg This represents the balance coefficient (e.g., 2.0, which can be adjusted according to the actual situation).
[0149] Overall model loss function L total Calculate using the following formula:
[0150] ;
[0151] In the formula: L cls This represents the category classification loss (using the label smoothed cross-entropy loss function L). ce (used to supervise the model to distinguish between "labor action" and "background / non-labor action" categories), λ cls L represents the class classification loss balance coefficient (e.g., set to 0.5); dfl The distributed focus loss (used for regression of target bounding box coordinates such as left, top, right, and bottom distances, discretizing continuous coordinate values into a distribution of multiple intervals, allowing the model to output the probability of each interval, thus improving the localization accuracy of small targets (piglets); its calculation is well known to those skilled in the art and can be obtained through platforms such as PyTorch), λ dflλ represents the distribution focus loss balance coefficient (e.g., taken as 1.5); comp L represents the integrity branch loss balance coefficient (e.g., taken as 2.0); box The bounding box position loss is represented by CIoU loss, which considers the overlap of the boxes, the distance between the center points, and the aspect ratio to improve positioning accuracy; those skilled in the art are familiar with the formula for calculating this loss: CIoU = 1 - IoU + center distance penalty + adaptive aspect ratio penalty, which can be calculated using the PyTorch platform. λ box This represents the bounding box position loss balance factor (e.g., 7.5).
[0152] Thus, the hybrid ordinal loss function of this invention retains the strong discriminative power of classification tasks on features while incorporating the sensitivity of regression tasks to numerical distance, effectively solving the mean regression trap in labor progress assessment. Classification tasks can directly use cross-entropy loss, while regression tasks can use a combination of DFL loss (distribution focus loss) and CIoU loss (reflecting bounding box position loss).
[0153] Example 2
[0154] As another preferred embodiment of the present invention, based on the above-described sow farrowing detection system scheme, an application method of a sow farrowing detection system based on spatiotemporal motion localization includes:
[0155] Step S1, Hardware Deployment: Install high-definition cameras on the side and back of each farrowing pen in the pig farm, with the cameras facing the perineum area of the sow to ensure clear capture of the sow's side-lying position, the piglets' farrowing actions, and the piglets' activities after farrowing; connect the cameras to the server to achieve real-time transmission of the sow's activity video stream.
[0156] Step S2, Model Deployment: Deploy the trained CP-YOWO model on the server, setting the input parameters for model inference to a video clip length of 16 frames and an image size of 448×448. In this embodiment, the CP-YOWO model uses I3D as the 3D backbone and YOLOv11m as the 2D backbone. The training dataset uses a dedicated dataset containing 113 farrowing clips and 63 non-farming clips from 11 sows. Data filtering and balancing strategies are used to ensure the ratio of farrowing to non-farming video data is close to 1:1, avoiding the impact of imbalanced samples on model performance. The dataset is divided into training and testing sets at an 8:2 ratio for model training and performance validation. The dataset was collected from a camera positioned behind and to the side of the farrowing pen in the pig farm. This perspective clearly captures the process of piglets moving outwards from the perineum while the sow is lying on her side, as well as the activity of piglets behind the sow after farrowing, providing effective feature data for the model.
[0157] Step S3, Video Stream Inference: The server captures video streams transmitted from the camera in real time as 16-frame / segment video segments, and inputs them into the CP-YOWO model of this invention for inference; the model obtains two-dimensional spatial features and three-dimensional spatiotemporal features through dual-stream feature extraction, and after being fused by the MGAF module and background interference suppressed, the FBD-Head outputs the farrowing target detection box, category information (farming / not farrowing) and the predicted value of piglet birth integrity.
[0158] Step S4, Labor Monitoring and Early Warning: The server determines the piglet's birthing progress based on the completeness prediction value. A completeness of 0.1-0.3 indicates "just emerging," 0.3-0.5 indicates "head emerging," 0.5-0.7 indicates "trunk emerging," 0.7-1.0 indicates "almost fully born," and 1.0 indicates "fully born." If the completeness remains at a certain level for an extended period (e.g., 0.3-0.5 exceeding a preset time threshold), it is determined to be labor stagnation / dystocia. The server immediately sends an early warning message to the farmer's terminal device, prompting timely assistance in the birthing process.
[0159] Example 3: Performance Evaluation
[0160] The experimental environment for this invention is an NVIDIA A100. The experimental parameters of the model proposed in this invention are shown in Table 1 below when running on the open-source platform PyTorch 2.0.1.
[0161] Table 1. Operating parameters of the model of this invention
[0162]
[0163] To comprehensively and objectively verify the effectiveness of the CP-YOWO model proposed in this invention in the task of detecting and assessing the completeness of sow farrowing, the mean absolute error (MAE) and root mean square error (RMSE) were used to evaluate the regression accuracy of the completeness branch, while mAP@50, precision, and recall were used to evaluate the regression box.
[0164] MAE measures the average deviation between the completeness of the model's predictions and the true labels. A lower MAE value indicates a more accurate assessment of labor progress and less numerical fluctuation.
[0165] ;
[0166] In the formula, N represents the total number of samples; This represents the expected value of the completeness of the model's predictions; This indicates the authenticity and completeness of the manually labeled data.
[0167] RMSE is extremely sensitive to large prediction errors; in labor monitoring, if the model misclassifies "just emerging (0.1)" as "about to be born (0.9)", it will lead to serious false alarms; RMSE is used to evaluate the stability of the model in handling such extreme biases.
[0168] .
[0169] Since labor monitoring primarily focuses on the occurrence of actions rather than pixel-level bounding box overlap, this approach uses the mean accuracy (mAP@50) at an IoU threshold of 0.5 as the core detection metric. This metric comprehensively reflects the robustness of the model across different confidence thresholds.
[0170] To verify the overall performance of the proposed model, this embodiment conducted comprehensive cross-combination validation on a sow farrowing dataset. The experiment selected various 3D backbone networks (such as I3D, ResNext101, ShuffleNetv2) and 2D benchmark models (such as YOLOv8 / v11 series) for comparison, and the results are shown in Table 2 below.
[0171] Table 2. Validation of different 3D-2D cross-combinations of the dataset of this invention
[0172]
[0173] Regarding the performance trade-offs of 3D backbone networks, experimental data shows that while the ResNeXt101 group (such as experiment F06) achieved a peak mAP of 0.9419, establishing an upper limit for accuracy, its parameter count exceeded 110M, and the high computational load made it difficult to meet the low-cost deployment requirements of edge computing devices. Although the ShuffleNetv2 group had the advantage of lightweight design, its feature extraction capabilities were limited, making it difficult to capture subtle movement features such as "pushing" and "slipping" during childbirth, resulting in mAP generally below 0.90 and significant integrity regression errors. In contrast, the I3D group showed the best performance balance. Taking C15 as an example, with a parameter count (approximately 81.94M), which was about two-thirds that of the ResNeXt101 group, it still achieved a high mAP of 0.9284, significantly outperforming the ShuffleNetv2 group and approaching the ResNeXt101 group.
[0174] Regarding the evolution benefits of the 2D architecture, by comparing the performance of YOLOv8 and YOLOv11 under the same I3D backbone (comparing C20 and C06), it can be found that the YOLOv11 architecture brings significant gains. Compared with C20 (YOLOv8m + I3D), the mAP of C06 (YOLOv11m + I3D) increased from 0.9070 to 0.9284, and the number of parameters decreased from 69.86M to 59.9M. This result strongly demonstrates that the C3k2 module and improved feature pyramid structure introduced in the YOLOv11 series adopted in this invention have higher parameter efficiency when dealing with complex backgrounds in pig houses and multi-scale targets (covering the entire process from fetal emergence to full delivery).
[0175] Regarding the adaptability of model size, experiments revealed that simply increasing model depth and width did not bring sustained performance gains. For example, the mAP of C16 (YOLOv11l) unexpectedly dropped to 0.8874, while the mAP of C15 (YOLOv11x), with its extremely large number of parameters, rebounded to 0.9255, but was still slightly lower than that of the medium-sized C06 (0.9284), and the number of parameters increased by about 36%. This indicates that in the specific scenario of sow farrowing, excessively large receptive fields or excessively deep network structures are prone to overfitting or feature redundancy, while medium-sized models are better able to capture pure and effective features.
[0176] In the integrity regression task, the C06 model exhibits extremely high stability, with a Comp MAE (mean absolute error) of 0.1245 and a Comp RMSE (root mean square error) of 0.2136. Given that integrity labels are divided in 0.2 increments, an MAE of approximately 0.12 means that the model's average prediction bias is less than one quantization level. This data validates that the "feature bridging decoupling head" proposed in this invention can effectively fuse I3D motion features with YOLOv11 geometric features, achieving accurate fitting of the physical process of childbirth.
[0177] The experimental results above show that the CP-YOWO model (C06) of this invention, which uses I3D as the 3D backbone and YOLOv11m as the 2D backbone, achieves an mAP@50 of 0.9284 with only 59.90M parameters. It has a small integrity assessment deviation and achieves the optimal balance in detection accuracy, computing power adaptability, and assessment stability. It is the optimal configuration for farrowing monitoring in large-scale pig farms.
[0178] The above descriptions are merely embodiments of the present invention. Commonly known technical knowledge in the solutions is not described in detail here. Those skilled in the art are aware of all common technical knowledge in the field prior to the filing date, are aware of all existing technologies in that field, and have the ability to apply conventional experimental methods prior to that date. Those skilled in the art can, under the guidance of this application, improve and implement this solution in combination with their own capabilities. Some typical well-known technologies should not be obstacles for those skilled in the art to implement this application. It should be noted that those skilled in the art can make several adjustments and improvements without departing from the structure of the present invention. These should also be considered within the scope of protection of the present invention, and will not affect the effectiveness of the implementation of the present invention or the practicality of the patent. The scope of protection claimed in this application should be determined by the content of its claims, and the specific embodiments described in the specification can be used to interpret the content of the claims.
Claims
1. A sow farrowing detection system based on spatiotemporal motion localization, characterized in that: The CP-YOWO model is used to detect the farrowing status of sows in real time. The input of the model is the monitoring video. The CP-YOWO model is an improvement on the YOWO3 model and includes a dual-stream feature extraction module, an action-guided attention fusion module, and a feature bridging and decoupling detection head. The dual-stream feature extraction module includes a two-dimensional spatial branch and a three-dimensional spatiotemporal branch, which extract video spatial texture features and spatiotemporal motion features, respectively. The action-guided attention fusion module generates an action mask using the spatiotemporal action features, and uses the action mask to perform weighted suppression on the background region in the video spatial texture features extracted by the two-dimensional spatial branch. Then, the weighted video spatial texture features and the spatiotemporal action features are fused based on an attention mechanism to output the fused features. The feature bridging and decoupling detection head receives the fusion features output by the action-guided attention fusion module, decouples the fusion features into target box regression features and category classification features, then concatenates the target box regression features and category classification features in the channel dimension to form bridging features, and finally determines the piglet production status based on the bridging features.
2. The sow farrowing detection system based on spatiotemporal motion localization according to claim 1, characterized in that: In the dual-stream feature extraction module, the two-dimensional spatial branch extracts features from key frames in the video segment to obtain a spatial feature map containing texture, edges, and geometric shapes; the three-dimensional spatiotemporal branch extracts three-dimensional features from the entire video segment to obtain a spatiotemporal motion feature map containing information on changes in the time dimension.
3. The sow farrowing detection system based on spatiotemporal motion localization according to claim 2, characterized in that: The action-guided attention fusion module is used to connect the two-dimensional spatial branch and the three-dimensional spatiotemporal branch. Its processing flow includes: A1, Action mask generation: receiving the three-dimensional spatiotemporal feature map output by the three-dimensional spatiotemporal branch. , where C 3D H represents the number of spatiotemporal channels in a three-dimensional spatiotemporal feature map. 3D W 3D The height and width of the 3D spatiotemporal feature map are represented respectively; after processing by the following lightweight action gating sub-network, an action mask M is generated. motion : ; In the formula: Indicates F 3D The 3×3 convolution operation is used to extract local action context; δ represents the batch normalization operation; δ represents the SiLU activation function operation. σ represents a 1×1 convolution operation; σ represents the Sigmoid function, which maps the output value to the (0,1) interval. in, The pixel value m i,j ∈(0,1), representing the significance of the childbirth action in the i-th row and j-th column at the corresponding position; A2. Cross-scale spatial alignment: Extracting two-dimensional spatial feature maps F 2D Features, among which C 2D H represents the number of channels in a two-dimensional spatial feature map. 2D W 2D These represent the height and width of the feature map in the two-dimensional space, respectively; a bilinear interpolation algorithm is used to interpolate M... motion and F 3D Perform upsampling alignment: ; ; In the formula: This represents the action mask after the upsampling operation; This represents the 3D spatiotemporal feature map after the upsampling operation; Upsample() represents the bilinear interpolation upsampling operation; size() represents the target space size of the upsampling operation; A3. Feature gating for motion guidance: Upsampling the motion mask For F 2D Element-wise multiplication yields a spatially gated two-dimensional spatial feature map: ; In the formula: It represents the Hadamardi (or Hadama) stack; Generated by the Sigmoid activation function, its value is a continuous floating-point number in the range (0,1). When the action mask value approaches 1, the spatial texture features of the corresponding position are completely preserved and transmitted; when the action mask value approaches 0, the feature response is suppressed; for the intermediate value in the range (0,1), the model scales the feature amplitude proportionally according to its probability. A4. Cross-modal feature fusion and reconstruction: and The splicing is performed along the channel dimension to obtain the splicing spatial feature map F. concat : ; In the formula: Concat() represents the channel dimension concatenation operation; dim=Channel indicates that the target dimension of the concatenation operation is the channel dimension; The spliced F concat The input is a channel feature aggregation block with a channel attention mechanism. The channel weights are adaptively adjusted through the following operations, and the final output is the fused feature map F. final : ; In the formula: This represents the channel attention operation, which captures channel dependencies by calculating the covariance matrix between channels; Indicates the input convolution transformation operation; Indicates the output convolution transformation operation; The final output fused feature map F final It is then fed into a subsequent detection head for decoupling detection.
4. The sow farrowing detection system based on spatiotemporal motion localization according to claim 3, characterized in that: The feature bridging and decoupling detection head is used to map the fused feature map output by the action-guided attention fusion module to the final detection result. Its process includes: B1. Feature Decoupling and Primary Extraction: Receive the fused feature map F final The input feature F of the feature bridging decoupling detection head in ,Right now The decoupling head decouples the features into bounding box regression features. and category classification features The following operations are performed respectively: Among them, F box It contains geometric information about the target's boundaries and aspect ratio, F cls It contains the target's texture and category semantic information; among which and The decoupling operation yields the bounding box regression features and the category classification features, respectively. in Represents input channel, C mid This represents the channel after decoupling. B2, "H" type feature bridging: Connecting F box With F cls By splicing along the channel dimension, a bridging feature is formed. : ; In the formula: Concat() represents the channel dimension concatenation operation; dim=Channel indicates that the target dimension of the concatenation operation is the channel dimension; B3. Enhanced Coordinate Attention: For F bridge Apply coordinate attention processing to capture spatial location information: First, perform feature aggregation along the horizontal and vertical directions respectively using adaptive average pooling kernels to obtain feature vectors in the height and width directions. ; In the formula: This represents the average pooling characteristic of the c-th channel along row h in the height direction; The c-th channel represents the average pooling feature along the width column w; W and H represent the bridging feature F, respectively. bridge The width and height of the feature map; Represents the pixel value of the c-th channel of the bridging feature map at position (h,i) or (j,w); Then, the feature vectors from the two directions are concatenated, dimensionality reduction is performed using a shared 1×1 convolution function, and SiLU activation is applied. The result is then split into two independent tensors to obtain the height-direction feature g. h and width direction feature g w : ; In the formula: [z h ,z w ] represents the height-direction feature z h With width direction feature z w The splicing features in the channel dimension; This indicates that a 1×1 convolutional layer operation is performed on the spliced feature, and then it is processed. Batch normalization; finally, δ represents the SiLU function activation; Split() indicates that the channel dimension is split to obtain the features g in the height and width directions. h and g w ; The height and width features are then mapped to attention weights through convolutional layers. Finally, the generated coordinate attention weights are applied to the original bridging features to obtain the final complete feature F. comp : ; ; In the formula: A h A w These represent the attention weights in the height and width directions, respectively. () () represent the height and width features g respectively. h g w A 1×1 convolutional layer that maps the original output of attention weights in the height and width directions; σ represents the attention weights between (0,1) obtained by the Sigmoid function operation; B4. Multi-task prediction output: Three independent convolutional layers are used to map features into target box regression output, category classification output, and completeness evaluation output, respectively, to achieve simultaneous detection of multiple tasks.
5. The sow farrowing detection system based on spatiotemporal motion localization according to claim 4, characterized in that: The completeness assessment output is graded as follows: 0.1-0.3 is "just emerging", 0.3-0.5 is "head emerging", 0.5-0.7 is "trunk emerging", 0.7-1.0 is "about to be fully delivered", and 1.0 is "fully delivered". If the completeness remains at a certain level for a long time and exceeds the preset time threshold, it is judged as labor stagnation / dystocia.
6. The sow farrowing detection system based on spatiotemporal motion localization according to any one of claims 1-5, characterized in that: The CP-YOWO model uses a hybrid ordinal loss function to calculate the error between the predicted value and the true label. The hybrid ordinal loss function is composed of a weighted sum of label smoothing cross-entropy loss and expected value regression loss. Label smoothing cross-entropy loss: the smoothed true probability distribution q of the i-th sample i : ; In the formula: ε represents the smoothing factor; This indicates an indicator function, meaning that the value is 1 if the condition inside the parentheses is true and 0 if it is false; This represents the actual category index; K represents the number of categories; Label smoothing cross-entropy loss function L ce : ; In the formula: p i (k) is the probability of belonging to the k-th unit as output by the model after Softmax; Expected value regression loss: Model predicts expected value for: ; In the formula: v k Represents the k-th discrete gear element; Expected value regression loss function L reg : ; In the formula: t i Indicates a true floating-point label; The label smoothing cross-entropy loss is weighted with the expected value regression loss to obtain the completeness branch loss function L. comp : ; In the formula: λ reg Indicates the balance coefficient; Overall model loss function L total : ; In the formula: L cls λ represents the category classification loss. cls L represents the category classification loss balance coefficient; dfl λ represents the distribution focus loss. dfl λ represents the distribution focus loss balance coefficient; comp L represents the balance coefficient of branch loss in terms of completeness; box λ represents the bounding box position loss. box This represents the boundary box position loss balance coefficient.
7. The sow farrowing detection system based on spatiotemporal motion localization according to claim 6, characterized in that: The smoothing factor ε is 0.2, the number of categories K is 6, and the balance coefficient λ is... reg The class classification loss balance coefficient is 2.
0. cls The distribution focus loss balance coefficient λ is 0.
5. dfl The integrity branch loss balance coefficient λ is 1.
5. comp It is version 2.
0.
8. The sow farrowing detection system based on spatiotemporal motion localization according to claim 7, characterized in that: The CP-YOWO model uses I3D as the 3D backbone and YOLOv11m as the 2D backbone.
9. A method for detecting farrowing in sows based on spatiotemporal motion localization, characterized in that, The detection system according to any one of claims 1-8 is used to detect sow farrowing.