Piglet weight evaluation method and system based on timing characteristics and attention mechanism
By constructing a dual-branch fusion network using time-series data of piglet natural behavior and attention mechanism-based piglet weight assessment method, the accuracy and robustness issues of weight estimation in existing technologies are solved, and efficient and stable weight monitoring is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-02
- Publication Date
- 2026-07-03
Smart Images

Figure CN122336863A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent livestock farming technology, specifically to a method and system for assessing piglet weight based on temporal characteristics and attention mechanisms. Background Technology
[0002] Piglet weight is a core indicator for evaluating their growth and development performance and health status, and it is also a key basis for refined breeding, feed formulation optimization, and disease early warning in large-scale pig farms. With the development of smart animal husbandry, non-contact weight estimation based on computer vision has become a research hotspot in the industry, which can effectively solve the pain points of traditional contact weighing, such as high stress, low efficiency, and high labor costs.
[0003] Currently, existing piglet weight estimation technologies mainly fall into two categories. One category is weight estimation schemes based on depth cameras, such as the patent with publication number CN120070534A entitled "A Pig Weight Calculation Scheme Based on Body Size Fusion Depth Data," which estimates weight by obtaining the three-dimensional body size parameters of piglets through depth information. However, depth camera equipment is costly, difficult to maintain, and severely affected by dust and moisture in pigsties. Most commercial pig farms have not deployed it throughout their entire pigsties, making large-scale implementation difficult.
[0004] Another type is the weight estimation scheme based on two-dimensional visible light images, such as the patent with publication number CN120997500A, entitled "A Method and System for Estimating the Average Weight of Piglets in a Litter Based on Instance Segmentation." This scheme extracts body size features through instance segmentation of a single frame image and obtains the litter weight by averaging multiple frames. This is currently the mainstream solution in the industry, but it still faces the following problems in actual production implementation:
[0005] First, behavioral constraints lead to a "long-tail effect" in effective data. Piglets are highly active, frequently engaging in behaviors such as feeding, rooting, and contorting their bodies. To ensure estimation accuracy, current technologies typically employ strict posture screening mechanisms, retaining only instantaneous frames where the piglet's body is completely straight and balanced. This "static instead of dynamic" strategy results in over 90% of video frames in long videos being discarded as "noise," meaning only a very small number of valid samples can be obtained in a single acquisition, severely limiting the timeliness of weight estimation. Furthermore, relying solely on the projected area of a specific posture cannot cover the complete body posture information of piglets during natural activities, making sampling bias highly likely.
[0006] Secondly, there is a lack of dimensional perception of the dynamic biological characteristics. As living organisms, piglets' behavioral dynamics are strongly correlated with their body size, muscle density, and skeletal development. However, a single static image can only capture a two-dimensional planar projection, completely ignoring the three-dimensional information contained in the dynamic characteristics. For example, the maximum stride of a piglet is a dynamic manifestation of its linear skeletal dimensions, which is more robust than its static body length. The compression and stretching deformation of the back and buttock muscles during movement can compensate for the missing body thickness information in a two-dimensional image. However, a single frame image cannot perceive these characteristics, which can easily lead to misjudgments of "different weights for the same shape."
[0007] Third, the complexity of the environment leads to instantaneous jumps in estimated values. Pig farm environments are characterized by complex lighting and shadows, with unfavorable factors such as fence obstruction, dust interference, and ground reflection. Regression models relying solely on single-frame images lack contextual constraints; even a slight deviation in keypoint localization or contour segmentation within a single frame can cause significant instantaneous jumps in predicted values. Furthermore, the lack of temporal smoothing mechanisms means that while piglet weight is a constant physical property in continuous video streams, single-frame estimates often exhibit drastic, discrete fluctuations, failing to meet the needs of continuous and stable monitoring in large-scale pig farms.
[0008] In summary, existing technologies cannot simultaneously achieve the accuracy, timeliness, and robustness of weight estimation. There is an urgent need for a solution that breaks through the limitations of fixed postures, is compatible with existing common monitoring equipment in pig farms, and utilizes time-series data of piglets' natural behavior to achieve high-precision weight assessment. Summary of the Invention
[0009] To address the problems existing in the prior art, the present invention aims to provide a method for assessing piglet weight based on temporal features and attention mechanisms. This method can effectively solve the problems of low effective data rate, lack of dynamic information, and insufficient robustness in the current method of assessing piglet weight using single-frame static images. This improves the effective data utilization rate in complex breeding scenarios, enhances the perception accuracy of piglet fullness, and reduces the stringent environmental and posture requirements for engineering deployment.
[0010] The objective of this invention is achieved through the following technical solution:
[0011] A method for assessing piglet weight based on temporal features and attention mechanisms, comprising the following steps:
[0012] S1. After video stream preprocessing and dynamic target separation and tracking, a time sequence of piglet key points with real physical scale is obtained. The dynamic target separation and tracking includes sequentially performing pixel-level instance segmentation, single target purification and background suppression, sliding window sampling and dynamic key point extraction, and spatial normalization calibration.
[0013] S2. Based on biomechanical dynamic feature calculation, multi-dimensional dynamic features characterizing the size and developmental status of piglets are obtained. The dynamic features include gait feature factor, trunk twisting entropy, and dynamic mask area diffusion coefficient.
[0014] S3. By fusing spatiotemporal attention features, a dual-branch fusion network is constructed to obtain the global comprehensive feature vector;
[0015] S4. Input the global comprehensive feature vector into the regression output head and output the predicted weight of piglets within the corresponding time window;
[0016] S5. Model Training: Construct a dynamic time-series dataset based on the label broadcasting mechanism, and use an invariant feature-forced learning strategy to jointly train the dual-branch fusion network.
[0017] S6. The trained model will be used for dynamic assessment of piglet weight.
[0018] Based on further optimization of the above scheme, the pixel-level instance segmentation in S1 is specifically as follows: the YOLO11-Seg instance segmentation model is used to perform frame-by-frame reasoning on the video frames to obtain the pixel-level foreground contour mask of all piglets in the picture; the ByteTrack, DeepSORT, BoT-SORT, OC-SORT or a pixel-level tracking algorithm based on optical flow is used to calculate the intersection-over-union ratio (IoU) and appearance feature similarity of the piglet masks between adjacent frames, and a unique identity ID is assigned and continuously bound to each piglet in the video stream to realize the full-cycle tracking of a single pig in a group-raising environment.
[0019] Based on the further optimization of the above scheme, the single target purification separation and background suppression in S1 are specifically as follows: For the tracked specific ID piglet, calculate the minimum bounding rectangle cropping box with appropriate expansion according to the mask of its current frame; within the cropped image area, only retain the original RGB (Red Green Blue, representing the three primary color light modes) pixel information within the coverage area of the single target mask, and uniformly replace all areas outside the mask boundary (including the background of the manure board, light and shadow interference, the edge of the adjacent piglet's body, etc.) with a preset single gray value (such as RGB [128,128,128]), generating a single piglet image sequence with "real foreground and pure background", isolating the interference of complex environment on feature extraction.
[0020] Based on further optimization of the above scheme, the sliding window sampling and dynamic key point extraction in S1 are specifically as follows: for a single piglet image sequence, the YOLO-Pose key point detection network is used to accurately locate the key parts of the piglet's head, tail, limb joints, left and right shoulders and left and right buttocks; and a sliding window of fixed length is used to extract the key point temporal sequence and foreground contour sequence of a specific ID piglet along the time axis.
[0021] Based on further optimization of the above scheme, the spatial normalization calibration in S1 specifically involves: using fixed-size ground reference objects within the pigsty (such as the known physical spacing of standardized slatted floors), during the calibration phase of system deployment, selecting at least four coplanar known physical feature points on the ground plane as reference points, based on image pixel coordinates (u k ,v k ) and its corresponding coordinates in the real physical world (X k ,Y k ), calculate the 3×3 homography transformation matrix from the image plane to the physical ground plane, denoted as H;
[0022] During the real-time preprocessing stage of the video stream, for any extracted piglet keypoint or contour pixel coordinates (u,v) in the image, homogeneous coordinate mapping is performed according to the following formula:
[0023] ;
[0024] In the formula: the right column vector represents the homogeneous coordinates obtained by vector transposing the coordinates (u,v,w) formed by the keypoint or contour pixel coordinates (u,v,w) and the non-zero scale scaling factor w in the homogeneous coordinate system; the left column vector represents the homogeneous physical coordinate column vector obtained by multiplying the right column vectors by a 3×3 homography transformation matrix; where x´ and y´ represent the x and y components of the transformed homogeneous coordinates, respectively, w represents the non-zero scale scaling factor in the homogeneous coordinate system, w´ represents the w component of the transformed homogeneous coordinates, and H represents the 3×3 homography transformation matrix operation;
[0025] Finally, convert it to the actual physical coordinates (X, Y) using the following formula:
[0026] ;
[0027] .
[0028] Through the above mapping, the piglet's movement trajectory, stride length, and projected area extracted by the system are all transformed into real geometric features with absolute physical scale. These coordinates will be directly input into the subsequent calculation of dynamic step length and area diffusion coefficient, ensuring the absolute physical accuracy and spatial translation invariance of the model's geometric parameter deduction when the piglet crosses different spatial positions between the center and edge of the image.
[0029] Based on further optimization of the above scheme, the gait feature factor in S2 is calculated according to the following steps: first, the dynamic stride L within the sliding window T frames is calculated. stride :
[0030] ;
[0031] In the formula: T represents the total number of video frames within the currently captured sliding window, and 𝑡 represents a specific video frame within the sliding window; X and Y both represent two-dimensional coordinate values, and the specific meanings of the two-dimensional coordinate values defined by the subscripts and superscripts are as follows: This represents the two-dimensional coordinates of the key point on the left shoulder of the piglet in the real physical plane after spatial normalization in frame t. This represents the two-dimensional coordinates of the piglet's right rump keypoint in frame t, after spatial normalization, on the real physical plane; max indicates taking the maximum value of the calculated result.
[0032] Then calculate the gait characteristic factor using the following formula. :
[0033] ;
[0034] In the formula: Δt represents the time taken for the piglet to complete the maximum stride extension; V avg This represents the average speed of the piglet's center of mass in physical space within the time window corresponding to the total number of video frames T within the currently captured sliding window; where Δt is the speed of movement of the piglet's center of mass in physical space within the current dynamic stride L. stride Frame number f within time window T max Subtract the initial frame number f start The absolute value after dividing by the camera's FPS is obtained as follows:
[0035] ;
[0036] Where V avg Calculate using the following formula:
[0037] ;
[0038] Both X and Y represent two-dimensional coordinate values, and the specific meanings of the two-dimensional coordinate values defined by the superscripts and subscripts are as follows: This represents the two-dimensional coordinates of the piglet's center of mass in the real physical plane after spatial normalization at frame T. This represents the two-dimensional coordinates of the piglet's center of mass in the real physical plane after spatial normalization, at frame 1; the denominator is... This represents the absolute physical time interval from frame 1 to frame T, which is obtained by subtracting 1 from the total number of video frames T and then dividing by the camera's FPS.
[0039] Based on further optimization of the above scheme, the torso twisting entropy in S2 is calculated according to the following steps;
[0040] For any t-th frame within the sliding window T, firstly, the coordinates of the center point of the piglet's shoulder are calculated using the spatially normalized physical coordinates. :
[0041] ;
[0042] In the formula, This represents the two-dimensional coordinates of the key point on the left shoulder of the piglet in the real physical plane after spatial normalization in frame t. This represents the two-dimensional coordinates of the key point on the right shoulder of the piglet in the real physical plane after spatial normalization in frame t.
[0043] Then, the vertical distance from the center point of the shoulder to the body's central axis formed by the line connecting the piglet's head and tail is calculated, and normalized by dividing by the length of the body's central axis to obtain the shoulder deviation r in frame t. s,t :
[0044] ;
[0045] In the formula: X and Y both represent two-dimensional coordinate values, and the specific meanings of the two-dimensional coordinate values defined by the superscripts and subscripts are as follows: This represents the actual physical two-dimensional coordinates of the key points on the piglet's head in frame t; This represents the actual physical two-dimensional coordinates of the key point on the piglet's tail in frame t; This represents the actual physical two-dimensional coordinates of the center point of the piglet's shoulder in frame t;
[0046] Then obtain the complete deviation sequence R={r} within the sliding window of T frames. s,1 , r s,2 ,…r s,t ,… r s,T After that, its torso twisting entropy was further calculated. :
[0047] ;
[0048] In the formula: K represents the total number of statistical bins that divide the deviation value range into equally wide intervals; P(r i ) represents the probability that the deviation value falls within the i-th statistical bin interval (i.e., the frequency of deviation occurring in this frequency band).
[0049] Based on further optimization of the above scheme, the dynamic mask area dispersion coefficient in S2 Calculate using the following formula:
[0050] ;
[0051] In the formula: This represents the pixel area or physical mapping area of the foreground mask of a single piglet extracted through instance segmentation in frame t. This represents the arithmetic mean of the foreground mask area of the piglet within the total number of video frames T captured in the current sliding window.
[0052] Based on further optimization of the above scheme, the dual-branch fusion network in S3 includes static branches, dynamic branches, and a spatiotemporal attention module; wherein:
[0053] The static branch uses a ResNet50 backbone network to extract the clean contour feature vector f for each frame. static,t ;
[0054] Dynamic branches will incorporate gait feature factors Torso twisting entropy Area dispersion coefficient The vectors are spliced together to form the dynamic feature vector V for that time window. dynamic ;
[0055] The spatiotemporal attention module employs a Transformer model encoder structure to calculate the correlation between features in T frames and normalizes the self-attention scores. Weighted fusion is performed on each frame:
[0056] ;
[0057] In the formula: e t represents the original energy score of the attention of the feature vector of frame t before it is input into the Softmax activation function, and exp represents the exponential operation;
[0058] Then, the global comprehensive feature vector output after weighted fusion by the spatiotemporal attention module is calculated according to the following formula. :
[0059] ;
[0060] In the formula: This indicates the feature concatenation operator.
[0061] Based on a further optimization of the above scheme, step S4 specifically involves: integrating the global feature vector... Finally, the data is fed into a regression output head composed of a multilayer perceptron (MLP); this regression output head directly outputs a continuous scalar value through nonlinear mapping. The absolute weight of the piglets within that time window is predicted (in kg). When the piglets are at rest or in a state of slight movement (such as eating or standing), dynamic features (such as stride) approach zero. At this time, the Transformer's self-attention mechanism will automatically reduce the weight of the dynamic branches and instead rely on the feature consistency of the static branches in consecutive frames for regression, thereby achieving adaptive weight assessment throughout the entire behavioral cycle.
[0062] Based on further optimization of the above scheme, the weight prediction in S4 introduces a total loss function L that includes temporal prediction consistency loss. total Perform correction:
[0063] ;
[0064] In the formula: N represents the total number of samples in the current training batch; This represents the true physical weight label corresponding to the nth sample; This represents the predicted weight value output by the model for the nth sample; The weighting coefficients represent the consistency loss; τ represents the set of adjacent time windows segmented within the same continuous long video. and Let i and j represent the predicted weight values of the same piglet in adjacent time segments i and j, respectively, where i and j both belong to the time window set τ.
[0065] Based on a further optimization of the above scheme, S5 specifically refers to:
[0066] S51. Time-series tag broadcasting mechanism based on absolute truth value: During the data acquisition phase, the absolute weight truth value W of piglets bound with unique IDs at a specific physiological time point is obtained through contact weighing equipment (such as physical weighbridges). gt The piglets were released into natural group-raising pens, and continuous video streams of them in an unrestricted state (eating, running, turning, etc.) were collected using overhead cameras.
[0067] The continuous video stream is sliced according to a preset sliding window length (e.g., T=30 frames) to generate a large number of time-series video segments; the absolute weight truth value W is then calculated. gt As a label, all video clips within the corresponding time period are uniformly assigned to the piglet with this ID to construct a dynamic time-series dataset;
[0068] S52. Invariant Feature-Forced Learning Strategy: During the training phase, time-series video clips of the same piglet exhibiting completely different behavioral patterns (e.g., clip A is "walking in a straight line at a constant speed" and clip B is "turning its head and rooting its head") are input into the dual-branch fusion network in batches. Since clips of different behavioral patterns correspond to the same ground truth weight label, this "different shapes, same label" training constraint will force the model's spatiotemporal attention module to automatically reduce its dependence on the variable feature of "two-dimensional projected area" during backpropagation.
[0069] After numerous iterations, the network is "forced" to uncover and focus on deep biomechanical laws that remain relatively constant across various motion postures (such as the aforementioned dynamic step size factor and trunk torsional entropy), thereby enabling the model to leap from "learning appearances" to "learning essence." Combined with the consistency loss function, the final trained model can effectively resist the interference of complex environments and extreme postures, outputting a highly stable dynamic evaluation curve.
[0070] On the other hand, the present invention also provides a system for the above-mentioned piglet weight assessment method based on temporal features and attention mechanisms, comprising:
[0071] The video preprocessing and target tracking module is used to process the continuous video stream collected by the overhead monitoring of the pigsty frame by frame, complete instance segmentation, multi-target tracking, background suppression and spatial normalization calibration, and output a clean image sequence of each piglet with a unique ID and a key point time sequence with real physical scale.
[0072] The dynamic feature calculation module is used to extract time series sequences using a sliding window of fixed length and calculate multi-dimensional dynamic features that characterize the size and developmental status of piglets. The dynamic features include gait feature factor, trunk twisting entropy, and dynamic mask area diffusion coefficient.
[0073] The spatiotemporal attention fusion module has a built-in dual-branch fusion network. It extracts the static contour feature vector of a single frame through the static branch and integrates it through the dynamic branch to obtain the dynamic feature vector. The spatiotemporal attention module completes the adaptive weighted fusion of temporal features and outputs a global comprehensive feature vector.
[0074] The weight regression output module has a built-in regression output head composed of a multi-layer sensing mechanism, which is used to receive the global comprehensive feature vector and output the predicted weight value of piglets within the corresponding time window.
[0075] The model training module is used to construct a dynamic time-series dataset based on a label broadcasting mechanism and employs an invariant feature-forced learning strategy to complete the joint training of the model.
[0076] The following are the technical effects of the present invention:
[0077] This invention overcomes the limitations of fixed postures, significantly improving the utilization rate of effective data. By replacing single-frame static analysis with temporal modeling, it eliminates the need for rigorous selection of specific posture frames where piglets are "standing upright." Weight assessment is performed using video data from the entire behavioral cycle of piglets, including stillness, walking, eating, and wriggling. Experimental results show that the proportion of effective prediction frames in this invention increases from 19.5% in existing technologies to 82.3%, and the effective monitoring time is increased by more than three times. This completely solves the problem of the "long tail effect" of effective data in existing technologies, significantly improving the timeliness of weight monitoring.
[0078] Meanwhile, this invention indirectly obtains three-dimensional information such as piglet skeleton size, body thickness, and muscle fullness, which are missing from two-dimensional images, by extracting three types of biomechanical dynamic features: gait feature factors, trunk torsional entropy, and dynamic mask area diffusion coefficient. This effectively alleviates the evaluation bias of "different weights for the same projected area." Experimental results show that, under the premise of relaxing posture restrictions, this invention achieves a mean absolute error (MAE) as low as 0.22 kg, a root mean square error (RMSE) as low as 0.33 kg, and a coefficient of determination (R²) as low as [missing value]. 2 The accuracy reached 0.95, which significantly improved both prediction accuracy and stability compared to existing single-frame static models and multi-frame averaging models.
[0079] Furthermore, this invention only requires the use of existing ordinary overhead monitoring equipment in pig farms, without the need for additional deployment of hardware such as depth cameras, significantly reducing engineering deployment costs. By isolating environmental interference through a background suppression mechanism and automatically reducing the weight of distorted and occluded frames through a spatiotemporal attention module, combined with temporal consistency loss constraints, it completely eliminates the common numerical jump problem in single-frame prediction. It exhibits extremely strong anti-interference capabilities in complex scenarios such as pigpen lighting, occlusion, and changes in piglet posture, making it highly valuable for engineering promotion.
[0080] The label broadcasting mechanism and invariant feature forced learning strategy proposed in this invention solve the industry pain point of high labeling cost of dynamic time series data. At the same time, it forces the model to learn the essential biological characteristics related to weight rather than the posture appearance, which greatly improves the model's generalization ability in different breeds and different breeding environments. Attached Figure Description
[0081] Figure 1 This is a flowchart of the piglet weight assessment method based on temporal features and attention mechanism in Embodiment 1 of the present invention. Detailed Implementation
[0082] 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.
[0083] The YOLO11-Seg instance segmentation model used in this invention refers to a known end-to-end real-time instance segmentation model in the art. It adds a dedicated segmentation branch to the YOLO11 detection architecture, outputting detection boxes, categories, and pixel-level masks simultaneously during a single inference, balancing speed and accuracy. The YOLO-Pose model used in this invention is a single-stage object pose estimation model based on the YOLO architecture.
[0084] The ByteTrack algorithm, DeepSORT (Deep Simple Online and Realtime Tracking), BoT-SORT (Bag of TricksSORT), OC-SORT (Observation-Centric SORT), and the pixel-level tracking algorithm based on optical flow used in this invention are all known tracking algorithms in the field.
[0085] The mask used in this invention refers to a binary map used to distinguish between valid and invalid regions, which informs the model which regions to use during model computation.
[0086] The homography matrix used in this invention is a 3×3 mathematical matrix used to describe the projection mapping relationship between two planes. For example, it is the core transformation matrix for turning a perspective view captured by a camera into a bird's-eye view, and can be used for inverse perspective transformation.
[0087] The Inverse Perspective Mapping (IPM) used in this invention straightens a perspective-distorted image taken at an angle by a camera through a homography transformation matrix, transforming it into a top-down view.
[0088] The homogeneous coordinate mapping used in this invention adds an extra dimension to ordinary coordinates, allowing all geometric transformations (translation, rotation, scaling, perspective, etc.) to be calculated uniformly using matrix multiplication. It is the underlying mathematical foundation of inverse perspective transformation (IPM) and homography matrix.
[0089] The individual operations used in this invention, such as splicing, are all operations well known to those skilled in the art, and can be obtained through channels such as GitHub or directly run and trained on conventional platforms such as PyTorch or Python.
[0090] Example 1
[0091] A method for assessing piglet weight based on temporal features and attention mechanisms, comprising:
[0092] S1. Video stream preprocessing and dynamic target separation and tracking: The continuous video stream collected from the overhead monitoring of the pigsty is preprocessed in sequence, including pixel-level instance segmentation, single target purification and background suppression, sliding window sampling and dynamic key point extraction, and spatial normalization calibration, to obtain the time sequence of piglet key points with real physical scale.
[0093] Pixel-level instance segmentation specifically involves: using the YOLO11-Seg instance segmentation model to perform frame-by-frame inference on the video frames to obtain pixel-level foreground contour masks of all piglets in the frame; and using either ByteTrack or BoT-SORT multi-target tracking algorithm to assign and continuously bind a unique identity ID to each piglet in the video stream by calculating the intersection-over-union ratio (IoU) and appearance feature similarity of the piglet masks between adjacent frames, thereby achieving full-cycle tracking of a single pig in a group-housed environment.
[0094] The specific process of single-target purification and background suppression is as follows: For a tracked piglet with a specific ID, a minimum bounding rectangle cropping box with appropriate expansion is calculated based on the mask of its current frame; within the cropped image area, only the original RGB pixel information within the coverage area of the single-target mask is retained, and all areas outside the mask boundary (including the background of the manure board, light and shadow interference, and the edges of the adjacent piglet's body, etc.) are uniformly replaced with a preset single gray value (such as RGB [128,128,128]), generating a single piglet image sequence with "real foreground and pure background", thus isolating the interference of complex environment on feature extraction.
[0095] The sliding window sampling and dynamic key point extraction are as follows: For a single piglet image sequence, the YOLO-Pose key point detection network is used to accurately locate the key parts of the piglet's head, tail, limb joints, left and right shoulders, and left and right buttocks; and a sliding window of fixed length (e.g., T=30 frames) is used to extract the temporal sequence of key points and the foreground contour sequence of a specific ID piglet along the time axis.
[0096] Spatial normalization calibration specifically involves: following the inverse perspective transformation method, using fixed-size ground reference objects within the pigsty (such as the known physical spacing of standardized slatted floors), during the system deployment calibration phase, selecting at least four coplanar known physical feature points on the ground plane as reference points, based on image pixel coordinates (u... k ,v k ) and its corresponding coordinates in the real physical world (X k ,Y k ), calculate the 3×3 homography transformation matrix from the image plane to the physical ground plane, denoted as H;
[0097] During the real-time preprocessing stage of the video stream, the homogeneous coordinate mapping of any extracted piglet keypoints or contour pixel coordinates (u,v) in the image is performed according to the following formula:
[0098] ;
[0099] In the formula: the right-hand column vector represents the homogeneous coordinates obtained by transposing the coordinates (u,v,w) formed by the keypoint or contour pixel coordinates (u,v) and the non-zero scaling factor w in the homogeneous coordinate system; the left-hand column vector represents the homogeneous physical coordinate column vector obtained by multiplying the right-hand column vectors by a 3×3 homography transformation matrix; where x´ and y´ represent the x and y components of the transformed homogeneous coordinates, respectively, w represents the non-zero scaling factor in the homogeneous coordinate system, w´ represents the w component of the transformed homogeneous coordinates, and H represents the 3×3 homography transformation matrix operation. Transpose is the process of writing a row vector as a column vector to facilitate matrix multiplication. For example, the left-hand vector transpose operation can be expressed as: , where T represents the transpose operation.
[0100] Finally, convert it to the actual physical coordinates (X, Y) using the following formula:
[0101] ;
[0102] .
[0103] Through the above mapping, the piglet's movement trajectory, stride length, and projected area extracted by the system are all transformed into real geometric features with absolute physical scale. These coordinates will be directly input into the subsequent calculation of dynamic step length and area diffusion coefficient, ensuring the absolute physical accuracy and spatial translation invariance of the model's geometric parameter deduction when the piglet crosses different spatial positions between the center and edge of the image.
[0104] S2. Derivation of dynamic features based on biomechanics: Using a fixed-length sliding window, the key point time sequence and foreground contour sequence of a single piglet are extracted along the time axis. Multi-dimensional dynamic features characterizing the size and developmental status of the piglet are calculated. The dynamic features include gait feature factor, trunk twisting entropy, and dynamic mask area diffusion coefficient.
[0105] Gait feature factors are used to characterize the skeletal support scale of piglets independent of movement speed; first, the dynamic stride L within a sliding window of T frames is calculated. stride (Unit: cm), which is defined as the maximum stretching distance of the contralateral limb's key points on the horizontal plane, and is calculated using the following formula:
[0106] ;
[0107] In the formula: T represents the total number of video frames within the currently captured sliding window, and 𝑡 represents a specific video frame within the sliding window; X and Y both represent two-dimensional coordinate values, and the specific meanings of the two-dimensional coordinate values defined by the subscripts and superscripts are as follows: This represents the two-dimensional coordinates of the key point on the left shoulder of the piglet in the real physical plane after spatial normalization in frame t. denoted as the two-dimensional coordinates of the piglet's right rump keypoint in frame t, after spatial normalization, on the real physical plane; max represents taking the maximum value of the calculated result.
[0108] Then, to eliminate the influence of piglet walking speed on stride length, a gait characteristic factor was introduced. :
[0109] ;
[0110] In the formula: Δt represents the time (in seconds) taken for the piglet to complete the maximum stride extension; V avg This represents the average speed (in centimeters per second) of the piglet's center of mass in physical space within the time window corresponding to the total number of video frames T within the currently captured sliding window; where Δt is measured through the current dynamic stride L. stride Frame number f within time window T max (i.e., the frame number relative to the start of the window) minus the initial frame number f start The absolute value of (i.e., the frame number of the first frame at the beginning of the video processing window) divided by the camera's FPS (Frames Per Second) is obtained:
[0111] ;
[0112] Where V avg Calculate using the following formula:
[0113] ;
[0114] Both X and Y represent two-dimensional coordinate values, and the specific meanings of the two-dimensional coordinate values defined by the superscripts and subscripts are as follows: This represents the two-dimensional coordinates of the piglet's center of mass in the real physical plane after spatial normalization at frame T. This represents the two-dimensional coordinates of the piglet's center of mass in the real physical plane after spatial normalization, at frame 1; the denominator is... This represents the absolute physical time interval from frame 1 to frame T, which is obtained by subtracting 1 from the total number of video frames T and then dividing by the camera's FPS.
[0115] Trunk torsional entropy is used to describe the "steadiness" of piglet movement and to distinguish piglets of the same body size but different degrees of fatness. For any t-th frame in the total number of video frames T within the currently captured sliding window, the coordinates of the center point of the piglet's shoulder are first calculated using the physical coordinates after spatial normalization through inverse perspective transformation. :
[0116] ;
[0117] In the formula, This represents the two-dimensional coordinates of the key point on the left shoulder of the piglet in the real physical plane after spatial normalization in frame t. This represents the two-dimensional coordinates of the key point on the right shoulder of the piglet in the real physical plane after spatial normalization in frame t.
[0118] Then, the vertical distance from the center point of the shoulder to the body's central axis formed by the line connecting the piglet's head and tail is calculated, and normalized by dividing by the length of the body's central axis to obtain the shoulder deviation r in frame t. s,t :
[0119] ;
[0120] In the formula: X and Y both represent two-dimensional coordinate values, and the specific meanings of the two-dimensional coordinate values defined by the superscripts and subscripts are as follows: This represents the actual physical two-dimensional coordinates of the key points on the piglet's head in frame t; This represents the actual physical two-dimensional coordinates of the key point on the piglet's tail in frame t; This represents the actual physical two-dimensional coordinates of the center point of the piglet's shoulder in frame t;
[0121] To obtain the complete deviation sequence R = {r} within the currently captured sliding window, the total number of video frames T is obtained. s,1 , r s,2 ,…r s,t ,… r s,T Then, its torso twisting entropy was further calculated:
[0122] ;
[0123] In the formula: K represents the total number of statistical bins that divide the deviation value range into equally wide intervals; P(r i ) represents the probability that the deviation value falls within the i-th statistical bin interval (i.e., the frequency of deviation occurring in this frequency band).
[0124] Dynamic mask area diffusion coefficient (i.e., area variation coefficient) To compensate for the inability of two-dimensional images to measure piglet body thickness, and to characterize the muscle fullness of piglets (the area diffusion coefficient of muscular piglets is significantly higher than that of lean individuals when they walk), it is calculated using the following formula:
[0125] ;
[0126] In the formula: This represents the pixel area or physical mapping area of the foreground mask of a single piglet extracted through instance segmentation in frame t. This represents the arithmetic mean of the foreground mask area of the piglet within the total number of video frames T captured in the current sliding window.
[0127] S3. Spatiotemporal Attention Feature Fusion: A dual-branch fusion network is constructed to obtain a global comprehensive feature vector. The dual-branch fusion network includes a static branch, a dynamic branch, and a spatiotemporal attention module. The static branch uses a ResNet50 backbone network to extract the clean contour feature vector of each frame, denoted as f. static,t Dynamic branches will incorporate gait feature factors. Torso twisting entropy Area dispersion coefficient The vectors are spliced together to form the dynamic feature vector V for that time window. dynamic Feature stitching is a common technique in the field of image feature processing.
[0128] The spatiotemporal attention module uses the encoder structure of Transformer (a neural network architecture model) to calculate the correlation between features in T frames and normalize the self-attention score. Weighted fusion is performed on each frame:
[0129] ;
[0130] In the formula: e t represents the original energy score of the attention of the feature vector of frame t before it is input into the Softmax activation function, and exp represents the exponential operation;
[0131] Then, the global comprehensive feature vector output after weighted fusion by the spatiotemporal attention module is calculated according to the following formula. :
[0132] ;
[0133] In the formula: This represents the feature concatenation operator, which is a common technique in the field of image feature processing.
[0134] S4. Weight Regression and Stability Constraints: Globally integrated feature vectors... The input is a regression output head composed of a multilayer sensing mechanism, which outputs the predicted weight of piglets within the corresponding time window. The global integrated feature vector is then used. The regression output head of the input multilayer perceptron is specifically: the fused global comprehensive feature vector. The input is fed into a regression output head composed of a multilayer perceptron (MLP) (such as an MLP regression head composed of 3 fully connected layers); this regression output head directly outputs a continuous scalar value through nonlinear mapping. The absolute weight of the piglets within that time window is predicted (in kg). When the piglets are at rest or in a state of slight movement (such as eating or standing), dynamic features (such as stride) approach zero. At this time, the Transformer's self-attention mechanism will automatically reduce the weight of the dynamic branches and instead rely on the feature consistency of the static branches in consecutive frames for regression, thereby achieving adaptive weight assessment throughout the entire behavioral cycle.
[0135] To ensure that the model learns a constant attribute such as weight, a total loss function L, which includes the temporal prediction consistency loss, is introduced. total :
[0136] ;
[0137] In the formula: N represents the total number of samples in the current training batch; This represents the ground truth label of the physical weight of the nth sample. λ represents the predicted weight value output by the model for the nth sample; λ represents the weight coefficient of the consistency loss; τ represents the set of adjacent time windows segmented within the same continuous long video. and Let i and j represent the predicted weight values of the same piglet in adjacent time segments i and j, respectively, where i and j both belong to the time window set τ.
[0138] S5. Model Training: Construct a dynamic time-series dataset based on a label broadcasting mechanism, and jointly train the dual-branch fusion network using an invariant feature-forced learning strategy, specifically:
[0139] S51. Time-series tag broadcasting mechanism based on absolute truth value: During the data acquisition phase, the absolute weight truth value W of piglets bound with unique IDs at a specific physiological time point is obtained through contact weighing equipment (such as physical weighbridges). gt The piglets were released into natural group-raising pens, and continuous video streams of them in an unrestricted state (eating, running, turning, etc.) were collected using overhead cameras.
[0140] The continuous video stream is sliced according to a preset length (e.g., T=30 frames) based on the total number of video frames within the currently captured sliding window, generating a large number of time-series video segments; the absolute weight truth value W is then used. gt As a label, all video clips within the corresponding time period are uniformly assigned to the piglet with this ID to construct a dynamic time-series dataset;
[0141] S52. Invariant Feature-Forced Learning Strategy: During the training phase, time-series video clips of the same piglet exhibiting completely different behavioral patterns (e.g., clip A is "walking in a straight line at a constant speed" and clip B is "turning its head and rooting its head") are input into the dual-branch fusion network in batches. Since clips of different behavioral patterns correspond to the same absolute weight ground truth label, this "different shapes, same label" training constraint will force the model's spatiotemporal attention module (i.e., the Transformer encoder) to automatically reduce its dependence on the variable feature of "two-dimensional projected area" during backpropagation.
[0142] The specific training process is as follows: 100 healthy piglets aged 1-8 weeks are selected, and each piglet is bound with a unique ear tag ID; every morning, the absolute weight of each piglet is measured using a high-precision weighbridge (accuracy ±50g), and then the piglets are released back into the pen. 8 hours of natural behavior video are continuously collected using a top-down camera; the video is sliced using a sliding window of T=30 frames, and the absolute weight measured that day is used as a label to assign to all video clips of that piglet for that day, constructing a dynamic dataset containing no less than 100,000 time-series clips, and dividing it into training, validation, and test sets in a 7:2:1 ratio. Then, the AdamW optimizer (a mainstream optimizer used in deep learning models) was employed, with an initial learning rate of 1e-4, a batch size of 16, and 100 training epochs. During training, different behavioral pattern segments of the same piglet were grouped into training batches, with the same absolute weight as the regression target. The proposed total loss function with temporal consistency loss was used for optimization, where the consistency loss weight coefficient λ was set to 0.3. An early stopping mechanism was used during training to prevent overfitting, ultimately resulting in a converged weight model. Finally, the trained model was deployed to an edge computing device to perform inference on the real-time video stream from the pig farm, outputting a predicted piglet weight every 30 frames. Simultaneously, an external Kalman filter was used to perform secondary smoothing on the continuously output weight sequence, ultimately generating a piglet weight growth curve, which was then synchronized to the pig farm's smart farming management platform.
[0143] After numerous iterations, the network is "forced" to uncover and focus on deep biomechanical laws that remain relatively constant across various motion postures (such as the aforementioned dynamic step size factor and trunk torsional entropy), thereby enabling the model to leap from "learning appearances" to "learning essence." Combined with the consistency loss function, the final trained model can effectively resist the interference of complex environments and extreme postures, outputting a highly stable dynamic evaluation curve.
[0144] Experimental verification:
[0145] The method in this embodiment, along with a conventional baseline model (single-frame static contour estimation: employing a strict pose selection mechanism, retaining only images of the body standing upright, using ResNet50 to extract single-frame 2D image features and directly regressing body weight) and a temporal smoothing model (multi-frame simple averaging: eliminating strict pose selection, introducing target tracking to obtain prediction results from 30 consecutive frames and performing a simple arithmetic average, but without introducing dynamic gait feature derivation and attention mechanism) under the same hardware environment and dataset, were used to estimate piglet body weight. Simultaneously, mean absolute error (MAE), root mean square error (RMSE), and coefficient of determination (R²) were used. 2 To measure the model's prediction accuracy, the "usable image ratio (percentage of effective prediction frames)" is introduced as a core indicator for evaluating system engineering usability (this indicator directly reflects the model's adaptability to the natural behaviors of piglets (feeding, walking, wriggling)). The usable image ratio is calculated as: (Number of video frames from which the system can successfully output effective weight predictions / Total number of frames in the video containing the piglet) × 100%. The test results are shown in Table 1 below.
[0146] Table 1. Prediction accuracy and adaptability data of the model of this invention and the control model.
[0147]
[0148] As shown in Table 1, the existing baseline model (single-frame static detection) achieves a good accuracy of 0.24 kg on MAE, but at the cost of extremely stringent posture constraints, resulting in up to 81.5% of images containing piglets turning, lowering their heads to eat, and twisting their torsos being discarded as "unusable images" (the proportion of usable images is only 19.5%). In contrast, the model of this invention, by introducing temporal dynamic features, increases the proportion of usable images to 82.3%, achieving effective coverage of the entire behavioral cycle of piglets.
[0149] Simply relaxing the pose constraints can lead to a significant drop in accuracy (e.g., the RMSE of the "temporally smoothed model" deteriorates to 0.46kg); however, the model of this invention, under conditions of almost completely relaxing the pose constraints and receiving a large number of "distorted images", not only maintains a high accuracy comparable to the stringent baseline model (0.22kg), but also performs better in terms of RMS (reduced to 0.33kg) and R² (improved to 0.95).
[0150] The significant reduction in RMSE demonstrates the effectiveness of the Transformer attention mechanism in the model of this invention. By automatically assigning high weights to smooth stepping frames, reducing the weights of distorted frames, and combining temporal consistency loss, it successfully eliminates the "instantaneous numerical jumps" common in single-frame prediction, and still outputs extremely smooth and accurate weight prediction trajectories with extremely high image retention rates.
[0151] The tracking algorithm used in this invention can be selected from ByteTrack, DeepSORT, BoT-SORT, OC-SORT, or a pixel-level tracking algorithm based on optical flow. As long as the consistency of the piglet ID in consecutive frames can be guaranteed, the prerequisite of this invention can be met.
[0152] For edge computing devices with limited computing power, the Transformer structure model in the spatiotemporal attention module of this invention can be replaced with a training model with fewer parameters, such as a bidirectional long short-term memory network (Bi-LSTM) or a 3D convolutional neural network (C3D), which can still achieve effective aggregation of temporal gait features.
[0153] At the actual output end, in addition to relying on the consistency inherent in the model, this invention can also connect external filters such as median filters or Kalman filters to perform secondary smoothing on the continuously output weight trajectory.
[0154] Example 2:
[0155] As another preferred embodiment of the technical solution of the present invention, based on the above embodiment 1, the present invention provides a piglet weight assessment system based on temporal features and attention mechanisms, comprising:
[0156] The video preprocessing and target tracking module is used to process the continuous video stream collected by the overhead monitoring of the pigsty frame by frame, complete instance segmentation, multi-target tracking, background suppression and spatial normalization calibration, and output a clean image sequence of each piglet with a unique ID and a key point time sequence with real physical scale.
[0157] The dynamic feature calculation module is used to extract time series sequences using a sliding window of fixed length and calculate multi-dimensional dynamic features that characterize the size and developmental status of piglets. The dynamic features include gait feature factor, trunk twisting entropy, and dynamic mask area diffusion coefficient.
[0158] The spatiotemporal attention fusion module has a built-in dual-branch fusion network. It extracts the static contour feature vector of a single frame through the static branch and integrates it through the dynamic branch to obtain the dynamic feature vector. The spatiotemporal attention module completes the adaptive weighted fusion of temporal features and outputs a global comprehensive feature vector.
[0159] The weight regression output module has a built-in regression output head composed of a multi-layer sensing mechanism, which is used to receive the global comprehensive feature vector and output the predicted weight value of piglets within the corresponding time window.
[0160] The model training module is used to construct a dynamic time-series dataset based on a label broadcasting mechanism and employs an invariant feature-forced learning strategy to complete the joint training of the model.
[0161] 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 method for assessing piglet weight based on temporal features and attention mechanisms, characterized in that... Including the following steps: S1. After video stream preprocessing and dynamic target separation and tracking, a time sequence of piglet key points with real physical scale is obtained. The dynamic target separation and tracking includes sequentially performing pixel-level instance segmentation, single target purification and background suppression, sliding window sampling and dynamic key point extraction, and spatial normalization calibration. S2. Based on biomechanical dynamic feature calculation, multi-dimensional dynamic features characterizing the size and developmental status of piglets are obtained. The dynamic features include gait feature factor, trunk twisting entropy, and dynamic mask area diffusion coefficient. S3. By fusing spatiotemporal attention features, a dual-branch fusion network is constructed to obtain the global comprehensive feature vector; S4. Input the global comprehensive feature vector into the regression output head and output the predicted weight of piglets within the corresponding time window; S5. Model Training: Construct a dynamic time-series dataset based on the label broadcasting mechanism, and use an invariant feature-forced learning strategy to jointly train the dual-branch fusion network. S6. The trained model will be used for dynamic assessment of piglet weight.
2. The method for assessing piglet weight based on temporal features and attention mechanisms according to claim 1, characterized in that: The pixel-level instance segmentation in S1 specifically involves: using the YOLO11-Seg instance segmentation model to perform frame-by-frame reasoning on the video frames to obtain the pixel-level foreground contour mask of all piglets in the image; and using a pixel-level tracking algorithm based on ByteTrack, DeepSORT, BoT-SORT, OC-SORT, or optical flow to assign and continuously bind a unique identity ID to each piglet in the video stream by calculating the intersection-union ratio and appearance feature similarity of the piglet masks between adjacent frames.
3. The method for assessing piglet weight based on temporal features and attention mechanisms according to claim 2, characterized in that: The specific steps of single-target purification separation and background suppression in S1 are as follows: For a tracked piglet with a specific ID, calculate the minimum bounding rectangle cropping box based on the mask of its current frame; within the cropped image area, retain only the original RGB pixel information within the mask coverage area, and uniformly replace all areas outside the mask boundary with a preset single grayscale value to generate a single piglet image sequence with a realistic foreground and a pure background.
4. The method for assessing piglet weight based on temporal features and attention mechanisms according to claim 3, characterized in that: The sliding window sampling and dynamic key point extraction in S1 are as follows: for a single piglet image sequence, the YOLO-Pose key point detection network is used to accurately locate the key parts of the piglet's head, tail, limb joints, left and right shoulders and left and right buttocks; and a sliding window of fixed length is used to extract the key point temporal sequence and foreground contour sequence of a specific ID piglet along the time axis.
5. The method for assessing piglet weight based on temporal features and attention mechanisms according to claim 4, characterized in that: The spatial normalization calibration in S1 specifically involves: using a fixed-size ground reference object inside the pigsty, during the calibration phase of system deployment, selecting at least four known physical feature points on the ground plane as reference points, and calculating the 3×3 homography transformation matrix H from the image plane to the physical ground plane based on the image pixel coordinates and their corresponding coordinates in the real physical world. During the real-time preprocessing stage of the video stream, the homogeneous coordinate mapping of any extracted piglet keypoints or contour pixel coordinates (u,v) in the image is performed according to the following formula: ; In the formula: the right column vector represents the homogeneous coordinates obtained by vector transposing the coordinates (u,v,w) formed by the keypoint or contour pixel coordinates (u,v,w) and the non-zero scale scaling factor w in the homogeneous coordinate system; the left column vector represents the homogeneous physical coordinate column vector obtained by multiplying the right column vectors by a 3×3 homography transformation matrix; where x´ and y´ represent the x and y components of the transformed homogeneous coordinates, respectively, w represents the non-zero scale scaling factor in the homogeneous coordinate system, w´ represents the w component of the transformed homogeneous coordinates, and H represents the 3×3 homography transformation matrix operation; Finally, convert it to the actual physical coordinates (X, Y) using the following formula: ; 。 6. The method for assessing piglet weight based on temporal features and attention mechanisms according to claim 5, characterized in that: The gait feature factor in S2 is calculated as follows: first, the dynamic stride L in the sliding window T frames is calculated stride : ; In the formula: T represents the total number of video frames within the currently captured sliding window, and 𝑡 represents a specific video frame within the sliding window; X and Y both represent two-dimensional coordinate values, and the specific meanings of the two-dimensional coordinate values defined by the subscripts and superscripts are as follows: This represents the two-dimensional coordinates of the key point on the left shoulder of the piglet in the real physical plane after spatial normalization in frame t. This represents the two-dimensional coordinates of the piglet's right rump keypoint in frame t, after spatial normalization, on the real physical plane; max indicates taking the maximum value of the calculated result. Then calculate the gait characteristic factor using the following formula. : ; In the formula: Δt represents the time taken for the piglet to complete the maximum stride extension; V avg This represents the average speed of the piglet's center of mass in physical space within the time window corresponding to the total number of video frames T within the currently captured sliding window; where Δt is the speed of movement of the piglet's center of mass in physical space within the current dynamic stride L. stride Frame number f within time window T max Subtract the initial frame number f start The absolute value after dividing by the camera's FPS is obtained as follows: ; Where V avg Calculate using the following formula: ; Both X and Y represent two-dimensional coordinate values, and the specific meanings of the two-dimensional coordinate values defined by the superscripts and subscripts are as follows: This represents the two-dimensional coordinates of the piglet's center of mass in the real physical plane after spatial normalization at frame T. This represents the two-dimensional coordinates of the piglet's center of mass in the real physical plane after spatial normalization, at frame 1; the denominator is... This represents the absolute physical time interval from frame 1 to frame T, which is obtained by subtracting 1 from the total number of video frames T and then dividing by the camera's FPS.
7. The method for assessing piglet weight based on temporal features and attention mechanisms according to claim 6, characterized in that: The torsional entropy in S2 is calculated according to the following steps; For any t-th frame within the sliding window T, firstly, the coordinates of the center point of the piglet's shoulder are calculated using the spatially normalized physical coordinates. : ; In the formula, This represents the two-dimensional coordinates of the key point on the left shoulder of the piglet in the real physical plane after spatial normalization in frame t. This represents the two-dimensional coordinates of the key point on the right shoulder of the piglet in the real physical plane after spatial normalization in frame t. Then, the vertical distance from the center point of the shoulder to the body's central axis formed by the line connecting the piglet's head and tail is calculated, and normalized by dividing by the length of the body's central axis to obtain the shoulder deviation r in frame t. s,t : ; In the formula: X and Y both represent two-dimensional coordinate values, and the specific meanings of the two-dimensional coordinate values defined by the superscripts and subscripts are as follows: This represents the actual physical two-dimensional coordinates of the key points on the piglet's head in frame t; This represents the actual physical two-dimensional coordinates of the key point on the piglet's tail in frame t; This represents the actual physical two-dimensional coordinates of the center point of the piglet's shoulder in frame t; Then obtain the complete deviation sequence R={r} within the sliding window of T frames. s,1 , r s,2 ,…r s,t ,… r s,T After that, its torso twisting entropy was further calculated. : ; In the formula: K represents the total number of statistical bins that divide the deviation value range into equally wide intervals; P(r i ) represents the probability that the deviation value falls within the interval of the i-th statistical bin.
8. The method for assessing piglet weight based on temporal features and attention mechanisms according to claim 7, characterized in that: The dynamic mask area dispersion coefficient in S2 Calculate using the following formula: ; In the formula: This represents the pixel area or physical mapping area of the foreground mask of a single piglet extracted through instance segmentation in frame t. This represents the arithmetic mean of the foreground mask area of the piglet within the total number of video frames T captured in the current sliding window.
9. The method for assessing piglet weight based on temporal features and attention mechanisms according to claim 8, characterized in that: The dual-branch fusion network in S3 includes static branches, dynamic branches, and a spatiotemporal attention module; wherein: The static branch uses a ResNet50 backbone network to extract the clean contour feature vector f for each frame. static,t ; Dynamic branches will incorporate gait feature factors Torso twisting entropy Area dispersion coefficient The vectors are spliced together to form the dynamic feature vector V for that time window. dynamic ; The spatiotemporal attention module employs a Transformer model encoder structure to calculate the correlation between features in T frames and normalizes the self-attention scores. Weighted fusion is performed on each frame: ; In the formula: e t represents the original energy score of the attention of the feature vector of frame t before it is input into the Softmax activation function, and exp represents the exponential operation; Then, the global comprehensive feature vector output after weighted fusion by the spatiotemporal attention module is calculated according to the following formula. : ; In the formula: This indicates the feature concatenation operator.
10. The method for assessing piglet weight based on temporal features and attention mechanisms according to claim 9, characterized in that: The weight prediction in S4 introduces a total loss function L that includes the temporal prediction consistency loss. total Perform correction: ; In the formula: N represents the total number of samples in the current training batch; This represents the true physical weight label corresponding to the nth sample; λ represents the predicted weight value output by the model for the nth sample; λ represents the weight coefficient of the consistency loss; τ represents the set of adjacent time windows segmented within the same continuous long video. and Let i and j represent the predicted weight values of the same piglet in adjacent time segments i and j, respectively, where i and j both belong to the time window set τ.
11. A system for the piglet weight assessment method based on temporal features and attention mechanisms as described in any one of claims 1-10, characterized in that... include: The video preprocessing and target tracking module is used to process the continuous video stream collected by the overhead monitoring of the pigsty frame by frame, complete instance segmentation, multi-target tracking, background suppression and spatial normalization calibration, and output a clean image sequence of each piglet with a unique ID and a key point time sequence with real physical scale. The dynamic feature calculation module is used to extract time series sequences using a sliding window of fixed length and calculate multi-dimensional dynamic features that characterize the size and developmental status of piglets. The dynamic features include gait feature factor, trunk twisting entropy, and dynamic mask area diffusion coefficient. The spatiotemporal attention fusion module has a built-in dual-branch fusion network. It extracts the static contour feature vector of a single frame through the static branch and integrates it through the dynamic branch to obtain the dynamic feature vector. The spatiotemporal attention module completes the adaptive weighted fusion of temporal features and outputs a global comprehensive feature vector. The weight regression output module has a built-in regression output head composed of a multi-layer sensing mechanism, which is used to receive the global comprehensive feature vector and output the predicted weight value of piglets within the corresponding time window. The model training module is used to construct a dynamic time-series dataset based on a label broadcasting mechanism and employs an invariant feature-forced learning strategy to complete the joint training of the model.
Citation Information
Patent Citations
Pig weight measuring and calculating scheme based on body size fusion depth data
CN120070534A
Piglet nest average weight estimation method and system based on instance segmentation
CN120997500A